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

Function writeSolutionFile

highs/lp_data/HighsModelUtils.cpp:495–549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495void writeSolutionFile(FILE* file, const HighsOptions& options,
496 const HighsModel& model, const HighsBasis& basis,
497 const HighsSolution& solution, const HighsInfo& info,
498 const HighsModelStatus model_status,
499 const HighsInt style) {
500 const bool have_primal = solution.value_valid;
501 const bool have_dual = solution.dual_valid;
502 const bool have_basis = basis.valid;
503 const HighsLp& lp = model.lp_;
504 const HighsLogOptions& log_options = options.log_options;
505 assert(lp.col_names_.size() == static_cast<size_t>(lp.num_col_));
506 assert(lp.row_names_.size() == static_cast<size_t>(lp.num_row_));
507 if (style == kSolutionStyleOldRaw) {
508 writeOldRawSolution(file, log_options, lp, basis, solution);
509 } else if (style == kSolutionStylePretty) {
510 const HighsVarType* integrality =
511 lp.integrality_.size() > 0 ? lp.integrality_.data() : nullptr;
512 writeModelBoundSolution(file, log_options, true, lp.num_col_, lp.col_lower_,
513 lp.col_upper_, lp.col_names_, have_primal,
514 solution.col_value, have_dual, solution.col_dual,
515 have_basis, basis.col_status, integrality);
516 writeModelBoundSolution(file, log_options, false, lp.num_row_,
517 lp.row_lower_, lp.row_upper_, lp.row_names_,
518 have_primal, solution.row_value, have_dual,
519 solution.row_dual, have_basis, basis.row_status);
520 highsFprintfString(file, log_options, "\n");
521 std::stringstream ss;
522 ss.str(std::string());
523 ss << highsFormatToString("Model status: %s\n",
524 utilModelStatusToString(model_status).c_str());
525 highsFprintfString(file, log_options, ss.str());
526 auto objStr = highsDoubleToString((double)info.objective_function_value,
527 kHighsSolutionValueToStringTolerance);
528 highsFprintfString(file, log_options, "\n");
529 ss.str(std::string());
530 ss << highsFormatToString("Objective value: %s\n", objStr.data());
531 highsFprintfString(file, log_options, ss.str());
532 } else if (style == kSolutionStyleGlpsolRaw ||
533 style == kSolutionStyleGlpsolPretty) {
534 const bool raw = style == kSolutionStyleGlpsolRaw;
535 writeGlpsolSolution(file, options, model, basis, solution, model_status,
536 info, raw);
537 } else {
538 // Standard raw solution file, possibly sparse => only nonzero primal values
539 const bool sparse = style == kSolutionStyleSparse;
540 assert(style == kSolutionStyleRaw || sparse);
541 highsFprintfString(file, log_options, "Model status\n");
542 std::stringstream ss;
543 ss.str(std::string());
544 ss << highsFormatToString("%s\n",
545 utilModelStatusToString(model_status).c_str());
546 highsFprintfString(file, log_options, ss.str());
547 writeModelSolution(file, log_options, model, solution, info, sparse);
548 }
549}
550
551void writeGlpsolCostRow(FILE* file, const HighsLogOptions& log_options,
552 const bool raw, const bool is_mip,

Callers 2

writeSolutionMethod · 0.85
writeSolutionMethod · 0.85

Calls 12

writeOldRawSolutionFunction · 0.85
writeModelBoundSolutionFunction · 0.85
highsFprintfStringFunction · 0.85
highsFormatToStringFunction · 0.85
utilModelStatusToStringFunction · 0.85
highsDoubleToStringFunction · 0.85
writeGlpsolSolutionFunction · 0.85
writeModelSolutionFunction · 0.85
dataMethod · 0.80
strMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected