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

Function writeMps

highs/io/HMPSIO.cpp:595–1001  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593}
594
595HighsStatus writeMps(
596 const HighsLogOptions& log_options, const std::string& filename,
597 const std::string& model_name, const HighsInt& num_row,
598 const HighsInt& num_col, const HighsInt& q_dim, const ObjSense& sense,
599 const double& offset, const vector<double>& col_cost,
600 const vector<double>& col_lower, const vector<double>& col_upper,
601 const vector<double>& row_lower, const vector<double>& row_upper,
602 const vector<HighsInt>& a_start, const vector<HighsInt>& a_index,
603 const vector<double>& a_value, const vector<HighsInt>& q_start,
604 const vector<HighsInt>& q_index, const vector<double>& q_value,
605 const vector<HighsVarType>& integrality, const std::string& objective_name,
606 const vector<std::string>& col_names, const vector<std::string>& row_names,
607 const bool use_free_format) {
608 HighsInt num_no_cost_zero_columns = 0;
609 HighsInt num_no_cost_zero_columns_in_bounds_section = 0;
610 highsLogDev(log_options, HighsLogType::kInfo,
611 "writeMPS: Trying to open file %s\n", filename.c_str());
612 FILE* file = fopen(filename.c_str(), "w");
613 if (file == 0) {
614 highsLogUser(log_options, HighsLogType::kError, "Cannot open file %s\n",
615 filename.c_str());
616 return HighsStatus::kError;
617 }
618 highsLogDev(log_options, HighsLogType::kInfo, "writeMPS: Opened file OK\n");
619 // Check that the names are no longer than 8 characters for fixed format write
620 HighsInt max_name_length =
621 std::max(maxNameLength(col_names), maxNameLength(row_names));
622 if (!use_free_format && max_name_length > 8) {
623 highsLogUser(
624 log_options, HighsLogType::kError,
625 "Cannot write fixed MPS with names of length (up to) %" HIGHSINT_FORMAT
626 "\n",
627 max_name_length);
628 fclose(file);
629 return HighsStatus::kError;
630 }
631 assert(objective_name != "");
632 vector<HighsInt> r_ty;
633 vector<double> rhs, ranges;
634 bool have_rhs = false;
635 bool have_ranges = false;
636 bool have_bounds = false;
637 bool have_int = false;
638 r_ty.resize(num_row);
639 rhs.assign(num_row, 0);
640 ranges.assign(num_row, 0);
641 for (HighsInt r_n = 0; r_n < num_row; r_n++) {
642 if (row_lower[r_n] == row_upper[r_n]) {
643 // Equality constraint - Type E - range = 0
644 r_ty[r_n] = MPS_ROW_TY_E;
645 rhs[r_n] = row_lower[r_n];
646 } else if (!highs_isInfinity(row_upper[r_n])) {
647 // Upper bounded constraint - Type L
648 r_ty[r_n] = MPS_ROW_TY_L;
649 rhs[r_n] = row_upper[r_n];
650 if (!highs_isInfinity(-row_lower[r_n])) {
651 // Boxed constraint - range = u-l
652 ranges[r_n] = row_upper[r_n] - row_lower[r_n];

Callers 1

writeModelAsMpsFunction · 0.85

Calls 8

highsLogDevFunction · 0.85
highsLogUserFunction · 0.85
maxNameLengthFunction · 0.85
highs_isInfinityFunction · 0.85
highsBoolToStringFunction · 0.85
c_strMethod · 0.80
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected