|
1 | 1 | import time |
2 | 2 | import flowpaths.abstractpathmodeldag as pathmodel |
| 3 | +import flowpaths.utils as utils |
3 | 4 |
|
4 | 5 | class NumPathsOptimization(pathmodel.AbstractPathModelDAG): # Note that we inherit from AbstractPathModelDAG to be able to use this class to also compute safe paths, |
5 | 6 |
|
@@ -106,6 +107,8 @@ def __init__( |
106 | 107 | self.__solution = None |
107 | 108 | self.solve_statistics = None |
108 | 109 |
|
| 110 | + utils.logger.info(f"{__name__}: created NumPathsOptimization with model_type = {model_type}") |
| 111 | + |
109 | 112 | def solve(self) -> bool: |
110 | 113 | """ |
111 | 114 | Attempts to solve the optimization problem by iterating over a range of path counts, creating and |
@@ -151,29 +154,35 @@ def solve(self) -> bool: |
151 | 154 |
|
152 | 155 | for k in range(max(self.min_num_paths,self.get_lowerbound_k()), self.max_num_paths+1): |
153 | 156 | # Create the model |
| 157 | + utils.logger.info(f"{__name__}: model id = {id(self)}, iteration with k = {k}") |
154 | 158 | model = self.model_type(**self.kwargs, k=k) |
155 | 159 | model.solve() |
156 | 160 | if model.is_solved(): |
157 | 161 | found_feasible = True |
| 162 | + current_solution_objective_value = model.get_objective_value() |
| 163 | + utils.logger.info(f"{__name__}: model id = {id(self)}, iteration with k = {k}, current_solution_objective_value = {current_solution_objective_value}") |
158 | 164 | if self.stop_on_first_feasible: |
159 | 165 | solve_status = NumPathsOptimization.solved_status_name |
160 | 166 | break |
161 | 167 | if self.stop_on_delta_abs: |
162 | 168 | if previous_solution_objective_value is None: |
163 | | - previous_solution_objective_value = model.get_objective_value() |
| 169 | + previous_solution_objective_value = current_solution_objective_value |
164 | 170 | else: |
165 | | - if abs(previous_solution_objective_value - model.get_objective_value()) <= self.stop_on_delta_abs: |
| 171 | + if abs(previous_solution_objective_value - current_solution_objective_value) <= self.stop_on_delta_abs: |
166 | 172 | solve_status = NumPathsOptimization.solved_status_name |
167 | 173 | break |
168 | 174 | if self.stop_on_delta_rel: |
169 | 175 | if previous_solution_objective_value is None: |
170 | | - previous_solution_objective_value = model.get_objective_value() |
| 176 | + previous_solution_objective_value = current_solution_objective_value |
171 | 177 | else: |
172 | | - if abs(previous_solution_objective_value - model.get_objective_value()) / previous_solution_objective_value <= self.stop_on_delta_rel: |
| 178 | + if abs(previous_solution_objective_value - current_solution_objective_value) / previous_solution_objective_value <= self.stop_on_delta_rel: |
173 | 179 | solve_status = NumPathsOptimization.solved_status_name |
174 | 180 | break |
| 181 | + else: |
| 182 | + utils.logger.info(f"{__name__}: model id = {id(self)}, iteration with k = {k}, model is not solved") |
175 | 183 | if time.time() - start_time > self.time_limit: |
176 | 184 | solve_status = NumPathsOptimization.timeout_status_name |
| 185 | + utils.logger.info(f"{__name__}: model id = {id(self)}, iteration with k = {k}, time out") |
177 | 186 | break |
178 | 187 |
|
179 | 188 | if solve_status != NumPathsOptimization.timeout_status_name: |
|
0 commit comments