-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
93 lines (77 loc) · 3.13 KB
/
generator.py
File metadata and controls
93 lines (77 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
"""Assignment 1 - Parcel and Truck data generator (No tasks)
CSC148, Winter 2021
This code is provided solely for the personal and private use of
students taking the CSC148 course at the University of Toronto.
Copying for purposes other than this use is expressly prohibited.
All forms of distribution of this code, whether as given or with
any changes, are expressly prohibited.
Authors: Diane Horton, Ian Berlott-Atwell, Jonathan Calver,
Sophia Huynh, Maryam Majedi, and Jaisie Sin.
All of the files in this directory and all subdirectories are:
Copyright (c) 2021 Diane Horton, Ian Berlott-Atwell, Jonathan Calver,
Sophia Huynh, Maryam Majedi, and Jaisie Sin.
===== Module Description =====
This module generates random parcel and truck data and writes each to a file.
Values defined in the module control the amount of data, the range of possible
values, etc.
You have no tasks associated with this module. It is provided to you to assist
in testing. However, your best test cases will likely be very small ones that
you hand-craft to force important conditions to arise.
"""
from random import randint, choice
def generate(parcel_filename: str = 'data/demo-parcel-data.txt',
truck_filename: str = 'data/demo-truck-data.txt') -> None:
"""Generate random truck and parcel data, and save to the files
<parcel_filename> and <truck_filename> respectively. File format is as
defined in Assignment 1.
"""
# Set constants controlling parcel data
num_ids_to_pick_from = 20
num_ids = 15
cities = ['Belleville', 'Guelph', 'Hamilton', 'Toronto', 'London', 'Ottawa']
min_volume = 5
max_volume = 25
depot = 'Toronto'
# Generate some random parcels
ids = list(range(num_ids_to_pick_from))
with open(parcel_filename, 'w') as file:
for dummy in range(num_ids):
# Pick a random id from among those left and remove it so we
# don't pick it again.
id_ = choice(ids)
ids.remove(id_)
source = choice(cities)
temp = cities.copy()
temp.remove(source)
if source != depot:
temp.remove(depot)
destination = choice(temp)
volume = randint(min_volume, max_volume)
file.write(f'{id_}, {source}, {destination}, {volume}\n')
# Set constants controlling truck data
num_ids_to_pick_from = 10
num_ids = 5
min_volume = 20
max_volume = 50
# Generate some random trucks
ids = list(range(num_ids_to_pick_from))
with open(truck_filename, 'w') as file:
for dummy in range(num_ids):
# Pick a random id from among those left and remove it so we
# don't pick it again.
id_ = choice(ids)
ids.remove(id_)
volume = randint(min_volume, max_volume)
file.write(f'{id_}, {volume}\n')
if __name__ == '__main__':
import python_ta
python_ta.check_all(config='.pylintrc')
generate()