赞
踩
问题一:
我在安装好了Cplex并且把图片中的路径加入到MATLAB中后,
在MATLAB命令窗口输入“Cplex”,出现以下错误信息:
Undefined function 'cplexlink1251' for input arguments of type 'double'.
然后 我运行一些Cplex自带的例子,比如blend,会出现如下错误信息:
Error using blend (line 190)
Undefined function 'cplexlink1251' for input arguments of type 'double'.
但是我输入 help cplexqp 这样的命令是可以正确出现对cplexqp的解释的。
根据错误信息,我怀疑是不是我的x86_win32目录下面少了cplexlink1251.m这个文件(该目录下的确没有这个文件)
问题二:
使用 Cplex ClassAPI的一个官方样例的程序代码解释,是qcpex1.m这个例子:
源码如下:
function qcpex1()
% Enter and optimize a quadratically constrained programming problem
%
% This function fills in the data structures for the quadratic constraint
% program:
%
% Maximize
% obj: x1 + 2 x2 + 3 x3
% - 0.5 ( 33x1*x1 + 22*x2*x2 + 11*x3*x3
% - 12*x1*x2 - 23*x2*x3 )
% Subject To
% c1: - x1 + x2 + x3 <= 20
% c2: x1 - 3 x2 + x3 <= 30
% q1: [ x1^2 + x2^2 + x3^3 ] <= 1.0
% Bounds
% 0 <= x1 <= 40
% 0 <= x2
% 0 <= x3
% End
% ---------------------------------------------------------------------------
% File: qcpex1.m
% Version 12.5
% ---------------------------------------------------------------------------
% Licensed Materials - Property of IBM
% 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
% Copyright IBM Corporation 2008, 2013. All Rights Reserved.
%
% US Government Users Restricted Rights - Use, duplication or
% disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
% ---------------------------------------------------------------------------
try
% Initialize the CPLEX object
cplex = Cplex('qcpex1'); %The constructor for Cplex objects.
cplex.Model.sense = 'maximize'; %one of the Properties
% Fill in the data for the problem with populatebyrow
populatebyrow();
% Optimize the problem
cplex.solve();
% Write the solution
fprintf ('\nSolution status = %s\n', cplex.Solution.statusstring);
fprintf ('Solution value = %f\n', cplex.Solution.objval);
disp ('Values = ');
disp (cplex.Solution.x');
disp ('Slacks = ');
disp (cplex.Model.rhs - cplex.Solution.ax);
% Finally, write a copy of the problem to a file
cplex.writeModel('qc.lp');
catch m
throw (m);
end
function populatebyrow()
cplex.addCols([1 2 3]', [], [0; 0; 0], [40; inf; inf]);
cplex.Model.Q = [-33 6 0; ...
6 -22 11.5; ...
0 11.5 -11];
cplex.addRows(-inf, [-1 1 1], 20);
cplex.addRows(-inf, [ 1 -3 1], 30);
cplex.addQCs([0 0 0]', [1 0 0;0 1 0;0 0 1], 'L', 1.0);
end
end
能否详细解释一下尤其是populatebyrow函数中语句是怎么与目标函数以及约束条件等对应的,尤其是cplex.Model.Q、cplex.addQCs 那些系数为什么要这样构造矩阵,怎样与原来模型中的系数对应。
一些可能的解决资料:
1、Cplex IBM官方网站有对Cplex for MATLAB安装、样例等的解释。
2、\cplex\matlab\x86_win32\@Cplex 下的Cplex.m也有对类方法的解释、
求大神,也感谢各位的耐心解答!~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。