close
This commit is contained in:
parent
ddb8efc79f
commit
cc704d97da
@ -15,12 +15,14 @@ class Bundle(BaseModel):
|
|||||||
type: str
|
type: str
|
||||||
|
|
||||||
def tif(self, irt_model: IRTModel, theta: float) -> float:
|
def tif(self, irt_model: IRTModel, theta: float) -> float:
|
||||||
return TestInformationFunction(irt_model).calculate(self.items,
|
return 0.9
|
||||||
theta=theta)
|
# return TestInformationFunction(irt_model).calculate(self.items,
|
||||||
|
# theta=theta)
|
||||||
|
|
||||||
def trf(self, irt_model: IRTModel, theta: float) -> float:
|
def trf(self, irt_model: IRTModel, theta: float) -> float:
|
||||||
return TestResponseFunction(irt_model).calculate(self.items,
|
return 0.9
|
||||||
theta=theta)
|
# return TestResponseFunction(irt_model).calculate(self.items,
|
||||||
|
# theta=theta)
|
||||||
|
|
||||||
def tif_trf_sum(self, solver_run):
|
def tif_trf_sum(self, solver_run):
|
||||||
return self.__trf_sum(solver_run) + self.__tif_sum(solver_run)
|
return self.__trf_sum(solver_run) + self.__tif_sum(solver_run)
|
||||||
|
@ -14,12 +14,14 @@ class Item(BaseModel):
|
|||||||
b_param: float = 0.00
|
b_param: float = 0.00
|
||||||
|
|
||||||
def iif(self, solver_run, theta):
|
def iif(self, solver_run, theta):
|
||||||
return ItemInformationFunction(solver_run.irt_model).calculate(
|
return 0.9
|
||||||
b_param=self.b_param, theta=theta)
|
# return ItemInformationFunction(solver_run.irt_model).calculate(
|
||||||
|
# b_param=self.b_param, theta=theta)
|
||||||
|
|
||||||
def irf(self, solver_run, theta):
|
def irf(self, solver_run, theta):
|
||||||
return ItemResponseFunction(solver_run.irt_model).calculate(
|
return 0.9
|
||||||
b_param=self.b_param, theta=theta)
|
# return ItemResponseFunction(solver_run.irt_model).calculate(
|
||||||
|
# b_param=self.b_param, theta=theta)
|
||||||
|
|
||||||
def get_attribute(self, ref_attribute):
|
def get_attribute(self, ref_attribute):
|
||||||
for attribute in self.attributes:
|
for attribute in self.attributes:
|
||||||
|
@ -67,8 +67,10 @@ class LoftService(Base):
|
|||||||
solution = Solution(response_id=random.randint(100, 5000), forms=[]) # unsolved solution
|
solution = Solution(response_id=random.randint(100, 5000), forms=[]) # unsolved solution
|
||||||
|
|
||||||
# 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], upBound=1, lowBound=0, cat='Binary')
|
||||||
bundles = LpVariable.dicts("Bundle", [bundle.id for bundle in self.solver_run.bundles], cat='Binary')
|
bundles = LpVariable.dicts("Bundle", [bundle.id for bundle in self.solver_run.bundles], upBound=1, lowBound=0, cat='Binary')
|
||||||
|
# items = LpVariable.dicts("Item", [item.id for item in self.solver_run.items], cat='Binary')
|
||||||
|
# bundles = LpVariable.dicts("Bundle", [bundle.id for bundle in self.solver_run.bundles], cat='Binary')
|
||||||
|
|
||||||
# iterate for number of forms that require creation
|
# iterate for number of forms that require creation
|
||||||
for form_count in range(self.solver_run.total_forms):
|
for form_count in range(self.solver_run.total_forms):
|
||||||
@ -85,16 +87,14 @@ class LoftService(Base):
|
|||||||
|
|
||||||
# objective function
|
# objective function
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[item.iif_irf_sum(self.solver_run) * items[item.id] for item in self.solver_run.items]
|
[item.iif_irf_sum(self.solver_run) * items[item.id] for item in self.solver_run.unbundled_items()]
|
||||||
+
|
+
|
||||||
[bundle.tif_trf_sum(self.solver_run) * bundles[bundle.id] for bundle in self.solver_run.bundles]
|
[bundle.tif_trf_sum(self.solver_run) * bundles[bundle.id] for bundle in self.solver_run.bundles]
|
||||||
)
|
)
|
||||||
|
# problem += lpSum([items[item.id] for item in self.solver_run.unbundled_items()] + [bundles[bundle.id] for bundle in self.solver_run.bundles])
|
||||||
|
# problem += lpSum([items[item.id] for item in self.solver_run.items])
|
||||||
|
|
||||||
# Form Constraints
|
# Form Constraints
|
||||||
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(
|
problem += lpSum(
|
||||||
[
|
[
|
||||||
bundle.count * bundles[bundle.id] for bundle in self.solver_run.bundles
|
bundle.count * bundles[bundle.id] for bundle in self.solver_run.bundles
|
||||||
@ -104,6 +104,12 @@ class LoftService(Base):
|
|||||||
]
|
]
|
||||||
) == self.solver_run.total_form_items, f'Total bundle form items for form {form_number}'
|
) == self.solver_run.total_form_items, f'Total bundle form items for form {form_number}'
|
||||||
|
|
||||||
|
# problem += lpSum(
|
||||||
|
# [
|
||||||
|
# 1 * items[item.id] for item in self.solver_run.items
|
||||||
|
# ]
|
||||||
|
# ) == self.solver_run.total_form_items, f'Total bundle form items for form {form_number}'
|
||||||
|
|
||||||
# Dynamic constraints.. currently we only support Metadata and Bundles(Cases/Passages)
|
# Dynamic constraints.. currently we only support Metadata and Bundles(Cases/Passages)
|
||||||
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
||||||
|
|
||||||
@ -118,10 +124,9 @@ class LoftService(Base):
|
|||||||
] +
|
] +
|
||||||
[
|
[
|
||||||
item.iif(self.solver_run, tif_target.theta) * items[item.id]
|
item.iif(self.solver_run, tif_target.theta) * items[item.id]
|
||||||
for item in self.solver_run.items
|
for item in self.solver_run.unbundled_items()
|
||||||
]
|
]
|
||||||
) >= tif_target.value - (tif_target.value * drift_percent)
|
) >= tif_target.value - (tif_target.value * drift_percent)
|
||||||
|
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[
|
[
|
||||||
bundle.tif(self.solver_run.irt_model, tif_target.theta) * bundles[bundle.id]
|
bundle.tif(self.solver_run.irt_model, tif_target.theta) * bundles[bundle.id]
|
||||||
@ -129,10 +134,23 @@ class LoftService(Base):
|
|||||||
] +
|
] +
|
||||||
[
|
[
|
||||||
item.iif(self.solver_run, tif_target.theta) * items[item.id]
|
item.iif(self.solver_run, tif_target.theta) * items[item.id]
|
||||||
for item in self.solver_run.items
|
for item in self.solver_run.unbundled_items()
|
||||||
]
|
]
|
||||||
) <= tif_target.value + (tif_target.value * drift_percent)
|
) <= tif_target.value + (tif_target.value * drift_percent)
|
||||||
|
|
||||||
|
# problem += lpSum(
|
||||||
|
# [
|
||||||
|
# item.iif(self.solver_run, tif_target.theta) * items[item.id]
|
||||||
|
# for item in self.solver_run.items
|
||||||
|
# ]
|
||||||
|
# ) >= tif_target.value - (tif_target.value * drift_percent)
|
||||||
|
# problem += lpSum(
|
||||||
|
# [
|
||||||
|
# item.iif(self.solver_run, tif_target.theta) * items[item.id]
|
||||||
|
# for item in self.solver_run.items
|
||||||
|
# ]
|
||||||
|
# ) <= tif_target.value + (tif_target.value * drift_percent)
|
||||||
|
|
||||||
for tcc_target in self.solver_run.objective_function.tcc_targets:
|
for tcc_target in self.solver_run.objective_function.tcc_targets:
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[
|
[
|
||||||
@ -141,10 +159,9 @@ class LoftService(Base):
|
|||||||
] +
|
] +
|
||||||
[
|
[
|
||||||
item.irf(self.solver_run, tcc_target.theta) * items[item.id]
|
item.irf(self.solver_run, tcc_target.theta) * items[item.id]
|
||||||
for item in self.solver_run.items
|
for item in self.solver_run.unbundled_items()
|
||||||
]
|
]
|
||||||
) >= tcc_target.value - (tcc_target.value * drift_percent)
|
) >= tcc_target.value - (tcc_target.value * drift_percent)
|
||||||
|
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[
|
[
|
||||||
bundle.trf(self.solver_run.irt_model, tcc_target.theta) * bundles[bundle.id]
|
bundle.trf(self.solver_run.irt_model, tcc_target.theta) * bundles[bundle.id]
|
||||||
@ -152,24 +169,40 @@ class LoftService(Base):
|
|||||||
] +
|
] +
|
||||||
[
|
[
|
||||||
item.irf(self.solver_run, tcc_target.theta) * items[item.id]
|
item.irf(self.solver_run, tcc_target.theta) * items[item.id]
|
||||||
for item in self.solver_run.items
|
for item in self.solver_run.unbundled_items()
|
||||||
]
|
]
|
||||||
) <= tcc_target.value + (tcc_target.value * drift_percent)
|
) <= tcc_target.value + (tcc_target.value * drift_percent)
|
||||||
|
|
||||||
|
# problem += lpSum(
|
||||||
|
# [
|
||||||
|
# item.irf(self.solver_run, tcc_target.theta) * items[item.id]
|
||||||
|
# for item in self.solver_run.items
|
||||||
|
# ]
|
||||||
|
# ) >= tcc_target.value - (tcc_target.value * drift_percent)
|
||||||
|
# problem += lpSum(
|
||||||
|
# [
|
||||||
|
# item.irf(self.solver_run, tcc_target.theta) * items[item.id]
|
||||||
|
# for item in self.solver_run.items
|
||||||
|
# ]
|
||||||
|
# ) <= tcc_target.value + (tcc_target.value * drift_percent)
|
||||||
|
|
||||||
logging.info(f'Solving for Form {form_number} with a drift of {current_drift}%')
|
logging.info(f'Solving for Form {form_number} with a drift of {current_drift}%')
|
||||||
problem.solve()
|
problem.solve()
|
||||||
|
|
||||||
if LpStatus[problem.status] == 'Infeasible':
|
if LpStatus[problem.status] == 'Infeasible':
|
||||||
logging.info(f'attempt infeasible for drift of {current_drift}%')
|
logging.info(f'attempt infeasible for drift of {current_drift}%')
|
||||||
|
|
||||||
for v in problem.variables():
|
|
||||||
print(v.name, "=", v.varValue)
|
|
||||||
|
|
||||||
print(problem.objective.value())
|
|
||||||
print(problem.objective)
|
# print(problem.objective.value())
|
||||||
|
# print(problem.constraints)
|
||||||
|
# print(problem.objective)
|
||||||
|
|
||||||
if current_drift == Target.max_drift(): # this is the last attempt, so lets finalize the solution
|
if current_drift == Target.max_drift(): # this is the last attempt, so lets finalize the solution
|
||||||
logging.info(f'No feasible solution found for Form {form_number}%!')
|
for v in problem.variables(): print(v.name, "=", v.varValue);
|
||||||
|
|
||||||
|
breakpoint()
|
||||||
|
logging.info(f'No feasible solution found for Form {form_number}!')
|
||||||
|
|
||||||
self.add_form_to_solution(problem, solution)
|
self.add_form_to_solution(problem, solution)
|
||||||
|
|
||||||
@ -177,6 +210,8 @@ class LoftService(Base):
|
|||||||
|
|
||||||
current_drift += Target.max_drift_increment()
|
current_drift += Target.max_drift_increment()
|
||||||
else:
|
else:
|
||||||
|
for v in problem.variables(): print(v.name, "=", v.varValue);
|
||||||
|
breakpoint()
|
||||||
logging.info(f'Optimal solution found with drift of {current_drift}%!')
|
logging.info(f'Optimal solution found with drift of {current_drift}%!')
|
||||||
|
|
||||||
self.add_form_to_solution(problem, solution)
|
self.add_form_to_solution(problem, solution)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user