1- """
2- $TYPEDEF
3- """
4- abstract type AbstractInstance end
5-
61"""
72$TYPEDEF
83
@@ -11,86 +6,85 @@ Instance of the stochastic VSP problem.
116# Fields
127$TYPEDFIELDS
138"""
14- struct Instance{G<: AbstractGraph ,M1<: AbstractMatrix ,M2<: AbstractMatrix ,F,C} < :
15- AbstractInstance
16- " associated city"
17- city:: City
18- " graph computed from `city` with the `create_VSP_graph(city::City)` method."
19- graph:: G
20- " features matrix computed from `city`"
21- features:: Matrix{F}
22- " "
23- slacks:: M1
24- " "
25- delays:: M2
26- " "
27- vehicle_cost:: C
28- " "
29- delay_cost:: C
30- end
31-
32- """
33- $TYPEDEF
34-
35- Instance of the stochastic VSP problem.
36-
37- # Fields
38- $TYPEDFIELDS
39- """
40- struct CompactInstance{G<: AbstractGraph ,M1<: AbstractMatrix ,M2<: AbstractMatrix ,F,C} < :
41- AbstractInstance
9+ struct Instance{G<: AbstractGraph ,M1<: AbstractMatrix ,M2<: AbstractMatrix ,F,C}
4210 " graph computed from `city` with the `create_VSP_graph(city::City)` method"
4311 graph:: G
4412 " features matrix computed from `city`"
4513 features:: Matrix{F}
46- " "
14+ " slack matrix "
4715 slacks:: M1
48- " "
16+ " intrinsic delays scenario matrix "
4917 delays:: M2
50- " "
18+ " cost of a vehicle "
5119 vehicle_cost:: C
52- " "
20+ " cost of one minute delay "
5321 delay_cost:: C
5422end
5523
5624"""
5725$TYPEDSIGNATURES
5826
59- Constructor for [`Instance`](@ref).
60- Build an `Instance` from a `City`, by computing its graph, features, slacks and delays.
61- """
62- function Instance (city:: City )
63- graph = create_VSP_graph (city)
64- features = compute_features (city)
65- slacks = compute_slacks (city, graph)
66- delays = compute_delays (city)
67- return Instance (
68- city, graph, features, slacks, delays, city. vehicle_cost, city. delay_cost
69- )
27+ Return the acyclic directed graph corresponding to `city`.
28+ Each vertex represents a task. Vertices are ordered by start time of corresponding task.
29+ There is an edge from task u to task v the (end time of u + tie distance between u and v <= start time of v).
30+ """
31+ function create_VSP_graph (city:: City )
32+ # Initialize directed graph
33+ nb_vertices = city. nb_tasks + 2
34+ graph = SimpleDiGraph (nb_vertices)
35+ starting_task = 1
36+ end_task = nb_vertices
37+ job_tasks = 2 : (city. nb_tasks + 1 )
38+
39+ travel_times = [
40+ distance (task1. end_point, task2. start_point) for task1 in city. tasks,
41+ task2 in city. tasks
42+ ]
43+
44+ # Create existing edges
45+ for iorigin in job_tasks
46+ # link every task to base
47+ add_edge! (graph, starting_task, iorigin)
48+ add_edge! (graph, iorigin, end_task)
49+
50+ for idestination in (iorigin + 1 ): (city. nb_tasks + 1 )
51+ travel_time = travel_times[iorigin, idestination]
52+ origin_end_time = city. tasks[iorigin]. end_time
53+ destination_begin_time = city. tasks[idestination]. start_time # get_prop(graph, idestination, :task).start_time
54+
55+ # there is an edge only if we can reach destination from origin before start of task
56+ if origin_end_time + travel_time <= destination_begin_time
57+ add_edge! (graph, iorigin, idestination)
58+ end
59+ end
60+ end
61+
62+ return graph
7063end
7164
7265"""
7366$TYPEDSIGNATURES
7467
75- Constructor for [`CompactInstance `](@ref).
76- Build a `CompactInstance` from a `City`, by computing its graph, features, slacks and delays .
68+ Constructor for [`Instance `](@ref).
69+ Build an `Instance` for the stochatsic vehicle scheduling problem, with `nb_tasks` tasks and `nb_scenarios` scenarios .
7770"""
78- function CompactInstance (city:: City )
71+ function Instance (;
72+ nb_tasks:: Int , nb_scenarios:: Int , rng:: AbstractRNG = Random. default_rng (), kwargs...
73+ )
74+ city = create_random_city (; rng= rng, nb_tasks, nb_scenarios, kwargs... )
7975 graph = create_VSP_graph (city)
8076 features = compute_features (city)
8177 slacks = compute_slacks (city, graph)
8278 delays = compute_delays (city)
83- return CompactInstance (
84- graph, features, slacks, delays, city. vehicle_cost, city. delay_cost
85- )
79+ return Instance (graph, features, slacks, delays, city. vehicle_cost, city. delay_cost)
8680end
8781
8882"""
8983$TYPEDSIGNATURES
9084
9185Returns the number of scenarios in instance.
9286"""
93- function get_nb_scenarios (instance:: AbstractInstance )
87+ function get_nb_scenarios (instance:: Instance )
9488 return size (instance. delays, 2 )
9589end
9690
@@ -99,22 +93,11 @@ $TYPEDSIGNATURES
9993
10094Returns the number of tasks in `instance`.
10195"""
102- get_nb_tasks (instance:: AbstractInstance ) = nv (instance. graph) - 2
103-
104- """
105- $TYPEDSIGNATURES
106-
107- Returns a random instance created with city_kwargs.
108- """
109- function create_random_instance (; city_kwargs... )
110- return Instance (create_random_city (; city_kwargs... ))
111- end
96+ get_nb_tasks (instance:: Instance ) = nv (instance. graph) - 2
11297
11398"""
11499$TYPEDSIGNATURES
115100
116- Returns a random instance created with city_kwargs .
101+ Returns the feature matrix associated to `instance` .
117102"""
118- function create_random_compact_instance (; city_kwargs... )
119- return CompactInstance (create_random_city (; city_kwargs... ))
120- end
103+ get_features (instance:: Instance ) = instance. features
0 commit comments