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:
|
||||
logging.info('Generating Solution...')
|
||||
|
||||
# unsolved solution
|
||||
solution = Solution(response_id=random.randint(100, 5000), forms=[])
|
||||
solution = Solution(response_id=random.randint(100, 5000), forms=[]) # unsolved solution
|
||||
|
||||
# setup common Solver variables
|
||||
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])
|
||||
|
||||
# constraints
|
||||
# problem += lpSum([items[item.id]
|
||||
# for item in self.solver_run.items]) == self.solver_run.total_form_items, 'Total form items'
|
||||
problem += lpSum([items[item.id]
|
||||
for item in self.solver_run.items]) == self.solver_run.total_form_items, f'Total form items for form {form_number}'
|
||||
problem += lpSum(
|
||||
[
|
||||
bundle.count * bundles[bundle.id]
|
||||
@ -95,11 +94,10 @@ class LoftService(Base):
|
||||
1 * items[item.id]
|
||||
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
|
||||
problem = solver_helper.build_constraints(self.solver_run, problem,
|
||||
items, bundles)
|
||||
# Dynamic constraints.. currently we only support Metadata and Bundles(Cases/Passages)
|
||||
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
||||
|
||||
# multi-objective constraints
|
||||
logging.info('Creating TIF and TCC constraints')
|
||||
@ -146,19 +144,21 @@ class LoftService(Base):
|
||||
for item in self.solver_run.items])
|
||||
constraint = LpConstraint(
|
||||
e=e,
|
||||
sense=0,
|
||||
name=f'tcc theta ({target.theta}) @{target.value}',
|
||||
sense=-1,
|
||||
name=f'tcc theta ({target.theta}) @{target.value} for form {form_number}',
|
||||
rhs=target.value)
|
||||
|
||||
elasticized_constraint = solver_helper.elasticize_constraint(constraint)
|
||||
problem.extend(elasticized_constraint)
|
||||
# problem.extend(elasticized_constraint)
|
||||
|
||||
# solve problem
|
||||
logging.info('Solving...')
|
||||
# print(problem)
|
||||
logging.info('Solving for Form %s...', form_number)
|
||||
|
||||
print(problem)
|
||||
problem.solve()
|
||||
# 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
|
||||
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...')
|
||||
|
||||
# successfull form, increment
|
||||
f += 1
|
||||
form_count += 1
|
||||
|
||||
logging.info('Solution Generated.')
|
||||
# print(problem)
|
||||
|
Loading…
x
Reference in New Issue
Block a user