Decision Optimization

 View Only
  • 1.  Defining a domain in a form of set

    Posted Thu February 25, 2021 08:40 AM
    I could not figure out how to define a domain in a form of set. Please help. Thanks!

    range pd = 1..5;
    dvar int+ P in pd;  //we can define a domain of variable with a range

    {int} sd={50, 2, 30, 4};
    dvar int+ S in {sd};  // how to define a domain in a form of set?

    ------------------------------
    Andy Ham
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Defining a domain in a form of set

    Posted Thu February 25, 2021 11:17 AM
    Hello Andy,

    You might try
    dvar int+ S in (min(i in sd) i)..(max(i in sd) i);
    subject to {
      S in sd;
    }

    I hope this helps,



    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 3.  RE: Defining a domain in a form of set

    Posted Thu February 25, 2021 12:47 PM
    Edited by System Fri January 20, 2023 04:12 PM

    Thanks for your help. After second-thought, your suggestion seems to work but it does not look like an efficient way. Better way, please?



  • 4.  RE: Defining a domain in a form of set

    Posted Thu February 25, 2021 01:02 PM
    I don't understand.
    The example I suggested uses a set.
    {int} sd={50, 2, 30, 4};
    dvar int+ S in (min(i in sd) i)..(max(i in sd) i);
    subject to  {
      S in sd;
    }​


    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 5.  RE: Defining a domain in a form of set

    Posted Thu February 25, 2021 01:38 PM
    {int} sd = {50, 2, 30, 4};
    dvar int+ S;
    subject to {
    S==50 || S==2 ||S==30 ||S==4;   //this is what I want. 
    //sd.contains(S)!=0;    //How can I define a domain of S like in this way?
    }

    ------------------------------
    Andy Ham
    ------------------------------



  • 6.  RE: Defining a domain in a form of set

    Posted Thu February 25, 2021 04:14 PM
    Hello Andy
    The constraint
    S in sd;​

    in my sample, states exactly what you are looking for.
    I mean "The variable S must take its value in the set sd".
    I hope this clarifies.



    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 7.  RE: Defining a domain in a form of set

    Posted Thu February 25, 2021 06:16 PM

    Thanks!

    Finally got it. I had to put "using CP;"

    The constraint does not work with Cplex. 



    ------------------------------
    Andy Ham
    ------------------------------



  • 8.  RE: Defining a domain in a form of set

    Posted Fri February 26, 2021 04:43 AM
    Yes I should have specified it, sorry for this lack of precision.

    ------------------------------
    Christiane Bracchi
    ------------------------------