basic funcionality improvements, as well as bundle refactor prep
This commit is contained in:
parent
872397e825
commit
744abbb7b8
@ -1,6 +1,7 @@
|
|||||||
import csv
|
import csv
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
|
from tokenize import String
|
||||||
|
|
||||||
def items_csv_to_dict(items_csv_reader, solver_run):
|
def items_csv_to_dict(items_csv_reader, solver_run):
|
||||||
items = []
|
items = []
|
||||||
@ -14,10 +15,11 @@ def items_csv_to_dict(items_csv_reader, solver_run):
|
|||||||
item = { 'attributes': [] }
|
item = { 'attributes': [] }
|
||||||
|
|
||||||
# ensure that the b param is formatted correctly
|
# ensure that the b param is formatted correctly
|
||||||
if len(re.findall(".", row[len(headers) - 1])) >= 3:
|
if row[len(headers) - 1] != '' and is_float(row[len(headers) - 1]):
|
||||||
for key, col in enumerate(headers):
|
for key, col in enumerate(headers):
|
||||||
if solver_run.irt_model.formatted_b_param() == col:
|
if solver_run.irt_model.formatted_b_param() == col:
|
||||||
item['b_param'] = row[key]
|
value = float(row[key])
|
||||||
|
item['b_param'] = value
|
||||||
elif solver_run.get_constraint(col) and solver_run.get_constraint(col).reference_attribute.type == 'bundle':
|
elif solver_run.get_constraint(col) and solver_run.get_constraint(col).reference_attribute.type == 'bundle':
|
||||||
if row[key]:
|
if row[key]:
|
||||||
item[solver_run.get_constraint(col).reference_attribute.id] = row[key]
|
item[solver_run.get_constraint(col).reference_attribute.id] = row[key]
|
||||||
@ -81,10 +83,18 @@ def solution_items(variables, solver_run):
|
|||||||
form_items = []
|
form_items = []
|
||||||
|
|
||||||
for v in variables:
|
for v in variables:
|
||||||
if v.varValue is not None and v.varValue > 0:
|
if v.varValue > 0 and 'Item_' in v.name:
|
||||||
item_id = v.name.replace('Item_', '')
|
item_id = v.name.replace('Item_', '')
|
||||||
item = solver_run.get_item(item_id)
|
item = solver_run.get_item(item_id)
|
||||||
# add item to list and then remove from master item list
|
# add item to list and then remove from master item list
|
||||||
form_items.append(item)
|
form_items.append(item)
|
||||||
|
|
||||||
return form_items
|
return form_items
|
||||||
|
|
||||||
|
# probably a better place for this...
|
||||||
|
def is_float(element: String) -> bool:
|
||||||
|
try:
|
||||||
|
float(element)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
@ -4,7 +4,7 @@ import logging
|
|||||||
|
|
||||||
from lib.errors.item_generation_error import ItemGenerationError
|
from lib.errors.item_generation_error import ItemGenerationError
|
||||||
|
|
||||||
def build_constraints(solver_run, problem, items):
|
def build_constraints(solver_run, problem, items, bundles):
|
||||||
try:
|
try:
|
||||||
total_form_items = solver_run.total_form_items
|
total_form_items = solver_run.total_form_items
|
||||||
constraints = solver_run.constraints
|
constraints = solver_run.constraints
|
||||||
|
@ -19,7 +19,7 @@ class ServiceListener(SqsListener):
|
|||||||
logging.info('Process complete for %s', service.file_name)
|
logging.info('Process complete for %s', service.file_name)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.info('Starting Solver Service (v1.1.1)...')
|
logging.info('Starting Solver Service (v1.1.2)...')
|
||||||
listener = ServiceListener(
|
listener = ServiceListener(
|
||||||
os.environ['SQS_QUEUE'],
|
os.environ['SQS_QUEUE'],
|
||||||
region_name=os.environ['AWS_REGION'],
|
region_name=os.environ['AWS_REGION'],
|
||||||
|
@ -68,6 +68,9 @@ 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(
|
||||||
|
"Bundle", [bundle.id for bundle in self.solver_run.bundles], lowBound=1, upBound=1, cat='Binary')
|
||||||
|
|
||||||
problem_objection_functions = []
|
problem_objection_functions = []
|
||||||
|
|
||||||
# create problem
|
# create problem
|
||||||
@ -82,7 +85,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)
|
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
||||||
|
|
||||||
# multi-objective constraints
|
# multi-objective constraints
|
||||||
for target in self.solver_run.objective_function.tif_targets:
|
for target in self.solver_run.objective_function.tif_targets:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user