Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  assign values to IloNumArray

    Posted 07/10/13 12:38 AM

    Originally posted by: lluvia


    Hi, I'm new with CPLEX. 

    I want to assign the values in an Array Cost to IloNumArray FoodCost.

    But the first element of FoodCost is always 0.  The first element in Cost is assigned to the second place in FoodCost and the last one in Cost is missing. 

    Here is my code:

    IloNumArray FoodCost (env, ILOINT);
    IloNumArray2 CplPenalty (env);
     
    for (i=0; i<30; ++i)
    {
    FoodCost.add(cost[i]);
    cout<<"FoodCost["<<i<<"]"<<"= "<<FoodCost[i]<<endl;
    }
     
    for (i=0; i<30; ++i)
    {
    cout<<"cost["<<i<<"]"<<"= "<<cost[i]<<endl;
    }

    Could you please me help with these problem? I also have the problem on how to add values to IloNumArray2 CplPenalty from a 2-D array in C++. 

    Thank you very much.

    Jacinda

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: assign values to IloNumArray

    Posted 07/10/13 02:41 AM

    Please take a look at the reference documentation of class IloNumArray. The constructor

    IloNumArray FoodCost (env, ILOINT);

    will most likely not do what you intend it to do. It invokes

    IloNumArray(const IloEnv env, IloInt n = 0)

    which creates an array with n elements that are all set to 0. In your case n is the value to which the ILOINT macro happens to expand. What are you trying to achieve by passing ILOINT to the constructor? Just removing IloInt from the call to the constructor will probably give the expected result.

    To fill an IloNumArray2 concertarray from a plain 2-D array array you can do this:

    IloNumArray2 concertarray(env);
    for (int i = 0; i < n; ++i) {
       concertarray.add(IloNumArray(env));
       for (int j = 0; j < m; ++j)
          concertarray[i].add(array[i][j]);
    }

     


    #CPLEXOptimizers
    #DecisionOptimization