Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem with re-directing output to a different stream

    Posted 04/20/10 11:39 AM

    Originally posted by: Rahimeh


    Hello everyone,
    I have a strange problem with ILOG Concert in C++;
    When I set
    ofstream myLog(_strOutFile.c_str());
            m_env.setOut(myLog);
            m_env.setWarning(myLog);
            m_env.setError(myLog);
    

    The output still appears on standard output, i.e. screen.
    AT some point I was able to re-direct the output by doing
    m_cplex.setOut(myLog);
            m_cplex.setWarning(myLog);
            m_cplex.setError(myLog);
    

    for cplex object but it is also no longer possible.

    Any comment?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with re-directing output to a different stream

    Posted 04/20/10 11:58 AM

    Originally posted by: SystemAdmin


    Does none of your output get redirected or is only part of it redirected?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with re-directing output to a different stream

    Posted 04/20/10 12:02 PM

    Originally posted by: Rahimeh


    no part of output is re-directed.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Problem with re-directing output to a different stream

    Posted 04/21/10 12:47 AM

    Originally posted by: SystemAdmin


    Hm, this code works well for me:
    #include <iostream>
    #include <fstream>
    #include <ilcplex/ilocplex.h>
     
    int
    main(int argc, char **argv)
    {
       try {
          for (int i = 1; i < argc; ++i) {
             IloEnv env;
             IloModel model(env);
             IloCplex cplex(model);
     
             std::ofstream log("/dev/null");
             cplex.setOut(log);
             cplex.setWarning(log);
             cplex.setError(log);
     
             cplex.importModel(model, argv[i]);
             cplex.solve();
     
             std::cout << "Optimal solution: " << cplex.getObjValue() << std::endl;
     
             env.end();
          }
       } catch (std::exception& e) {
          std::cerr << "std::exception: " << e.what() << std::endl;
       } catch (IloException& e) {
          std::cerr << "IloException: " << e << std::endl;
       }
     
       return 0;
    }
    

    It solves all models given on the command line without any output from CPLEX.
    Does your code look the same? What CPLEX version do you use?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Problem with re-directing output to a different stream

    Posted 04/21/10 03:48 AM

    Originally posted by: SystemAdmin


    The same for me.
    I when I change the environment stream it does not work but when I change the cplex stream it SOMETIMES works and sometimes says gives an error that in debug mode goes to some where in system files that says stream size is problematic.
    This snippet is the same as at least what I do and does not work on my machine.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Problem with re-directing output to a different stream

    Posted 04/21/10 04:01 AM

    Originally posted by: SystemAdmin


    IloEnv and IloCplex both have their own pointers/references to output streams.
    If you instantiate IloCplex in one of the following ways
    IloCplex cplex(env);
    IloCplex cplex(model);
    

    then the stream pointers in 'cplex' are initialized from the stream pointers in 'env' or the environment on which 'model' was built.
    However, subsequent changes to the streams in these environments do not affect the streams stored for 'cplex'.
    This means you must either redirect the streams in the environments before you instantiate IloCplex or change the streams of the IloCplex instance explicitly.

    The errors concerning stream size are probably not related to CPLEX. What streams do you use when you encounter these errors?
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Problem with re-directing output to a different stream

    Posted 04/21/10 05:30 AM

    Originally posted by: SystemAdmin


    this idea of setting the stream for the environment before instantiating the cplex object seems working BUT still there are cases where setting stream for cplex in the course of algorithm fails. seems something to do with the size of stream.

    stream is a simply a text file for me.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Problem with re-directing output to a different stream

    Posted 04/21/10 08:16 AM

    Originally posted by: Rahimeh


    Thanks for the comment, it worked.
    #CPLEXOptimizers
    #DecisionOptimization