5

我正在尝试开始使用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包含objcons和对 Yalmip 的调用可以在我朋友的计算机上运行,​​我们很困惑为什么它不能在我的计算机上运行。


以下是我在Ubuntu 12.04机器上使用Matlab R2012b进行的 CPLEX 和 Yalmip 的设置步骤:

  1. 在此处安装 IBM CPLEX:/home/user/ibm/ILOG/CPLEX_Studio125/cplex
  2. 在这里安装 Yalmip:home/user/yalmip
  3. 在我的 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
4

1 回答 1

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.0、12.1、12.2、12.3 和 12.4。但是,我使用的是 CPLEX 12.5,并且对于 CPLEX 12.5 没有这样的声明。

我替换了 with 的所有实例12.412.5替换了cplexlink124with的实例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。

于 2012-11-26T01:00:29.497 回答