modify the sandbox to get it more closer to the actual impl
This commit is contained in:
parent
ff9d9b3d49
commit
ddb8efc79f
@ -61,27 +61,26 @@ class SolverSandbox:
|
|||||||
break
|
break
|
||||||
|
|
||||||
def yas_elastic(tif_target = 140.0): # 140 is the optimal
|
def yas_elastic(tif_target = 140.0): # 140 is the optimal
|
||||||
Items = [1,2,3,4,5]
|
Items = [1,2,3,4,5]
|
||||||
|
Bundles = [1,2]
|
||||||
|
|
||||||
# For TIF target
|
# For TIF target
|
||||||
tif = {
|
tif = {
|
||||||
1: 10,
|
1: 10,
|
||||||
2: 20,
|
2: 20
|
||||||
3: 40,
|
|
||||||
4: 60,
|
|
||||||
5: 80
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iif = {
|
iif = {
|
||||||
1: 10,
|
1: 10,
|
||||||
2: 20,
|
2: 20,
|
||||||
3: 30,
|
3: 30,
|
||||||
4: 50,
|
4: 40,
|
||||||
5: 70
|
5: 50
|
||||||
}
|
}
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
items = LpVariable.dicts('Item', Items, cat='Binary')
|
items = LpVariable.dicts('Item', Items, cat='Binary')
|
||||||
|
bundles = LpVariable.dicts('Bundle', Bundles, cat='Binary')
|
||||||
|
|
||||||
drift = 0
|
drift = 0
|
||||||
max_drift = 10 # 10% elasticity
|
max_drift = 10 # 10% elasticity
|
||||||
@ -91,20 +90,27 @@ class SolverSandbox:
|
|||||||
problem = LpProblem('TIF_TCC', LpMinimize)
|
problem = LpProblem('TIF_TCC', LpMinimize)
|
||||||
|
|
||||||
# objective function
|
# objective function
|
||||||
problem += lpSum([(tif[i] + iif[i]) * items[i] for i in Items])
|
problem += lpSum([items[i] for i in Items])
|
||||||
|
|
||||||
# Constraint 1
|
# Constraint 1
|
||||||
problem += lpSum([items[i] for i in Items]) == 3, 'TotalItems'
|
problem += lpSum([items[i] for i in Items] + [bundles[b] for b in Bundles]) == 2, 'TotalItems'
|
||||||
|
|
||||||
print(f"Calculating TIF target of {tif_target} with drift of {drift}%")
|
print(f"Calculating TIF target of {tif_target} with drift of {drift}%")
|
||||||
|
|
||||||
# Our own "Elastic Constraints"
|
# Our own "Elastic Constraints"
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
[iif[i] * items[i] for i in Items]
|
||||||
) >= tif_target - (tif_target * drift_percent), 'TifIifMin'
|
) >= tif_target - (tif_target * drift_percent), 'ItemIifMin'
|
||||||
problem += lpSum(
|
problem += lpSum(
|
||||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
[iif[i] * items[i] for i in Items]
|
||||||
) <= tif_target + (tif_target * drift_percent), 'TifIifMax'
|
) <= tif_target + (tif_target * drift_percent), 'ItemIifMax'
|
||||||
|
|
||||||
|
problem += lpSum(
|
||||||
|
[tif[i] * bundles[i] for i in Bundles]
|
||||||
|
) >= tif_target - (tif_target * drift_percent), 'BundleTifMin'
|
||||||
|
problem += lpSum(
|
||||||
|
[tif[i] * bundles[i] for i in Bundles]
|
||||||
|
) <= tif_target + (tif_target * drift_percent), 'BundleTifMax'
|
||||||
|
|
||||||
problem.solve()
|
problem.solve()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user