我正在尝试开始使用YALMIP,这是一个Matlab接口,用于优化求解器,如CPLEX我有一个目标函数和约束条件,我把它们插入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'

在上面的代码中,obj打印警告:找不到解算器包含conssolvesdp.m和对Yalmip的调用在我朋友的计算机上工作,我们对它为什么不在我的计算机上工作感到困惑。
下面是我在我的Ubuntu12.04机器上用Matlab R2012b为CPLEX和Yalmip所做的设置步骤:
在此处安装IBM CPLEX:obj
在此处安装Yalmip:cons
将CPLEX和YALMIP添加到我的Matlab路径中(并确认所有目录都存在):
    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,我运行了/home/user/ibm/ILOG/CPLEX_Studio125/cplex它给出了有效的输出:
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.
...

此外,home/user/yalmip还提供此输出:help cplexlp
并且which cplex给出这个输出:/home/user/ibm/ILOG/CPLEX_Studio125/cplex/matlab/@Cplex/Cplex.p
我在Matlab命令提示符下运行了which yalmip输出验证了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论坛,寻找对此的答案一个朋友给我指了指关于诊断CPLEX/Yalmip的this post in the IBM forums,但是这个帖子更关注Windows,并没有真正解决我的问题。
更多细节:
Yalmip版本2012-09-26
CPLEX版本12.5

最佳答案

在深入研究Yalmip源代码之后,我最终发现了问题所在。
在Yalmip源代码中,有一个名为yalmip/solvers/definesolvers.m的文件在definesolvers.m中,有很多这样的语句:

solver(i) = lpsolver;
solver(i).tag     = 'CPLEX';
solver(i).version = 'IBM';
solver(i).subversion = '12.4';
solver(i).checkfor = {'cplexlp.m','cplexlink124'};
...

这些语句存在于CPLEX 12、12.1、12.2、12.3和12.4。但是,我使用的是CPLEX 12.5,对于cplex12.5没有这样的语句。
我用12.4替换了12.5的所有实例,用cplexlink124替换了cplexlink125的实例我的优化代码现在可以工作了!
以下是yalmiptest的新输出:
>> yalmiptest
+++++++++++++++++++++++++++++++++++++++++++++++
|       Searching for installed solvers       |
+++++++++++++++++++++++++++++++++++++++++++++++
|        Solver|   Version/module|      Status|
+++++++++++++++++++++++++++++++++++++++++++++++
|         CPLEX|              IBM|       found|
|         CPLEX|              IBM|       found|
|         CPLEX|              IBM|       found|
|       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 12.0、12.1、12.2和12.3。

关于matlab - CPLEX + YALMIP —“找不到求解器”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13556208/

10-13 06:11