Originally posted by: Olivia.w
I am very, very new of using cplex with c++. I am trying to solve a problem using the column generation algorithm. But firstly I need to input data from a .csv file like this:
I have write something using IloCsvReader:
#include <ilcplex/ilocplex.h>
#include <ilconcert/ilocsvreader.h>
ILOSTLBEGIN
#define RC_EPS 1.0e-6 // optimality tolerance
//function of data reading
void readArray (IloIntArray ordername, char const *file)
{
ordername.clear();
IloCsvReader reader;
try {
reader = IloCsvReader(ordername.getEnv(),file);
IloInt const lines = reader.getNumberOfItems();
for (IloInt i=0; i < lines; ++i)
{
IloCsvLine const line = reader.getLineByNumber(i);
ordername.add(IloIntArray(ordername.getEnv()));
ordername[i]=line.getIntByPosition(4);
}
reader.end();
} catch (...){
reader.end();
throw;
}
}
int main(int argc, const char **argv) {
char const *filename = "/Users/wy/Documents/Programs/PD151201/RSS3_2014-10-24.csv";
try {
IloEnv env;
//************* Read Parameters *************//
//orders
IloIntArray ordername(env);
readArray(ordername, filename);
for (IloInt i=0; i< ordername.getSize(); ++i)
{
cout<< ordername[i]<<endl;
}
env.end();
}
catch (IloException& ex) {
cerr << "Error: " << ex << endl;
}
catch (...) {
cerr << "Error" << endl;
}
return 0;
}
While debug it says
X& IloArray::operator[] (IloInt i) : Out of bounds operation: index superior to size of array
Assertion failed: ((i < _impl->getSize()) || (ILOSTD(cerr) << "X& IloArray::operator[] (IloInt i) : Out of bounds operation: index superior to size of array" << ILOSTD(endl), ilo_stop_assert())), function operator[], file /Applications/IBM_CPLEX/ILOG/CPLEX_Studio125/concert/include/ilconcert/iloenv.h, line 2204.
Program ended with exit code: 9
I have no idea what is wrong... Maybe I just did not understand the class at all...Could somebody please tell me what should I do...Thank you!
#CPLEXOptimizers#DecisionOptimization