fix for non bundles runs as well as some typing
This commit is contained in:
parent
2576c982e0
commit
24168f6bbb
@ -1,12 +1,14 @@
|
|||||||
from pulp import lpSum
|
from pulp import lpSum, LpProblem
|
||||||
from random import randint, sample
|
from random import randint, sample
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from models.bundle import Bundle
|
from models.bundle import Bundle
|
||||||
|
from models.solver_run import SolverRun
|
||||||
|
from models.item import Item
|
||||||
|
|
||||||
from lib.errors.item_generation_error import ItemGenerationError
|
from lib.errors.item_generation_error import ItemGenerationError
|
||||||
|
|
||||||
def build_constraints(solver_run, problem, items, bundles):
|
def build_constraints(solver_run: SolverRun, problem: LpProblem, items: list[Item]) -> LpProblem:
|
||||||
logging.info('Creating Constraints...')
|
logging.info('Creating Constraints...')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -25,7 +25,7 @@ class LoftService(Base):
|
|||||||
logging.error(error)
|
logging.error(error)
|
||||||
self.result = self.stream_to_s3_bucket(ItemGenerationError("Provided params causing error in calculation results"))
|
self.result = self.stream_to_s3_bucket(ItemGenerationError("Provided params causing error in calculation results"))
|
||||||
|
|
||||||
def create_solver_run_from_attributes(self):
|
def create_solver_run_from_attributes(self) -> SolverRun:
|
||||||
logging.info('Retrieving attributes from message...')
|
logging.info('Retrieving attributes from message...')
|
||||||
# get s3 object
|
# get s3 object
|
||||||
self.key = aws_helper.get_key_from_message(self.source)
|
self.key = aws_helper.get_key_from_message(self.source)
|
||||||
@ -52,7 +52,7 @@ class LoftService(Base):
|
|||||||
|
|
||||||
return solver_run
|
return solver_run
|
||||||
|
|
||||||
def generate_solution(self):
|
def generate_solution(self) -> Solution:
|
||||||
logging.info('Generating Solution...')
|
logging.info('Generating Solution...')
|
||||||
|
|
||||||
# unsolved solution
|
# unsolved solution
|
||||||
@ -70,8 +70,8 @@ class LoftService(Base):
|
|||||||
# setup vars
|
# setup vars
|
||||||
items = LpVariable.dicts(
|
items = LpVariable.dicts(
|
||||||
"Item", [item.id for item in self.solver_run.items], lowBound=1, upBound=1, cat='Binary')
|
"Item", [item.id for item in self.solver_run.items], lowBound=1, upBound=1, cat='Binary')
|
||||||
bundles = LpVariable.dicts(
|
# bundles = LpVariable.dicts(
|
||||||
"Bundle", [bundle.id for bundle in self.solver_run.bundles], lowBound=1, upBound=1, cat='Binary')
|
# "Bundle", [bundle.id for bundle in self.solver_run.bundles], lowBound=1, upBound=1, cat='Binary')
|
||||||
|
|
||||||
problem_objection_functions = []
|
problem_objection_functions = []
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class LoftService(Base):
|
|||||||
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, 'Total form items'
|
||||||
|
|
||||||
# dynamic constraints
|
# dynamic constraints
|
||||||
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
problem = solver_helper.build_constraints(self.solver_run, problem, items)
|
||||||
|
|
||||||
# multi-objective constraints
|
# multi-objective constraints
|
||||||
logging.info('Creating TIF and TCC constraints')
|
logging.info('Creating TIF and TCC constraints')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user