Merge branch 'feature/QUANT-1667-bundle-first-ordering' into feature/QUANT-1656-bundle-first-ordering
This commit is contained in:
commit
50e00c5e3b
@ -105,6 +105,8 @@ def key_to_uuid(key):
|
|||||||
|
|
||||||
def solution_items(variables: list, solver_run: SolverRun) -> Tuple[list]:
|
def solution_items(variables: list, solver_run: SolverRun) -> Tuple[list]:
|
||||||
form_items = []
|
form_items = []
|
||||||
|
form_bundles = []
|
||||||
|
final_items = []
|
||||||
solver_variables = []
|
solver_variables = []
|
||||||
|
|
||||||
for v in variables:
|
for v in variables:
|
||||||
@ -120,11 +122,17 @@ def solution_items(variables: list, solver_run: SolverRun) -> Tuple[list]:
|
|||||||
bundle_id = v.name.replace('Bundle_', '')
|
bundle_id = v.name.replace('Bundle_', '')
|
||||||
bundle = solver_run.get_bundle(int(bundle_id))
|
bundle = solver_run.get_bundle(int(bundle_id))
|
||||||
|
|
||||||
if bundle:
|
if bundle: form_bundles.append(bundle)
|
||||||
for item in bundle.items:
|
|
||||||
if item: form_items.append(item)
|
|
||||||
|
|
||||||
return form_items, solver_variables
|
for bundle in form_bundles:
|
||||||
|
items = bundle.ordered_items if solver_run.bundle_first_ordering else bundle.items
|
||||||
|
for item in items:
|
||||||
|
final_items.append(item)
|
||||||
|
|
||||||
|
for item in form_items:
|
||||||
|
final_items.append(item)
|
||||||
|
|
||||||
|
return final_items, solver_variables
|
||||||
|
|
||||||
def print_problem_variables(problem):
|
def print_problem_variables(problem):
|
||||||
# Uncomment this as needed in local dev
|
# Uncomment this as needed in local dev
|
||||||
|
@ -46,3 +46,6 @@ class Bundle(BaseModel):
|
|||||||
total += self.trf(solver_run.irt_model, target.theta)
|
total += self.trf(solver_run.irt_model, target.theta)
|
||||||
|
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
def ordered_items(self) -> List[Item]:
|
||||||
|
return sorted(self.items, key=lambda item: item.position)
|
||||||
|
@ -8,6 +8,7 @@ from lib.irt.item_information_function import ItemInformationFunction
|
|||||||
|
|
||||||
class Item(BaseModel):
|
class Item(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
|
position: Optional[int]
|
||||||
passage_id: Optional[int]
|
passage_id: Optional[int]
|
||||||
workflow_state: Optional[str]
|
workflow_state: Optional[str]
|
||||||
attributes: List[Attribute]
|
attributes: List[Attribute]
|
||||||
|
@ -14,7 +14,8 @@ from models.advanced_options import AdvancedOptions
|
|||||||
|
|
||||||
class SolverRun(BaseModel):
|
class SolverRun(BaseModel):
|
||||||
items: List[Item] = []
|
items: List[Item] = []
|
||||||
bundles: list[Bundle] = []
|
bundles: List[Bundle] = []
|
||||||
|
bundle_first_ordering: bool = True
|
||||||
constraints: List[Constraint]
|
constraints: List[Constraint]
|
||||||
irt_model: IRTModel
|
irt_model: IRTModel
|
||||||
objective_function: ObjectiveFunction
|
objective_function: ObjectiveFunction
|
||||||
@ -40,7 +41,7 @@ class SolverRun(BaseModel):
|
|||||||
if type == constraint.reference_attribute.type:
|
if type == constraint.reference_attribute.type:
|
||||||
return constraint
|
return constraint
|
||||||
|
|
||||||
def remove_items(self, items: list[Item]) -> bool:
|
def remove_items(self, items: List[Item]) -> bool:
|
||||||
self.items = [item for item in self.items if item not in items]
|
self.items = [item for item in self.items if item not in items]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ class SolverRun(BaseModel):
|
|||||||
return next((constraint for constraint in self.constraints
|
return next((constraint for constraint in self.constraints
|
||||||
if constraint.reference_attribute.id == name), None)
|
if constraint.reference_attribute.id == name), None)
|
||||||
|
|
||||||
def unbundled_items(self) -> list:
|
def unbundled_items(self) -> List[Item]:
|
||||||
# since the only bundles are based on passage id currently
|
# since the only bundles are based on passage id currently
|
||||||
# in the future when we have more than just passage based bundles
|
# in the future when we have more than just passage based bundles
|
||||||
# we'll need to develop a more sophisticated way of handling this concern
|
# we'll need to develop a more sophisticated way of handling this concern
|
||||||
@ -113,7 +114,7 @@ class SolverRun(BaseModel):
|
|||||||
else:
|
else:
|
||||||
return self.items
|
return self.items
|
||||||
|
|
||||||
def select_items_by_percent(self, percent: int) -> list[Item]:
|
def select_items_by_percent(self, percent: int) -> List[Item]:
|
||||||
items = self.unbundled_items()
|
items = self.unbundled_items()
|
||||||
total_items = len(items)
|
total_items = len(items)
|
||||||
selected_items_amount = round(total_items - (total_items *
|
selected_items_amount = round(total_items - (total_items *
|
||||||
@ -121,7 +122,7 @@ class SolverRun(BaseModel):
|
|||||||
|
|
||||||
return random.sample(items, selected_items_amount)
|
return random.sample(items, selected_items_amount)
|
||||||
|
|
||||||
def select_bundles_by_percent(self, percent: int) -> list[Bundle]:
|
def select_bundles_by_percent(self, percent: int) -> List[Bundle]:
|
||||||
total_bundles = len(self.bundles)
|
total_bundles = len(self.bundles)
|
||||||
selected_bundles_amount = round(total_bundles - (total_bundles *
|
selected_bundles_amount = round(total_bundles - (total_bundles *
|
||||||
(percent / 100)))
|
(percent / 100)))
|
||||||
|
@ -83,11 +83,11 @@ class LoftService(Base):
|
|||||||
lowBound=0,
|
lowBound=0,
|
||||||
upBound=1,
|
upBound=1,
|
||||||
cat='Binary')
|
cat='Binary')
|
||||||
bundles = LpVariable.dicts(
|
bundles = LpVariable.dicts("Bundle",
|
||||||
"Bundle", [bundle.id for bundle in selected_bundles],
|
[bundle.id for bundle in selected_bundles],
|
||||||
lowBound=0,
|
lowBound=0,
|
||||||
upBound=1,
|
upBound=1,
|
||||||
cat='Binary')
|
cat='Binary')
|
||||||
|
|
||||||
logging.info(f'Generating Solution for Form {form_number}')
|
logging.info(f'Generating Solution for Form {form_number}')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user