BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization

Home Page:https://machinelearning.byu.edu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimization within a set of numbers

keeeen5678 opened this issue · comments

Dear,
I wonder if there is a function to set our variable to differ within set of number. For example [0.5,0.3,.8] . Let the final answer select which one amongst the 3 perform best.

Try the m.sos1() function as shown here: https://scicomp.stackexchange.com/questions/33253/minlp-with-gekko-modeling-discrete-variables and in the documentation: https://gekko.readthedocs.io/en/latest/model_methods.html For future questions, please post to Stack Overflow with tag gekko.

Thank you. But another issue is I am facing is probably indexing a pair of values. Please have a short look at my code

import numpy as np
from gekko import GEKKO
import random
m = GEKKO(remote=True)
Total_Cost = 16000000
Total_Duration = 200
Q = 10000
k = 1
f = 0.87
E = 0.7
s_load = 7 
s_empty = 8 
dist = 0.3
dens = 1200
cm = 0.98
rand_index_l = 0
rand_index_t = 0
l_min= 1
l_max= 1
t_min= 1
t_max= 3

## PARAMETER
Total_Cost = m.Param(Total_Cost)
Total_Duration = m.Param(Total_Duration)
Q = m.Param(Q)
k = m.Param(k)
f = m.Param(f)
E = m.Param(E)
s_load = m.Param(s_load)
s_empty = m.Param(s_empty)
dist = m.Param(dist)
dens = m.Param(dens)
cm= m.Param(cm)
rand_index_l = rand_index_l
rand_index_t = rand_index_t
l_min= l_min
l_max= l_max
t_min= t_min
t_max= t_max

#Travel_Time = m.Const((dist/s_load+dist/s_empty)*60)

#VARIABLE

l_s = [2.5, 1.7,1]
l_c = [21000, 19000,17000]
t_s = [20,25.5,15]
t_c = [62500,80000,57000]

#rand_index = m.Const(m.Var(value=0,lb=1, ub=2, integer =True))
Loader = m.Var(value = 1, lb=l_min, ub=l_max,integer = True)
Loader_Size = m.FV(l_s[rand_index_l])
Loader_Cost = m.FV(l_c[rand_index_l])
Truck = m.Var(value = 1, lb=t_min, ub=t_max,integer = True)
Truck_Size = m.FV(t_s[rand_index_t])
Truck_Cost = m.FV(t_c[rand_index_t])

In here I was wondering if there is any variable function to let the algorithm search for the right combination of index to meet a certain objective without setting the initial value. Because as describe below, for examplet when l_s=1.7, l_c must equal to 19000, the same way for t_s=25.5, t_c must equal to 80000
l_s = [2.5, 1.7,1]
l_c = [21000, 19000,17000]
t_s = [20,25.5,15]
t_c = [62500,80000,57000]

Try a cubic spline:

# Create model
c = gekko()

# Cubic spline
x = c.Var()
y = c.Var()
x_data = l_s
y_data = l_c
c.cspline(x,y,x_data,y_data,True)

This allows the optimizer to have continuous derivatives as it is searching for a solution but then is exactly equal to that lookup. Please ask additional questions on Stack Overflow: https://stackoverflow.com/questions/tagged/gekko