Decision Optimization

Decision Optimization

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

 View Only
  • 1.  how to use exportmodel

    Posted Thu October 17, 2013 03:59 PM

    Originally posted by: PingLiu


    excuse me,

    I am using cplex in the following format in matlab,

    cplex=Cplex('');
    cplex.Model.sense = 'minimize';

    cplex.addCols(obj,A,lb,ub,ctype)

    cplex.addRows(lhs,A,rhs)

    right now, I use the following code to Write a copy of the problem to a file.

    cplex.writeModel('enr.lp');

    cplex.solve();

    so how may I use exportmodel to write the file as an additional option?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: how to use exportmodel

    Posted Tue October 29, 2013 03:51 PM

    Why would you want to use the exportmodel option if writeModel() achieves the exact same thing?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: how to use exportmodel

    Posted Tue October 29, 2013 04:03 PM

    Originally posted by: PingLiu


    because I call a sub-function iteratively., which solve an optimization problem with cplexlp or cplexmilp.

    for each time, I would like to write the .lp file with different names.

    If I use writeModel(), I cannot change the name for .lp inside the sub-function.

    what I want to do is assign a different name for the .lp file from the outside of the sub-function.

    so that I don't need to change anything in the sub-function.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: how to use exportmodel

    Posted Tue October 29, 2013 04:10 PM

    If you use cplexlp and cplexmilp then you can use options created by cplexoptimset(). The reference documentation of this function has an example of how to set the exportmodel parameter.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: how to use exportmodel

    Posted Tue October 29, 2013 04:16 PM

    Originally posted by: PingLiu


    the following is the sub-function used to solve any optimization problem.

    How may I change the .lp name through the input parameter 'option'?

    function [cpxsol]=CplexSol(f,Aineq,bineq,Aeq,beq,lb,ub,ctype,option)

    cplex=Cplex('');

     cplex.Model.sense = 'minimize';

    cplex.addCols(f,[],lb,ub,ctype);

    cplex.addRows([-inf*ones(size(bineq,1),1);beq], [Aineq;Aeq], [bineq;beq]);

    cplex.solve();

    cpxsol=cplex.Solution;


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: how to use exportmodel

    Posted Wed October 30, 2013 04:27 AM

    So you don't use cplexlp() or cplexmilp() in the subfunction. I still don't understand why you cannot just call cplex.writeModel() in that subfunction. If you want to control the name of LP file from the place that invokes the subfunction then you could just pass the file name as an argument to the subfunction. Or just read the filename from the 'option' argument.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: how to use exportmodel

    Posted Wed October 30, 2013 09:47 AM

    Originally posted by: PingLiu


    if the file name is passed an an argument, how may I call it in the CplexSol.m?

    for the second method, how may I read the filename from the 'option' argument?


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: how to use exportmodel

    Posted Thu October 31, 2013 04:35 AM

    I am not a matlab expert but I think something like this should work:

    function [cpxsol]=CplexSol(f,Aineq,bineq,Aeq,beq,lb,ub,ctype,option,filename)
    cplex=Cplex('');
    cplex.Model.sense = 'minimize';
    cplex.addCols(f,[],lb,ub,ctype);
    cplex.addRows([-inf*ones(size(bineq,1),1);beq], [Aineq;Aeq], [bineq;beq]);
    cplex.writeModel(filename);
    cplex.solve();
    cpxsol=cplex.Solution;

    or, to read it from the options argument:

    function [cpxsol]=CplexSol(f,Aineq,bineq,Aeq,beq,lb,ub,ctype,option)
    cplex=Cplex('');
    cplex.Model.sense = 'minimize';
    cplex.addCols(f,[],lb,ub,ctype);
    cplex.addRows([-inf*ones(size(bineq,1),1);beq], [Aineq;Aeq], [bineq;beq]);
    cplex.writeModel(option.exportmodel);
    cplex.solve();
    cpxsol=cplex.Solution;

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: how to use exportmodel

    Posted Thu October 31, 2013 10:39 AM

    Originally posted by: PingLiu


    that is a good method, It works really.

    but I have another question.

    each time when I try to write any model, the screen will display something like

    Default variable names x1, x2 ... being created.
    Default row names c1, c2 ... being created.

    how may I turn off such display because I don't want to see it during each iteration?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: how to use exportmodel

    Posted Sun November 24, 2013 09:08 AM

    Sorry for the long delay. One very simple way to avoid this message is to assign to your columns and rows. Then CPLEX does not have to create default names. Or do not write models to text files (like .lp or .mps). Instead write them to the binary .sav format. That format does not require names, hence CPLEX will not have to create any.


    #CPLEXOptimizers
    #DecisionOptimization