Topic
  • 8 replies
  • Latest Post - ‏2013-01-02T08:52:47Z by SystemAdmin
beckywang
beckywang
38 Posts

Pinned topic remove IloOr constraint

‏2012-12-09T20:46:15Z |
IloOr constraint is added to the model with some other constraints. The solver is called to solve the model. Then the IloOr is deleted and another IloOr constraint is added. Unfornatly the first IloOr constraint doesn't seem to be deleted as I checked *.lp output file. the second IloOr constraint did added. Here is the code:

for (int i = 0; i < 10; i++) {
IloOr pOr;
//for each loop x, y are different
pOr.add(x == 0 && y == 10);
pOr.add(y == 0 && x == 10);

mod.add(pOr);
mod.solve();

mod.remove(pOr);
pOr.end();
}

So it just adds more IloOr constraint for each loop.
Updated on 2013-01-02T08:52:47Z at 2013-01-02T08:52:47Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: remove IloOr constraint

    ‏2012-12-11T12:49:44Z  
    What version of CPLEX do you use? If I remember correctly then some of the older version had a bug that would result in exactly the behavior you observe (I take it you initialize pOr correctly with 'IloOr pOr(env)' and do not leave out the 'env' argument as you did in your post).
  • beckywang
    beckywang
    38 Posts

    Re: remove IloOr constraint

    ‏2012-12-11T13:42:21Z  
    What version of CPLEX do you use? If I remember correctly then some of the older version had a bug that would result in exactly the behavior you observe (I take it you initialize pOr correctly with 'IloOr pOr(env)' and do not leave out the 'env' argument as you did in your post).
    cplex 12.1

    Yes, IloOr is defined correctly
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: remove IloOr constraint

    ‏2012-12-11T14:47:29Z  
    • beckywang
    • ‏2012-12-11T13:42:21Z
    cplex 12.1

    Yes, IloOr is defined correctly
    The bug I mentioned was fixed for CPLEX 12.4.0.1. Any option to upgrade to this or an even more recent version of CPLEX?
    If not then the only workaround I see is to explicitly re-extract the model:
    for (int i = 0; i < 10; i++) {
       IloOr pOr(env);
       //for each loop x, y are different
       pOr.add(x == 0 && y == 10);
       pOr.add(y == 0 && x == 10);
     
       mod.add(pOr);
     
       // Explicitly re-extract the model.
       // To do this first extract a different model and then
       // extract the original model again.
       IloModel old = cplex.getModel();
       IloModel empty(cplex.getEnv());
       cplex.extract(empty);
       cplex.extract(old);
       empty.end();
     
       cplex.solve();
     
       mod.remove(pOr);
       pOr.end();
    }
    
    Updated on 2014-03-24T22:44:00Z at 2014-03-24T22:44:00Z by iron-man
  • beckywang
    beckywang
    38 Posts

    Re: remove IloOr constraint

    ‏2012-12-11T21:11:12Z  
    The bug I mentioned was fixed for CPLEX 12.4.0.1. Any option to upgrade to this or an even more recent version of CPLEX?
    If not then the only workaround I see is to explicitly re-extract the model:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">for (int i = 0; i < 10; i++) { IloOr pOr(env); //for each loop x, y are different pOr.add(x == 0 && y == 10); pOr.add(y == 0 && x == 10); mod.add(pOr); // Explicitly re-extract the model. // To do this first extract a different model and then // extract the original model again. IloModel old = cplex.getModel(); IloModel empty(cplex.getEnv()); cplex.extract(empty); cplex.extract(old); empty.end(); cplex.solve(); mod.remove(pOr); pOr.end(); } </pre>
    Thanks. The work around works.
  • beckywang
    beckywang
    38 Posts

    Re: remove IloOr constraint

    ‏2012-12-13T22:21:39Z  
    • beckywang
    • ‏2012-12-11T21:11:12Z
    Thanks. The work around works.
    We have upgraded to cplex 12.5. So I have both programs with work around(using cplex 12.0) and without. I ran both programs. It produced different results. The one without the work around is faster which I sort of understand, but why different results. Then I tried the work around program on the upgraded version. This time both programs came to the same result.
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: remove IloOr constraint

    ‏2012-12-14T07:38:19Z  
    • beckywang
    • ‏2012-12-13T22:21:39Z
    We have upgraded to cplex 12.5. So I have both programs with work around(using cplex 12.0) and without. I ran both programs. It produced different results. The one without the work around is faster which I sort of understand, but why different results. Then I tried the work around program on the upgraded version. This time both programs came to the same result.
    What is the exact difference you observe?
    Different optimal objective function values? Different optimal x vectors?
  • beckywang
    beckywang
    38 Posts

    Re: remove IloOr constraint

    ‏2012-12-14T17:45:24Z  
    What is the exact difference you observe?
    Different optimal objective function values? Different optimal x vectors?
    Both the optimal obj. value and optimal x are different.
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: remove IloOr constraint

    ‏2013-01-02T08:52:47Z  
    • beckywang
    • ‏2012-12-14T17:45:24Z
    Both the optimal obj. value and optimal x are different.
    Could you show us log files for the runs that produce different results?
    Could you export the two models to SAV files and attach them here?