make sure to generate the correct solution before breaking the loop

This commit is contained in:
Adrian Manteza 2022-03-14 14:45:02 +00:00
parent 98922bfc4c
commit ff9d9b3d49
3 changed files with 22 additions and 16 deletions

View File

@ -9,7 +9,7 @@ class Target(BaseModel):
@classmethod
def max_drift(cls):
return 15 # 10% elasticity
return 10 # 10% elasticity
@classmethod
def max_drift_increment(cls):

View File

@ -156,9 +156,7 @@ class LoftService(Base):
]
) <= tcc_target.value + (tcc_target.value * drift_percent)
# solve problem
logging.info(f'Solving for Form {form_number}')
logging.info(f'Solving for Form {form_number} with a drift of {current_drift}%')
problem.solve()
if LpStatus[problem.status] == 'Infeasible':
@ -170,25 +168,34 @@ class LoftService(Base):
print(problem.objective.value())
print(problem.objective)
if current_drift == Target.max_drift(): # this is the last attempt, so lets finalize the solution
logging.info(f'No feasible solution found for Form {form_number}%!')
self.add_form_to_solution(problem, solution)
break
current_drift += Target.max_drift_increment()
else:
logging.info(f'solution found with drift of {current_drift}%!')
logging.info(f'Optimal solution found with drift of {current_drift}%!')
self.add_form_to_solution(problem, solution)
break
logging.info(f'Solved for Form {form_number}...generating form and adding to solution')
# add return items and create as a form
form_items = service_helper.solution_items(problem.variables(), self.solver_run)
# add form to solution
solution.forms.append(Form.create(form_items, self.solver_run, LpStatus[problem.status]))
logging.info('Form generated and added to solution...')
logging.info('Solution Generated.')
return solution
def add_form_to_solution(self, problem, solution):
# add return items and create as a form
form_items = service_helper.solution_items(problem.variables(), self.solver_run)
form = Form.create(form_items, self.solver_run, LpStatus[problem.status])
solution.forms.append(form)
logging.info('Form generated and added to solution...')
def stream_to_s3_bucket(self, error=None):
self.file_name = f'{service_helper.key_to_uuid(self.key)}.csv'
solution_file = None

View File

@ -119,7 +119,6 @@ class SolverSandbox:
print(problem.objective)
drift += 1
else:
print(f"solution found with drift of {drift}!")