【问题标题】:Gekko non linear mixed integer programming. Problem setting up objective functionGekko 非线性混合整数规划。设置目标函数的问题
【发布时间】:2020-09-22 19:49:04
【问题描述】:

我是使用 Gekko 的新手,我正在设置一个问题

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))

其中simulate_game(x) 是一个外部函数,它给定一个参数化策略来计算游戏中的性能。 当我运行求解器时,我得到以下输出

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
 ---------------------------------------------------

在我看来,输出中的一些警告说明了问题所在,但我无法真正解释它们……我没有方程式,因为我的问题没有约束……任何帮助都是非常感谢。对于初学者的问题,请提前道歉。

【问题讨论】:

    标签: gekko


    【解决方案1】:

    问题出在m.Obj(simulate_game(x)),正如您所猜测的那样。 Gekko 不能使用黑盒模型,但需要根据数据(例如 c-splineb-splinemachine learningtime series modeling)或使用封闭式方程来构建模型。如果您需要使用黑盒模型,另一个优化器可能更适合您的应用程序。这是一个关于 Python 中整数变量的相关问题:Restrict scipy.optimize.minimize to integer values

    【讨论】:

    • 这确实是我的疑问...感谢您的确认!我会寻找替代方法,因为我的功能是一个黑匣子。感谢您的链接
    猜你喜欢
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 2021-02-23
    相关资源
    最近更新 更多