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

Method writeLocalModel

highs/lp_data/Highs.cpp:886–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884}
885
886HighsStatus Highs::writeLocalModel(HighsModel& model,
887 const std::string& filename) {
888 HighsStatus return_status = HighsStatus::kOk;
889 HighsStatus call_status;
890 HighsLp& lp = model.lp_;
891
892 // Dimensions in a_matrix_ may not be set, so take them from lp
893 lp.setMatrixDimensions();
894
895 // Normalise names according to file type
896 HighsFileType file_type = getFileType(filename);
897 call_status = normaliseNames(this->options_.log_options, lp, file_type);
898 return_status = interpretCallStatus(options_.log_options, call_status,
899 return_status, "normaliseNames");
900 assert(call_status != HighsStatus::kError);
901
902 // Ensure that the LP is column-wise
903 lp.ensureColwise();
904
905 // Ensure that the dimensions are OK
906 if (!lpDimensionsOk("writeLocalModel", lp, options_.log_options))
907 return HighsStatus::kError;
908
909 if (model.hessian_.dim_ > 0) {
910 call_status = assessHessianDimensions(options_, model.hessian_);
911 if (call_status == HighsStatus::kError) return call_status;
912 }
913
914 // Check that the matrix starts are OK
915 call_status = lp.a_matrix_.assessStart(options_.log_options);
916 if (call_status == HighsStatus::kError) return call_status;
917
918 // Check that the matrix indices are within bounds
919 call_status = lp.a_matrix_.assessIndexBounds(options_.log_options);
920 if (call_status == HighsStatus::kError) return call_status;
921
922 // Check for repeated column or row names that would corrupt the file
923 if (model.lp_.col_hash_.hasDuplicate(model.lp_.col_names_)) {
924 highsLogUser(options_.log_options, HighsLogType::kError,
925 "Model has repeated column names\n");
926 return returnFromHighs(HighsStatus::kError);
927 }
928 if (model.lp_.row_hash_.hasDuplicate(model.lp_.row_names_)) {
929 highsLogUser(options_.log_options, HighsLogType::kError,
930 "Model has repeated row names\n");
931 return returnFromHighs(HighsStatus::kError);
932 }
933 if (filename == "") {
934 // Empty file name: report model on logging stream
935 reportModel(model);
936 } else {
937 Filereader* writer =
938 Filereader::getFilereader(options_.log_options, filename);
939 if (writer == NULL) {
940 highsLogUser(options_.log_options, HighsLogType::kError,
941 "Model file %s not supported\n", filename.c_str());
942 return HighsStatus::kError;
943 }

Callers 1

TestFilereader.cppFile · 0.80

Calls 13

getFileTypeFunction · 0.85
normaliseNamesFunction · 0.85
interpretCallStatusFunction · 0.85
lpDimensionsOkFunction · 0.85
assessHessianDimensionsFunction · 0.85
highsLogUserFunction · 0.85
setMatrixDimensionsMethod · 0.80
assessStartMethod · 0.80
assessIndexBoundsMethod · 0.80
hasDuplicateMethod · 0.80
c_strMethod · 0.80
ensureColwiseMethod · 0.45

Tested by

no test coverage detected