13
13
from torch .nn import Module
14
14
from translators .instance2graph_translator import translate
15
15
from translators .graph2solution_translator import translate_solution
16
- from debug .debug_gns import check_completeness , debug_printer
16
+ from debug .debug_gns import debug_printer
17
17
from multi_stage_pre_training import multi_stage_pre_train , load_training_dataset
18
18
from model .agent import MultiAgent_OneInstance
19
19
import pickle
35
35
AGENT = 0
36
36
SOLVING_REPETITIONS = 10
37
37
GNN_CONF = {
38
- 'resource_and_material_embedding_size' : 16 ,
39
- 'operation_and_item_embedding_size' : 24 ,
38
+ 'resource_and_material_embedding_size' : 12 ,
39
+ 'operation_and_item_embedding_size' : 12 ,
40
40
'nb_layers' : 2 ,
41
- 'embedding_hidden_channels' : 128 ,
42
- 'value_hidden_channels' : 256 ,
43
- 'actor_hidden_channels' : 256 }
41
+ 'embedding_hidden_channels' : 64 ,
42
+ 'value_hidden_channels' : 128 ,
43
+ 'actor_hidden_channels' : 128 }
44
44
small_steps : float = 0.85
45
45
big_steps : float = 0.15
46
46
50
50
51
51
def reccursive_outourcing_actions (instance : Instance , graph : GraphInstance , item_id : int ):
52
52
actions = []
53
- external = graph .item (item_id , 'external' )
53
+ p , e = graph .items_g2i [item_id ]
54
+ external : bool = instance .external [p ][e ]
54
55
decision_made = graph .item (item_id , 'outsourced' )
55
56
available = graph .item (item_id , 'is_possible' )
56
57
if available == YES :
57
- if external == YES and decision_made == NOT_YET :
58
- p , e = graph .items_g2i [item_id ]
58
+ if external and decision_made == NOT_YET :
59
59
need_to_be_outsourced = False
60
60
for o in instance .loop_item_operations (p ,e ):
61
61
for rt in instance .required_rt (p , o ):
@@ -68,7 +68,7 @@ def reccursive_outourcing_actions(instance: Instance, graph: GraphInstance, item
68
68
actions .append ((item_id , YES ))
69
69
else :
70
70
actions .extend ([(item_id , YES ), (item_id , NO )])
71
- elif external == NO or decision_made == NO :
71
+ elif not external or decision_made == NO :
72
72
for child in graph .get_direct_children (instance , item_id ):
73
73
actions .extend (reccursive_outourcing_actions (instance , graph , child ))
74
74
return actions
@@ -89,7 +89,7 @@ def get_scheduling_and_material_use_actions(instance: Instance, graph: GraphInst
89
89
item_id = graph .items_i2g [p ][e ]
90
90
timescale = 60 * instance .H if instance .in_days [p ][o ] else 60 if instance .in_hours [p ][o ] else 1
91
91
if graph .item (item_id , 'is_possible' )== YES \
92
- and ( graph .item (item_id , 'external' ) == NO or graph . item ( item_id , ' outsourced' )== NO ) \
92
+ and graph .item (item_id , 'outsourced' )== NO \
93
93
and graph .operation (operation_id , 'is_possible' ) == YES \
94
94
and graph .operation (operation_id , 'available_time' ) <= current_time \
95
95
and current_time % timescale == 0 :
@@ -250,12 +250,10 @@ def outsource_item(graph: GraphInstance, instance: Instance, item_id: int, t: in
250
250
graph .update_item (item_id , [
251
251
('outsourced' , YES ),
252
252
('is_possible' , YES ),
253
- ('remaining_physical_time' , 0 ),
254
- ('remaining_design_time' , 0 ),
253
+ ('remaining_time' , 0 ),
255
254
('children_time' , 0 ),
256
255
('start_time' , outsourcing_start_time ),
257
256
('end_time' , end_date )])
258
- graph .executed_items += 1
259
257
graph .oustourced_items += 1
260
258
for o in instance .loop_item_operations (p ,e ):
261
259
op_id = graph .operations_i2g [p ][o ]
@@ -354,7 +352,7 @@ def schedule_operation(graph: GraphInstance, instance: Instance, operation_id: i
354
352
rt = instance .get_resource_familly (r )
355
353
estimated_processing_time = instance .operation_resource_time (p , o , rt , max_load = True )
356
354
item_id = graph .items_i2g [p ][e ]
357
- graph .inc_resource (resource_id , [('executed_operations' , 1 ), ( ' remaining_operations' , - 1 )])
355
+ graph .inc_resource (resource_id , [('remaining_operations' , - 1 )])
358
356
graph .update_resource (resource_id , [('available_time' , operation_end )])
359
357
graph .update_need_for_resource (operation_id , resource_id , [
360
358
('status' , YES ),
@@ -379,14 +377,11 @@ def schedule_operation(graph: GraphInstance, instance: Instance, operation_id: i
379
377
graph , _max_next_operation_end = shift_next_operations (graph , instance , p , e , o , shift )
380
378
_end_of_item = max (_max_next_operation_end , operation_end )
381
379
graph .update_item (item_id , [('start_time' , current_time )], minn = True )
380
+ graph .inc_item (item_id , [('remaining_time' , - estimated_processing_time )])
382
381
if instance .is_design [p ][o ]:
383
- graph .inc_item (item_id , [('remaining_design_time' , - estimated_processing_time )])
384
382
graph , _max_end_of_children = shift_children_and_operations (graph , instance , p , e , shift )
385
383
_end_of_item = max (_end_of_item , _max_end_of_children )
386
384
else :
387
- graph .inc_item (item_id , [('remaining_physical_time' , - estimated_processing_time )])
388
- if graph .item (item_id , 'remaining_physical_time' )<= 0 :
389
- graph .executed_items += 1
390
385
for child in instance .get_children (p , e , direct = False ):
391
386
graph .inc_item (graph .items_i2g [p ][child ], [('parents_physical_time' , - estimated_processing_time )])
392
387
graph .update_item (item_id , [('end_time' , _end_of_item )], maxx = True )
@@ -482,10 +477,11 @@ def policy(probabilities: Tensor, greedy: bool=True):
482
477
def update_processing_time (instance : Instance , graph : GraphInstance , op_id : int , res_id : int ):
483
478
p , o = graph .operations_g2i [op_id ]
484
479
r = graph .resources_g2i [res_id ]
480
+ basic_processing_time = instance .execution_time [r ][p ][o ]
485
481
op_setup_time = 0 if (instance .get_operation_type (p , o ) == graph .current_operation_type [res_id ] or graph .current_operation_type [res_id ]< 0 ) else instance .operation_setup [r ]
486
482
for d in range (instance .nb_settings ):
487
483
op_setup_time += 0 if (graph .current_design_value [res_id ][d ] == instance .design_value [p ][o ][d ] or graph .current_design_value [res_id ][d ]< 0 ) else instance .design_setup [r ][d ]
488
- return graph . need_for_resource ( op_id , res_id , ' basic_processing_time' ) + op_setup_time
484
+ return basic_processing_time + op_setup_time
489
485
490
486
def next_possible_time (instance : Instance , current_time : int , p : int , o : int ):
491
487
scale = 60 * instance .H if instance .in_days [p ][o ] else 60 if instance .in_hours [p ][o ] else 1
@@ -532,21 +528,16 @@ def manage_queue_of_possible_actions(instance: Instance, graph: GraphInstance, u
532
528
DEBUG_PRINT (f"New current time t={ t } ..." )
533
529
return graph , utilization , t , False
534
530
else :
535
- if debug_mode :
536
- DEBUG_PRINT ("End of solving stage!" )
537
- check_completeness (graph , DEBUG_PRINT )
538
531
return graph , utilization , t , True
539
532
540
533
def reward (init_cmax : int , init_cost : int , makespan_old : int , makespan_new : int , last_op_old : int , last_op_new : int , cost_old : int = - 1 , cost_new : int = - 1 , a : float = - 1 , use_cost : bool = False ):
541
534
"""
542
535
Compute the reward for each decision
543
536
"""
544
- _r = None
545
537
if use_cost :
546
- _r = a * (big_steps * (makespan_old - makespan_new ) + small_steps * (last_op_old - last_op_new )) + (1 - a ) * (cost_old - cost_new )
538
+ return a * (big_steps * (makespan_old - makespan_new ) + small_steps * (last_op_old - last_op_new )) + (1 - a ) * (cost_old - cost_new )
547
539
else :
548
- _r = a * (big_steps * makespan_old - makespan_new + small_steps * (last_op_old - last_op_new ))
549
- return _r / (a * init_cmax + (1 - a )* init_cost )
540
+ return a * (big_steps * makespan_old - makespan_new + small_steps * (last_op_old - last_op_new ))
550
541
551
542
def solve_one (instance : Instance , agents : list [(Module , str )], trainable : list , train : bool , device : str , debug_mode : bool , greedy : bool = False ):
552
543
graph , current_cmax , current_cost , previous_operations , next_operations , related_items , parent_items = translate (i = instance , device = device )
0 commit comments