首页 > 其他分享 >Matlab使用yalmip与cplex12.10

Matlab使用yalmip与cplex12.10

时间:2024-08-12 22:07:16浏览次数:7  
标签:end IBM CPLEX cplex12.10 Matlab found 安装 yalmip 12.6

本文同步发布于我的网站

软件版本

  • MATLAB R2023b
  • yalmip 2021-03-31
  • CPLEX 12.10

不求新,但求适配。此版本组合经过我在两台电脑上成功安装

下载链接

链接:https://pan.baidu.com/s/1-FBktdRcaCjRw62u76SQGw?pwd=fkl5

提取码:fkl5

安装yalmip

解压 YALMIP-master.zip,并将解压出来的 YALMIP-master 文件夹移动到 MATLAB安装目录\R2023b\toolbox下。

alt

启动MATLAB,在上方的主页中找到设置路径

点击添加并包含子文件夹

alt

找到方才移动的 MATLAB安装目录\R2023b\toolbox\YALMIP-master 文件夹,选择文件夹

alt

点击保存然后点击关闭

alt

这时候去命令行测试一下是否正常工作,在MATLAB命令行中输入 yalmiptest。如果有结果,说明yalmip安装成功。

首先映入眼帘的应该是一份很长很长的清单,这是在搜索已安装的求解器。向上滑动,可以看到不同版本的 CPLEX,但是其状态都为 not found

+++++++++++++++++++++++++++++++++++++++++++++++
|       Searching for installed solvers       |
+++++++++++++++++++++++++++++++++++++++++++++++
|        Solver|   Version/module|      Status|
+++++++++++++++++++++++++++++++++++++++++++++++
|         BARON|                 |   not found|
|      BINTPROG|                 |   not found|
|     BISECTION|                 |       found|
|        BMIBNB|                 |       found|
|           BNB|                 |       found|
|        BONMIN|                 |   not found|
|         BPMPD|                 |   not found|
|           CBC|                 |   not found|
|          CDCS|                 |   not found|
|           CDD|           CDDMEX|   not found|
|           CLP|        CLPMEX-LP|   not found|
|           CLP|        CLPMEX-QP|   not found|
|           CLP|             OPTI|   not found|
|      CONEPROG|                 |       found|
|         CPLEX|      IBM 12.10.0|   not found|
|         CPLEX|      IBM 12.10.0|   not found|
|         CPLEX|       IBM 12.9.0|   not found|
|         CPLEX|       IBM 12.9.0|   not found|
|         CPLEX|       IBM 12.8.0|   not found|
|         CPLEX|       IBM 12.8.0|   not found|
|         CPLEX|       IBM 12.7.1|   not found|
|         CPLEX|       IBM 12.7.1|   not found|
|         CPLEX|       IBM 12.7.0|   not found|
|         CPLEX|       IBM 12.7.0|   not found|
|         CPLEX|       IBM 12.6.3|   not found|
|         CPLEX|       IBM 12.6.3|   not found|
|         CPLEX|       IBM 12.6.2|   not found|
|         CPLEX|       IBM 12.6.2|   not found|
|         CPLEX|       IBM 12.6.1|   not found|
|         CPLEX|       IBM 12.6.1|   not found|
|         CPLEX|       IBM 12.6.0|   not found|
|         CPLEX|       IBM 12.6.0|   not found|
|         CPLEX|       IBM 12.5.1|   not found|

此时,你可以 Press any key to continue test 按下任意键以继续测试,也可以 Ctrl+C 以取消继续的测试。

安装CPLEX

双击 cplex_entserv1210.win-x86-64.exe 开始安装CPLEX。该过程中只有一个选择安装路径的选择,默认/安装到你想要安装的地方即可。

alt

(这一步我更换安装路径为 D:\Software\CPLEX1210

请记住安装路径,之后要用到。

如果您没有安装 Microsoft Visual C++ 2015 Redistributable Package (x64)的话,请点击下方链接以安装。安装的过程较为简单,在此不作赘述。

alt

恭喜!CPLEX12.10.0已经成功安装至你指定的目录

alt

现在回到MATLAB,继续设置路径添加并包含子文件夹,找到方才指定的CPLEX安装路径下CPLEX_Studio\cplex\matlab选择文件夹

alt

点击保存然后点击关闭

alt

重新在MATLAB命令行窗口中输入 yalmiptest

|           CLP|        CLPMEX-QP|   not found|
|           CLP|             OPTI|   not found|
|      CONEPROG|                 |       found|
|         CPLEX|      IBM 12.10.0|       found| <------!!!
|         CPLEX|      IBM 12.10.0|       found| <------!!!
|         CPLEX|       IBM 12.9.0|   not found|
|         CPLEX|       IBM 12.9.0|   not found|
|         CPLEX|       IBM 12.8.0|   not found|
|         CPLEX|       IBM 12.8.0|   not found|
|         CPLEX|       IBM 12.7.1|   not found|
|         CPLEX|       IBM 12.7.1|   not found|
|         CPLEX|       IBM 12.7.0|   not found|
|         CPLEX|       IBM 12.7.0|   not found|

可以注意到此时找到了CPLEX求解器。

实操测试

既然已经安装好了,那么就来用一道题目测试一下吧!

假设有一块原材料木板,长宽确定为 \(3000\times1500\),有两种切割形状(可是更多切割形状),切割形状 p1 为长宽 \((373,201)\),切割形状 p2 为长宽 \((406,229)\)。在保证原材料木板利用率最高的情况下,求两种切割数量以及最后的切割位置?

代码(解不出来的,这道题不能这样做……)

clear;
W = 3000;
H = 1500;
sizes = [373, 201; 406, 229];
% W = 15;
% H = 20;
% sizes = [3, 2; 4, 5];
numTypes = size(sizes, 1);

x=binvar(W,H,numTypes);
% cover=binvar(W,H);

C=[];
for t = 1:numTypes
    w = sizes(t, 1);
    h = sizes(t, 2);
    for i = 1:W
        fprintf("构建第%d行\n",i);
        for j = 1:H
            if i+w-1>W || j+h-1>H
                C = [C, x(i,j,t)==0];
            else
                % 如果在 (i, j) 放置了形状 t
                % 则 (i:i+w-1, j:j+h-1) 内的所有点都不能再放置其他形状
                for ii=i:i+w-1
                    for jj=j:j+h-1
                        for tt=1:numTypes
                            if i==ii && j==jj && t==tt
                                continue
                            end
                            C=[C,x(i,j,t)~=x(ii,jj,tt)];
                        end
                    end
                end
            end
        end
    end
end

disp("约束条件构建完毕");
ops=sdpsettings('verbose',0,'solver','cplex');
area=sizes(:,1).*sizes(:,2);
z=(sum(x(:,:,1))*area(1)+sum(x(:,:,2))*area(2));
reuslt=optimize(C,z);
if result.problem == 0
    % value(x)
    value(z)
else
    disp('求解过程中出错');
end

参考文献

一条龙教程:Matlab下使用yalmip(工具箱)+cplex(求解器)_matlab cplex一条龙-CSDN博客

从这篇博文中,我学习了基本的安装方法,但是基于MATLAB R2023b安装这位博主提供的安装包(yalmip+CPLEX12.8),运行时会出现报错,原因暂不详。

标签:end,IBM,CPLEX,cplex12.10,Matlab,found,安装,yalmip,12.6
From: https://www.cnblogs.com/Vanilla-chan/p/18355832/Matlab-use-yalmip-and-cplex12-10

相关文章