Peer
Peer

Reputation: 51

Gekko Optimization Suite for Python - if3 always <0

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!

Upvotes: 3

Views: 85

Answers (1)

Peer
Peer

Reputation: 51

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.

Upvotes: 2

Related Questions