Skip to content

Commit

Permalink
added "allcsv" (like "all" but in csv format) as new printing mode (#622
Browse files Browse the repository at this point in the history
)
  • Loading branch information
raller09 authored Oct 10, 2024
1 parent a5f753c commit d1dbc98
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/CbcParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,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",
Expand Down
1 change: 1 addition & 0 deletions src/CbcParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class CBCLIB_EXPORT CbcParameters {
PMBoundsAll,
PMFixInt,
PMFixAll,
PMAllCsv,
PMEndMarker
};

Expand Down
109 changes: 87 additions & 22 deletions src/CbcSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10776,6 +10776,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
Expand Down Expand Up @@ -11139,18 +11148,27 @@ clp watson.mps -\nscaling off\nprimalsimplex");
}
break;
}

char printFormat[50];
sprintf(printFormat, " %s %s\n",
CLP_QUOTE(CLP_OUTPUT_FORMAT),
CLP_QUOTE(CLP_OUTPUT_FORMAT));
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;
Expand All @@ -11161,18 +11179,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]);
}
}
}
}
Expand All @@ -11193,11 +11232,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;
Expand All @@ -11214,18 +11261,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) {
Expand All @@ -11248,6 +11312,7 @@ clp watson.mps -\nscaling off\nprimalsimplex");
}
}
}

if (cbcParamCode == CbcParam::WRITENEXTSOL) {
if (saveLpSolver) {
clpSolver->swapModelPtr(saveLpSolver);
Expand Down

0 comments on commit d1dbc98

Please sign in to comment.