Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Discrete domain for a variable

  • 1.  Discrete domain for a variable

    Posted Tue February 11, 2014 07:39 AM

    Originally posted by: SatishKumarA


    Hi All,

     

    I have a set of resources {1,2,3,4} each one belongs to certain type called Resource_Type {1,2}. While defining a variable say X, I would like to declare it as

    dvar int+ X[Resource_Type] in Resources[Resource_Type];
    

    whereas data should be like

    Resources[1] = {1,3};
    Resources[2] = {2,4};
    

    which indicates Resources 1,3 are of Resource_Type and 2,4 are of Resource_Type 2.

    Currently, the domain for variable X is all Resources independent of its type. But I would like to reduce the domain and so would like to assign the domain based on Resource_Type.

    How can I implement this in OPL?


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Discrete domain for a variable

    Posted Tue February 11, 2014 08:30 AM

    Hi,

    what I would do

     

    {int} Resources[1..2]=[{1,3},{2,4}];

    dvar int+ X[Resource_Type] in 1..4;

    and then

    subject to

    {

    forall(i in Resource-Type) X[i] in Resources[i];

    }

     

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Discrete domain for a variable

    Posted Tue February 11, 2014 08:45 AM

    Originally posted by: SatishKumarA


    Thanks for the reply Alex.

    I am getting the resource set from the database. I am trying to generalize the grouping of resources from above code as follows.

    {int} Resources[j in ResourceTypes]= all(k in ResourceSet:Parameter_Resource_Type[k]==j) k;
    

    It is showing an error saying

    Cannot use type int[] for {int}
    

     

    Help me out.

    Thanks,

    Satish


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Discrete domain for a variable

    Posted Tue February 11, 2014 08:49 AM

    what about

     

    {int} Resources[j in ResourceTypes]= {k | k in ResourceSet:Parameter_Resource_Type[k]==j};

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Discrete domain for a variable

    Posted Tue February 11, 2014 08:58 AM

    Originally posted by: SatishKumarA


    Thanks Alex. Its working.

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer