BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization
https://machinelearning.byu.edu
Other
580 stars 103 forks source link

APM model error: string > 15000 characters #72

Closed elegantcoin closed 4 years ago

elegantcoin commented 4 years ago

In my object function,I have 70*10 dimensional variables, and the error info is as follows:

APM model error: string > 15000 characters Consider breaking up the line into multiple equations

The may also be due to only using newline character CR instead of CR LF (for Windows) or LF (for MacOS/Linux) To fix this problem, save APM file with appropriate newline characters

STOPPING...

raise Exception(response) Exception: @error: Max Equation Length

can I add if-else in the source code of the Obj(self,obj) function in gekko.py? def Obj(self,obj): self._objectives.append('minimize ' + str(obj))

APMonitor commented 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]?

loganbeal commented 4 years ago

@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 commented 4 years ago

@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!

elegantcoin commented 4 years ago
.Obj(m.sum(expr

Wow, Thank you! I have tried modified 1 and it works perfectly.

APMonitor commented 4 years ago

Let us know if you need any additional help.