Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Formulating Constraints with a variable array

    Posted Thu July 23, 2009 03:00 AM

    Originally posted by: SystemAdmin


    [ArushGadkar said:]

    Hello all,
    I have the following problem and would appreciate any suggestions on it.

    I have a a variable matrix A[5][2] declared as an IloNumVarArray and a variable vector say U[5]. What i want to do is this:

    Lets say for example A= [1  0]
                                    [1  0]
                                    [0  1]
                                    [0  1]
                                    [1  0]

    then for every column of A I want to perform the following procedure:
    add the index to a vector S (C++) if the value is 1. i.e in the first step it will take the first column of A and add to S the numbers 1,2,5 (since it is 1 at that position) 
    The procedure( some function) will add constraints to the model (for example in the form U1 + U2 <=100, U5 <30... so on)<br />
    then it takes the second column and i want to add 3, 4 to S and repeat the procedure.

    I am having difficulties adding these indices to S.
    I tried the following pseudocode

    for(all j = 1 to 2)
    {
      for(all i= 1 to 5)
      {if(A[i][j] = = 1)
      S.push_back(i)
      }
    call procedure to add constraints.
    }

    this wont work as it says cannot use if to IloNumVar.

    Could you help me out with this problem. your help is greatly appreciated.

    Thanks
    Arush



    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Formulating Constraints with a variable array

    Posted Tue July 28, 2009 08:13 PM

    Originally posted by: SystemAdmin


    [akshayg said:]

    Shouldnt it be if(A[i][j] == 1)

    That could be the source of your error.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Formulating Constraints with a variable array

    Posted Tue July 28, 2009 11:06 PM

    Originally posted by: SystemAdmin


    [ArushGadkar said:]

    Hello,
    Actually i did implement A[i][j]. It was a typo here. Sorry about that.
    I was wondering if u have a Variable array declared as IloNumVarArray can u access it's elements by using the if condition.
    e.g if(Y[j] == 1) where Y is declared as IloNumVarArray.

    Thanks
    Arush.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Formulating Constraints with a variable array

    Posted Sun August 02, 2009 04:48 PM

    Originally posted by: SystemAdmin


    [notdarkyet said:]

    I do not quite understand: If A is a IloNumVarAray, its elements are VARIABLES and not fixed values - so of course you can't use their values in the decision about formulating constraints.
    If your matrix is fixed, you should use IloNumArray instead. This should be possible to be used i a way you intend.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Formulating Constraints with a variable array

    Posted Sun August 02, 2009 11:43 PM

    Originally posted by: SystemAdmin


    [notdarkyet said:]

    Or was just the subject wrong and you wanted to evaluate a solution and not formulate problem constraints?
    #CPLEXOptimizers
    #DecisionOptimization