Decision Optimization

Decision Optimization

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

 View Only
  • 1.  variable mismatch

    Posted Fri April 05, 2013 02:54 AM

    Originally posted by: SystemAdmin


    I have a huge number of variables which are generated and initialized in advance.
    Then each subset of this set of variables is used to generate certain subproblem.

    In the beginning I generate all the IloRanges needed for each subproblem. These constraints remain the same in all the iterations and only the objective function associated with each subproblem will change.

    The first iteration runs fine.
    In the next iteration I already have the constraints, I add them to the model and build a new objective function.

    when I export the lp file , the variables in the objective function (which are the same variables I used to build my constraints set) appear differently, the names are different and do not appear in any of the constraints. They are totally different vars.
    This cause my problem do not terminate to optimality as I have Free variables which are in the objective function and do not appear in any constraints.

    I attach an example.
    sdp[0][0][1].lp is the one from the first iterations which has optimal solution and the 0.lp is the one from the next iteration which fails.

    The only change is that I created another objective with the same set of variables.
    All comments are appreciated.

    regards
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: variable mismatch

    Posted Fri April 05, 2013 05:16 AM

    Originally posted by: SystemAdmin


    That indeed looks weird. However, the export of named variables may disguise the real issue here. Your variable names are auto-adjusted (they receive a trailing '#XXXX') because some of your names do not conform to LP format.
    Is it possible/easy to repeat your experiment without assigning any names to the variables (or explicitly clear the names of the variables before the export)? In that case the variables will automatically be named idYYYY where YYYY is a Concert-internal unique id. This will allow to tell whether the variables in the LP file are as expected.
    Other questions: Are the variables that are supposed to be the same the same IloNumVar instances or are they just different IloNumVar instances that have the same name? I ask because in 0.lp I see variables called 'u1(1)#0' and 'u1(1)#1620'. That suggests that you have two different variables called 'u1(1)' in your model.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: variable mismatch

    Posted Fri April 05, 2013 08:52 AM

    Originally posted by: SystemAdmin


    I already tried that with or without name is the same. I put the names to be easier to understand.
    ---Other questions: Are the variables that are supposed to be the same the same IloNumVar instances or are they just different IloNumVar instances that have the same name? I ask because in 0.lp I see variables called 'u1(1)#0' and 'u1(1)#1620'. That suggests that you have two different variables called 'u1(1)' in your model.

    The variables are definitely the same. This time I made a model and each time I copy my model in a temporal model to keep y array of model unchanged.
    If I make a getClone of my model, I get the same issue.
    but if I copy the model by assigning tempmodel = model[i][j].
    then there is another issue that the original model model[i][j] is modified. I do not really want it to be touched. I would like to manipulate a copy of the model and manipulate it and later on destroy it. Later I do not have to build the huge model again and can simply copy it from model[i][j].
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: variable mismatch

    Posted Fri April 05, 2013 11:38 AM

    Originally posted by: SystemAdmin


    Do I understand correctly: you use IloModel::getClone() to create the model for the second iteration from the model for the first iteration?
    This may be the cause of trouble since getClone() creates a deep copy of the model. It will create new IloNumVar instances etc. You can easily see this from a code snippet like that:
    #include <iostream>
    #include <ilcplex/ilocplex.h>
    int
    main(void)
    {
       IloEnv env;
       IloNumVar x(env);
       std::cout << x << std::endl;
       IloModel m1(env);
       m1.add(x <= 5);
       IloModel m2 = m1.getClone();
       for (IloModel::Iterator it(m2); it.ok(); ++it) {
          IloExtractable e = *it;
          std::cout << e << std::endl;
       }
     
       env.end();
       return 0;
    }
    

    This prints
    IloNumVar(0)[0 .. inf] 
    IloNumVar(6)[0 .. inf]  <= 5
    

    As you can see, the two IloNumVar instances are different (one has id 0, the other id 6).
    I think what you want is a shallow copy. This can be achieved via
    IloModel shallow(env);
    for (IloModel::Iterator it(model); it.ok(); ++it)
       shallow.add(*it);
    

    If you don't want your ranges to be in different models then you need to copy the ranges within this loop as well.
    #CPLEXOptimizers
    #DecisionOptimization