| 357 | } |
| 358 | |
| 359 | HighsStatus FilereaderLp::writeModelToFile(const HighsOptions& options, |
| 360 | const std::string filename, |
| 361 | const HighsModel& model) { |
| 362 | const HighsLp& lp = model.lp_; |
| 363 | |
| 364 | const bool ok_names = lp.okNames(); |
| 365 | assert(ok_names); |
| 366 | if (!ok_names) return HighsStatus::kError; |
| 367 | |
| 368 | // Create a row-wise copy of the matrix |
| 369 | HighsSparseMatrix ar_matrix = lp.a_matrix_; |
| 370 | ar_matrix.ensureRowwise(); |
| 371 | |
| 372 | FILE* file = fopen(filename.c_str(), "w"); |
| 373 | |
| 374 | // write comment at the start of the file |
| 375 | this->writeToFile(file, "\\ %s", LP_COMMENT_FILESTART); |
| 376 | this->writeToFileLineEnd(file); |
| 377 | |
| 378 | // write objective |
| 379 | this->writeToFile(file, "%s", |
| 380 | lp.sense_ == ObjSense::kMinimize ? "min" : "max"); |
| 381 | this->writeToFileLineEnd(file); |
| 382 | this->writeToFile(file, " obj:"); |
| 383 | for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) { |
| 384 | double coef = lp.col_cost_[iCol]; |
| 385 | if (coef != 0.0) { |
| 386 | this->writeToFileValue(file, coef); |
| 387 | this->writeToFileVar(file, lp.col_names_[iCol]); |
| 388 | } |
| 389 | } |
| 390 | this->writeToFile(file, |
| 391 | " "); // ToDo Unnecessary, but only to give empty diff |
| 392 | if (model.isQp()) { |
| 393 | this->writeToFile(file, "+ ["); |
| 394 | for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) { |
| 395 | for (HighsInt iEl = model.hessian_.start_[iCol]; |
| 396 | iEl < model.hessian_.start_[iCol + 1]; iEl++) { |
| 397 | HighsInt iRow = model.hessian_.index_[iEl]; |
| 398 | if (iCol <= iRow) { |
| 399 | double coef = model.hessian_.value_[iEl]; |
| 400 | if (iCol != iRow) coef *= 2; |
| 401 | if (coef != 0.0) { |
| 402 | this->writeToFileValue(file, coef); |
| 403 | this->writeToFileVar(file, lp.col_names_[iCol]); |
| 404 | this->writeToFile(file, " *"); |
| 405 | this->writeToFileVar(file, lp.col_names_[iRow]); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | this->writeToFile(file, |
| 411 | " ]/2 "); // ToDo Surely needs only to be one space |
| 412 | } |
| 413 | double coef = lp.offset_; |
| 414 | if (coef != 0) this->writeToFileValue(file, coef); |
| 415 | this->writeToFileLineEnd(file); |
| 416 |
no test coverage detected