Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Copying a cplex instance without reference in Python

    Posted 09/24/13 08:24 PM

    Originally posted by: alvarolorca


    Hi,

    I am trying to copy an instance of cplex, not by reference, in Python.

    That is, I create an instance of cplex with "cpx1 = cplex.Cplex()", then I add lots of variables and constraints, but then I want to create a copy of it, that is, I do "cpx2 = cpx1", and want to add variables and constraints to cpx2 without changing cpx1, however, Python created cpx2 as a reference to cpx1 and I haven't found a way to avoid that. I want to do stuff with cpx2 and different stuff with cpx1, but create cpx2 at some point in the middle as an exact copy of cpx1.

    (I know I could simply create cpx2 in the exact same way I created cpx1, but in my case that will take too long so I want to avoid that.)

    Thank you,

    Alvaro


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Copying a cplex instance without reference in Python

    Posted 09/25/13 12:04 PM

    You could do the following:

    import cplex

    cpx1 = cplex.Cplex()
    # do stuff
    cpx1.parameters.write_file('tmp.prm')
    cpx1.write('tmp.sav')

    cpx2 = cplex.Cplex()
    cpx2.parameters.read_file('tmp.prm')
    cpx2.read('tmp.sav')
    # now cpx2 has a copy of cpx1's model

    This isn't as ideal as being able to do something like this:

    cpx2 = cpx1.copy() # this doesn't exist, it's just an example

    I will add this to our user wish list for future consideration.

    Regards,

    Ryan


     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Copying a cplex instance without reference in Python

    Posted 09/25/13 12:23 PM

    Originally posted by: alvarolorca


    Thank you Ryan, that's actually fine enough for my purposes.

    Best regards

    Alvaro


    #CPLEXOptimizers
    #DecisionOptimization