Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Cplex model modification

    Posted Fri June 28, 2019 10:44 AM

    Originally posted by: Atefeh alizadeh


    Hello,

    I want to build a CPLEX model using Python where some of the parameters of the model change (NOT a sensitivity analysis) and each different value is dictated by information at a node of the BB. So, I do not want to build a model from ground up at each node, rather I want to pass a previously built model and just change a few parameters and solve it. Is it possible to introduce parameters in the model so that before solving it I just set the value of the parameter and CPLEX solves it? Or I  need to build the whole model every time I have a different value for the parameters? The goal is to save time by avoiding to build the model every time a small number of parameters change.

    I tried to solve this problem using following code:

    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')

    because I could not find some thing like cpx2 = cpx1.copy() in Cplex and then I tried to modify the model at each node. but I get this error:

    CPLEX Error  1219: No names exist.
    

    Is there any other way to handle this or solve the error?

    Thank you in advance


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex model modification

    Posted Fri June 28, 2019 11:46 AM

    With regards to your first question, you can clone model with the following syntax:

    cpx2 = cplex.Cplex(cpx1)
    

    As for the 1219 error, can you show us the full traceback and the code that triggers it? Even though you created a copy of the model using SAV files (and this required some disk I/O), it should still give you a more or less exact copy (including names from the original model). So, the error doesn't make sense without more details.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex model modification

    Posted Fri June 28, 2019 01:26 PM

    Originally posted by: Atefeh alizadeh


    Thanks for your quick reply. I am calling it in a user cut call back and I get the attached error.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex model modification

    Posted Mon July 01, 2019 02:08 AM

    Can you wrap your callback code into a try/expect statement, catch the exception in the except block, print its message and stack-trace and then re-throw it? That would give a better idea at where exactly the error is triggered. Could you please also show the offending code then?

    Wrap your callback like so:

    import traceback
    try:
        # Your callback code here
        ...
    except:
        traceback.print_exc()
        raise

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex model modification

    Posted Mon July 01, 2019 02:08 PM

    Originally posted by: Atefeh alizadeh


    Hello. Actually I solved the issue by cpx2=cplex.cplex(cpx1). Thank you so much.


    #CPLEXOptimizers
    #DecisionOptimization