IBM ILOG Solver User's Manual > Extending the Library > Writing a Goal: Car Sequencing > Writing a goal: Car sequencing > Building the model

You create a constrained variable for each car that should be assembled on the line and organize those variables into an array. You assume that the order in which the cars appear on the line is the same as the order of the constrained variables in the array. That is, cars[0] is the first car; cars[n-1] is the last.

The values that the constrained variables can assume correspond to the configurations. If a constrained variable is bound to the value 3, for example, the corresponding car will have options corresponding to configuration 3. Initially, a car can have any configuration.

Here is the code for the model

void secondModel(IloInt mode, IloInt example)
{
  IloEnv env;
  try {
    IloModel model(env);

    IloInt nbOptions;
    IloInt nbCars;
    IloIntArray confs(env); // array of required configurations
    IloIntArray nbCarsByConf(env); // number of cars to assign
                                    // to each configuration
    IloIntArray nbMax(env);
    IloIntArray seqWidth(env);

    IloArray<IloIntArray> optConf = readData(env,
                                             example,
                                             nbCars,
                                             nbOptions,
                                             nbMax,
                                             seqWidth,
                                             confs,
                                             nbCarsByConf);


    cout << "Pass 1 " << endl;
    const IlcInt nbConfs   = confs.getSize();

    IloInt i,j;
    IloIntVarArray cars(env,nbCars,0,nbConfs-1);
    IloIntVarArray cards(env,nbConfs);
    for (i = 0; i < nbConfs; i++){
      cards[i] = IloIntVar(env,nbCarsByConf[i],nbCarsByConf[i]);
    }
    cout << "Pass 2 " << endl;