如何保存CPLEX求解器的查询结果?
How to save the query results of CPLEX solver?
我正在使用 CPLEX Concert 技术(使用 C++)在循环中多次求解线性程序。在每次迭代中,我想将 cplex.getCplexStatus()
的输出保存到一个向量中,以便稍后将其打印到一个文件中。我首先使用 vector <string> LP_STATUS;
引入了一个向量,然后尝试通过在循环中使用 LP_STATUS.push_back (cplex.getCplexStatus() ) ;
来捕获输出。但是,我最终遇到以下错误:
severity: 'Error' message: 'no instance of overloaded function
"std::vector<_Tp, _Alloc>::push_back [with _Tp=std::__cxx11::string,
_Alloc=std::allocator]" matches the argument list -- argument types are: (IloCplex::CplexStatus) -- object type is:
std::vector>' at: '132,13' source: '' code:
'undefined'
你能帮我解决这个问题吗?
您收到编译器错误,因为 getCplexStatus method returns a value from the IloCplex::CplexStatus 枚举 不是 字符串。解决此问题的一种方法是:
vector<IloCplex::CplexStatus> LP_STATUS;
LP_STATUS.push_back (cplex.getCplexStatus());
也就是说,我们将 LP_STATUS
声明为 IloCplex::CplexStatus
的向量而不是 string
的向量。
我正在使用 CPLEX Concert 技术(使用 C++)在循环中多次求解线性程序。在每次迭代中,我想将 cplex.getCplexStatus()
的输出保存到一个向量中,以便稍后将其打印到一个文件中。我首先使用 vector <string> LP_STATUS;
引入了一个向量,然后尝试通过在循环中使用 LP_STATUS.push_back (cplex.getCplexStatus() ) ;
来捕获输出。但是,我最终遇到以下错误:
severity: 'Error' message: 'no instance of overloaded function "std::vector<_Tp, _Alloc>::push_back [with _Tp=std::__cxx11::string, _Alloc=std::allocator]" matches the argument list -- argument types are: (IloCplex::CplexStatus) -- object type is: std::vector>' at: '132,13' source: '' code: 'undefined'
你能帮我解决这个问题吗?
您收到编译器错误,因为 getCplexStatus method returns a value from the IloCplex::CplexStatus 枚举 不是 字符串。解决此问题的一种方法是:
vector<IloCplex::CplexStatus> LP_STATUS;
LP_STATUS.push_back (cplex.getCplexStatus());
也就是说,我们将 LP_STATUS
声明为 IloCplex::CplexStatus
的向量而不是 string
的向量。