[sdpb] 120/233: Removed SDPSolverStatus class
Tobias Hansen
thansen at moszumanska.debian.org
Thu Mar 9 04:06:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository sdpb.
commit e17d2c200e09beb3453cadbc8a8f38fedfd18739
Author: David Simmons-Duffin <davidsd at gmail.com>
Date: Fri Jan 9 12:20:06 2015 +1300
Removed SDPSolverStatus class
---
src/SDPSolver.cpp | 18 +++++++++---------
src/SDPSolver.h | 55 +++++++++++++++++++++++++----------------------------
src/SDPSolverIO.cpp | 40 +++++++++++++++++---------------------
src/main.cpp | 8 +++++++-
4 files changed, 59 insertions(+), 62 deletions(-)
diff --git a/src/SDPSolver.cpp b/src/SDPSolver.cpp
index 00c81d8..242e0bf 100644
--- a/src/SDPSolver.cpp
+++ b/src/SDPSolver.cpp
@@ -28,8 +28,8 @@ SDPSolver::SDPSolver(const SDP &sdp):
dX(X),
dy(y),
dY(Y),
- dualResidues(x),
PrimalResidues(X),
+ dualResidues(x),
XCholesky(X),
YCholesky(X),
Z(X),
@@ -641,14 +641,14 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
// PrimalResidues = sum_p F_p x_p - X - F_0 (F_0 is zero for now)
computePrimalResidues(sdp, x, X, PrimalResidues);
- status.primalError = PrimalResidues.maxAbs();
- status.dualError = maxAbsVector(dualResidues);
- status.primalObjective = sdp.objectiveConst + dotProduct(sdp.primalObjective, x);
- status.dualObjective = sdp.objectiveConst + dotProduct(sdp.dualObjective, y);
+ primalError = PrimalResidues.maxAbs();
+ dualError = maxAbsVector(dualResidues);
+ primalObjective = sdp.objectiveConst + dotProduct(sdp.primalObjective, x);
+ dualObjective = sdp.objectiveConst + dotProduct(sdp.dualObjective, y);
- const bool isPrimalFeasible = status.primalError < parameters.primalErrorThreshold;
- const bool isDualFeasible = status.dualError < parameters.dualErrorThreshold;
- const bool isOptimal = status.dualityGap() < parameters.dualityGapThreshold;
+ const bool isPrimalFeasible = primalError < parameters.primalErrorThreshold;
+ const bool isDualFeasible = dualError < parameters.dualErrorThreshold;
+ const bool isOptimal = dualityGap() < parameters.dualityGapThreshold;
if (isPrimalFeasible && isDualFeasible && isOptimal)
return PrimalDualOptimal;
@@ -696,7 +696,7 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
dualStepLength = primalStepLength;
}
- printSolverInfo(iteration, mu, status, primalStepLength, dualStepLength,
+ printSolverInfo(iteration, mu, primalObjective, dualObjective, primalError, dualError, primalStepLength, dualStepLength,
betaCorrector, sdp.dualObjective.size(), Q.rows);
// Update current point
diff --git a/src/SDPSolver.h b/src/SDPSolver.h
index 17fdb75..cb18afa 100644
--- a/src/SDPSolver.h
+++ b/src/SDPSolver.h
@@ -86,24 +86,6 @@ enum SDPSolverTerminateReason {
ostream &operator<<(ostream& os, const SDPSolverTerminateReason& r);
-// SDPSolverStatus contains the information needed to determine
-// whether to terminate or not.
-//
-class SDPSolverStatus {
-public:
- Real primalObjective; // f + c . x
- Real dualObjective; // f + b . y
- Real primalError; // maxAbs(PrimalResidues)
- Real dualError; // maxAbs(dualResidues)
-
- Real dualityGap() const {
- return abs(primalObjective - dualObjective) /
- max(Real(abs(primalObjective) + abs(dualObjective)), Real(1));
- }
-
- friend ostream& operator<<(ostream& os, const SDPSolverStatus& s);
-};
-
// SDPSolver contains the data structures needed during the running of
// the interior point algorithm. Each structure is allocated when an
// SDPSolver is initialized, and reused in each iteration.
@@ -113,11 +95,8 @@ public:
// SDP to solve.
SDP sdp;
- // Objective values and errors, re-evaluated each iteration
- SDPSolverStatus status;
-
/********************************************/
- // The current point.
+ // Current point
// a Vector of length P = sdp.primalObjective.size()
Vector x;
@@ -132,7 +111,7 @@ public:
BlockDiagonalMatrix Y;
/********************************************/
- // The search direction.
+ // Search direction
//
// These quantities have the same structure as (x, X, y, Y). They
// are computed twice each iteration: once in the predictor step,
@@ -143,12 +122,12 @@ public:
Vector dy;
BlockDiagonalMatrix dY;
- // Discrepancy in the dual equality constraints, a Vector of length
- // P, called 'd' in the manual:
- //
- // dualResidues = c - Tr(A_* Y) - B y
+
+ /********************************************/
+ // Solver status
//
- Vector dualResidues;
+ Real primalObjective; // f + c . x
+ Real dualObjective; // f + b . y
// Discrepancy in the primal equality constraints, a
// BlockDiagonalMatrix with the same structure as X, called 'P' in
@@ -157,6 +136,15 @@ public:
// PrimalResidues = \sum_p A_p x_p - X
//
BlockDiagonalMatrix PrimalResidues;
+ Real primalError; // maxAbs(PrimalResidues)
+
+ // Discrepancy in the dual equality constraints, a Vector of length
+ // P, called 'd' in the manual:
+ //
+ // dualResidues = c - Tr(A_* Y) - B y
+ //
+ Vector dualResidues;
+ Real dualError; // maxAbs(dualResidues)
/********************************************/
// Intermediate computations.
@@ -290,6 +278,12 @@ public:
vector<Vector> QRWorkspace;
SDPSolver(const SDP &sdp);
+
+ Real dualityGap() const {
+ return abs(primalObjective - dualObjective) /
+ max(Real(abs(primalObjective) + abs(dualObjective)), Real(1));
+ }
+
void initialize(const SDPSolverParameters ¶meters);
SDPSolverTerminateReason run(const SDPSolverParameters ¶meters, const path checkpointFile);
void initializeSchurComplementSolver(const BlockDiagonalMatrix &BilinearPairingsXInv,
@@ -305,7 +299,10 @@ public:
void printSolverHeader();
void printSolverInfo(int iteration,
Real mu,
- SDPSolverStatus status,
+ Real primalObjective,
+ Real dualObjective,
+ Real primalError,
+ Real dualError,
Real primalStepLength,
Real dualStepLength,
Real betaCorrector,
diff --git a/src/SDPSolverIO.cpp b/src/SDPSolverIO.cpp
index 92d1fed..5b4c603 100644
--- a/src/SDPSolverIO.cpp
+++ b/src/SDPSolverIO.cpp
@@ -31,7 +31,10 @@ void printSolverHeader() {
void printSolverInfo(int iteration,
Real mu,
- SDPSolverStatus status,
+ Real primalObjective,
+ Real dualObjective,
+ Real primalError,
+ Real dualError,
Real primalStepLength,
Real dualStepLength,
Real betaCorrector,
@@ -46,11 +49,11 @@ void printSolverInfo(int iteration,
iteration,
ss.str().substr(0, 8).c_str(),
mu.get_mpf_t(),
- status.primalObjective.get_mpf_t(),
- status.dualObjective.get_mpf_t(),
- status.dualityGap().get_mpf_t(),
- status.primalError.get_mpf_t(),
- status.dualError.get_mpf_t(),
+ primalObjective.get_mpf_t(),
+ dualObjective.get_mpf_t(),
+ dualityGap().get_mpf_t(),
+ primalError.get_mpf_t(),
+ dualError.get_mpf_t(),
primalStepLength.get_mpf_t(),
dualStepLength.get_mpf_t(),
betaCorrector.get_mpf_t(),
@@ -114,15 +117,6 @@ ostream &operator<<(ostream& os, const SDPSolverTerminateReason& r) {
return os;
}
-ostream& operator<<(ostream& os, const SDPSolverStatus& s) {
- os << "primalObjective = " << s.primalObjective << endl;
- os << "dualObjective = " << s.dualObjective << endl;
- os << "dualityGap = " << s.dualityGap() << endl;
- os << "primalError = " << s.primalError << endl;
- os << "dualError = " << s.dualError << endl;
- return os;
-}
-
void backupCheckpointFile(path const& checkpointFile) {
path backupFile(checkpointFile);
backupFile.replace_extension(".ck.bk");
@@ -151,14 +145,14 @@ void SDPSolver::saveSolution(const SDPSolverTerminateReason terminateReason, con
boost::filesystem::ofstream ofs(outFile);
float runtime = static_cast<float>(timers["Solver runtime"].elapsed().wall)/1000000000;
cout << "Saving solution to : " << outFile << endl;
- ofs.precision(static_cast<int>(status.primalObjective.get_prec() * 0.31 + 5));
- ofs << "terminateReason = \"" << terminateReason << "\";\n";
- ofs << "primalObjective = " << status.primalObjective << ";\n";
- ofs << "dualObjective = " << status.dualObjective << ";\n";
- ofs << "dualityGap = " << status.dualityGap() << ";\n";
- ofs << "primalError = " << status.primalError << ";\n";
- ofs << "dualError = " << status.dualError << ";\n";
- ofs << "runtime = " << runtime << ";\n";
+ ofs.precision(static_cast<int>(primalObjective.get_prec() * 0.31 + 5));
+ ofs << "terminateReason = \"" << terminateReason << "\";\n";
+ ofs << "primalObjective = " << primalObjective << ";\n";
+ ofs << "dualObjective = " << dualObjective << ";\n";
+ ofs << "dualityGap = " << dualityGap() << ";\n";
+ ofs << "primalError = " << primalError << ";\n";
+ ofs << "dualError = " << dualError << ";\n";
+ ofs << "runtime = " << runtime << ";\n";
ofs << "y = " << y << ";\n";
// ofs << "Y = " << Y << ";\n";
ofs << "x = " << x << ";\n";
diff --git a/src/main.cpp b/src/main.cpp
index 2349a69..774d85a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -68,7 +68,13 @@ int solveSDP(const path &sdpFile,
timers["Solver runtime"].stop();
cout << "-----" << setfill('-') << setw(116) << std::left << reason << endl;
- cout << endl << solver.status << endl;
+ cout << endl;
+ cout << "primalObjective = " << solver.primalObjective << endl;
+ cout << "dualObjective = " << solver.dualObjective << endl;
+ cout << "dualityGap = " << solver.dualityGap() << endl;
+ cout << "primalError = " << solver.primalError << endl;
+ cout << "dualError = " << solver.dualError << endl;
+ cout << endl;
if (!parameters.noFinalCheckpoint)
solver.saveCheckpoint(checkpointFile);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sdpb.git
More information about the debian-science-commits
mailing list