| 25 | } |
| 26 | |
| 27 | void HighsDebugSol::activate() { |
| 28 | if (!mipsolver->submip && |
| 29 | debugSolObjective <= mipsolver->mipdata_->upper_limit && |
| 30 | !mipsolver->options_mip_->mip_debug_solution_file.empty()) { |
| 31 | highsLogDev(mipsolver->options_mip_->log_options, HighsLogType::kInfo, |
| 32 | "reading debug solution file %s\n", |
| 33 | mipsolver->options_mip_->mip_debug_solution_file.c_str()); |
| 34 | std::ifstream file(mipsolver->options_mip_->mip_debug_solution_file); |
| 35 | if (file) { |
| 36 | std::string varname; |
| 37 | double varval; |
| 38 | std::string line; |
| 39 | bool incolsection = false; |
| 40 | std::map<std::string, int> nametoidx; |
| 41 | |
| 42 | for (HighsInt i = 0; i != mipsolver->orig_model_->num_col_; ++i) |
| 43 | nametoidx[mipsolver->orig_model_->col_names_[i]] = i; |
| 44 | |
| 45 | debugOrigSolution.resize(mipsolver->orig_model_->num_col_, 0.0); |
| 46 | while (std::getline(file, line)) { |
| 47 | // Check for start and stop markers |
| 48 | if (line.find("# Columns") != std::string::npos) { |
| 49 | incolsection = true; |
| 50 | continue; |
| 51 | } |
| 52 | if (line.find("# Rows") != std::string::npos) { |
| 53 | break; |
| 54 | } |
| 55 | if (!incolsection) continue; |
| 56 | |
| 57 | std::istringstream linestream(line); |
| 58 | linestream >> varname; |
| 59 | auto it = nametoidx.find(varname); |
| 60 | if (it != nametoidx.end()) { |
| 61 | linestream >> varval; |
| 62 | debugOrigSolution[it->second] = varval; |
| 63 | highsLogDev(mipsolver->options_mip_->log_options, HighsLogType::kInfo, |
| 64 | "%s = %g\n", varname.c_str(), varval); |
| 65 | } |
| 66 | } |
| 67 | debugSolution = debugOrigSolution; |
| 68 | |
| 69 | HighsCDouble debugsolobj = 0.0; |
| 70 | for (HighsInt i = 0; i != mipsolver->orig_model_->num_col_; ++i) |
| 71 | debugsolobj += mipsolver->orig_model_->col_cost_[i] * |
| 72 | HighsCDouble(debugOrigSolution[i]); |
| 73 | |
| 74 | debugSolObjective = double(debugsolobj + mipsolver->orig_model_->offset_); |
| 75 | debugSolActive = true; |
| 76 | printf("debug sol active\n"); |
| 77 | registerDomain(mipsolver->mipdata_->getDomain()); |
| 78 | } else { |
| 79 | highsLogUser(mipsolver->options_mip_->log_options, HighsLogType::kWarning, |
| 80 | "debug solution: could not open file '%s'\n", |
| 81 | mipsolver->options_mip_->mip_debug_solution_file.c_str()); |
| 82 | HighsModel model; |
| 83 | model.lp_ = *mipsolver->model_; |
| 84 | model.lp_.col_names_.clear(); |
no test coverage detected