-1

I want to declare a variable in PYOMO which must take any of the three values.

For example, the variable must take a value from these 0.037364, 0.03174, 0.03797.

Model.cost =Var(within=NonNegativeReals)??

1 Answers1

0

model.A=Set(initialize=[0.037364, 0.03174, 0.03797])

model.Y=Var(within=model.A)

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 25 '22 at 12:37
  • I do not believe this to be a complete answer. This will just create an indexed variable using the set "A", and not assign the values to "Y". The set need not have the exacts values, just an arbitrary index. Then create a parameter which holds these values, a binary variable indexed over set "A" and then a constraint to assign only one of those values to the variable. I think? – EJay Apr 26 '22 at 23:23
  • Thanks for highlighting the issue. Did you mean this way? model.A = Set(initialize=[0.037364, 0.03174, 0.03797) model.y = Var(within=model.A) model.r = Var(domain=Reals) model.w = Var(within=Boolean) If I am still wrong, please guide – Waqas Swati Apr 30 '22 at 15:12