Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Apple XCode ifstream - import txt.file

    Posted Wed July 12, 2017 09:37 AM

    Originally posted by: JodokusQuak


    Hello guys,

    My used versions are:

    • Visual Studio for Mac Community 7.0.1 (build 24)
    • cplex_studio1263.osx

    Actually I am not that sure what the problem is. When I am running my program it ends and the value of the objective function is 0 (that's not right). 

    I think the problem is the data file. The program finds the data file, because there is no "file not found" message. But beside that the value is 0 the output txt.file doesn't appear.

        ifstream myfile("/Users/Jodokus/OneDrive/Dokumente/Uni/test_v2.txt");

        if (!myfile) {

            cout << "file not found" << endl;

            system("break");

            return 1;

        }


    (...)

     

     if (solved){

     fstream f1("output.txt", ios::out);

     

    (...)

     

    Does anybody know what the problem could be or do you need any more specific details?

    Regards

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Apple XCode ifstream - import txt.file

    Posted Wed July 12, 2017 12:31 PM

    Well this is way too little information to help you. And it is unclear what your question is.

    So you open a text file. Fine. But what do you do with that file? You say the data you read from the file may be incorrect since you get an unexpected objective value. Did you actually check the data you read (maybe by printing it to the screen)? Did you check your model? One way to do this is to call cplex.exportModel("model.lp") right before calling cplex.solve(). Then look at the model.lp file and see if the model looks as expected.

    Then you say that the output.txt file does not appear. How and why is that related to getting an unexpected objective value? If the file does not appear, are you sure that 'solved' is actually true? Did you check whether creation of the file did succeed at all (does f1 evaluate to true in a boolean context?)?

    The code you posted here seems completely unrelated to CPLEX?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Apple XCode ifstream - import txt.file

    Posted Thu July 13, 2017 03:15 AM

    Originally posted by: JodokusQuak


    Sorry, you're right it's not really a topic for this forum.

    I already fixed the problem it was a configuration issue of Apple X Code. The description how to solve such a problem is here: 

    https://stackoverflow.com/questions/16779149/c-program-in-xcode-not-outputting-simple-text-file-using-outfile
     

    And sorry Daniel, next time it will be more detailed and a topic of CPLEX if I put a question in this forum.

    Regards
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Apple XCode ifstream - import txt.file

    Posted Thu July 13, 2017 03:21 AM

    Note that your code most likely did create the file. It just created it in a different directory than you expected (it created it in the current working directory which you probably changed by now following this SO quote).

    In general, if you output files from an IDE or similar and they don't seem to appear, then it is a good idea to try using absolute paths in your code, at least for debugging. This way you can know exactly where the file should appear. Another option would be to always print the current working directory from your application since any relative path names will be resolved with respect to that directory.


    #CPLEXOptimizers
    #DecisionOptimization