Search code examples
c++modelconstraintscplexmulti-dimensional-scaling

How to add multi dimensional IloRangeArray to the model on CPLEX


I'm a beginner in CPLEx and using it to wite my mathematical model. I defined and built a three dimensional IloRangeArray as my constraint as follows:

typedef IloArray<IloArray<IloRangeArray>> ThreeDimRange;
con = IloArray <IloArray <IloRangeArray> > (env, n);
for () 
{
    con [h] = IloArray <IloRangeArray> (env, nbRow);
    for ()
    {
        con[h][m] = IloRangeArray (env);
        for () 
        {
            IloExpr tempExp(env); 
            if ()
                 con [h][m].add(0 <= tempExp <= 0);
        }
    }
}

When I want to add "con" to the model (model.add(con);), I have the following error:

error C2664: 'IloExtractable IloModel::add(const IloExtractable) const' : cannot convert parameter 1 from 'ThreeDimRange' to 'const IloExtractable'

It is the same for 2 dim IloArrangeArray. What is your opinion?

Thanks


Solution

  • Solved! It seems that though we have a multi-dimensional vector of IloRangeArray , we have to add each IloRangeArray seperately to the model.

    typedef IloArray<IloArray<IloRangeArray>> ThreeDimRange;
    con = IloArray <IloArray <IloRangeArray> > (env, n);
    for () 
    {
        con [h] = IloArray <IloRangeArray> (env, nbRow);
        for ()
        {
            con[h][m] = IloRangeArray (env);
            for () 
            {
                IloExpr tempExp(env); 
                if ()
                     con [h][m].add(0 <= tempExp <= 0);
            }
            **model.add(con[h][m]);**
        }
    }