jeudi 3 octobre 2019

Want to limit the output on the terminal when using the CPLEX library

What I want to achieve

When using the CPLEX library in C++, I want to erase output because the output of the solution information on the terminal becomes an obstacle when using the library repeatedly.

Source Code

The original source code is long enough not to be listed here. Thus, the following is a sample code that shows only the problems in the question.

#include <cstring>
#include <ilcplex/ilocplex.h>
#include <bits/stdc++.h>
ILOSTLBEGIN

int main()
{
  IloEnv env;
  IloModel model(env);
  IloNumVarArray x_var(env);
  IloNumVarArray y_var(env);
  IloCplex cplex(model);

  x_var.add(IloNumVar(env, 0, IloInfinity, "x"));
  y_var.add(IloNumVar(env, 0, IloInfinity, "y"));
  model.add(IloMaximize(env, 3*x_var[0] + 5*y_var[0]));
  model.add(IloRange(env, x_var[0] + 7*y_var[0], 140, "c_1"));
  model.add(IloRange(env, x_var[0] + 2*y_var[0], 50, "c_2"));
  model.add(IloRange(env, 3*x_var[0] + 2*y_var[0], 130, "c_3"));

  cplex.setParam(IloCplex::Param::RootAlgorithm, IloCplex::Primal);
  cplex.setOut(env.getNullStream());//Error on this line

  cplex.solve();
  cplex.end();
  env.end();

  return 0;
}

cplex.setOut(env.getNullStream());

This line is supposed to limit the output to the terminal, but it causes an error during compilation.

Error Message

A link error occurs as follows.

Undefined symbols for architecture x86_64:
  "IloAlgorithm::setOut(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      _main in ccY3umy3.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

For the IloCplex and IloAlgorithm classes, see the following URL

https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.9.0/ilog.odms.cplex.help/refcppcplex/html/classes/IloCplex.html

https://www.ibm.com/support/knowledgecenter/SSSA5P_12.5.0/ilog.odms.ide.help/refcppopl/html/classes/IloAlgorithm.html

What I tried

・If the source code does not have a "cplex.setOut()" line, it can be compiled and run without problems.

・There are various functions in the IloAlgorithm class, but functions like "getTime()" and "printTime()" with no arguments can be used without problems.

・I also make sure that functions with arguments like "getValues(const IloIntVarArray vars, IloNumArray vals)" do not cause link errors.

・However, if I use a function like "setOut(ostream &)" or "setWarning(ostream &)" with an argument of (ostream &) as in the example code, I will get a link error.

I cannot solve the problem of link error only for (ostream &).

Please help me.

Aucun commentaire:

Enregistrer un commentaire