Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only

How to get objective function (obj_lambda) together with decision variables (X) and the sorted decision variables (S) ? (Is it possible to combine two models within one python file?)

  • 1.  How to get objective function (obj_lambda) together with decision variables (X) and the sorted decision variables (S) ? (Is it possible to combine two models within one python file?)

    Posted 07/22/22 04:04 AM
    Edited by System Admin 01/20/23 04:43 PM
    Dear All,
    Good day to you.

    As a background, my objective of MILP case is to minimize the lead time (obj_lambda) by using docplex.mp only.
    Supposing the decision variables for the minimizing the lead time are several x in X as model.integer_variables with several constraints.
    Then, I also would like to sort the decision variables x in X into s in S as model.integer_list_variables for the next constraints. In short, S is X.sort(). 

    Based on my manual calculation, the obj_lambda is 270 and the value of x should be different each other in range of 2 to 270, for example: 2,...,100, and 270. 

    I have tried 4 scenarios by using Pycharm (all files are attached and named respectively).

    File A: Running the CPLEX by defining S = np.array(np.sort(x))
                 Result:
                         obj_lambda=310.000 ,
                         obj_lambda=310.000
                         x2=2.000
                         x3=103.000
                         x4=105.000
                         x5=306.000
                         x6=308.000
                         no result for S

    File B: Running the CPLEX by defining S just as S[k] = mdl.integer_var(lb= 0, ub= inf, name='S' + str(k+1)) 
                 Result:
                 objective: 207
                 obj_lambda=207
                  x1=8
                  x2=10
                  x3=4
                  x4=6
                  x6=2
                  S2=2
                  S3=4
                  S4=6
                  S5=8
                  S6=10

    File C:  Running CPLEX by using the example from: howtowithdocplex/sortdecisionvariablesMP.py at main · AlexFleischerParis/howtowithdocplex and combine into 1 Model. (S = y_temp.reshape(Total_T,1))
                   Result:
                   objective: 207
                   obj_lambda=207
                   x1=8
                   x2=10
                   x3=4
                   x4=6
                   x6=2
                   S_1=2
                   S_2=4
                   S_3=6
                   S_4=8
                   S_5=10

    File D:  Running CPLEX by using the example from: howtowithdocplex/sortdecisionvariablesMP.py at main · AlexFleischerParis/howtowithdocplex and use 2 Model within the same coding. (mdl = Model(name='Scheduling') and mdl2 = Model(name='sortvariables').
                 Result:
                  Error: docplex.mp.utils.DOcplexException: Cannot mix objects from different models in new_binary_constraint. obj1=x_temp_0, obj2=x1

    In this case,
    1. is it impossible if we have two Models run within the same python coding but still with the same main objective ? (Model 1 (main objective) for minimizing and  Model 2 for sorting for the respective constraints) ?

    2. Given I would like to get the minimum obj_lambda, x in X, and s in S, could anyone help me, please?

    Here is the original objective function and constraints.
    S is X.sort().

    Thank you in advance for your help.
    (cc: @ALEX FLEISCHER , @Hugues Juille @Vincent Beraudier @Paul Rubin)

    Best regards,
    Nicholas
    ​​​​
    #DecisionOptimization