add some labels to constraints and rename variables to be a bit more descriptive
This commit is contained in:
parent
cec7429913
commit
0b41c341b7
@ -63,8 +63,7 @@ class LoftService(Base):
|
|||||||
def generate_solution(self) -> Solution:
|
def generate_solution(self) -> Solution:
|
||||||
logging.info('Generating Solution...')
|
logging.info('Generating Solution...')
|
||||||
|
|
||||||
# unsolved solution
|
solution = Solution(response_id=random.randint(100, 5000), forms=[]) # unsolved solution
|
||||||
solution = Solution(response_id=random.randint(100, 5000), forms=[])
|
|
||||||
|
|
||||||
# setup common Solver variables
|
# setup common Solver variables
|
||||||
items = LpVariable.dicts("Item", [item.id for item in self.solver_run.items], cat='Binary')
|
items = LpVariable.dicts("Item", [item.id for item in self.solver_run.items], cat='Binary')
|
||||||
@ -85,8 +84,8 @@ class LoftService(Base):
|
|||||||
problem += lpSum([items[item.id] for item in self.solver_run.items])
|
problem += lpSum([items[item.id] for item in self.solver_run.items])
|
||||||
|
|
||||||
# constraints
|
# constraints
|
||||||
# problem += lpSum([items[item.id]
|
problem += lpSum([items[item.id]
|
||||||
# for item in self.solver_run.items]) == self.solver_run.total_form_items, 'Total form items'
|
for item in self.solver_run.items]) == self.solver_run.total_form_items, f'Total form items for form {form_number}'
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[
|
[
|
||||||
bundle.count * bundles[bundle.id]
|
bundle.count * bundles[bundle.id]
|
||||||
@ -95,11 +94,10 @@ class LoftService(Base):
|
|||||||
1 * items[item.id]
|
1 * items[item.id]
|
||||||
for item in self.solver_run.unbundled_items()
|
for item in self.solver_run.unbundled_items()
|
||||||
]
|
]
|
||||||
) == self.solver_run.total_form_items, 'Total bundle form items for form'
|
) == self.solver_run.total_form_items, f'Total bundle form items for form {form_number}'
|
||||||
|
|
||||||
# dynamic constraints
|
# Dynamic constraints.. currently we only support Metadata and Bundles(Cases/Passages)
|
||||||
problem = solver_helper.build_constraints(self.solver_run, problem,
|
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
||||||
items, bundles)
|
|
||||||
|
|
||||||
# multi-objective constraints
|
# multi-objective constraints
|
||||||
logging.info('Creating TIF and TCC constraints')
|
logging.info('Creating TIF and TCC constraints')
|
||||||
@ -146,19 +144,21 @@ class LoftService(Base):
|
|||||||
for item in self.solver_run.items])
|
for item in self.solver_run.items])
|
||||||
constraint = LpConstraint(
|
constraint = LpConstraint(
|
||||||
e=e,
|
e=e,
|
||||||
sense=0,
|
sense=-1,
|
||||||
name=f'tcc theta ({target.theta}) @{target.value}',
|
name=f'tcc theta ({target.theta}) @{target.value} for form {form_number}',
|
||||||
rhs=target.value)
|
rhs=target.value)
|
||||||
|
|
||||||
elasticized_constraint = solver_helper.elasticize_constraint(constraint)
|
elasticized_constraint = solver_helper.elasticize_constraint(constraint)
|
||||||
problem.extend(elasticized_constraint)
|
# problem.extend(elasticized_constraint)
|
||||||
|
|
||||||
# solve problem
|
# solve problem
|
||||||
logging.info('Solving...')
|
logging.info('Solving for Form %s...', form_number)
|
||||||
# print(problem)
|
|
||||||
|
print(problem)
|
||||||
problem.solve()
|
problem.solve()
|
||||||
# problem.sequentialSolve(problem_objective_functions)
|
# problem.sequentialSolve(problem_objective_functions)
|
||||||
logging.info('Solved...generating form and adding to solution')
|
|
||||||
|
logging.info(f'Solved for Form {form_number}...generating form and adding to solution')
|
||||||
|
|
||||||
# add return items and create as a form
|
# add return items and create as a form
|
||||||
form_items = service_helper.solution_items(problem.variables(), self.solver_run)
|
form_items = service_helper.solution_items(problem.variables(), self.solver_run)
|
||||||
@ -170,7 +170,7 @@ class LoftService(Base):
|
|||||||
logging.info('Form generated and added to solution...')
|
logging.info('Form generated and added to solution...')
|
||||||
|
|
||||||
# successfull form, increment
|
# successfull form, increment
|
||||||
f += 1
|
form_count += 1
|
||||||
|
|
||||||
logging.info('Solution Generated.')
|
logging.info('Solution Generated.')
|
||||||
# print(problem)
|
# print(problem)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user