Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  using expression inside for loops

    Posted 04/07/12 10:13 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Hi, dear all

    I spend a long time in trying to solve a problem in cplex and I have just one error and I can't fix it, could you please help me
    1- Define the variable array as following

    typedef IloArray<IloNumVarArray> IloNumVarArrayArray;
    typedef IloArray<IloNumVarArrayArray> IloNumVarArrayArrayArray;
    typedef IloArray<IloNumVarArrayArrayArray> IloNumVarArrayArrayArrayArray;
    typedef IloArray<IloNumVarArrayArrayArrayArray>IloNumVarArrayArrayArrayArrayArray;

    IloNumVarArrayArrayArrayArray DEV_hot(env,nbWoundedCat);
    for(int h = 0; h <= nbWoundedCat; h++)
    {
    DEV_hot[h] = IloNumVarArrayArrayArray (env, nbDNodes);
    for(int o=0; o<= nbDNodes; o++)
    {
    DEV_hot[h][o] = IloNumVarArrayArray (env, nbTimes);
    for(int t = 0; t <= nbTimes; t++)
    DEV_hot[h][o][t] = IloNumVarArray(env, nbTimes, 0.0, IloInfinity);
    }
    }
    2- using expression as following:

    IloExpr costSum(env);

    for (int h=0; h<nbWoundedCat; h++){

    for(int o=0; o<nbDNodes; o++){

    for (int t=0; t<curr_t; t++){
    costSum = 2 * costSum + DEV_hot[h][o][t] - 110; }}}

    model.add(IloMinimize(env, costSum ));
    costSum.end();

    3- the error I received is

    error: no match for ‘operator+’ in ‘operator*(IloNum, IloNumExprArg)(IloNumExprArg(((const IloNumExprArg&)((const IloNumExprArg*)(& costSum.IloExpr::<anonymous>.IloNumExpr::<anonymous>))))) + ((IloArray<IloNumVarArray>*)((IloArray<IloArray<IloNumVarArray> >*)DEV_hot.IloArray<X>::operator[] with X = IloArray<IloArray<IloNumVarArray> >](((long int)h)))->IloArray<X>::operator[ with X = IloArray<IloNumVarArray>](((long int)o)))->IloArray<X>::operator[ with X = IloNumVarArray(((long int)t))’

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: using expression inside for loops

    Posted 04/07/12 10:21 PM

    Originally posted by: FANS_Nader_Al_Theeb


    I have one change in the previous post, the cost sum is as

    costSum = costSum + DEV_hot[h][o][t]; }}}

    not
    costSum = 2 * costSum + DEV_hot[h][o][t] - 110; }}}

    sorry about that
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: using expression inside for loops

    Posted 04/09/12 03:21 AM

    Originally posted by: SystemAdmin


    The problem is that
    DEV_hot[h][o][t]
    

    is an IloNumVarArray ( DEV_hot is a 4-dimensional array) and costSum is just an expression. You cannot add an array of variables and an expression, you need one more index (a total of 4 indices) into the DEV_hot array to specify the variable that should be added to costSum. Or do you want to add the sum of all the variables in the array to costSum ?
    #CPLEXOptimizers
    #DecisionOptimization