make it a single target calculation for yas_elastic
This commit is contained in:
parent
26571cffc6
commit
e1176365f3
@ -61,7 +61,7 @@ class SolverSandbox:
|
||||
print(v.name, "=", v.varValue)
|
||||
break
|
||||
|
||||
def yas_elastic(tif_target = 50.0):
|
||||
def yas_elastic(tif_target = 140.0): # 140 is the optimal
|
||||
Items = [1,2,3,4,5]
|
||||
|
||||
# For TIF target
|
||||
@ -82,57 +82,55 @@ class SolverSandbox:
|
||||
}
|
||||
# ---
|
||||
|
||||
total_forms = 2
|
||||
|
||||
items = LpVariable.dicts('Item', Items, cat='Binary')
|
||||
|
||||
for form in range(total_forms):
|
||||
drift = 0
|
||||
max_drift = 10 # 10% elasticity
|
||||
drift = 0
|
||||
max_drift = 10 # 10% elasticity
|
||||
|
||||
while drift <= max_drift:
|
||||
drift_percent = drift / 100
|
||||
problem = LpProblem('TIF_TCC', LpMinimize)
|
||||
while drift <= max_drift:
|
||||
drift_percent = drift / 100
|
||||
problem = LpProblem('TIF_TCC', LpMinimize)
|
||||
|
||||
# objective function
|
||||
problem += lpSum([(tif[i] + iif[i]) * items[i] for i in Items])
|
||||
# objective function
|
||||
problem += lpSum([(tif[i] + iif[i]) * items[i] for i in Items])
|
||||
|
||||
# Constraint 1
|
||||
problem += lpSum([items[i] for i in Items]) == 3, 'TotalItems'
|
||||
# Constraint 1
|
||||
problem += lpSum([items[i] for i in Items]) == 3, 'TotalItems'
|
||||
|
||||
print(f"Calculating TIF target of {tif_target} with drift of {drift} for Form {form + 1}")
|
||||
print(f"Calculating TIF target of {tif_target} with drift of {drift}%")
|
||||
|
||||
# Our own "Elastic Constraints"
|
||||
problem += lpSum(
|
||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
||||
) >= tif_target - (tif_target * drift_percent), 'TifIifMin'
|
||||
problem += lpSum(
|
||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
||||
) <= tif_target + (tif_target * drift_percent), 'TifIifMax'
|
||||
# Our own "Elastic Constraints"
|
||||
problem += lpSum(
|
||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
||||
) >= tif_target - (tif_target * drift_percent), 'TifIifMin'
|
||||
problem += lpSum(
|
||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
||||
) <= tif_target + (tif_target * drift_percent), 'TifIifMax'
|
||||
|
||||
problem.solve()
|
||||
problem.solve()
|
||||
|
||||
if LpStatus[problem.status] == 'Infeasible':
|
||||
print(f"attempt infeasible for drift of {drift}")
|
||||
if LpStatus[problem.status] == 'Infeasible':
|
||||
print(f"attempt infeasible for drift of {drift}")
|
||||
|
||||
for v in problem.variables():
|
||||
print(v.name, "=", v.varValue)
|
||||
for v in problem.variables():
|
||||
print(v.name, "=", v.varValue)
|
||||
|
||||
print(problem.constraints)
|
||||
print(problem.objective)
|
||||
print(problem.objective.value())
|
||||
print(problem.constraints)
|
||||
print(problem.objective)
|
||||
|
||||
drift += 1
|
||||
drift += 1
|
||||
|
||||
else:
|
||||
print(f"solution found with drift of {drift}!")
|
||||
else:
|
||||
print(f"solution found with drift of {drift}!")
|
||||
|
||||
for v in problem.variables():
|
||||
print(v.name, "=", v.varValue)
|
||||
for v in problem.variables():
|
||||
print(v.name, "=", v.varValue)
|
||||
|
||||
print(problem.constraints)
|
||||
print(problem.objective)
|
||||
print(problem.constraints)
|
||||
print(problem.objective)
|
||||
|
||||
break
|
||||
break
|
||||
|
||||
# Implementation of the Whiskas Cat problem, with elastic constraints
|
||||
# https://www.coin-or.org/PuLP/CaseStudies/a_blending_problem.html
|
||||
|
Loading…
x
Reference in New Issue
Block a user