Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Define decision variable on a set of integer numbers

    Posted 11/03/21 08:56 AM

    Hi IBM community,

     

    I would like to define an integer decision variable that would take values in a set of integers, example, 5, 7, 30, 87, 103, 317, etc.

     

    How can I do that?

     

    Thanks,

     


     

    Description: Description: email-signature-image_0014_H_COC-CTR_Surprint_1_-TO-3__BIL_ENG.png

    Nourredine Hail, PhD in Applied Mathematics
    Senior Operations Research & Data Scientist

    Data Analytics Governance team
    Canadian Tire Corporation
    2111 Steeles Avenue East, Brampton, ON, L6T4L5
    Phone: 905.792.5983  
    nourredine.hail@cantire.com

    "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young."  Henry Ford

     

    This message, including any attachments, is privileged and may contain confidential information intended only for the person(s) named above. If you are not the intended recipient or have received this message in error, please notify the sender immediately by reply email and permanently delete the original transmission from the sender, including any attachments, without making a copy. Thank you.

    Ce message, y compris toutes ses pièces jointes, est confidentiel et peut contenir des renseignements destinés uniquement aux personnes dont le nom est indiqué ci-dessus. Si vous n'êtes pas le destinataire prévu ou si vous avez reçu ce message par erreur, veuillez en aviser l'expéditeur immédiatement, en lui répondant par courriel. Veuillez aussi supprimer définitivement le message original de l'expéditeur, y compris toute pièce jointe, sans faire de copie. Merci.


    #DecisionOptimization


  • 2.  RE: Define decision variable on a set of integer numbers

    Posted 11/03/21 09:54 AM
    Edited by System Admin 01/20/23 04:26 PM

    Hi,
    The first idea that comes to my mind is that you need some form of indirection.
    In the case of a combinatorial problem using CP, this can be implemented using the "element" function.

    Here is a simple OPL example to illustrate the use of this function:

    using CP;
    
    int NB_ELEMENTS = 7;
    range elements_idx = 0..NB_ELEMENTS;
    int elements_list[elements_idx] = [1, 3, 5, 17, 21, 13, 7, 11];
    
    dvar int idx in elements_idx;
    dvar int element_val;
    
    maximize element_val;
    
    subject to {
      element_val == element(elements_list, idx);
    }

    which would result in the following solution:

    // solution with objective 21
    element_val = 21;
    idx = 4;
    


    In the case of a MIP model, a similar approach could be used by creating as many boolean decision variables as there are elements to choose from, and to enforce that the sum over all these binary variables is equal to 1.
    The actual value for the desired decision variable is then a dot product between the vector of boolean decision variables and the list of values.

    Regards,



    ------------------------------
    Hugues Juille
    ------------------------------



  • 3.  RE: Define decision variable on a set of integer numbers

    Posted 11/03/21 10:41 AM

    Thanks, Hugues.

     

    Let us assume, the decision variable element_val is defined on the range elements_idx (element_val [elements_idx]) taking different values in {1, 3, 5, 17, 21, 13, 7, 11}.

     

    How would you formulate this?

     

    Thanks

     


     

    Description: Description: email-signature-image_0014_H_COC-CTR_Surprint_1_-TO-3__BIL_ENG.png

    Nourredine Hail, PhD in Applied Mathematics
    Senior Operations Research & Data Scientist

    Data Analytics Governance team
    Canadian Tire Corporation
    2111 Steeles Avenue East, Brampton, ON, L6T4L5
    Phone: 905.792.5983  
    nourredine.hail@cantire.com

    "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young."  Henry Ford

     






  • 4.  RE: Define decision variable on a set of integer numbers

    Posted 11/03/21 01:11 PM

    Hi Nourredine,
    I'm a bit confused...

    In the example of my previous e-mail, the decision variable element_val can only take values in {1, 3, 5, 17, 21, 13, 7, 11} because of the "element" constraint. This is the formulation in the OPL language (if CP is used as a solver).
    Then, constraints in your model would be formulated using this element_val decision variable.
    I thought this was the purpose of your question.

    I'm certainly misunderstanding what you are asking for.
    Can you please give more details about your context? Are you using a MIP or a CP model ? Which modelling language are you using (OPL, docplex, Cplex API... ?)
    Thanks,



    ------------------------------
    Hugues Juille
    ------------------------------



  • 5.  RE: Define decision variable on a set of integer numbers

    Posted 11/03/21 01:42 PM

    Hi Hugues,

     

    I got your answer to my first question, but I realized that this question did not describe the real issue I have.

     

    Below is a part of the problem I am trying to formulate.

     

    Given n integer decision variables that I want to define on a set of integers, e.g. {1, 3, 5, 17, 21, 13, 7, 11}. Here n = 8.

    How can I define formulate this knowing that all decision variables must take different value?

     

    I hope it is clearer now.

     

    Thanks, and I am sorry for the confusion.

     


     

    Description: Description: email-signature-image_0014_H_COC-CTR_Surprint_1_-TO-3__BIL_ENG.png

    Nourredine Hail, PhD in Applied Mathematics
    Senior Operations Research & Data Scientist

    Data Analytics Governance team
    Canadian Tire Corporation
    2111 Steeles Avenue East, Brampton, ON, L6T4L5
    Phone: 905.792.5983  
    nourredine.hail@cantire.com

    "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young."  Henry Ford

     






  • 6.  RE: Define decision variable on a set of integer numbers

    Posted 11/04/21 03:49 AM
    Hi,

    using CP;
    
    {int} S={1, 3, 5, 17, 21, 13,  7, 11};
    
    int n=card(S);
    range r=1..n;
    
    int v[i in r]=item(S,i-1);
    
    dvar int x[r];
    dvar int perm[r] in r;
    
    subject to
    {
      allDifferent(perm);
      forall(i in r) x[i]==v[perm[i]];
    }​


    gives

    perm = [6 4 1 2 3 8 7 5];
    x = [13 17 1 3 5 11 7 21];

    but could also give other results



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 7.  RE: Define decision variable on a set of integer numbers

    Posted 11/04/21 05:21 AM
    Hi Alex,

    Thanks a lot. This is exactly what I am looking for. I usually don't use CP, but I had no choice this time!

    Best regards