3

I am new in using Gekko, I am setting up a problem as

def optimise():

    m = GEKKO() # Initialize gekko
    m.options.SOLVER=1  # APOPT is an MINLP solver

    # optional solver settings with APOPT
    m.solver_options = ['minlp_maximum_iterations 500', \
                    # minlp iterations with integer solution
                    'minlp_max_iter_with_int_sol 10', \
                    # treat minlp as nlp
                    'minlp_as_nlp 0', \
                    # nlp sub-problem max iterations
                    'nlp_maximum_iterations 50', \
                    # 1 = depth first, 2 = breadth first
                    'minlp_branch_method 1', \
                    # maximum deviation from whole number
                    'minlp_integer_tol 0.05', \
                    # covergence tolerance
                    'minlp_gap_tol 0.01']

    # Initialize variables
    x=[]
    for i in range(0,18) :
        x.append(m.Var(lb=4,ub=21,integer=True))

    #initialise objective
    m.Obj(simulate_game(x)) # Objective
    m.options.IMODE = 3 
    m.solve(disp=True) # Solve
    print('Results')
    print('Strategy:'+str(initialise_strategy(x)))
    print('Objective: ' + str(m.options.objfcnval))

where simulate_game(x) is an external function that given a parametrise strategy computes the performance in the game. When I run the solver I get the following output

apm 90.250.179.168_gk_model16 <br><pre> ----------------------------------------------------------------
 APMonitor, Version 0.9.2
 APMonitor Optimization Suite
 ----------------------------------------------------------------


 Warning: there is insufficient data in CSV file 90.250.179.168_gk_model16.csv

 --------- APM Model Size ------------
 Each time step contains
   Objects      :            0
   Constants    :            0
   Variables    :           18
   Intermediates:            0
   Connections  :            0
   Equations    :            1
   Residuals    :            1

 ________________________________________________
 WARNING: objective equation           1 has no variables
 ss.Eqn(1)
 0 = -0.06
 ________________________________________________
 Number of state variables:             18
 Number of total equations: -            0
 Number of slack variables: -            0
 ---------------------------------------
 Degrees of freedom       :             18

 ----------------------------------------------
 Steady State Optimization with APOPT Solver
 ----------------------------------------------
Iter:     1 I:  0 Tm:      0.00 NLPi:    1 Dpth:    0 Lvs:    0 Obj: -6.00E-02 Gap:  0.00E+00
 Successful solution

 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :   3.450000000884756E-002 sec
 Objective      :  -6.000000000000000E-002
 Successful solution
 ---------------------------------------------------

It seems to me that some of the warning in the output are telling what the problem is but I cannot really interpret them... I do not have equations because I do not have constraints in my problem... Any help is greatly appreciate. Apologies in advance for the beginner question.

1 Answer 1

1

The problem is with m.Obj(simulate_game(x)) as you guessed. Gekko cannot use a black-box model but needs to constuct the model either from data (such as a c-spline, b-spline, machine learning, time series modeling) or with closed-form equations. If you need to use a black-box model, another optimizer may be better for your application. Here is a related question about integer variables in Python: Restrict scipy.optimize.minimize to integer values

Sign up to request clarification or add additional context in comments.

1 Comment

That was my doubt indeed... thanks for confirming it! I'll look for an alternative as my function is a black box. Thanks for the link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.