1

I want that a design variable assumes only specified values during optimization process.

For example: Let x be the variable which can assume only specific value, e.g.:

x = [0.1,0.5,1.0,1.7,2.3]

How can be written in python using pyomo (if it's possible)?

I hope I was clear.

  • You might want to edit your question to make it clear that you are looking for a syntax that will allow you to define variables like this automatically -- not for a modeling trick in which you declare new variables to accomplish this. – LarrySnyder610 May 30 '19 at 12:38

1 Answers1

3

You have to do this with integer variables. For example, if there are N possible values of x, then let x[n] = 1 if x equals the nth possible value, and 0 otherwise. Any time you have an x in your original model, replace it with

sum {n=1,...,N} v[n] * x[n]

where v[n] is the nth possible value. Finally, add a constraint that says:

sum {n=1,...,N} x[n] == 1 

I'm not writing these in Pyomo syntax, but this is a general modeling approach that is the same no matter what modeling language/package you use.

LarrySnyder610
  • 2,277
  • 12
  • 24
  • Thank you for the answer. I've already modelled the problem as a MINLP, i've already defined the variable as an integer variable. But now i want to be more specific. – cicciobombacannoniere May 29 '19 at 21:40
  • More specific about what? Are you asking whether you can model variables that come from a discrete set, in Pyomo, *without* declaring new integer variables? – LarrySnyder610 May 29 '19 at 21:43
  • Maybe I didn't explain myself clearly, I'm sorry. What I want to do is declare that my variable can take only specific values, such as those in a list, which I fill personally. – cicciobombacannoniere May 30 '19 at 07:06
  • 1
    In that case, I don't think it's possible to do this automatically. For example, if you declare `model.A = Set(initialize=[0.1,0.5,1.0,1.7,2.3])` and then declare your variable like `model.x = Var(domain=model.A)`, Pyomo gives an error that the domain is not continuous, integer or binary -- suggesting that those are the only allowable domains. However, note that even if Pyomo *could* do what you are asking, it would still convert to integer variables "behind the scenes", so it might be easier syntactically but it would not be faster computationally. – LarrySnyder610 May 30 '19 at 12:37