IBM ILOG Solver User's Manual > Extending the Library > Writing a Goal: Car Sequencing > Writing a goal: Car sequencing > Inputting data |
Inputting data |
INDEX
![]() |
The input for the program in this example is data read from a file. To read the data from the input file, you write a function, readData
. This function assumes that the data are recorded in a text file with a format based on the following:
You can edit either of the two input files among the examples to get a better idea of how the file is formatted.
The function readData
reads the information from the input file. That function looks like this:
IloArray<IloIntArray> readData(IloEnv env, IloInt example, IloInt& nbCars, IloInt& nbOpt, IloIntArray& nbMax, IloIntArray& seqWidth, IloIntArray& confs, IloIntArray& nbCarsByConf){ char globalName[200]; switch(example){ case 1:{ strcpy(globalName,"../../../examples/data/carseq1.dat"); } break; case 2:{ strcpy(globalName,"../../../examples/data/carseq2.dat"); } break; } IloInt nbConfs; ifstream fin(globalName,ios::in); if (!fin) env.out() << "problem with file:" << globalName << endl; fin >> nbCars >> nbOpt >> nbConfs; IloInt i; confs = IloIntArray(env, nbConfs); // required configurations for(i=0;i<nbConfs;i++){ confs[i]=i; } IloArray<IloIntArray> confsByOption(env, nbConfs); for (i=0;i<nbConfs;i++){ confsByOption[i] = IloIntArray(env, nbOpt); } IloIntArray nbConfsByOption(env, nbOpt); for (i=0;i<nbOpt;i++){ nbConfsByOption[i]=0; } // read the maximum number of cars of each sequence that can take the // invoked option nbMax=IloIntArray(env, nbOpt); for(i=0;i<nbOpt;i++){ fin >> nbMax[i]; } // read the size of a sequence for each option seqWidth=IloIntArray(env, nbOpt); for(i=0;i<nbOpt;i++){ fin >> seqWidth[i]; } // read the options required by each configuration nbCarsByConf=IloIntArray(env, nbConfs); IloInt dummy; IloInt j; for(i=0;i<nbConfs;i++){ fin >> dummy; fin >> nbCarsByConf[i]; for (j=0;j<nbOpt;j++){ fin >> confsByOption[i][j]; if (confsByOption[i][j] == 1){ nbConfsByOption[j]++; } } }
To represent the data for any given option, you need to know the configurations that require it. The following code does that.
As it is read, the data is displayed on the screen by the following code.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |