From 7df838ba1c34409e926192cf225b3c1e33af6c74 Mon Sep 17 00:00:00 2001 From: "ralf.moorbrink" Date: Wed, 4 Oct 2023 13:21:50 +0200 Subject: [PATCH 1/2] added "allcsv" (like "all" but in csv format) as new printing mode --- src/CbcParameters.cpp | 1 + src/CbcParameters.hpp | 3 +- src/CbcSolver.cpp | 109 +++++++++++++++++++++++++++++++++--------- 3 files changed, 90 insertions(+), 23 deletions(-) diff --git a/src/CbcParameters.cpp b/src/CbcParameters.cpp index a4a4f883f..29e57cf3e 100644 --- a/src/CbcParameters.cpp +++ b/src/CbcParameters.cpp @@ -1212,6 +1212,7 @@ void CbcParameters::addCbcSolverKwdParams() { parameters_[CbcParam::INTPRINT]->appendKwd("boundsall", CbcParameters::PMBoundsAll); parameters_[CbcParam::INTPRINT]->appendKwd("fixint", CbcParameters::PMFixInt); parameters_[CbcParam::INTPRINT]->appendKwd("fixall", CbcParameters::PMFixAll); + parameters_[CbcParam::INTPRINT]->appendKwd("allcsv", CbcParameters::PMAllCsv); parameters_[CbcParam::NODESTRATEGY]->setup( "node!Strategy", diff --git a/src/CbcParameters.hpp b/src/CbcParameters.hpp index 406484d3f..38ed52b73 100644 --- a/src/CbcParameters.hpp +++ b/src/CbcParameters.hpp @@ -464,7 +464,8 @@ class CBCLIB_EXPORT CbcParameters { PMBoundsAll, PMFixInt, PMFixAll, - PMEndMarker + PMEndMarker, + PMAllCsv }; /*! \brief Major status codes for branch-and-cut diff --git a/src/CbcSolver.cpp b/src/CbcSolver.cpp index 5fa5f383f..811dcf632 100644 --- a/src/CbcSolver.cpp +++ b/src/CbcSolver.cpp @@ -10680,6 +10680,15 @@ clp watson.mps -\nscaling off\nprimalsimplex"); #endif break; } + + bool printingAllAsCsv = false; + if (printMode == 15) { + // when allcsv then set printMode to all and + // change the output format to csv + printMode = 4; + printingAllAsCsv = true; + } + if (printMode < 5) { if (cbcParamCode == CbcParam::WRITENEXTSOL) { // save @@ -11043,6 +11052,7 @@ clp watson.mps -\nscaling off\nprimalsimplex"); } break; } + char printFormat[50]; sprintf(printFormat, " %s %s\n", CLP_QUOTE(CLP_OUTPUT_FORMAT), @@ -11050,11 +11060,19 @@ clp watson.mps -\nscaling off\nprimalsimplex"); if (printMode > 2 && printMode < 5) { for (iRow = 0; iRow < numberRows; iRow++) { int type = printMode - 3; + + std::string valueHasTolerance; + std::string rowName; + if (primalRowSolution[iRow] > rowUpper[iRow] + primalTolerance || primalRowSolution[iRow] < rowLower[iRow] - primalTolerance) { - fprintf(fp, "** "); + if (printingAllAsCsv) { + valueHasTolerance = "**"; + } else { + fprintf(fp, "** "); + } type = 2; } else if (fabs(primalRowSolution[iRow]) > 1.0e-8) { type = 1; @@ -11065,18 +11083,39 @@ clp watson.mps -\nscaling off\nprimalsimplex"); !maskMatches(maskStarts, masks, rowNames[iRow])) type = 0; if (type) { - fprintf(fp, "%7d ", iRow); + if (!printingAllAsCsv) { + fprintf(fp, "%7d ", iRow); + } + if (lengthName) { - const char *name = rowNames[iRow].c_str(); - size_t n = strlen(name); - size_t i; - for (i = 0; i < n; i++) - fprintf(fp, "%c", name[i]); - for (; i < lengthPrint; i++) - fprintf(fp, " "); + if (printingAllAsCsv) { + rowName = rowNames[iRow]; + } + else{ + const char *name = rowNames[iRow].c_str(); + size_t n = strlen(name); + size_t i; + + for (i = 0; i < n; i++) + fprintf(fp, "%c", name[i]); + for (; i < lengthPrint; i++) + fprintf(fp, " "); + } + } + + if (!printingAllAsCsv) { + fprintf(fp, printFormat, primalRowSolution[iRow], + dualRowSolution[iRow]); } - fprintf(fp, printFormat, primalRowSolution[iRow], - dualRowSolution[iRow]); + else{ + fprintf(fp, + "%s,%d,%s,%.15g,%.15g\n", + valueHasTolerance.c_str(), + iRow, + rowName.c_str(), + primalRowSolution[iRow], + dualRowSolution[iRow]); + } } } } @@ -11097,11 +11136,19 @@ clp watson.mps -\nscaling off\nprimalsimplex"); } for (iColumn = 0; iColumn < numberColumns; iColumn++) { int type = (printMode > 3) ? 1 : 0; + + std::string valueHasTolerance; + std::string colName; + if (primalColumnSolution[iColumn] > columnUpper[iColumn] + primalTolerance || primalColumnSolution[iColumn] < columnLower[iColumn] - primalTolerance) { - fprintf(fp, "** "); + if (printingAllAsCsv) { + valueHasTolerance = "**"; + } else { + fprintf(fp, "** "); + } type = 2; } else if (fabs(primalColumnSolution[iColumn]) > 1.0e-8) { type = 1; @@ -11118,18 +11165,35 @@ clp watson.mps -\nscaling off\nprimalsimplex"); type = 0; if (type) { if (printMode != 5) { - fprintf(fp, "%7d ", iColumn); + if (!printingAllAsCsv) { + fprintf(fp, "%7d ", iColumn); + } + if (lengthName) { - const char *name = columnNames[iColumn].c_str(); - size_t n = strlen(name); - size_t i; - for (i = 0; i < n; i++) - fprintf(fp, "%c", name[i]); - for (; i < lengthPrint; i++) - fprintf(fp, " "); + if (printingAllAsCsv) { + colName = columnNames[iColumn]; + } else { + const char *name = columnNames[iColumn].c_str(); + size_t n = strlen(name); + size_t i; + for (i = 0; i < n; i++) + fprintf(fp, "%c", name[i]); + for (; i < lengthPrint; i++) + fprintf(fp, " "); + } + } + if (!printingAllAsCsv) { + fprintf(fp, printFormat, primalColumnSolution[iColumn], + dualColumnSolution[iColumn]); + } else { + fprintf(fp, + "%s,%d,%s,%.15g,%.15g\n", + valueHasTolerance.c_str(), + iColumn, + colName.c_str(), + primalColumnSolution[iColumn], + dualColumnSolution[iColumn]); } - fprintf(fp, printFormat, primalColumnSolution[iColumn], - dualColumnSolution[iColumn]); } else { char temp[100]; if (lengthName) { @@ -11152,6 +11216,7 @@ clp watson.mps -\nscaling off\nprimalsimplex"); } } } + if (cbcParamCode == CbcParam::WRITENEXTSOL) { if (saveLpSolver) { clpSolver->swapModelPtr(saveLpSolver); From 50e72f23838a37cf318fbf5f2df5cb723682bce8 Mon Sep 17 00:00:00 2001 From: raller09 Date: Thu, 10 Oct 2024 12:11:09 +0200 Subject: [PATCH 2/2] enum IntPrintMode: swap position of PMEndMarker +PMAllCsv so PMEndMarker is the last element --- src/CbcParameters.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CbcParameters.hpp b/src/CbcParameters.hpp index 3ceb57823..aac4ff63e 100644 --- a/src/CbcParameters.hpp +++ b/src/CbcParameters.hpp @@ -474,8 +474,8 @@ class CBCLIB_EXPORT CbcParameters { PMBoundsAll, PMFixInt, PMFixAll, - PMEndMarker, - PMAllCsv + PMAllCsv, + PMEndMarker }; /*! \brief Major status codes for branch-and-cut