Closed elegantcoin closed 4 years ago
If your objective function is very long, you can also use multiple m.Obj
declarations as:
# original
m.Obj(sum(expr))
# modified 1
for i in range(len(expr)):
m.Obj(expr[i])
# modified 2
m.Obj(m.sum(expr))
Regarding the if-else
statements, you need to use the if3
or if2
functions in Gekko if the conditions are based on variables from the problem. If they are based on fixed values like constants that are specified at run-time then it is fine to use python if-else
statements.
These are great questions. Could you post questions like this to StackOverflow with tag [gekko]?
@elegantcoin are you suggesting modifying the Obj method to automatically separate long objective functions to multiple lines? I think that's a great idea. We'll have to be really careful about breaking at appropriate +/- operators.
@elegantcoin are you suggesting modifying the Obj method to automatically separate long objective functions to multiple lines? I think that's a great idea. We'll have to be really careful about breaking at appropriate +/- operators.
Yeah, that's exactly what I mean. And I agree with the considuration of breaking at appropriate +/- operators. Thank you!
.Obj(m.sum(expr
Wow, Thank you! I have tried
modified 1
and it works perfectly.
Let us know if you need any additional help.
In my object function,I have 70*10 dimensional variables, and the error info is as follows:
can I add
if-else
in the source code of theObj(self,obj)
function ingekko.py
?def Obj(self,obj):
self._objectives.append('minimize ' + str(obj))