MCPcopy Create free account
hub / github.com/LiangliangNan/PolyFit / load

Method load

code/math/linear_program_io.cpp:244–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242
243
244bool LinearProgram::load(const std::string& file_name) {
245 if (!details::is_file(file_name)) {
246 std::cerr << "file does not exist: \'" << file_name << "\'" << std::endl;
247 return false;
248 }
249
250 clear();
251
252 const std::string& ext = details::extension(file_name);
253 if (ext != "lp" && ext != "mps" && ext != "cip") {
254 std::cerr << "unsupported format: \'" << ext << "\'" << std::endl;
255 return false;
256 }
257
258 Scip* scip = 0;
259 SCIP_CALL(SCIPcreate(&scip));
260 SCIP_CALL(SCIPincludeDefaultPlugins(scip));
261
262 // disable scip output to stdout
263 SCIPmessagehdlrSetQuiet(SCIPgetMessagehdlr(scip), TRUE);
264
265 SCIP_CALL(SCIPreadProb(scip, file_name.c_str(), 0));
266
267 // SCIPgetProbName() returns the original file name
268 name_ = details::base_name(SCIPgetProbName(scip));
269 LinearObjective::Sense s = SCIPgetObjsense(scip) == SCIP_OBJSENSE_MINIMIZE ? LinearObjective::MINIMIZE : LinearObjective::MAXIMIZE;
270 objective_->set_sense(s);
271
272 const double infinity = Bound::infinity();
273
274 // create variables
275 int num_var = SCIPgetNVars(scip);
276 SCIP_VAR** scip_variables = SCIPgetVars(scip);
277 const std::vector<Variable*>& variables = create_n_variables(num_var);
278 for (std::size_t i = 0; i < num_var; ++i) {
279 SCIP_VAR* v = scip_variables[i];
280 const std::size_t idx = SCIPvarGetIndex(v);
281 Variable* var = variables[idx];
282
283 const char* name = SCIPvarGetName(v);
284 var->set_name(name);
285
286 double lb = SCIPvarGetLbGlobal(v);
287 double ub = SCIPvarGetUbGlobal(v);
288 var->set_bounds(lb, ub);
289
290 switch (SCIPvarGetType(v))
291 {
292 case SCIP_VARTYPE_BINARY:
293 var->set_variable_type(Variable::BINARY);
294 break;
295 case SCIP_VARTYPE_INTEGER:
296 var->set_variable_type(Variable::INTEGER);
297 break;
298 case SCIP_VARTYPE_CONTINUOUS:
299 default:
300 var->set_variable_type(Variable::CONTINUOUS);
301 break;

Callers

nothing calls this directly

Calls 15

SCIPcreateFunction · 0.85
SCIPmessagehdlrSetQuietFunction · 0.85
SCIPgetMessagehdlrFunction · 0.85
SCIPreadProbFunction · 0.85
SCIPgetProbNameFunction · 0.85
SCIPgetObjsenseFunction · 0.85
SCIPgetNVarsFunction · 0.85
SCIPgetVarsFunction · 0.85
SCIPvarGetIndexFunction · 0.85
SCIPvarGetNameFunction · 0.85
SCIPvarGetLbGlobalFunction · 0.85

Tested by

no test coverage detected