Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Read .dat file

    Posted Sun September 20, 2020 05:46 PM

    Hello everyone,

    I need a help with the reading .dat file for my optimization problem coded by C++ (Under Visual Studio)

    I have a .dat file conrains three arrays like this

    [1, 1, 1]

    [[4, 5 ,5]

    [4 ,5 ,5]

    [4 ,5, 5]

    [4, 5, 5]]

    [4 ,5 ,5, 5]

    How can I open and read this .dat file ?

    Thank you in advance






    #DecisionOptimization
    #Support
    #SupportMigration


  • 2.  RE: Read .dat file

    Posted Mon September 21, 2020 09:09 AM

    Dear Milena,

    You could write an opl script to dump the .dat information in an easy-to-read format for C++ (e.g. whitespace separated tokens).

    Then use the << C++ operator on stream to read the data.

    I hope this helps.

    Cheers.






    #DecisionOptimization
    #Support
    #SupportMigration


  • 3.  RE: Read .dat file

    Posted Tue September 22, 2020 04:43 PM

    Thank you so much Renaud, I changed my .dat file and now it contains only one array (named Pr) , which is [10, 10, 10]

    I have written a script like this :


    IloNumArray Pr(env);

     const char* filename = "Project.dat";

     if (argc > 1)        

      filename = argv[1];  

     ifstream file(filename);

     if (!file) {

      cerr << "ERROR: could not open file '" << filename << "' for reading" << endl;  

       cerr << "ERROR: could not open file for reading" << endl; 

       cerr << "usage:  " << argv[0] << " <file>" << endl;        

       throw(-1);

      }


     file >> Pr ;

     cout << Pr << endl;


    When I print to check if it is written or not it gives me

    []

    not

    [10, 10, 10] as we expect ? I could not understand what is the problem? (When I say file <<, it does not recognize the << operator) I use Visual Studio for C++. Do you have any idea ? Thank you so mcuh in advance







    #DecisionOptimization
    #Support
    #SupportMigration