Topic
  • 1 reply
  • Latest Post - ‏2013-04-29T15:33:54Z by rdumeur
sundstrn
sundstrn
1 Post

Pinned topic How to make a copy or clone a model?

‏2013-04-24T20:03:14Z |

Hi,

I am using the CP Optimizer Java API to model an optimization problem. I have created a model using  IloCP cp = new IloCP() and added intervals and constraints to this model. I am interested in making a copy or clone this model but fail at every attempt I make. Should I use IloCP copy_cp = new IloCP(cp) or create an empty model IloCP copy_cp = new IloCP() and use some function to get all the information from my original model to this model? In the first case, I notice that constraints that I add to my original model after making the copy also affects my copy. 

I'm aim for adding extra conditions to my copy and solving both the original and copied/cloned model and compare the resulting schedules.

Thanks in advance,

sundstrn

  • rdumeur
    rdumeur
    109 Posts

    Re: How to make a copy or clone a model?

    ‏2013-04-29T15:33:54Z  

    Dear sundstrn,

     

    There is unfortunately no way to clone a model. The new IloCP(cp) constructors simply duplicates the handle of the solver has you have noticed. I suggest that you wrap the model-building code in a procedure that will take an IloCP as a parameter and populate the model. Then you'll be able to invoke this procedure a second time and add your extra conditions:

    IloCP cp1 = new IloCP();

    populateCP(cp1);

    IloCP cp2 = new IloCP();

    populateCP(cp2);

    addExtraConditions(cp2);

    I hope this helps,

     

    Cheers,