Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gekko Optimization Suite for Python - if3 always <0

Tags:

python

gekko

I am using python 3.8.10 and gekko 1.0.1. I tried to use the model.if3 to check if variables are equal or not with an inner -model.abs3. I observed a strange behavior which I could not explain and that is why I ran the sample code from https://gekko.readthedocs.io/en/latest/model_methods.html (if3):

import numpy as np
import matplotlib.pyplot as plt
from gekko import GEKKO
m = GEKKO(remote=False)
p = m.Param()
y = m.if3(p-4,p**2,p+1)

# solve with condition<0
p.value = 3
print(p.value)
m.solve(disp=False)
print(y.value)

# solve with condition>=0
p.value = 5
print(p.value)
m.solve(disp=False)
print(y.value)

but I got the following output:

3
[9.0]
5
[9.0]

I would be very grateful for any help!

like image 215
Peer Avatar asked Apr 14 '26 23:04

Peer


1 Answers

I upgraded gekko 1.0.1 to gekko 1.0.2 and this resolved my problem. Maybe there was something wrong in my cached variables or upgrading fixed that issue.

like image 109
Peer Avatar answered Apr 16 '26 13:04

Peer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!