Decision Optimization

 View Only
  • 1.  Modeling issue with OPL-CPLEX

    Posted Mon November 16, 2020 10:53 AM
    Dear community team,

    I'm trying to solve a basic inventory optimization problem (MILP) with OPL-CPLEX12.9. The problem is as follows:

    Where, S, X and Y is positive, positive and binary variables respectively.
    I have coded the problem in the following form:
    /***
    * The snippet code
    ***/
    
    // Sets
    {int} products = ...;
    {int} horizons = ...;
    range Periods = 0..card(horizons);
    
    *
    *
    *
    
    // Decision variables
    dvar float+ x[products][horizons];
    dvar float+ s[products][Periods];
    dvar int+ y[products][horizons] in 0..1;
    
    // Constraints
    subject to {
     forall(k in products, t in horizons)
     c1:
      s[k][t-1] + x[k][t] == d[k][t] + s[k][t];
    		
     forall(k in products)
     c2:
     s[k][0] == a[k];​​


    When the problem is solved the results are:

    * X variables
    p/h	1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20
    1	34	73	68	0	75	25	177	0	0	74	126	0	59	98	96	184	0	15	80	0
    2	2	19	49	34	173	0	110	0	0	90	141	0	117	0	26	41	70	34	71	50
    3	34	10	59	162	0	72	0	63	116	0	98	73	13	93	0	124	0	58	54	66
    4	12	0	82	122	0	30	122	0	23	28	0	12	36	89	32	151	0	66	35	90
    5	0	18	71	68	79	146	0	20	10	95	14	11	87	0	76	155	0	0	25	12
    
    ======================================
    * S variables
    p/h	0	1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20
    1	20	0	0	56	0	0	0	95	34	0	0	91	0	0	0	0	92	0	0	58	0
    2	46	0	0	0	0	95	0	51	17	0	0	64	0	100	0	0	0	0	0	0	0
    3	36	0	0	0	78	0	31	0	0	83	0	0	0	0	49	0	84	0	0	0	0
    4	53	22	0	0	69	0	0	57	0	0	15	0	0	0	0	0	100	0	0	0	0
    5	64	18	0	0	0	0	62	0	0	0	0	0	0	74	0	0	77	54	0	0	0
    
    
    


    Before that, I solved the problem using GAMS/CPLEX12.9 and the results were:

    ----     73 VARIABLE x.L  
    
               t1          t2          t3          t4          t5          t6          t7          t8          t9         t10         t11         t12         t13         t14         t15         t16         t17         t18         t19         t20
    
    1      54.000      73.000      68.000                  75.000      25.000     177.000                              74.000     126.000                  59.000      98.000      96.000     184.000                  15.000      80.000
    2      48.000      19.000      49.000      34.000     173.000                 110.000                              90.000     141.000                 117.000                  26.000      41.000      70.000      34.000      71.000      50.000
    3      70.000      10.000      59.000     162.000                  72.000                  63.000     116.000                  98.000      73.000      13.000      93.000                 124.000                  58.000      54.000      66.000
    4      65.000                  82.000     122.000                  30.000     122.000                  23.000      28.000                  12.000      36.000      89.000      32.000     151.000                  66.000      35.000      90.000
    5      46.000      36.000      71.000      68.000      79.000     146.000                  20.000      10.000      95.000      14.000      11.000      87.000                  76.000     155.000                              25.000      12.000
    
    
    ----     73 VARIABLE s.L  
    
               t0          t1          t3          t4          t5          t6          t7          t8          t9         t10         t11         t13         t14         t16         t17         t19
    
    1      20.000                  56.000                                          95.000      34.000                              91.000                              92.000                  58.000
    2      46.000                                          95.000                  51.000      17.000                              64.000     100.000
    3      36.000                              78.000                  31.000                              83.000                                          49.000      84.000
    4      53.000      22.000                  69.000                              57.000                              15.000                                         100.000
    5      64.000                                                      62.000                                                                  74.000                  77.000      54.000
    


    Would you say please, is above code correct? if no, where I'm wrong?



    ------------------------------
    Best regards
    Abbas Omidi
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Modeling issue with OPL-CPLEX

    Posted Mon November 30, 2020 09:51 AM
    Hi,

    I'm not sure if you posted an incomplete OPL model or you are missing
    (1) the objective function,
    (2) the bigM constraint that links x_kt and y_kt, and
    (3) the constraint that bounds sum_(k in K) (e_k * s_kt) <= C
    compared to the model in the embedded picture.

    Regarding your question - did you expect both models to deliver the same solution (I'd assume so, but it doesn't look like it)? If so, are you sure the optimal solution to your problem is unique?

    When trying to debug models it's usually a good idea to start small and easy with both, the model and the data, and work your way towards the full model and dataset step by step.

    Good luck.

    ------------------------------
    Sebastian Fink
    ------------------------------



  • 3.  RE: Modeling issue with OPL-CPLEX

    Posted Tue December 01, 2020 12:55 AM
    Dear Sebastian,

    Thanks for your reply.
    I am sorry if the question was not clear. Actually, my main question is about the modelling of the first constraint where S(k,t-1) should be defined.
    As per your question, yes, I expect both models deliver the same solution but, the results are different. I used to code the inventory problems in GAMS and they worked fine but in this case, I think it comes back to the definition of the initial inventory based on its related index, s(k,t-1) in the CPLEX Studio.

    I was wondering if, is my first constraint code correct? (please, note that I see the sailco example to benchmark).

    /***
    // Decision variables
    dvar float+ x[products][horizons];
    dvar float+ s[products][Periods];

    forall(k in products, t in horizons)
    c1:
    s[k][t-1] + x[k][t] == d[k][t] + s[k][t];
    ***/

    Regards

    ------------------------------
    Abbas Omidi
    ------------------------------



  • 4.  RE: Modeling issue with OPL-CPLEX

    Posted Tue December 01, 2020 03:10 AM
    Dear Abbas,

    well, if you are only interested in the first constraint, that looks syntactically correct and - together with c2 - forces the s[k][0] =a[k] as can be seen by comparing the outputs for S for the first period (which is "0"), they are identical for OPL and GAMS:

    * S variables
    p/h	0	
    1	20
    2	46
    3	36
    4	53
    5	64​
    and
    ----     73 VARIABLE s.L  
    
               t0    
    1      20.000
    2      46.000
    3      36.000
    4      53.000
    5      64.000​



    ------------------------------
    Sebastian Fink
    ------------------------------



  • 5.  RE: Modeling issue with OPL-CPLEX

    Posted Tue December 01, 2020 05:55 AM
    Dear Sebastian,

    Thank you so much for your help and attention.

    Regards


    ------------------------------
    Abbas Omidi
    ------------------------------