Decision Optimization

Decision Optimization

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

 View Only
  • 1.  CPLEX API in MATLAB: What are Cplex.subsref, cplexlink122, Cplex.subasgn

    Posted Thu June 23, 2011 07:03 PM

    Originally posted by: BerkUstun


    I'm currently designing a multistage stochastic programming solver that is built on the CPLEX MATLAB API.

    The solver works great so far, though I've been trying to decrease the runtime as much as possible.

    I recently ran a MATLAB Profiler Report and was hoping that someone could shed some light on the following functions within the API

    • Cplex.subsref
    • cplexlink122
    -Cplex.subasgn

    I basically need to know:

    I believe
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX API in MATLAB: What are Cplex.subsref, cplexlink122, Cplex.subasgn

    Posted Thu June 23, 2011 07:16 PM

    Originally posted by: BerkUstun


    Posted that too early. See below for the actual post:

    I'm currently designing a multistage stochastic programming solver using the CPLEX MATLAB API.

    The solver works great so far, but I am hoping to decrease its runtime as much as possible by reducing the overhead in MATLAB/CPLEX.

    I recently ran a MATLAB Profiler Report (see attachment) and saw that the following functions were taking a significant amount of time:

    • Cplex.subsref
    • cplexlink122
    • Cplex.subasgn

    Can anyone shed some light on these functions? I basically hoping to learn:

    • What do each of these function do?
    • Do any of these functions call each other?
    • Are these functions called each time I change of the parameters on a Cplex() pointer? (i.e. c = Cplex, c.Model.a(1) = 1)

    One possible improvement: I frequently have to change 10/20 elements in lhs/rhs in an LP before solving it again. I currently change each element one at a time, but perhaps there a way to change them all at once. For instance:

    c = Cplex()
    Model = struct()
    %specify Model.obj, Model.A, Model.lhs, Model.rhs, Model.ub, Model. lb, in MATLAB
    c.Model = Model

    Would the code above be functional?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX API in MATLAB: What are Cplex.subsref, cplexlink122, Cplex.subasgn

    Posted Thu June 23, 2011 11:10 PM

    Originally posted by: John Cui


    >What do each of these function do?

    cplexlink122 will call CPLEX to solve your problem.
    Cplex.subasgn will be called when you set some fields to Cplex.Model,
    Cplex.subsref will be called when you want to get some fields of Cplex.Model.

    >Do any of these functions call each other?

    NO.

    >Are these functions called each time I change of the parameters on a Cplex() pointer? (i.e. c = Cplex, c.Model.a(1) = 1)

    cplex.subasgn will be called.
    >c = Cplex()
    >Model = struct()
    >%specify Model.obj, Model.A, Model.lhs, Model.rhs, Model.ub, Model. lb, in MATLAB
    >c.Model = Model
    >Would the code above be functional?

    Sure, it works.
    You can construct the Model structure without Cplex, then set Cplex.Model by Model structure. It is faster.
    But the fastest way is use toolbox functions instead of Cplex class. You can take a look cplexmilpex.m example.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX API in MATLAB: What are Cplex.subsref, cplexlink122, Cplex.subasgn

    Posted Wed June 29, 2011 07:04 PM

    Originally posted by: BerkUstun


    Thanks for this. I will look at toolbox functions and do some tests. Meanwhile, I had two quick follow-up questions

    • If specify/reset the c.Model as I proposed, will that remove the warm-start information?
    • If so, could I preserve the warm-start information copying it and resetting it? I've included some pseudo-code below to illustrate:
    c = Cplex();
     
    Model = struct();
    %specify Model.obj, Model.A, Model.lhs, Model.rhs, Model.ub, Model.lb in MATLAB
    c.Model = Model
     
    c.solve %c now has c.Start 
     
    Start = c.Start; %save warm-start information in a structure
     
    %respecify Model.obj, Model.A, Model.lhs, Model.rhs, Model.ub, Model.lb in MATLAB
    c.Model = Model %do I lose c.Start here?
    c.Start  = Start %reset c.Start
     
    c.solve
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX API in MATLAB: What are Cplex.subsref, cplexlink122, Cplex.subasgn

    Posted Wed June 29, 2011 10:48 PM

    Originally posted by: John Cui


    No, we don't lose, we will use the Start still.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization