Hi,
Is there any way to use different indexing for same variable in the same script? The reason for trying this thing is that a variable behaves the same way but needs to be indexed differently to be used in different equations since the constraints are different for different components. Can anyone refer me to some example code.
Regards,
Jubeyer
Hi,
To cut it short, no.
Maybe you can provide a more elaborate example why you would want to do that. That might be helpful to suggest alternatives.
Best,
Fred
For example as a part of an optimization problem I need to calculate the electricity generation cost from different types of plant by this formula : generation*fuel_price. But for different fuels the price varies so even though the variable generation’s name is same but should be used with different indices for different fuels. generation(gas)*fuel_price(gas)+generation(Oil)*fuel_price(Oil)+…
Your example can written as a sum: sum(f, generation[f] * fuel_price[f])
where f is a set containing your different fuel types such as gas and oil.
You can also insert the set elements directly, for example: generation[“oil”] * fuel_price[“oil”] + generation[“gas”] * fuel_price[“gas”].
Does this solve your problem or could you give a different example?
Okay, this seems like the most common way to use an indexed variable… I had something different in mind when I read your initial question.
Fred
Sorry, I guess my example problem really didn’t match like my original problem ( I cannot share the exact formulation since it’s proprietary). But I guess, you can get it from the following description. Actually, I could have written the way you have shown but the problem is I need a fixed group of generators to be treated differently for some reason, since they belong to a different set (not in the sense that they are not generators but they belong to a different entity). So, for example I have Oil, gas, coal, nuclear plants whereas Oil,gas and coal is owned by a particular entity and nuclear is owned by another. And I am trying to do some optimization on the nuclear side as well so I don’t want them to be treated altogether but separately. It can be seen as a bilevel optimization (I am not sure whether I am quite certain about this, could be two-stage optimization ) problem where both of the entities are not solved simultaneously but in a sequential manner.
Hi,
What about
set p plants / Oil, gas, coal, nuclear /
p1(p) / Oil, gas, coal /
p2(p) / nuclear /
;
When you need to refer to all of them, use p.
When you need to refer to Oil, gas, coal, use p1.
When you need to refer to nuclear, use p2.
Fred