I want a binary variable, $inv_year$, to indicate the investment year, i.e., the year where the investment variable, $I$, turns greater than zero for the first time. Both variables ($inv_year$ and $I$) have two indices, time $t$ and project $i$.
In theory, the variable $inv_year[i,t]$ should equal to 1 for the minimum of time $t$ when I[i,t] is greater than 0. It should turn 1 once for each project $i$ to indicate the investment year for that project.
I am using the Big M method in Pyomo, but right now the binary variable, $inv_\year$, turns 1 always when the variable $I$ turns greater than zero. Therefore, the binary investment year variable equals 1 multiple times, rather than only once for each project.
Is there a ways to adjust the Big M method to work like this or do I have to use a different method for this purpose?
Right now, my solution looks as follows:
#First constraint, Big-M method for binary variable inv_year
def bigM_constraint1(model, i, t):
lhs_1 = model.inv_year[i,t]
rhs_1 = model.I[i,t]
return lhs_1<=rhs_1
#add the rule to the model as a constraint
model.BigM_Constraint1 = Constraint(model.project_type, model.time, rule=bigM_constraint1)
#Second constraint, Big-M method for binary variable inv_year
def bigM_constraint2(model, i, t):
lhs_2 = model.I[i,t]
rhs_2 = model.M[i] * model.inv_year[i,t]
return lhs_2<=rhs_2
#add the rule to the model as a constraint
model.BigM_Constraint2 = Constraint(model.project_type, model.time, rule=bigM_constraint2)