YALMIP + MOSEK

一、在matlab路径中安装yalmip

yalmip文件夹解压在toolbox文件夹里 然后添加路径 在 File->Set Path 加入你的路径 然后 刷新一下工具箱

二、例子

目标函数:max z=x1+x2+x3

s.t. x1+3x2<=8

x1+2x2+3x3<=10

5x1+x3<=8

x1、x2、x3>=0

具体代码如下:

x=[intvar(2,1);sdpvar(1,1)]; %要求x1 x2为整数 x3为实数

f=[1 1 1]*x;

F=set(x>0)+set([1 3 0]*x<=8)+set([1 2 3]*x<=10)+set([5 0 1]*x<=8);

%该约束条件即可使得x2为整数但在程序中不能转行写

solvesdp(F,-f);

double(f)

double(x)

三、MOSEK

yalmip中自带的解整数规划的求解器bnb,在解小规模的数据时效果还不错,但变量多了就不行了,它会破坏已有的约束条件,导致一些离奇古怪的解。后面为了求大规模数据解,需要一些功能更强的求解器,MOSEK就是一个。它是收费的,我用了一个月的授权文件,对于我们这种短期内求数值计算的够用了。

YALMIP和MOSEK受matlab版本影响较大,正常使用的话建议使用matlab2008、或matlab2009

安装:

Thank you for downloading and evaluating MOSEK

You will soon receive a 30 days trial license file by email that will allow you to test the power of MOSEK. The trial license is fully featured but limited to a 30 days trial period.

Installing the trial license on Windows

To install a trial license, replace the file

INSTALL_DIR\mosek\6\licenses\mosek.lic

with your trial license file send to you by email. WhereINSTALL_DIRis the location of your MOSEK installation.

Installing the trial license on LINUX/UNIX/OSX

To install a trial license set the environment variable

MOSEKLM_LICENSE_FILE = PATH_TO_LICENSE

where PATH_TO_LICENSE is the location of your trial license file send to you by e-mail (e.g/home/me/mosek/6/licenses/mosek.lic).

你可能感兴趣的:(YALMIP + MOSEK)