I'm trying to include a "great M" penalty in my objective function.
I want use the entry x vector values as entry values in a function. A fixed maximum value is took initially for the returned value of this function, and I want to avoid the solutions which, with x values given, returns values higher than the fixed one.
How is the best way to do it?
I wrote some code with an approach but I don't know if it is a good way to do that
#from calculator import calculateConcentration
'GEKKO MODELING'
from gekko import GEKKO
m = GEKKO()
m.options.SOLVER=1 # APOPT is an MINLP solver
a_max = 30
# Initialize variables
x = []
x1 = m.Var(value=20,lb=20, ub=6555) #integer=True
x2 = m.Var(value=0,lb=0,ub=10000) #integer=True
x3 = m.sos1([30, 42, 45, 55])
x = [x1, x2, x3]
# Equations
m.Equation((x1 * x2* x3) * 10 ** (-6)>=50)
def fun(x):
return 44440 + ((np.pi * x[0] * x[1] * x[2]) * 10 ** (-4))**0.613 #+ penalty(x)
#def penalty(x):
# a = calculateConcentration(x)
# if (a>a_max):
# return 10**10
# else:
# return 0
x = [400,300,19]
'GEKKO Optimization'
m.Obj(fun(x))
m.solve(disp=False) # Solve
print('Results')
print('x1: ' + str(x1.value))
print('x2: ' + str(x2.value))
print('x3: ' + str(x3.value))
print('Objective: ' + str(m.options.objfcnval))