Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

How to setup array member with neighbor constrain

  • 1.  How to setup array member with neighbor constrain

    Posted 02/02/17 12:27 AM

    Originally posted by: xx8615xx2


    Suppose that an array has 10 component.

    Only four format accepted

    0 0 0 0 0 0 0 0 0 0, all 0

    0 0 0 0 0 1 0 0 0 0, only one component is 1

    0 1 1 0 0 0 0 0 0 0, two components are 1, they are neighbors

    1 0 0 0 0 0 0 0 0 1, two components are 1, they are head and tail 

     

    in CPLEX

    sum( p in ArrayRange) array[p]<=2 only means there are less or equal to two boolean set up 1

     

    how to set up this constrain


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to setup array member with neighbor constrain

    Posted 02/02/17 03:42 AM

    Hi

    could

    range ArrayRange=1..10;

    dvar boolean array[ArrayRange];

    dvar boolean moveTo1[ArrayRange];

    subject to
    {
    sum( p in ArrayRange) array[p]<=2;

    moveTo1[1]==array[1];
    forall(p in ArrayRange:p!=1) moveTo1[p]==((array[p]==1) && (array[p-1]==0));

    sum( p in ArrayRange) moveTo1[p]<=1;
    }

    help ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to setup array member with neighbor constrain

    Posted 02/08/17 08:57 AM

    Originally posted by: xx8615xx2


    1 0 0 0 0 0 0 0 0 1 head and tail case not work

    moveTo1[1]==array[1]; //this line error

    moveTO1 will be 1 0 0 0 0 0 0 0 0 1

    moveTo1 == 2 not <=1

     

    finally

    range ArrayRange=1..10;

    dvar boolean array[ArrayRange];

    dvar boolean moveTo1[ArrayRange];

    subject to
    {
    sum( p in ArrayRange) array[p]<=2;

    moveTo1[10]==((array[1]==1)&& (array[10]==1));
    forall(p in ArrayRange:p!=10) moveTo1[p]==((array[p]==1) && (array[p+1]==1));

    sum( p in ArrayRange) moveTo1[p]<=1;
    }

    thank you

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer