繁体   English   中英

GEKKO 的二进制优化

[英]Binary Optimization for GEKKO

我试图通过随机定义一个 NxN 对称矩阵和一个 N 维偏置向量来解决带有qobj的 Gekko 的二次二元优化问题。 然而,我观察到计算时间非常低:2e-2s 用于解决 N=20 和 0.05s 以解决 200 维问题。 此外,我的迭代次数永远不会超过 3-4 次。 我在这里错过了什么吗?

import numpy as np
N = 20
#create square symmetric matrix for the quadratic term
b = np.random.normal(0,1,(N,N))
Q = (b + b.T)/2
#bias vector for linear term
c=np.random.normal(0,1,N)
from gekko import GEKKO
m = GEKKO(remote=False)
z = m.Array(m.Var,N,integer=True,lb=0,ub=1,value=1)
m.qobj(c,A=Q,x=z,otype='min')
m.solve(disp=True)

任何建议表示赞赏!

切换到混合 Integer 解决方案的 APOPT 求解器。

m.options.SOLVER=1

这是完整的脚本。 MIQP 问题通常非常快。 如果问题是非线性 (NLP) 与混合 integer 元素 (MINLP),它会显着减慢。

import numpy as np
N = 200
#create square symmetric matrix for the quadratic term
b = np.random.normal(0,1,(N,N))
Q = (b + b.T)/2
#bias vector for linear term
c=np.random.normal(0,1,N)
from gekko import GEKKO
m = GEKKO(remote=False)
z = m.Array(m.Var,N,integer=True,lb=0,ub=1,value=1)
m.qobj(c,A=Q,x=z,otype='min')
m.options.SOLVER=1
m.solve(disp=True)
print(z)
[[0.0] [1.0] [1.0] [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [0.0] [1.0] [1.0]
 [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [0.0] [1.0] [1.0] [1.0]
 [1.0] [1.0] [1.0] [1.0] [0.0] [1.0] [0.0] [1.0] [1.0] [0.0] [0.0] [0.0]
 [0.0] [1.0] [1.0] [0.0] [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [0.0] [1.0]
 [1.0] [1.0] [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [0.0]
 [0.0] [1.0] [0.0] [0.0] [0.0] [0.0] [1.0] [1.0] [0.0] [0.0] [0.0] [0.0]
 [1.0] [1.0] [0.0] [0.0] [1.0] [1.0] [0.0] [1.0] [1.0] [0.0] [1.0] [1.0]
 [0.0] [1.0] [0.0] [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0]
 [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0]
 [1.0] [1.0] [1.0] [0.0] [0.0] [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0]
 [0.0] [0.0] [1.0] [1.0] [0.0] [1.0] [0.0] [1.0] [0.0] [1.0] [1.0] [1.0]
 [0.0] [0.0] [0.0] [0.0] [1.0] [0.0] [0.0] [1.0] [1.0] [0.0] [0.0] [1.0]
 [1.0] [1.0] [0.0] [1.0] [0.0] [0.0] [1.0] [1.0] [1.0] [1.0] [0.0] [1.0]
 [0.0] [0.0] [0.0] [0.0] [0.0] [0.0] [1.0] [1.0] [1.0] [1.0] [1.0] [0.0]
 [0.0] [0.0] [1.0] [1.0] [1.0] [1.0] [0.0] [1.0] [0.0] [0.0] [1.0] [1.0]
 [0.0] [0.0] [0.0] [1.0] [1.0] [1.0] [0.0] [1.0] [0.0] [1.0] [0.0] [0.0]
 [0.0] [1.0] [1.0] [1.0] [0.0] [1.0] [1.0] [0.0]]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM