@@ -58,106 +58,107 @@ def run(self):
5858
5959 # Run indefinitely until there's no more work
6060 while True :
61- # Get job from queue for this process number
62- c = self .queues .get_work (self .p_num )
61+ # Get work from queue for this process number
62+ work = self .queues .get_work (self .p_num )
6363
64- # If no more jobs , break the loop
65- if not c :
64+ # If no more work , break the loop
65+ if not work :
6666 break
6767
68- # Process the job
69- log = f"Process: { self .p_num } , index: { c } , " # Initialize logging string
70- cp_end = self .opts .gp - 1 # Set the end index for this job
71- self .model .progress .increment () # Increment progress counter for this model
72-
73- # Define helper functions to handle jump, bypass, and early exit scenarios
74- def do_jump (i , jump ):
75- return min (jump , abs (cp_end - i ))
76-
77- def bypass_range (i ):
78- if i == 0 :
79- return range (c [i ], c [i ] + 1 )
80- else :
81- return range (c [i ], c [i ] + b [i ] + 1 )
82-
83- def early_exit_range (i ):
84- if i == 0 :
85- return range (c [i ], c [i ] + 1 )
86- else :
87- return range (c [i ], cp_end )
88-
89- # Check if flag is enabled and if the current job has a flag set
90- if self .opts .flag and self .flag .get (c ) != 0 and jump == 0 :
91- # If jump is not set and there's a flag for this job, set jump
92- jump = do_jump (c [0 ] - 1 , self .flag .get (c ))
93-
94- # If jump is set, skip to the next iteration of the loop
95- if jump > 0 :
96- jump = jump - 1
97- continue
98-
99- # Log model progress for each objective
100- for o in self .model .iter_obj2 :
101- log += f"e{ o + 1 } : { self .model .e [o , c [o ]]} , "
102- self .model .model .e [o + 2 ] = self .model .e [o , c [o ]]
103-
104- # Activate objective 0 and solve the model
105- self .model .obj_activate (0 )
106- self .model .solve ()
107- self .model .models_solved .increment ()
108-
109- # Check if early exit is enabled and if the model is infeasible
110- if self .opts .early_exit and self .model .is_infeasible ():
111- # If so, increment infeasibilities counter
112- self .model .infeasibilities .increment ()
113-
114- # Set flag if flag is enabled
115- if self .opts .flag :
116- self .flag .set (early_exit_range , self .opts .gp , self .model .iter_obj2 )
117-
118- jump = do_jump (c [0 ], self .opts .gp ) # Set jump
119- log += "infeasible" # Log infeasibility
120-
121- # Log progress if process logging is enabled
122- if self .opts .process_logging :
123- self .logger .info (log )
124-
125- continue # Skip to next iteration of loop
126-
127- # Calculate slack values and set jump if bypass is enabled
128- elif self .opts .bypass and self .model .is_optimal ():
129- b = []
130- for i in self .model .iter_obj2 :
131- step = self .model .obj_range [i ] / (self .opts .gp - 1 )
132- slack = round (self .model .slack_val (i + 1 ))
133- b .append (int (slack / step ))
134-
135- # Log jump and set flag if enabled
136- log += f"jump: { b [0 ]} , "
137- if self .opts .flag :
138- self .flag .set (bypass_range , b [0 ] + 1 , self .model .iter_obj2 )
139- jump = do_jump (c [0 ], b [0 ])
140-
141- # If model is optimal, calculate and log solutions
142- sols = []
143- if self .model .is_optimal ():
144- sols .append (
145- self .model .obj_val (0 )
146- - self .opts .eps
147- * sum (
148- 10 ** (- 1 * (o )) * self .model .slack_val (o + 1 ) / self .model .obj_range [o ]
149- for o in self .model .iter_obj2
68+ # Process each job in the work list
69+ for c in work :
70+ log = f"Process: { self .p_num } , index: { c } , " # Initialize logging string
71+ cp_end = self .opts .gp - 1 # Set the end index for this job
72+ self .model .progress .increment () # Increment progress counter for this model
73+
74+ # Define helper functions to handle jump, bypass, and early exit scenarios
75+ def do_jump (i , jump ):
76+ return min (jump , abs (cp_end - i ))
77+
78+ def bypass_range (i ):
79+ if i == 0 :
80+ return range (c [i ], c [i ] + 1 )
81+ else :
82+ return range (c [i ], c [i ] + b [i ] + 1 )
83+
84+ def early_exit_range (i ):
85+ if i == 0 :
86+ return range (c [i ], c [i ] + 1 )
87+ else :
88+ return range (c [i ], cp_end )
89+
90+ # Check if flag is enabled and if the current job has a flag set
91+ if self .opts .flag and self .flag .get (c ) != 0 and jump == 0 :
92+ # If jump is not set and there's a flag for this job, set jump
93+ jump = do_jump (c [0 ] - 1 , self .flag .get (c ))
94+
95+ # If jump is set, skip to the next iteration of the loop
96+ if jump > 0 :
97+ jump = jump - 1
98+ continue
99+
100+ # Log model progress for each objective
101+ for o in self .model .iter_obj2 :
102+ log += f"e{ o + 1 } : { self .model .e [o , c [o ]]} , "
103+ self .model .model .e [o + 2 ] = self .model .e [o , c [o ]]
104+
105+ # Activate objective 0 and solve the model
106+ self .model .obj_activate (0 )
107+ self .model .solve ()
108+ self .model .models_solved .increment ()
109+
110+ # Check if early exit is enabled and if the model is infeasible
111+ if self .opts .early_exit and self .model .is_infeasible ():
112+ # If so, increment infeasibilities counter
113+ self .model .infeasibilities .increment ()
114+
115+ # Set flag if flag is enabled
116+ if self .opts .flag :
117+ self .flag .set (early_exit_range , self .opts .gp , self .model .iter_obj2 )
118+
119+ jump = do_jump (c [0 ], self .opts .gp ) # Set jump
120+ log += "infeasible" # Log infeasibility
121+
122+ # Log progress if process logging is enabled
123+ if self .opts .process_logging :
124+ self .logger .info (log )
125+
126+ continue # Skip to next iteration of loop
127+
128+ # Calculate slack values and set jump if bypass is enabled
129+ elif self .opts .bypass and self .model .is_optimal ():
130+ b = []
131+ for i in self .model .iter_obj2 :
132+ step = self .model .obj_range [i ] / (self .opts .gp - 1 )
133+ slack = round (self .model .slack_val (i + 1 ))
134+ b .append (int (slack / step ))
135+
136+ # Log jump and set flag if enabled
137+ log += f"jump: { b [0 ]} , "
138+ if self .opts .flag :
139+ self .flag .set (bypass_range , b [0 ] + 1 , self .model .iter_obj2 )
140+ jump = do_jump (c [0 ], b [0 ])
141+
142+ # If model is optimal, calculate and log solutions
143+ sols = []
144+ if self .model .is_optimal ():
145+ sols .append (
146+ self .model .obj_val (0 )
147+ - self .opts .eps
148+ * sum (
149+ 10 ** (- 1 * (o )) * self .model .slack_val (o + 1 ) / self .model .obj_range [o ]
150+ for o in self .model .iter_obj2
151+ )
150152 )
151- )
152153
153- for o in self .model .iter_obj2 :
154- sols .append (self .model .obj_val (o + 1 ))
154+ for o in self .model .iter_obj2 :
155+ sols .append (self .model .obj_val (o + 1 ))
155156
156- # Put results into queue as a dictionary
157- sols_dict = {tuple (sols ): self .model .get_vars ()}
158- self .queues .put_result (sols_dict )
157+ # Put results into queue as a dictionary
158+ sols_dict = {tuple (sols ): self .model .get_vars ()}
159+ self .queues .put_result (sols_dict )
159160
160- # Log solutions if process logging is enabled
161- log += f"solutions: { sols } "
162- if self .opts .process_logging :
163- self .logger .info (log )
161+ # Log solutions if process logging is enabled
162+ log += f"solutions: { sols } "
163+ if self .opts .process_logging :
164+ self .logger .info (log )
0 commit comments