Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Ilog Script and MIP sove fixed solution, IloOplModel Usage

    Posted 05/19/21 10:48 AM

    IBM ILOG CPLEX: CPLEX Error 1217: No solution exists. workflow.mod /.../workflow.mod OPL-Problemmarkierung

    Hi Everyone,

    I am looking for help on solving the fixed version of an MIP porblem.

    A little of context:

    I am using ILOG scripting lenguage to coordinate the Data and model declaration, with the corresponding postprocessing.

    I am currently using : IBM ILOG CPLEX Optimization Studio Version: 12.8.0.0

    So far I understand that, in order to do so I will need to solve the MIP version and afterwards call the solveFixed routine.

    my problem migth just berelated to a wrong usage of the IloOplMdel Instances.

    I have following files which are included or explecitly calle in the main script.
    ------------------
    1. varDecl.mod : This file only include variable declaration of the form:
    type name = ...;
    {type} name = ...;
    type name[name_i] = ...;
    ------------------
    2. Data.dat : Here the data is written in the espected format for cplex
    name_i = mydataofName_i
    ------------------
    3. MIPproblemDecl.mod : This file define the decision variables, the objective and the constraints. it first calls the varDecl.mod file through including it.
    include "varDecl.mod";
    dvar type name;
    .
    .
    .
    minimize

    subject to {ct1:.... ct2:...}
    ------------------
    Now to the real problem where I am currently stock.

    my workflow filelooks like this:
    4. workflow.mod : here is written my script and where I believe all the problems are rigth now.

    include "varDecl.mod"; // it starts by includig the varaible name files.
    main
    { // start of script:main

    // Prepare OPL Model
    thisOplModel.generate(); // I see this appearing in some examples and some others not, i dont understandhow this global opl model works. But I noticed that inside this object there is the data from Data.dat, even when I never explicitely gave it to him (I supposue it goes like that because it is in the same directory
    var source = new IloOplModelSource("MIPproblemDecl.mod"); // read my model from the file
    var cplex = new IloCplex();
    var def = new IloOplModelDefinition(source);
    var data = thisOplModel.dataElements; // get the data out of the "thisOplModel" whichwas taken from "Data.dat"

    // Do some data Preprocessing
    // dataPre = function applied on data
    // data[i] <- dataPre[i]
    // Write pre processing to the console

    // Create OPL Model
    var opl_MIP = new IloOplModel(def, cplex);
    opl_MIP.addDataSource(data)
    opl_MIP.generate();

    // solve problem in MIP version
    if (cplex.solve())
    {
    cplex.exportModel("MIP.lp")
    writeln("MIP Objective = " + cplex.getObjValue());
    writeln(current.printSolution())
    } else
    {
    writeln("No solution");
    break
    }

    // solve problem in Fixed version
    if (cplex.solveFixed())
    {
    cplex.exportModel("FIX.lp")
    writeln("FIX Objective = " + cplex.getObjValue());
    writeln(current.printSolution())   // -----HERE--- is where the error occurs
    // Here I would like as well to acces the Dual variables, Reduced Costs, etc.
    } else
    {
    writeln("No solution");
    break
    }

    } // finisch of sript:main
    ------------------
    Questions:

    1- As you can see from the introduction PLEX returns the Error 1217 were no Solution can be accesed. This problem should appear in particular if somechange to the model has been made between solutions, but this time that is not the case.

    2- I suppose my main question is, how to write and use the oplModel instances (opl_MIP, and thisOplModel) such that i can solve the fixed MIP problem

    3- Why in some examples a second model (eg. opl2) is used when the data or some parameter is changed, and if in this case it should be aplied aswell.

    4- Why does the (thisOplModel) exist, and what should be its use, it confuses me that the routine IloOplModel.generate() is called two times, I dont know if some values are being mixed.

    5- The two ".lp" files show exactly the same problem. this let me to the conclusion that even when cplex.solveFixed returned True, (because it enters in the if clausel) the problem was not changed and the binary variables still exists. is that correct or I am wrong in my conclusion?

    6- Are these Problems that only occur on this version of CPLEX und Studio?

    7- Í also realized some examples use something like : var name = thisOplModel, why is that done in some cases and some others not?

    8- Finally I thougth one possibility would be to implement the solveFixed by my self, by invoking opl.convertAllIntVars(), but by doing so the Integer values are not saved, and if there is no solution by using solveFixed(), how could I go to fix these values without ading anothe equality constraint.

    thank you very much in advance,

    I am expecting your answers.

    ------------------------------
    Cesar Garcia
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Ilog Script and MIP sove fixed solution, IloOplModel Usage

    Posted 05/20/21 02:23 AM
    Hi

    about question 8, Relax integrity constraints and dual value in https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/

    can be a good starting point

    regards

    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Ilog Script and MIP sove fixed solution, IloOplModel Usage

    Posted 05/20/21 02:53 AM

    Hello Alex, 

    First, thanks for your time and nice post about OPL compendium.

    But there is a problem, the method used in " Relax integrity constraints and dual value" does not secures that the MIP solution will be used at the time of the second calculation. I need to fix the integer and/or binary variables to the values from the MIP solution and then solve again. (this is supposused to be done with solveFixed() but for some reason it does not works). If one reads the ".lp" file one notices that the difference ist that there are no binary variables and they are relaxed with lb =0  and ub = 1, but still they are not fixed.

    I have one more question if you dont mind.
    I have not found a good documentation where the the properties of the clases for the ILOG Scripting lenguage are listed. by example:

    writeln("dual of the kids constraint = ",thisOplModel.ctKids.dual)  I have not found  a place that says that an IloOplModel containts the constraints ct1.... ctn, as properties or attributes, neither that "dual" is contained in the ct1... , if you have a link to the page were I could see that, it would be wonderfull.

    Thanks in advance again.



    ------------------------------
    Cesar Garcia
    ------------------------------



  • 4.  RE: Ilog Script and MIP sove fixed solution, IloOplModel Usage

    Posted 05/20/21 04:02 AM
    you re right.
    And if you want to fix the decision variables you can have a look at https://github.com/AlexFleischerParis/modelbuilding/blob/master/tariffrates2.mod

    where you will notice

    for(var d in thisOplModel.demand) for(var p in thisOplModel.powerstation)
          {
            thisOplModel.nbUnitsOn[p][d].UB= thisOplModel.value[p][d];
            thisOplModel.nbUnitsOn[p][d].LB= thisOplModel.value[p][d];​


    that sets the decision variables.


    For scripting I suggest the CPLEX documentation and maybe you can have a look at

    https://www.linkedin.com/pulse/javascript-within-opl-cplex-alex-fleischer/



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 5.  RE: Ilog Script and MIP sove fixed solution, IloOplModel Usage

    Posted 05/20/21 05:32 AM
    Thankyou Alex,

    Again this partially works, I implemented an small example and while I use the same procedure as you it works, but when I try to implement it on my problem I get a lot of problems with the opl model which i am working with.

    I will keep looking for answer to my other questions, it still triggers me, that the solveFixed() does not work, and it should do exactly that, what you are doing, but without user assistance. If you know why it does not work please let me know.

    I currently observe, that most of my problem are due to the existance of multiple oplModel instances (thisOplModel and opl) I dont understand the differences between one another.

    thanks again for your fast responses.

    ------------------------------
    Cesar Garcia
    ------------------------------



  • 6.  RE: Ilog Script and MIP sove fixed solution, IloOplModel Usage

    Posted 05/21/21 03:52 AM
    Hi

    let me first give you a small example with the zoo and solveFixed:

        int nbKids=300;
        float costBus40=500;
        float costBus30=400;
         
        dvar float+ nbBus40;
        dvar int+ nbBus30;
         
        minimize
         costBus40*nbBus40  +nbBus30*costBus30;
         
        subject to
        {
         ctKids:40*nbBus40+nbBus30*30>=nbKids;
        }
        main {
          var status = 0;
          thisOplModel.generate();
          if (cplex.solve()) {
            writeln("Integer Model");   
            writeln("OBJECTIVE: ",cplex.getObjValue());   
            
          }
          
         
          if (cplex.solveFixed()) {
            writeln("Solve Fixed Model");   
            writeln("OBJECTIVE: ",cplex.getObjValue());  
            
            writeln("dual of the kids constraint = ",thisOplModel.ctKids.dual);
          }
           
         
        }
    ​


    which gives

    Integer Model
    OBJECTIVE: 3750
    Solve Fixed Model
    OBJECTIVE: 3750
    dual of the kids constraint = 12.5


    No surpise since 500/40=12.5

    In a flow control you can use many sub opl models. See an example at https://github.com/AlexFleischerParis/howtowithopl/blob/master/hybrid.mod

    regards



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------