我正在尝试开始使用YALMIP,它是优化求解器(如CPLEX )的 Matlab 接口。我有一个目标函数obj
和约束cons
,我已经将它们插入 Yalmip ......
options=sdpsettings('solver','Cplex'); %windows needs uppercase 'Cplex' and unix is ok with 'cplex' or 'Cplex'
solvesdp(cons,obj,options); %prints 'Warning: Solver not found'
在上面的代码中,solvesdp
打印出警告:未找到求解器。.m
包含obj
、cons
和对 Yalmip 的调用可以在我朋友的计算机上运行,我们很困惑为什么它不能在我的计算机上运行。
以下是我在Ubuntu 12.04机器上使用Matlab R2012b进行的 CPLEX 和 Yalmip 的设置步骤:
- 在此处安装 IBM CPLEX:
/home/user/ibm/ILOG/CPLEX_Studio125/cplex
- 在这里安装 Yalmip:
home/user/yalmip
- 在我的 Matlab 路径中添加了 CPLEX 和 Yalmip(并确认所有目录都存在):
addpath(genpath('/home/user/yalmip'))
addpath(genpath('/home/user/ibm/ILOG/CPLEX_Studio125/cplex/matlab'))
addpath(genpath('/home/user/ibm/ILOG/CPLEX_Studio125/cplex/examples/src/matlab'))
下面,我将解释我是如何尝试诊断问题的。很明显,Matlab 可以看到 CPLEX,Matlab 可以看到 Yalmip,但是 Yalmip 看不到 CPLEX。
确认 Yalmip 和 CPLEX 在我的 matlab 路径中:
MATLAB> path
/home/user/ibm/ILOG/CPLEX_Studio125/cplex/examples/src/matlab
/home/user/ibm/ILOG/CPLEX_Studio125/cplex/matlab
/home/forrest/ibm/ILOG/CPLEX_Studio125/cplex/matlab/help
/home/forrest/ibm/ILOG/CPLEX_Studio125/cplex/matlab/help/helpsearch
/home/forrest/ibm/ILOG/CPLEX_Studio125/cplex/matlab/help/topics
/home/user/yalmip
/home/user/yalmip/demos
/home/user/yalmip/extras
/home/user/yalmip/modules
/home/user/yalmip/modules/bilevel
/home/user/yalmip/modules/global
/home/user/yalmip/modules/moment
/home/user/yalmip/modules/parametric
/home/user/yalmip/modules/robust
/home/user/yalmip/modules/sos
/home/user/yalmip/operators
/home/user/yalmip/solvers
...
为了验证 Matlab 确实可以找到 CPLEX,我运行了help cplexlp
. 它给出了有效的输出:
MATLAB> help cplexlp
cplexlp
Solve linear programming problems.
x = cplexlp(f,Aineq,bineq) solves the linear programming problem min f*x such that Aineq*x <= bineq.
...
另外,which cplex
给出这个输出:/home/user/ibm/ILOG/CPLEX_Studio125/cplex/matlab/@Cplex/Cplex.p
并which yalmip
给出这个输出:/home/user/yalmip/extras/yalmip.m
我yalmiptest
在 Matlab 命令提示符下运行。输出验证 Matlab 可以找到 Yalmip,但 Yalmip 找不到 CPLEX:
MATLAB> yalmiptest
+++++++++++++++++++++++++++++++++++++++++++++++
| Searching for installed solvers |
+++++++++++++++++++++++++++++++++++++++++++++++
| Solver| Version/module| Status|
+++++++++++++++++++++++++++++++++++++++++++++++
| LINPROG| | found|
| QUADPROG| | found|
| LMILAB| | found|
| FMINCON| geometric| found|
| FMINCON| standard| found|
| FMINSEARCH| | found|
| BNB| | found|
| BINTPROG| | found|
| CUTSDP| | found|
| BMIBNB| | found|
| KKTQP| | found|
| NONE| | found|
| LSQNONNEG| | found|
| LSQLIN| | found|
| GUROBI| GUROBI| not found|
| GUROBI| MEX| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| IBM| not found|
| CPLEX| CPLEXINT| not found|
| CBC| | not found|
| GLPK| GLPKMEX-CC| not found|
我还查看了 IBM 论坛以寻找答案。一位朋友向我指出了 IBM 论坛中关于诊断 CPLEX/Yalmip 的这篇文章,但这篇文章更侧重于 Windows,并没有真正解决我的问题。
更多细节:
- Yalmip 版本 2012-09-26
- CPLEX 版本 12.5