Decision Optimization

Decision Optimization

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

 View Only
  • 1.  copy of IloExpr

    Posted Tue June 02, 2020 11:22 AM

    Hi!

    I would like to use an existing IloExpr to create new expressions which looks quite the same but have little changes in it.

    I would like to know how to make a deep copy of the existing IloExpr because I don't want to create the new ones from scratch but just adding some elements to it.

    Thanks



    ------------------------------
    Serge Bisaillon
    ------------------------------

    #DecisionOptimization


  • 2.  RE: copy of IloExpr

    Posted Tue June 02, 2020 11:33 AM
    If you write
    IloExpr b = a + 0;
    then b should be a deep copy of a. This code
       IloEnv env;
       IloNumVar x(env, 0, 1, "x");
       IloNumVar y(env, 0, 1, "y");
       IloNumVar z(env, 0, 1, "z");
    
       IloExpr a = x + y;
       IloExpr b = a + 0;
       std::cout << a << std::endl;
       std::cout << b << std::endl;
    
       b += z;
       std::cout << a << std::endl;
       std::cout << b << std::endl;

    prints

    x  + y 
    x  + y 
    x  + y 
    x  + y  + z ​


    ------------------------------
    Daniel Junglas
    ------------------------------



  • 3.  RE: copy of IloExpr

    Posted Tue June 02, 2020 11:57 AM
    Thanks.

    ------------------------------
    Serge Bisaillon
    ------------------------------