MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / readModelFromFile

Method readModelFromFile

highs/io/FilereaderLp.cpp:22–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#include "lp_data/HighsLpUtils.h"
21
22FilereaderRetcode FilereaderLp::readModelFromFile(const HighsOptions& options,
23 const std::string filename,
24 HighsModel& model) {
25 bool warning_issued = false;
26 HighsLp& lp = model.lp_;
27 HighsHessian& hessian = model.hessian_;
28 try {
29 Model m = readinstance(filename);
30
31 if (!m.soss.empty()) {
32 highsLogUser(options.log_options, HighsLogType::kError,
33 "SOS not supported by HiGHS\n");
34 return FilereaderRetcode::kParserError;
35 }
36
37 // build variable index and gather variable information
38 std::map<std::string, unsigned int> varindex;
39
40 lp.num_col_ = m.variables.size();
41 lp.num_row_ = m.constraints.size();
42 lp.row_names_.resize(m.constraints.size());
43 lp.integrality_.assign(lp.num_col_, HighsVarType::kContinuous);
44 HighsInt num_continuous = 0;
45 for (size_t i = 0; i < m.variables.size(); i++) {
46 varindex[m.variables[i]->name] = i;
47 lp.col_lower_.push_back(m.variables[i]->lowerbound);
48 lp.col_upper_.push_back(m.variables[i]->upperbound);
49 lp.col_names_.push_back(m.variables[i]->name);
50 if (m.variables[i]->type == VariableType::BINARY ||
51 m.variables[i]->type == VariableType::GENERAL) {
52 lp.integrality_[i] = HighsVarType::kInteger;
53 } else if (m.variables[i]->type == VariableType::SEMICONTINUOUS) {
54 lp.integrality_[i] = HighsVarType::kSemiContinuous;
55 } else if (m.variables[i]->type == VariableType::SEMIINTEGER) {
56 lp.integrality_[i] = HighsVarType::kSemiInteger;
57 } else {
58 lp.integrality_[i] = HighsVarType::kContinuous;
59 num_continuous++;
60 }
61 }
62 // Clear lp.integrality_ if problem is pure LP
63 if (static_cast<size_t>(num_continuous) == m.variables.size())
64 lp.integrality_.clear();
65 // get objective
66 lp.objective_name_ = m.objective->name;
67 // ToDo: Fix m.objective->offset and then use it here
68 //
69 lp.offset_ = m.objective->offset;
70 lp.col_cost_.resize(lp.num_col_, 0.0);
71 for (const auto& lt : m.objective->linterms) {
72 lp.col_cost_[varindex[lt->var->name]] = lt->coef;
73 }
74
75 std::map<std::shared_ptr<Variable>, std::vector<std::shared_ptr<Variable>>>
76 mat;
77 std::map<std::shared_ptr<Variable>, std::vector<double>> mat2;
78 for (std::shared_ptr<QuadTerm> qt : m.objective->quadterms) {
79 if (qt->var1 != qt->var2) {

Callers 1

readModelMethod · 0.45

Calls 12

readinstanceFunction · 0.85
highsLogUserFunction · 0.85
to_stringFunction · 0.85
push_backMethod · 0.80
countMethod · 0.80
c_strMethod · 0.80
isColwiseMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
clearMethod · 0.45
ensureColwiseMethod · 0.45

Tested by

no test coverage detected