Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Issue creating array from range using dvar int

  • 1.  Issue creating array from range using dvar int

    Posted Tue July 14, 2015 11:32 AM

    Originally posted by: AdamGregory


    Hey there,

    I'm trying to determine how many times a particular number appears in an array of ranges defined by start values and end values.

    My current approach is to iterate over the array of ranges and convert from a range to an array using:
    all (j in rangeStart..rangeEnd) j
    Where rangeStart and rangeEnd are both decision variables, and sum up or count the number of occurrences of a particular value.

    The issue is that the generated array does not appear to contain any of the values on the range rangeStart..rangeEnd if either rangeStart or rangeEnd is a decision variable. If put placeholder integers in their place, the array appears correctly.

     

    Can anyone advise on this particular problem or suggest an alternative approach to count the number of occurrences of a particular value in an array of ranges?

    Thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Issue creating array from range using dvar int

    Posted Thu July 16, 2015 03:52 PM

    Hi,

    if you use CPO, have you tried count ?

    Example

    
    
    using CP;
    
    range R = 1..10;
    
    dvar int+ x[R] in R;
    
    subject to {
    
      
    count(all(i in R) x[i], 2) == 10;
    
    }
    

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Issue creating array from range using dvar int

    Posted Fri July 17, 2015 11:02 AM

    Originally posted by: AdamGregory


    Thanks for your response.
    This is the exact problem I'm having.

    using CP;
    int findValue = 5;
    
    subject to {
    sum (t in Tasks) count(all (j in taskStart[t]..taskEnd[t]) j, findValue) <= 3;
    }
    

    The issue is that this constraint doesn't seem to work. The solver selects a solution for which this constraint is not satisfied.
    I believe that the section:
    all (j in taskStart[t]..taskEnd[t]) j
    is not correctly creating an array which contains all the values in the specified range and therefore the occurrences of findValue are not correctly counted.
    If I use ints for the endpoints of my range rather than dvar ints the array correctly contains the expected values and the count works as expected.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Issue creating array from range using dvar int

    Posted Tue July 21, 2015 04:09 AM

    Hi,

    could

    using CP;

    dvar int x[1..10] in 1..10;
    dvar int a in 1..10;
    dvar int b in 1..10;

    subject to
    {
    forall(i in 1..10) x[i]==1+i mod 3;
    2==sum(i in 1..10)  ((x[i]==2) && (a<=i) && (i<=b));
    }

    help ?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer