@@ -79,23 +79,35 @@ function create_random_city(; # TODO: use an rng here
7979 district_σ= default_district_σ,
8080 task_μ= default_task_μ,
8181 task_σ= default_task_σ,
82+ seed= nothing ,
83+ rng= MersenneTwister (0 ),
8284 city_kwargs... ,
8385)
86+ Random. seed! (rng, seed)
8487 city = City (; city_kwargs... )
85- init_districts! (city, district_μ, district_σ)
86- init_tasks! (city, αᵥ_low, αᵥ_high, first_begin_time, last_begin_time, task_μ, task_σ)
87- generate_scenarios! (city)
88+ init_districts! (city, district_μ, district_σ; rng= rng)
89+ init_tasks! (
90+ city, αᵥ_low, αᵥ_high, first_begin_time, last_begin_time, task_μ, task_σ; rng= rng
91+ )
92+ generate_scenarios! (city; rng= rng)
8893 compute_perturbed_end_times! (city)
8994 return city
9095end
9196
92- function init_districts! (city:: City , district_μ:: Distribution , district_σ:: Distribution )
97+ """
98+ $TYPEDSIGNATURES
99+
100+ Initialize the districts of the city.
101+ """
102+ function init_districts! (
103+ city:: City , district_μ:: Distribution , district_σ:: Distribution ; rng:: AbstractRNG
104+ )
93105 nb_scenarios = size (city. scenario_inter_area_factor, 1 )
94106 nb_district_per_edge = city. width ÷ city. district_width
95107 for x in 1 : nb_district_per_edge
96108 for y in 1 : nb_district_per_edge
97- μ = rand (district_μ)
98- σ = rand (district_σ)
109+ μ = rand (rng, district_μ)
110+ σ = rand (rng, district_σ)
99111 city. districts[x, y] = District (;
100112 random_delay= LogNormal (μ, σ), nb_scenarios= nb_scenarios
101113 )
@@ -104,14 +116,20 @@ function init_districts!(city::City, district_μ::Distribution, district_σ::Dis
104116 return nothing
105117end
106118
119+ """
120+ $TYPEDSIGNATURES
121+
122+ Draw the tasks of the city.
123+ """
107124function init_tasks! (
108125 city:: City ,
109126 αᵥ_low:: Real ,
110127 αᵥ_high:: Real ,
111128 first_begin_time:: Real ,
112129 last_begin_time:: Real ,
113130 task_μ:: Distribution ,
114- task_σ:: Distribution ,
131+ task_σ:: Distribution ;
132+ rng:: AbstractRNG ,
115133)
116134 nb_scenarios = size (city. scenario_inter_area_factor, 1 )
117135
@@ -120,16 +138,17 @@ function init_tasks!(
120138 travel_time_multiplier_distribution = Uniform (αᵥ_low, αᵥ_high)
121139
122140 for i_task in 1 : (city. nb_tasks)
123- start_point = draw_random_point (point_distribution)
124- end_point = draw_random_point (point_distribution)
141+ start_point = draw_random_point (point_distribution; rng = rng )
142+ end_point = draw_random_point (point_distribution; rng = rng )
125143
126- start_time = rand (start_time_distribution)
144+ start_time = rand (rng, start_time_distribution)
127145 end_time =
128146 start_time +
129- rand (travel_time_multiplier_distribution) * distance (start_point, end_point)
147+ rand (rng, travel_time_multiplier_distribution) *
148+ distance (start_point, end_point)
130149
131- μ = rand (task_μ)
132- σ = rand (task_σ)
150+ μ = rand (rng, task_μ)
151+ σ = rand (rng, task_σ)
133152 random_delay = LogNormal (μ, σ)
134153
135154 city. tasks[i_task + 1 ] = Task (;
@@ -180,29 +199,40 @@ function get_district(point::Point, city::City)
180199 trunc (Int, point. y / city. district_width) + 1
181200end
182201
183- function generate_scenarios! (city:: City )
202+ """
203+ $TYPEDSIGNATURES
204+
205+ Draw all delay scenarios for the city.
206+ """
207+ function generate_scenarios! (city:: City ; rng:: AbstractRNG )
184208 # roll all tasks
185209 for task in city. tasks
186- roll (task)
210+ roll (task, rng )
187211 end
188212
189213 # roll all districts
190214 for district in city. districts
191- roll (district)
215+ roll (district, rng )
192216 end
193217
194218 # roll inter-district
195219 nb_scenarios, nb_hours = size (city. scenario_inter_area_factor)
196220 for s in 1 : nb_scenarios
197221 previous_delay = 0.0
198222 for h in 1 : nb_hours
199- previous_delay = (previous_delay + 0.1 ) * rand (city. random_inter_area_factor) # TODO : study formula
223+ previous_delay =
224+ (previous_delay + 0.1 ) * rand (rng, city. random_inter_area_factor)
200225 city. scenario_inter_area_factor[s, h] = previous_delay
201226 end
202227 end
203228 return nothing
204229end
205230
231+ """
232+ $TYPEDSIGNATURES
233+
234+ Compute the end times of the tasks for each scenario.
235+ """
206236function compute_perturbed_end_times! (city:: City )
207237 nb_scenarios = size (city. scenario_inter_area_factor, 1 )
208238
0 commit comments