Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Find out if a variable exists in model

    Posted 06/04/18 08:07 AM

    Originally posted by: ouaigooo


    Hi,

    Is there a way (in a main script) to find out if a variable is defined in a model ?

    Something like model.variableExists("x")

    Thanks in advance for your help

    Lucien


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Find out if a variable exists in model

    Posted 06/06/18 09:04 AM

    Hi,

    what I would do : export into mps and then parse

    int nbKids=300;
    float costBus40=500;
    float costBus30=400;
     
    dvar int+ nbBus40;
    dvar int+ nbBus30;
     
    minimize
     costBus40*nbBus40  +nbBus30*costBus30;
     
    subject to
    {
     40*nbBus40+nbBus30*30>=nbKids;
    }
     
    main
    {
    thisOplModel.generate();
    cplex.exportModel("c:/zoo.mps");
    }

    gives

    zoo.mps

    * ENCODING=ISO-8859-1
    NAME          zooEnglish
    ROWS
     N  obj     
     G  c1      
    COLUMNS
        MARK0000  'MARKER'                 'INTORG'
        nbBus40   obj                           500
        nbBus40   c1                             40
        nbBus30   obj                           400
        nbBus30   c1                             30
        MARK0001  'MARKER'                 'INTEND'
    RHS
        rhs       c1                            300
    BOUNDS
     LI bnd       nbBus40   0
     LI bnd       nbBus30   0
    ENDATA

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Find out if a variable exists in model

    Posted 06/06/18 09:12 AM

    Originally posted by: ouaigooo


    So, no simple way :(
    BTW, I could parse directly the mod-file ...
    kr -- lucien


    #DecisionOptimization
    #OPLusingCPLEXOptimizer