Originally posted by: SystemAdmin
[niharika said:]
HI
my ilog code now cannot read data from the text file, it gives teh error message "cannot open the specified file"
Please HELP ME THIS TIME
I am pasting my code below
int main(int argc, char
*argv)
{
IloEnv env;
try {
IloInt i, j;
IloNumArray weight(env);
IloInt nbNodes;
IloInt topK = 2;
IntMatrix arcs(env);
//char ifilename[128];
//char ifilename = "example.txt";
char* wfilename = "../results/result.txt";
/*if (argc > 1)
{
topK = atoi(argv[1]);
nbNodes = atoi(argv[2]);
//sprintf(ifilename, "../data/%d.dat", nbNodes);
} */
ifstream file;
file.open("example.txt");
if (!file) {
cerr << "'ERROR: could not open file '" //<< ifilename<br /> << "' for reading" << endl;<br /> cerr << "usage: " << argv[0] << " <file>" << endl;<br /> throw(-1);
}
file >> weight >> arcs;
file.close();
nbNodes = weight.getSize();
// X: X[i][j]
NumVarMatrix X(env, nbNodes);
for(i = 0; i < nbNodes; i++)<br /> X[i] = IloNumVarArray(env, nbNodes, 0, 1, ILOINT);
IloNumVarArray N(env, nbNodes, 0, 1, ILOINT);
ofstream wfile(wfilename, ios::app);
if(!wfile)
{
cerr<<"ERROR: could not open file '" //<< ifilename<br /> << "' for reading" << endl;<br /> cerr << "usage: " << argv[0] << " <file>" << endl;<br /> throw(-1);
}
IloTimer timer(env);
timer.start();
IloSolution sol1 = exProblem(env, weight, X,N,topK,arcs);
timer.stop();
wfile << sol1.getObjectiveValue() << "\t" << timer.getTime() << "\t";
wfile.close();
}
catch(IloException &e) {
cerr << "ERROR: " << e << endl;<br /> }
catch( ... ) {
cerr << "ERROR" << endl;<br /> }
env.end();
return 0;
}
the program shows no Compilation or link error but does not open the file for reading. the file is present in the same directory
#CPLEXOptimizers#DecisionOptimization