Hi,

I'm having some trouble with my c++ CP model. In my objective I would like to do the following:

min sum_i distanceMatrix[ x_i ][ x_{i+1} ][ i ]

Here, x_i is a variable indicating the city I visit at time i and distanceMatrix is a 3 dimensional int array.

Here is part of my implementation:

==================

IloModel model(env);

**//Define constants**

**// create travel cost matrix**

IloIntArray3 distanceMatrix(env,tdTSP->nrVertices);

for( unsigned int i = 0; i < tdTSP->nrVertices; i++ ) {

distanceMatrix[i]=IloIntArray2(env,tdTSP->nrVertices);

for( unsigned int j = 0; j < tdTSP->nrVertices; j++ ) {

distanceMatrix[i][j]=IloIntArray(env,tdTSP->nrVertices);

for( unsigned int t = 0; t < tdTSP->nrVertices; t++ ) {

distanceMatrix[i][j][t]=tdTSP->getDistance(i,j,t);

}

}

}

**//Define variables**

IloIntVarArray visitAt = IloIntVarArray(env, tdTSP->nrVertices, 0, tdTSP->nrVertices-1);

for(int i=0; i<tdTSP->nrVertices; i++){

visitAt[i].setName("Vertex: "+i);

}

** //Define objective**

IloIntVar obj_var= IloIntVar(env, 0, INF, "obj");

model.add( IloMinimize(env, obj_var) );

IloIntExpr obj(env);

for(int i=0; i<tdTSP->nrVertices-1; i++){

obj += distanceMatrix[visitAt[i]][visitAt[i+1]][i];

}

model.add( obj_var == obj);

=================

The problem is that obj += distanceMatrix[visitAt[i]][visitAt[i+1]][i]; is not allowed. The compiler says: "no match for operator[]". Any suggestions on how to fix this?