Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  CSV reader

    Posted Mon April 09, 2012 03:23 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Hello

    I read a .csv file using the following command

    IloCsvReader reader(env, "arcs.csv"); // arcs.csv is 8 by 8 table contains numbers

    and I have an empty IloNumArrayArray

    how I can save the values come from CsvReader in the IloNumArrayArray

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CSV reader

    Posted Mon April 09, 2012 04:26 PM

    Originally posted by: SystemAdmin


    Something like this should do the trick (untested code):
    IloCsvReader reader(env, "arcs.csv");
    IloInt lines = reader.getNumberOfItems();
    IloNumArrayArray data(env);
    for (IloInt i = 0; i < lines; ++i) {
       IloNumArray lineData(env);
       IloCsvLine line = reader.getLineByNumber(i);
       IloInt fields = line.getNumberOfFields();
       for (IloInt f = 0; f < fields; ++f)
          lineData.add(line.getFloatByPosition(f));
       data.add(lineData);
    }
    

    Please see also the reference documentation of classes IloCsvReader and IloCsvLine. Looking through the available functions should already tell you how to get the table into the array.
    #CPLEXOptimizers
    #DecisionOptimization