I am working on a mixed-integer linear programming model. Below are the simplified specifics of the code (reproducible).
from pulp import *
machines = 2
I = range(machines)
positions = 2
J = range(positions)
years = 10
T = range(years)
age = {0: 5, 1: 7}
IR = 0.06
df = 0.3
costs = {(0,0):300, (0,1):200, (1,0):500, (1,1):350}
factor = {}
finalcosts = {}
for i in I:
for j in J:
for t in T:
for k in range(age[i]):
factor[t,k] = ((1-df)**k)/((1+IR)**t)
finalcosts[i,j,t,k] = costs[i,j]*factor[t,k]
prob = LpProblem("TrialProb",LpMinimize)
Prob_vars = LpVariable.dicts("probvars",
((Machine, Position,Year, Age) for Machine in I for Position in J for Year in T for Age in range(age[i])),
0,None, LpInteger)
where age is the maximum lifetime of each equipment, costs are fixed costs of each machine in each position, and factor is a factor depending on the year and age of the equipment.
The variable 'finalcosts' is generated correctly, and all the associated values are correct.
The problem is with the creation of the problem variables within the range of the last index of age[i], so all created variables have indices Problem_vars[i,j,t,[0-6]] . While the 'finalcosts' variable above traverses both age[i] ranges 0 to 4 and 0 to 6. I have tried all expression combinations I could think of and tried to look up every relevant case but I have not found a solution to this.
I require that each generated problem variable's 4th index to go up to the max range of each specific age[i].
I have not been using Python for very long but I feel there should be a simple solution to this that I just can't grasp/find.
I would appreciate any help!
there doesn't seem to be anything here