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
|
||||
|
||||
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
|
||||
tif = {
|
||||
1: 10,
|
||||
2: 20,
|
||||
3: 40,
|
||||
4: 60,
|
||||
5: 80
|
||||
2: 20
|
||||
}
|
||||
|
||||
iif = {
|
||||
1: 10,
|
||||
2: 20,
|
||||
3: 30,
|
||||
4: 50,
|
||||
5: 70
|
||||
4: 40,
|
||||
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
|
||||
max_drift = 10 # 10% elasticity
|
||||
@ -91,20 +90,27 @@ class SolverSandbox:
|
||||
problem = LpProblem('TIF_TCC', LpMinimize)
|
||||
|
||||
# objective function
|
||||
problem += lpSum([(tif[i] + iif[i]) * items[i] for i in Items])
|
||||
problem += lpSum([items[i] for i in Items])
|
||||
|
||||
# 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}%")
|
||||
|
||||
# Our own "Elastic Constraints"
|
||||
problem += lpSum(
|
||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
||||
) >= tif_target - (tif_target * drift_percent), 'TifIifMin'
|
||||
[iif[i] * items[i] for i in Items]
|
||||
) >= tif_target - (tif_target * drift_percent), 'ItemIifMin'
|
||||
problem += lpSum(
|
||||
[(tif[i] + iif[i]) * items[i] for i in Items]
|
||||
) <= tif_target + (tif_target * drift_percent), 'TifIifMax'
|
||||
[iif[i] * items[i] for i in Items]
|
||||
) <= 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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user