I wonder if we can limit variable range between a non-interger numbers , but discrete ones. Let say I have an array of N=[[2.3 ,4.5, 5.8] , [6.4,7.1,4.1]] . A is a variable array elment of N[0,i] for i<3, which means A = 2.3,4.5,5.8 . B is a variable and = array elment of N[1,i] for i<3 which means B = 6.4,7.1,4.1 . A,B are discrete by not integer. I want to find max of c = a+ b . so a = 4.5, b =7.1 . I am looking forward to you response. Thank you.
If A
and B
are separate variables then use the sos1()
function to define them as discrete, non-integer values.
from gekko import GEKKO
m = GEKKO()
A = m.sos1([2.3,4.5,5.8])
B = m.sos1([6.4,7.1,4.1])
m.Maximize(A+B)
m.solve()
print(A.value,B.value)
If the index must be the same for both A
and B
(same column) then define C
as an sos1()
type.
from gekko import GEKKO
import numpy as np
m = GEKKO()
A = np.array([2.3,4.5,5.8])
B = np.array([6.4,7.1,4.1])
C = m.sos1(A+B)
m.Maximize(C)
m.solve()
print(C.value)
Here is more information on Special Ordered Sets the sos1()
type in the Gekko documentation.