Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precision in solution file "all" #622

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CbcParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/CbcParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ class CBCLIB_EXPORT CbcParameters {
PMBoundsAll,
PMFixInt,
PMFixAll,
PMEndMarker
PMEndMarker,
PMAllCsv
svigerske marked this conversation as resolved.
Show resolved Hide resolved
};

/*! \brief Major status codes for branch-and-cut
Expand Down
109 changes: 87 additions & 22 deletions src/CbcSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -11043,18 +11052,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 @@ -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]);
}
}
}
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -11152,6 +11216,7 @@ clp watson.mps -\nscaling off\nprimalsimplex");
}
}
}

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