Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

CPLEX MATLAB manual and solution pool

  • 1.  CPLEX MATLAB manual and solution pool

    Posted Fri November 25, 2011 02:27 PM

    Originally posted by: aktm


    I use and teach MILP for large scale mixed integer programming and in the OR field we are very familiar with the robustness and proven ability of Cplex to solve large scale real world problems.
    I would mention kudos to release this for academic use and teaching. It is very useful.

    I am quite new myself to using CPLEX and I tend to use MATLAB and it is good to know that cplex seems integrated with MATLAB. My first problem is I cannot seem to find the documentation in pdf format so that my colleagues can also have a look at it. It is mentioned in the release notes which specifically says "This tutorial is available in the user's manual accompanying the CPLEX for MATLAB connector." This was on page 20 of the IBM ILOG CPLEX V12.1: Release notes for CPLEX which I obtained via a search on the CPLEX support site in the form of the document ps_releasenotescplex.pdf
    I cannot find this document called CPLEX for matlab connector though.

    Secondly, I would like to know how one can generate mutliple solutions with cplex for MATLAB for a MILP that I am working on. So that a novice, who is familiar with MATLAB but not familiar with the calling syntax can get to grips with generating this pool. This feature seems to be the much talked about one on some the manuals so I am wondering how to generate and store the solutions found.

    Any comments, from users and the development team, are much appreciated.

    aktm
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX MATLAB manual and solution pool

    Posted Mon December 05, 2011 07:43 AM

    Originally posted by: SystemAdmin


    What version of CPLEX are you using? The more recent versions no longer have any PDF documentation. Instead you can find the documentation online for CPLEX 12.2 and CPLEX 12.3.

    It is not exactly clear to me what you mean by "generating multiple solutions". The solution pool usually collects all feasible solutions CPLEX finds during the search. If you want to explicitly find more than the optimal solution then you should use the "populate" feature.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX MATLAB manual and solution pool

    Posted Mon December 05, 2011 10:27 AM

    Originally posted by: aktm


    >> What version of CPLEX are you using? The more recent versions no longer have any PDF documentation. Instead you can >> find the documentation online for CPLEX 12.2 and CPLEX 12.3.

    Thank you very much. I believe i am using 12.2. Thanks for the links to the documentation.
    >> It is not exactly clear to me what you mean by "generating multiple solutions". The solution pool usually collects all feasible solutions CPLEX finds during the search. If you want to explicitly find more than the optimal solution then you should use the "populate" feature.

    I have tried to use the populate feature but I am not quite sure why there is only one solution when I do it.
    I have done this in excel solver and managed to get a whole bunch of solutions for this problem.
    In the first place, am I doing it correctly?
    Is there something I need to change?
    Any advice greatly appreciated.
    % Initialize the CPLEX object
    cplex = Cplex('model 2');
    cplex.Model.sense = 'minimize';

    M = 100000;
    tt2 = 10;
    tt1 = 15;
    deltaA = 10;
    deltaB = 10;
    om1 = tt2+deltaB;
    om2 = tt2;
    om3 = tt1+deltaA;
    om4 = om3;
    %constraint1
    A1 = 1 -1 zeros(1,6);0,0,1 -1 zeros(1,4);
    b1 = -deltaA;-deltaB;

    %constraint2
    A2a = -1 0 1 0;0 -1 1 0;-1 0 0 1;0 -1 0 1;
    A2b = M 0 0 0;0 0 M 0; 0 M 0 0; 0 0 0 M;
    A2 = A2a A2b;
    b2 = M-om1;M - om1;M-om2;M-om2;

    %constraint3
    A3a = 1 0 -1 0;1 0 0 -1;0 1 -1 0;0 1 0 -1;
    A3b = -M 0 0 0;0 -M 0 0;0 0 -M 0;0 0 0 -M;
    A3 = A3a A3b;
    b3 = -om3;-om3;-om4;-om4;

    %set of dummy variable constraints
    A4a = zeros(4,4);
    A4b = 1 0 1 0;0 1 0 1;1 1 0 0;0 0 1 1;
    A4 = A4a A4b;
    b4 = ones(4,1);

    A=sparse(A1;A2;A3;A4);
    b=sparse(b1;b2;b3;b4);

    numdum = 4; %number of dummies
    numcon = 4; %number of continuous variables
    numvar = numcon+numdum; %total number of variables

    f=ones(numcon,1);ones(numdum,1);
    for i = 1:numcon
    vartype(i)='C';
    end

    for i = numcon+1:numvar
    vartype(i)='B';
    end

    lb=zeros(1,numvar);
    ub=http://ones(1,numcon).*inf,ones(1,numdum);
    % Use arrays to populate the model
    cplex.Model.obj = f;
    cplex.Model.lb = lb;
    cplex.Model.ub = ub;
    cplex.Model.ctype = vartype;
    cplex.Model.A = A;
    cplex.Model.lhs = -inf*ones(size(A,1),1);
    cplex.Model.rhs = [b];

    % Optimize the problem
    temp = cplex.solve();
    % Write the solution
    fprintf ('\nSolution status = %s \n', cplex.Solution.statusstring);
    fprintf ('Solution value = %f \n', cplex.Solution.objval);
    disp (cplex.Solution.x);

    cplex.Param.mip.pool.relgap.Cur = 10;

    % Optimize the problem and obtain multiple solutions
    temp= cplex.populate();
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX MATLAB manual and solution pool

    Posted Mon December 05, 2011 11:24 AM

    Originally posted by: John Cui


    solutions are in cplex.Solution.pool field.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 06:47 AM

    Originally posted by: aktm


    Thank you.

    I am still having a lot of difficulty trying to generate the multiple solutions with this problem.

    The interesting fact about this particular problem construct is that I know there are DEFINITELY multiple solutions.

    Unfortunately issuing the cplex.populate() command only returns one solution. I also tried the following:

    From reading another manual on IBM Cplex webpage under the chapter of discrete optimization I also tweaked the following parameters.

    cplex.Param.mip.pool.absgap.Cur = 0.0;
    cplex.Param.mip.pool.intensity.Cur = 4;
    cplex.Param.mip.pool.replace.Cur=1;
    cplex.Param.mip.limits.populate.Cur=2100000000;

    Despite all these efforts, I can only return a single solution..but I know for a fact that there are multiple for this problem..

    Furthermore: I cannot find a listing of all the possible cplex.Param options to tweak my problem...

    Can anyone help me, please? TIA
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 10:44 AM

    Originally posted by: John Cui


    Did you check cplex.Solution.pool field after you populate or solve your problem?

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 11:08 AM

    Originally posted by: aktm


    Hi this is an output of the run
    status: 130
    statusstring: 'all reachable solutions enumerated, pool tolerance'
    time: 0.0780
    objval: 120
    x: 8x1 double
    method: 12
    mipitcnt: 17
    ax: 14x1 double
    nodecnt: 9
    nodeleftcnt: 1
    bestobjval: 121
    cutoff: 120
    miprelgap: -0.0083
    pool: 1x1 struct

    issuing the command cplex.Solution.pool

    numreplaced: 0
    meanobj: 120
    solution: 1x1 struct

    Thus confirming that only one solution has been found...which is a little wierd
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 11:21 AM

    Originally posted by: John Cui


    OK, then could you please export your model to .sav file by writeModel? Then upload the .sav to here, we can give a try.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 02:09 PM

    Originally posted by: SystemAdmin


    The one thing to remember about your current settings is the mipgap requirement for solutions in the solution pool via the following setting:

    cplex.Param.mip.pool.absgap.Cur = 0.0;

    The above only allows optimal solutions to be part of the solution pool, i.e the solutions should all have an absolute gap of 0. So, when you say that you know that your model has multiple solutions, do you mean that it has multiple optimal solutions (alternate optimal solutions) since only those will be part of the pool currently. If you instead just wanted every feasible solution to be part of the pool, then you may want to comment out this line and run again.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 08:38 PM

    Originally posted by: aktm


    Please find the sav file for this model.

    There are at least two solutions with this (with the same optimal objective value). Can you please tell me how to detect both in a single run

    I hope this also answers the comment made by AbhishekRaman. I solved in in excel solver..got one answer...and use cplex in MATLAB and cplex in excel..and got another answer. Double checking both solutions, constraints all satisfied.

    I got the following two different solutions

    Excel Solver returned:
    x1=0 x2=40 x3=20 x4=60
    x5=0 x6=1 x7=0 x8=0
    CPLEX in MATLAB and CPLEX in EXCEL returned:
    x1=0 x2=20 x3=40 x4=60

    All binaries are 0
    Objective function = 120

    %Note: I am aware that populate is not available in excel..just checking the modelling impacts of the tools.%
    My populate comments arise in relation to running it and not obtaining say the excel solution as well!

    In lp format from writeModel as well for completeness.
    Minimize
    obj: x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8
    Subject To
    c1: x1 - x2 <= -20
    c2: x3 - x4 <= -20
    c3: - x1 + x3 + 100000 x5 <= 99980
    c4: - x2 + x3 + 100000 x6 <= 99980
    c5: - x1 + x4 + 100000 x7 <= 99980
    c6: - x2 + x4 + 100000 x8 <= 99980
    c7: x1 - x3 - 100000 x5 <= -20
    c8: x2 - x3 - 100000 x6 <= -20
    c9: x1 - x4 - 100000 x7 <= -20
    c10: x2 - x4 - 100000 x8 <= -20
    c11: x5 + x7 <= 1
    c12: x6 + x8 <= 1
    c13: x5 + x6 <= 1
    c14: x7 + x8 <= 1
    Bounds
    0 <= x5 <= 1
    0 <= x6 <= 1
    0 <= x7 <= 1
    0 <= x8 <= 1
    Binaries
    x5 x6 x7 x8
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: CPLEX MATLAB manual and solution pool

    Posted Tue January 10, 2012 08:45 PM

    Originally posted by: aktm


    My apologies...! Error in previous file

    This is the correct one:
    and the correct lp format
    \Problem name: simple model

    Minimize
    obj: x1 + x2 + x3 + x4
    Subject To
    c1: x1 - x2 <= -20
    c2: x3 - x4 <= -20
    c3: - x1 + x3 + 100000 x5 <= 99980
    c4: - x2 + x3 + 100000 x6 <= 99980
    c5: - x1 + x4 + 100000 x7 <= 99980
    c6: - x2 + x4 + 100000 x8 <= 99980
    c7: x1 - x3 - 100000 x5 <= -20
    c8: x2 - x3 - 100000 x6 <= -20
    c9: x1 - x4 - 100000 x7 <= -20
    c10: x2 - x4 - 100000 x8 <= -20
    c11: x5 + x7 <= 1
    c12: x6 + x8 <= 1
    c13: x5 + x6 <= 1
    c14: x7 + x8 <= 1
    Bounds
    0 <= x5 <= 1
    0 <= x6 <= 1
    0 <= x7 <= 1
    0 <= x8 <= 1
    Binaries
    x5 x6 x7 x8
    End
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: CPLEX MATLAB manual and solution pool

    Posted Wed January 11, 2012 12:49 AM

    Originally posted by: John Cui


    I use your .lp model, and solve it in matlab, below is the result, you can see we got 2 solutions.

    
    >> cplex=Cplex() ans= Cplex handle Properties: Model: [1x1 struct] Param: [1x1 struct] DisplayFunc: @disp Methods, Events, Superclasses >> cplex.readModel(
    'test.lp') ans= Cplex handle Properties: Model: [1x1 struct] Param: [1x1 struct] DisplayFunc: @disp Methods, Events, Superclasses >> cplex.Param.mip.pool.intensity.Cur = 4 ans= Cplex handle Properties: Model: [1x1 struct] Param: [1x1 struct] DisplayFunc: @disp Methods, Events, Superclasses >> cplex.populate()   Populate: phase I Tried aggregator 1 time. Probing fixed 0 vars, tightened 2 bounds. Probing time =    0.00 sec. Tried aggregator 1 time. Presolve time =    0.00 sec. Probing time =    0.00 sec. Clique table members: 4. MIP emphasis: balance optimality and feasibility. MIP search method: dynamic search. Parallel mode: deterministic, using up to 2 threads. Root relaxation solution time =    0.00 sec.   Nodes Cuts/  Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap   *     0+    0                          120.0000                      3     --- 0     0       80.0000     1      120.0000       80.0000        3   33.33% 0     0       80.0000     1      120.0000   Flowcuts: 1        4   33.33% 0     0      100.0040     2      120.0000       Cuts: 2        8   16.66% 0     0      106.6667     2      120.0000    MIRcuts: 1        9   11.11% 0     2      106.6667     2      120.0000      106.6667        9   11.11% Elapsed real time =   0.13 sec. (tree size =  0.01 MB, solutions = 1) Implied bound cuts applied:  1 Mixed integer rounding cuts applied:  2   Root node processing (before b&c): Real time             =    0.11 Parallel b&c, 2 threads: Real time             =    0.06 Sync time (average)   =    0.00 Wait time (average)   =    0.00 ------- Total (root+branch&cut) =    0.17 sec.   Populate: phase II MIP emphasis: balance optimality and feasibility. MIP search method: dynamic search. Parallel mode: deterministic, using up to 2 threads.   Nodes                                         Cuts/  Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap   1     3      120.0000     1      120.0000      120.0000       11    0.00% Elapsed real time =   0.02 sec. (tree size =  0.02 MB, solutions = 2) Implied bound cuts applied:  1 Mixed integer rounding cuts applied:  2   Root node processing (before b&c): Real time             =    0.00 Parallel b&c, 2 threads: Real time             =    0.02 Sync time (average)   =    0.00 Wait time (average)   =    0.00 ------- Total (root+branch&cut) =    0.02 sec.   ans =   status: 129 statusstring: 
    'all reachable solutions enumerated, integer optimal' time: 0.1870 objval: 120 x: [8x1 
    
    double] method: 12 mipitcnt: 20 ax: [14x1 
    
    double] nodecnt: 11 bestobjval: 1.0000e+075 cutoff: 120 miprelgap: -8.3333e+072 pool: [1x1 struct]   >> cplex.Solution.pool   ans =   numreplaced: 0 meanobj: 120 solution: [2x1 struct] >> cplex.Solution.pool.solution   ans =   2x1 struct array with fields: objval x ax   >> cplex.Solution.pool.solution(1)   ans =   objval: 120 x: [8x1 
    
    double] ax: [14x1 
    
    double]   >> cplex.Solution.pool.solution(2)   ans =   objval: 120 x: [8x1 
    
    double] ax: [14x1 
    
    double]   >> cplex.Solution.pool.solution(2).x   ans =   0 40 20 60 0 1 0 0   >> cplex.Solution.pool.solution(1).x   ans =   0 20 40 60 0 0 0 0
    


    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: CPLEX MATLAB manual and solution pool

    Posted Wed January 11, 2012 06:26 AM

    Originally posted by: aktm


    Thank you very much. Very grateful for helping me on this matter and demonstrating the ability on this very simple problem to get a multiple solution.I might have made an error in the formulation:

    For the cplex.Model.f the wrong initial reply to your request for the sav file showed that I had used f = ones(1,8) resulting in the objective of x1+x2+...+x8.

    In theory, though this would work for the model set up and the second solution would still be valid, the objective function value would be higher. For the solution (2) where x6, one of the binaries,=1. Combined with the parameter, cplex.Param.mip.pool.absgap.Cur = 0.0 then it would not be produced as a solution because indeed the objective is higher by 1.

    I have one other request:
    The MATLAB documentation accessible from the inbuilt MATLAB help does not go into detail showing all the options beyond say cplex.Param. For example I cannot find documentation on cplex.Param.mip and levels below that for example.

    Is there somewhere where I can find such information. So far I have been going to the webpage of
    IBM ILOG ODM Enterprise Developer Edition V3.4 manual online (the url is so long I wont bother to put it) and then searching around all the options for the documentation but it is quite timeconsuming when facing a steep learning curve.

    Thank you.
    AKTM
    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: CPLEX MATLAB manual and solution pool

    Posted Thu January 12, 2012 08:01 PM

    Originally posted by: John Cui


    Please go to this link to find out the manual of parameters, MATLAB connector has same parameter name as CPLEX interactive:

    http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r4/topic/ilog.odms.cplex.help/CPLEX/maps/ps_refparameterscplex_1.html

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization