Search code examples
python-3.xpyomo

Can Pyomo Optimise equations inside functions


I am trying to Maximize 10 very long linear equations, All equations are similar except for one variable (say Z).

I was thinking of putting a single equation inside a function and pass Z as a parameter.

Can we optimise the python functions?

I have looked into pyomo,pulp,cvxpy documentations and haven't found any code samples. which makes me think it this isn't possible

#This is what currently it is 

Maximize 

(X*fun(1,Z))   +  (X2*fun(1,Z)) + ...
(X*fun(1,Z1))  +  (X2*fun(1,Z1)) + ...
..
..
Solve for
X1 and X2


#This an example what I am trying to do

Def optimise(Z):
   (X*fun(1,Z))  +  (X2*fun(1,Z)) + ...
Maximize
optimise(13)
optimise(24)
optimise(34)
optimise(14)
optimise(12)
optimise(11)  #is optimizing with funtions possible ?

Solve for
X1 and X2

Solution

  • It depends on what your function returns. Pyomo is an algebraic modeling language and requires access to the full algebraic equations. If your Python function returns an expression involving Pyomo Var components then it should work. If the function simply returns a value depending on the current value of a Pyomo Var then it will not work. You need to provide more details on the function and the model you're trying to solve for us to say for sure if it's supported or not.