Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

discrete range in variable declaration

  • 1.  discrete range in variable declaration

    Posted Mon August 01, 2011 08:13 AM

    Originally posted by: mohsensalar


    Hi everybody
    I want declare a variable with this indices
    1..5 U 7..16 U 26 U 29..33
    I want use this variable with another variable in inverse function in CP
    I will grateful someone who can help me
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: discrete range in variable declaration

    Posted Wed August 03, 2011 09:01 AM

    Originally posted by: SystemAdmin


    Hello,
    Could you be more precise about what you want to do.

    > I want declare a variable with this indices 1..5 U 7..16 U 26 U 29..33
    > I want use this variable with another variable in inverse function in CP

    Which function do you want to inverse?
    The one that maps some index of the possible values (21 values => index in [1..21]) to the values themselves (1..5 U 7..16 U 26 U 29..33) ?

    You can do that with a constraint x==ARRAY[y] where x is a variable describing the value and y an index variable.

    
    using CP;   
    {
    
    int
    } domain = union(v in 1..5)   
    {v
    } union union(v in 7..16)  
    {v
    } union union(v in 26..26) 
    {v
    } union union(v in 29..33) 
    {v
    };   
    
    int n = card(domain); 
    
    int vmin = min(v in domain) v; 
    
    int vmax = max(v in domain) v; 
    
    int val[i in 1..n] = item(domain, i-1);   dvar 
    
    int x in vmin..vmax; 
    // Value dvar 
    
    int y in 1..n;       
    // Index constraints 
    { x in domain; x == val[y]; 
    };
    


    Philippe
    #DecisionOptimization
    #OPLusingCPOptimizer