Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Cloning a CPLEX model object.

    Posted 05/27/10 04:43 PM

    Originally posted by: sinhak


    Is there any particular reason that the CPLEX .NET API does not support cloning (deep copying) CPLEX model objects ? I see that the C API has the CPXcloneProb but there is no equivalent in C#. Does anyone have any suggestions on how I can go about cloning a model object ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cloning a CPLEX model object.

    Posted 05/28/10 01:43 PM

    Originally posted by: sinhak


    No insights ? To give some more background: my usage scenario involves having users connecting from different places and being able to solve tweaked versions of a model that could be considered as a foundation. Building this "foundation" model takes a while (5-6 minutes) and I was hoping to avoid this time penalty by copying the model object.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cloning a CPLEX model object.

    Posted 05/28/10 05:09 PM

    Originally posted by: SystemAdmin


    I am not a C# expert but it seems to me like this could work:
    // Create the "foundation" model.
    Cplex foundation = new Cplex();
    ...
     
    // Now create a copy in a new cplex object.
    Cplex cplex = new Cplex();
    cplex.SetModel((IModel)cplex.GetClone(foundation.GetModel()));
    

    I did not try it myself though.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cloning a CPLEX model object.

    Posted 05/28/10 06:02 PM

    Originally posted by: SystemAdmin


    When I tried what I suggested I got an UnsupportedOperationException.
    But this here worked:
    // Create the "foundation" model.
    Cplex foundation = new Cplex();
    ...
     
    // Now create a copy in a new cplex object.
    Cplex cplex = new Cplex();
    foreach (IAddable add in foundation.GetModel()) {
        cplex.GetModel().Add((IAddable)cplex.GetClone(add));
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cloning a CPLEX model object.

    Posted 06/01/10 05:47 PM

    Originally posted by: sinhak


    Thanks so much for the reply Daniel. I tried the method you suggested but CPLEX just seems to hang, i.e., it does not seem to come back from the foreach loop. We have a decent machine (quad core + 16 GB) so it should not be resource constrained. I do see the process pinning one core when it's copying. I will continue looking.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Cloning a CPLEX model object.

    Posted 06/03/10 05:45 AM

    Originally posted by: SystemAdmin


    If you don't find anything yourself, can you share the code? If not in public then maybe in private with me: daniel(dot)junglas(at)de(dot)ibm(dot)com.
    I could check if you ran into some kind of bug.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Cloning a CPLEX model object.

    Posted 06/03/10 05:25 PM

    Originally posted by: sinhak


    Daniel, I think the copying process is hanging because the ILpMatrix object is huge (constraints and variables are in the millions). I tried it on a toy example and everything worked as you had indicated. Now, I am wondering if I should just try to write out the model to a file and then when other users come in they would just read that file in.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Cloning a CPLEX model object.

    Posted 06/07/10 09:03 AM

    Originally posted by: SystemAdmin


    I also thought about that. But I am not sure if it would solve your problems. You can either save to .sav or .xml. Writing to .sav will not preserve the problem structure if you have higher-level constraints such as 'and', 'or' etc. If you instead write to an .xml file (using IloXmlContext) the file will grow very large and you may also run into numeric round-off errors during input/output.
    Is you problem just a matrix or do you have anything else?
    #CPLEXOptimizers
    #DecisionOptimization