@@ -48,30 +48,44 @@ function anticipative_solver(
4848 model_builder= highs_model,
4949 two_dimensional_features= env. instance. two_dimensional_features,
5050 reset_env= true ,
51- nb_epochs= typemax (Int) ,
51+ nb_epochs= nothing ,
5252 seed= get_seed (env),
53+ verbose= false ,
5354)
5455 if reset_env
5556 reset! (env; reset_rng= true , seed)
5657 end
5758
59+ @assert ! is_terminated (env)
60+
5861 start_epoch = current_epoch (env)
59- end_epoch = min (last_epoch (env), start_epoch + nb_epochs - 1 )
62+ end_epoch = if isnothing (nb_epochs)
63+ last_epoch (env)
64+ else
65+ min (last_epoch (env), start_epoch + nb_epochs - 1 )
66+ end
6067 T = start_epoch: end_epoch
68+ TT = (start_epoch + 1 ): end_epoch # horizon without start epoch
69+
70+ starting_state = deepcopy (env. state)
6171
6272 request_epoch = [0 ]
63- for t in T
73+ request_epoch = vcat (request_epoch, fill (start_epoch, customer_count (starting_state)))
74+ for t in TT
6475 request_epoch = vcat (request_epoch, fill (t, length (scenario. indices[t])))
6576 end
66- customer_index = vcat (1 , scenario. indices[T]. .. )
67- service_time = vcat (0.0 , scenario. service_time[T]. .. )
68- start_time = vcat (0.0 , scenario. start_time[T]. .. )
77+
78+ customer_index = vcat (starting_state. location_indices, scenario. indices[TT]. .. )
79+ service_time = vcat (
80+ starting_state. state_instance. service_time, scenario. service_time[TT]. ..
81+ )
82+ start_time = vcat (starting_state. state_instance. start_time, scenario. start_time[TT]. .. )
6983
7084 duration = env. instance. static_instance. duration[customer_index, customer_index]
7185 (; epoch_duration, Δ_dispatch) = env. instance
7286
7387 model = model_builder ()
74- set_silent (model)
88+ verbose || set_silent (model)
7589
7690 nb_nodes = length (customer_index)
7791 job_indices = 2 : nb_nodes
@@ -136,29 +150,25 @@ function anticipative_solver(
136150 value .(y), env, customer_index, epoch_indices
137151 )
138152
139- epoch_indices = Vector{Int}[]
140- N = 1
141- indices = [1 ]
142153 index = 1
143- for epoch in 1 : last_epoch (env)
144- M = length (scenario. indices[epoch])
145- indices = vcat (indices, (N + 1 ): (N + M))
146- push! (epoch_indices, copy (indices))
154+ indices = collect (1 : (customer_count (starting_state) + 1 )) # current known indices in global indexing
155+ epoch_indices = [indices] # store global indices present at each epoch
156+ N = length (indices) # current last index known in global indexing
157+ for epoch in TT # 1:last_epoch(env)
158+ # remove dispatched customers from indices
159+ dispatched = vcat (epoch_routes[index]. .. )
160+ indices = setdiff (indices, dispatched)
161+
162+ M = length (scenario. indices[epoch]) # number of new customers in epoch
163+ indices = vcat (indices, (N + 1 ): (N + M)) # add global indices of customers in epoch
164+ push! (epoch_indices, copy (indices)) # store global indices present at each epoch
147165 N = N + M
148- if epoch in T
149- dispatched = vcat (epoch_routes[index]. .. )
150- index += 1
151- indices = setdiff (indices, dispatched)
152- end
166+ index += 1
153167 end
154168
155- indices = vcat (1 , scenario. indices... )
156- start_time = vcat (0.0 , scenario. start_time... )
157- service_time = vcat (0.0 , scenario. service_time... )
158-
159169 dataset = map (enumerate (T)) do (i, epoch)
160170 routes = epoch_routes[i]
161- epoch_customers = epoch_indices[epoch ]
171+ epoch_customers = epoch_indices[i ]
162172
163173 y_true = VSPSolution (
164174 Vector{Int}[
@@ -167,7 +177,7 @@ function anticipative_solver(
167177 max_index= length (epoch_customers),
168178 ). edge_matrix
169179
170- location_indices = indices [epoch_customers]
180+ location_indices = customer_index [epoch_customers]
171181 new_coordinates = env. instance. static_instance. coordinate[location_indices]
172182 new_start_time = start_time[epoch_customers]
173183 new_service_time = service_time[epoch_customers]
@@ -184,7 +194,7 @@ function anticipative_solver(
184194 epoch_duration = env. instance. epoch_duration
185195 Δ_dispatch = env. instance. Δ_dispatch
186196 planning_start_time = (epoch - 1 ) * epoch_duration + Δ_dispatch
187- if epoch == last_epoch
197+ if epoch == end_epoch
188198 # If we are in the last epoch, all requests must be dispatched
189199 is_must_dispatch[2 : end ] .= true
190200 else
@@ -193,6 +203,7 @@ function anticipative_solver(
193203 new_start_time[2 : end ]
194204 end
195205 is_postponable[2 : end ] .= .! is_must_dispatch[2 : end ]
206+ # TODO : avoid code duplication with add_new_customers!
196207
197208 state = DVSPState (;
198209 state_instance= static_instance,
0 commit comments