Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

making combined vector

  • 1.  making combined vector

    Posted Sat June 18, 2016 01:51 PM

    Originally posted by: sandeepsinghchauhan


    A= [10 20 30 40];

    B = [1000 2000 3000 4000];

    C = [ -1000 -2000 -3000 -4000];

    How can i make

    Bound = [10 1000 -1000 20 2000 -2000 30 3000 -3000 40 4000 -4000];

    please help


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: making combined vector

    Posted Sun June 19, 2016 03:11 PM

    Hi,

    range r=1..4;
     
    int A[r]= [10,20, 30, 40];

    int B[r] = [1000 ,2000 ,3000 ,4000];

    int C[r] = [ -1000, -2000 ,-3000 ,-4000];

     

    int values[i in 1..3][j in r]=(i==1)?A[j]:((i==2)?B[j]:C[j]);
    int Bound[i in 1..12]=values[(i-1) mod 3+1][(i-1) div 3+1];

    execute
    {

    writeln(Bound);
    }

    gives

     [10 1000 -1000 20 2000 -2000 30 3000 -3000 40 4000 -4000]

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: making combined vector

    Posted Sun June 19, 2016 04:05 PM

    Originally posted by: sandeepsinghchauhan


    Thanks for your help

    If i want to go in reverse like if i have Bound =  [10 1000 -1000 20 2000 -2000 30 3000 -3000 40 4000 -4000]

    and i want to create A = [10,20, 30, 40]; B= [1000 ,2000 ,3000 ,4000]; C = [ -1000, -2000 ,-3000 ,-4000]

    how can i do it

    please help


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: making combined vector

    Posted Wed June 22, 2016 05:11 AM

    Hi

    int Bound[1..12]=[10, 1000, -1000, 20, 2000, -2000, 30 ,3000, -3000, 40, 4000 ,-4000];

    range r=1..4;
         
    int values[1..3][r]=[ ((i-1) mod 3)+1 : [ (i-1) div 3+1 : Bound[i] ] | i in 1..12 ];

    int A[i in r]=values[1][i];
    int B[i in r]=values[2][i];
    int C[i in r]=values[3][i];
     
    execute
    {
      writeln(A,B,C);
    }

    gives

    [10 20 30 40] [1000 2000 3000 4000] [-1000 -2000 -3000 -4000]

    But I wonder why you want to turn A,B,C into Bounds and then back again into A,B,C

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer