[sdpb] 109/233: More cosmetic changes from cpplint.py
Tobias Hansen
thansen at moszumanska.debian.org
Thu Mar 9 04:06:26 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 9e376b9859060b98ccb82a644ded2df3eb332173
Author: David Simmons-Duffin <dsd at minerva.sns.ias.edu>
Date: Tue Nov 18 19:34:03 2014 -0500
More cosmetic changes from cpplint.py
---
src/Polynomial.h | 3 +-
src/SDP.cpp | 11 +++---
src/SDP.h | 25 +++++++------
src/SDPSolver.cpp | 105 ++++++++++++++++++++++++++++++----------------------
src/SDPSolverIO.cpp | 9 +++--
src/Timers.h | 7 ++--
src/Vector.h | 8 +++-
src/main.cpp | 18 ++++-----
src/serialize.h | 4 +-
src/util.h | 16 --------
10 files changed, 107 insertions(+), 99 deletions(-)
diff --git a/src/Polynomial.h b/src/Polynomial.h
index 853d42a..f2d9b78 100644
--- a/src/Polynomial.h
+++ b/src/Polynomial.h
@@ -14,7 +14,7 @@
#include "Vector.h"
class Polynomial {
-public:
+ public:
Vector coefficients;
Polynomial(): coefficients(1, 0) {}
@@ -43,7 +43,6 @@ public:
}
return os;
}
-
};
#endif // SDPB_POLYNOMIAL_H_
diff --git a/src/SDP.cpp b/src/SDP.cpp
index 687dabf..6cc3f59 100644
--- a/src/SDP.cpp
+++ b/src/SDP.cpp
@@ -65,11 +65,12 @@ samplePolynomialVectorMatrix(const PolynomialVectorMatrix &m) {
m.sampleScalings));
int delta2 = (s.degree - 1)/2;
if (delta2 >= 0)
- s.bilinearBases.push_back(sampleBilinearBasis(delta2, numSamples,
- m.bilinearBasis,
- m.samplePoints,
- multiplyVectors(m.samplePoints,
- m.sampleScalings)));
+ s.bilinearBases
+ .push_back(sampleBilinearBasis(delta2, numSamples,
+ m.bilinearBasis,
+ m.samplePoints,
+ multiplyVectors(m.samplePoints,
+ m.sampleScalings)));
return s;
}
diff --git a/src/SDP.h b/src/SDP.h
index 76a73dc..ad34952 100644
--- a/src/SDP.h
+++ b/src/SDP.h
@@ -9,6 +9,7 @@
#ifndef SDPB_SDP_H_
#define SDPB_SDP_H_
+#include <algorithm>
#include <vector>
#include <iostream>
#include <ostream>
@@ -22,7 +23,7 @@ using std::vector;
using std::ostream;
class IndexTuple {
-public:
+ public:
int p;
int r;
int s;
@@ -32,7 +33,7 @@ public:
};
class SDP {
-public:
+ public:
vector<Matrix> bilinearBases;
Matrix FreeVarMatrix;
Vector primalObjective;
@@ -46,7 +47,8 @@ public:
vector<int> psdMatrixBlockDims() const {
vector<int> dims;
for (unsigned int j = 0; j < dimensions.size(); j++)
- for (vector<int>::const_iterator b = blocks[j].begin(); b != blocks[j].end(); b++)
+ for (vector<int>::const_iterator b = blocks[j].begin();
+ b != blocks[j].end(); b++)
dims.push_back(bilinearBases[*b].rows * dimensions[j]);
return dims;
}
@@ -54,7 +56,8 @@ public:
vector<int> bilinearPairingBlockDims() const {
vector<int> dims;
for (unsigned int j = 0; j < dimensions.size(); j++)
- for (vector<int>::const_iterator b = blocks[j].begin(); b != blocks[j].end(); b++)
+ for (vector<int>::const_iterator b = blocks[j].begin();
+ b != blocks[j].end(); b++)
dims.push_back(bilinearBases[*b].cols * dimensions[j]);
return dims;
}
@@ -80,7 +83,7 @@ public:
}
}
}
- assert(p == (int)primalObjective.size());
+ assert(p == static_cast<int>(primalObjective.size()));
}
friend ostream& operator<<(ostream& os, const SDP& sdp) {
@@ -92,13 +95,12 @@ public:
<< ", degrees = " << sdp.degrees
<< ", blocks = " << sdp.blocks
<< ")";
-
return os;
}
};
class SampledMatrixPolynomial {
-public:
+ public:
int dim;
int degree;
Matrix constraintMatrix;
@@ -107,7 +109,7 @@ public:
};
class PolynomialVectorMatrix {
-public:
+ public:
int rows;
int cols;
vector<vector<Polynomial> > elements;
@@ -125,12 +127,13 @@ public:
int degree() const {
int d = 0;
- for (vector<vector<Polynomial> >::const_iterator e = elements.begin(); e != elements.end(); e++)
- for (vector<Polynomial>::const_iterator p = e->begin(); p != e->end(); p++)
+ for (vector<vector<Polynomial> >::const_iterator e = elements.begin();
+ e != elements.end(); e++)
+ for (vector<Polynomial>::const_iterator p = e->begin();
+ p != e->end(); p++)
d = max(p->degree(), d);
return d;
}
-
};
SampledMatrixPolynomial samplePolynomialVectorMatrix(const PolynomialVectorMatrix &m);
diff --git a/src/SDPSolver.cpp b/src/SDPSolver.cpp
index 1e5d307..326c0df 100644
--- a/src/SDPSolver.cpp
+++ b/src/SDPSolver.cpp
@@ -6,7 +6,9 @@
//=======================================================================
+#include <algorithm>
#include <iostream>
+#include <vector>
#include "omp.h"
#include "boost/filesystem.hpp"
#include "SDPSolver.h"
@@ -43,11 +45,11 @@ SDPSolver::SDPSolver(const SDP &sdp):
Q(sdp.FreeVarMatrix.cols, sdp.FreeVarMatrix.cols),
Qpivots(sdp.FreeVarMatrix.cols),
basicKernelCoords(Q.rows),
- StepMatrixWorkspace(X)
-{
- // initialize bilinearPairingsWorkspace, eigenvaluesWorkspace, QRWorkspace
+ StepMatrixWorkspace(X) {
+ // initialize bilinearPairingsWorkspace, eigenvaluesWorkspace, QRWorkspace
for (unsigned int b = 0; b < sdp.bilinearBases.size(); b++) {
- bilinearPairingsWorkspace.push_back(Matrix(X.blocks[b].rows, BilinearPairingsXInv.blocks[b].cols));
+ bilinearPairingsWorkspace.push_back(Matrix(X.blocks[b].rows,
+ BilinearPairingsXInv.blocks[b].cols));
eigenvaluesWorkspace.push_back(Vector(X.blocks[b].rows));
QRWorkspace.push_back(Vector(3*X.blocks[b].rows - 1));
}
@@ -78,7 +80,6 @@ void tensorMatrixCongruenceTranspose(const Matrix &a,
int aColOffset = (c / b.cols) * b.rows;
for (int r = 0; r < work.rows; r++) {
-
Real tmp = 0;
for (int k = 0; k < b.rows; k++) {
tmp += a.elt(r, aColOffset + k) * b.elt(k, bCol);
@@ -90,7 +91,6 @@ void tensorMatrixCongruenceTranspose(const Matrix &a,
// result = b'^T work
for (int c = 0; c < result.cols; c++) {
-
// since result is symmetric, only compute its upper triangle
for (int r = 0; r <= c; r++) {
int bCol = r % b.cols;
@@ -161,7 +161,8 @@ void computeBilinearPairings(const BlockDiagonalMatrix &A,
BlockDiagonalMatrix &result) {
#pragma omp parallel for schedule(dynamic)
for (unsigned int b = 0; b < bilinearBases.size(); b++)
- tensorMatrixCongruenceTranspose(A.blocks[b], bilinearBases[b], workspace[b], result.blocks[b]);
+ tensorMatrixCongruenceTranspose(A.blocks[b], bilinearBases[b],
+ workspace[b], result.blocks[b]);
}
void computeInvBilinearPairingsWithCholesky(const BlockDiagonalMatrix &L,
@@ -170,7 +171,10 @@ void computeInvBilinearPairingsWithCholesky(const BlockDiagonalMatrix &L,
BlockDiagonalMatrix &result) {
#pragma omp parallel for schedule(dynamic)
for (unsigned int b = 0; b < bilinearBases.size(); b++)
- tensorMatrixInvCongruenceTransposeWithCholesky(L.blocks[b], bilinearBases[b], workspace[b], result.blocks[b]);
+ tensorMatrixInvCongruenceTransposeWithCholesky(L.blocks[b],
+ bilinearBases[b],
+ workspace[b],
+ result.blocks[b]);
}
// result = V D V^T, where D=diag(d) is a diagonal matrix
@@ -186,14 +190,13 @@ void diagonalCongruence(Real const *d,
const int blockRow,
const int blockCol,
Matrix &result) {
-
for (int p = 0; p < V.rows; p++) {
for (int q = 0; q <= p; q++) {
Real tmp = 0;
for (int n = 0; n < V.cols; n++)
tmp += *(d+n) * V.elt(p, n)*V.elt(q, n);
-
+
result.elt(blockRow*V.rows + p, blockCol*V.rows + q) = tmp;
if (p != q)
result.elt(blockRow*V.rows + q, blockCol*V.rows + p) = tmp;
@@ -247,11 +250,16 @@ void computeSchurBlocks(const SDP &sdp,
const int k2 = sdp.constraintIndices[j][u2].k;
Real tmp = 0;
- for (vector<int>::const_iterator b = sdp.blocks[j].begin(); b != sdp.blocks[j].end(); b++) {
- tmp += (BilinearPairingsXInv.blocks[*b].elt(ej_s1 + k1, ej_r2 + k2)*BilinearPairingsY.blocks[*b].elt(ej_s2 + k2, ej_r1 + k1) +
- BilinearPairingsXInv.blocks[*b].elt(ej_r1 + k1, ej_r2 + k2)*BilinearPairingsY.blocks[*b].elt(ej_s2 + k2, ej_s1 + k1) +
- BilinearPairingsXInv.blocks[*b].elt(ej_s1 + k1, ej_s2 + k2)*BilinearPairingsY.blocks[*b].elt(ej_r2 + k2, ej_r1 + k1) +
- BilinearPairingsXInv.blocks[*b].elt(ej_r1 + k1, ej_s2 + k2)*BilinearPairingsY.blocks[*b].elt(ej_r2 + k2, ej_s1 + k1))/4;
+ for (vector<int>::const_iterator b = sdp.blocks[j].begin();
+ b != sdp.blocks[j].end(); b++) {
+ tmp += (BilinearPairingsXInv.blocks[*b].elt(ej_s1 + k1, ej_r2 + k2) *
+ BilinearPairingsY .blocks[*b].elt(ej_s2 + k2, ej_r1 + k1) +
+ BilinearPairingsXInv.blocks[*b].elt(ej_r1 + k1, ej_r2 + k2) *
+ BilinearPairingsY .blocks[*b].elt(ej_s2 + k2, ej_s1 + k1) +
+ BilinearPairingsXInv.blocks[*b].elt(ej_s1 + k1, ej_s2 + k2) *
+ BilinearPairingsY .blocks[*b].elt(ej_r2 + k2, ej_r1 + k1) +
+ BilinearPairingsXInv.blocks[*b].elt(ej_r1 + k1, ej_s2 + k2) *
+ BilinearPairingsY .blocks[*b].elt(ej_r2 + k2, ej_s1 + k1))/4;
}
SchurBlocks.blocks[j].elt(u1, u2) = tmp;
if (u2 != u1)
@@ -278,12 +286,13 @@ void computeDualResidues(const SDP &sdp,
const int k = t->k;
dualResidues[p] = 0;
- for (vector<int>::const_iterator b = sdp.blocks[j].begin(); b != sdp.blocks[j].end(); b++) {
+ for (vector<int>::const_iterator b = sdp.blocks[j].begin();
+ b != sdp.blocks[j].end(); b++) {
dualResidues[p] -= BilinearPairingsY.blocks[*b].elt(ej_r+k, ej_s+k);
dualResidues[p] -= BilinearPairingsY.blocks[*b].elt(ej_s+k, ej_r+k);
}
dualResidues[p] /= 2;
-
+
for (int n = 0; n < sdp.FreeVarMatrix.cols; n++)
dualResidues[p] -= sdp.FreeVarMatrix.elt(p, n)*y[n];
dualResidues[p] += sdp.primalObjective[p];
@@ -291,7 +300,9 @@ void computeDualResidues(const SDP &sdp,
}
}
-void constraintMatrixWeightedSum(const SDP &sdp, const Vector x, BlockDiagonalMatrix &result) {
+void constraintMatrixWeightedSum(const SDP &sdp,
+ const Vector x,
+ BlockDiagonalMatrix &result) {
#pragma omp parallel for schedule(dynamic)
for (unsigned int j = 0; j < sdp.dimensions.size(); j++) {
const int ej = sdp.degrees[j] + 1;
@@ -304,9 +315,10 @@ void constraintMatrixWeightedSum(const SDP &sdp, const Vector x, BlockDiagonalMa
const int s = t->s;
assert(t->k == 0);
- for (vector<int>::const_iterator b = sdp.blocks[j].begin(); b != sdp.blocks[j].end(); b++) {
- diagonalCongruence(&x[p], sdp.bilinearBases[*b], r, s, result.blocks[*b]);
-
+ for (vector<int>::const_iterator b = sdp.blocks[j].begin();
+ b != sdp.blocks[j].end(); b++) {
+ diagonalCongruence(&x[p], sdp.bilinearBases[*b], r, s,
+ result.blocks[*b]);
if (r != s) {
const int u = sdp.bilinearBases[*b].rows;
for (int m = r*u; m < (r+1)*u; m++) {
@@ -327,7 +339,6 @@ void computeSchurRHS(const SDP &sdp,
const Vector &x,
Vector &r,
Vector &s) {
-
for (unsigned int p = 0; p < r.size(); p++)
r[p] = -dualResidues[p];
@@ -336,14 +347,14 @@ void computeSchurRHS(const SDP &sdp,
for (vector<IndexTuple>::const_iterator t = sdp.constraintIndices[j].begin();
t != sdp.constraintIndices[j].end();
t++) {
- for (vector<int>::const_iterator b = sdp.blocks[j].begin(); b != sdp.blocks[j].end(); b++) {
-
+ for (vector<int>::const_iterator b = sdp.blocks[j].begin();
+ b != sdp.blocks[j].end(); b++) {
const int delta = sdp.bilinearBases[*b].rows;
// Pointer to the k-th column of sdp.bilinearBases[*b]
const Real *q = &sdp.bilinearBases[*b].elements[(t->k) * delta];
r[t->p] -= bilinearBlockPairing(q, delta, Z.blocks[*b], t->r, t->s);
- }
+ }
}
}
@@ -366,7 +377,7 @@ void computePrimalResidues(const SDP &sdp,
PrimalResidues -= X;
}
-Real predictorCenteringParameter(const SDPSolverParameters ¶meters,
+Real predictorCenteringParameter(const SDPSolverParameters ¶meters,
const bool isPrimalDualFeasible) {
return isPrimalDualFeasible ? Real(0) : parameters.infeasibleCenteringParameter;
}
@@ -378,7 +389,6 @@ Real correctorCenteringParameter(const SDPSolverParameters ¶meters,
const BlockDiagonalMatrix &dY,
const Real &mu,
const bool isPrimalDualFeasible) {
-
Real r = frobeniusProductOfSums(X, dX, Y, dY) / (mu * X.dim);
Real beta = r < 1 ? r*r : r;
@@ -394,7 +404,6 @@ Real stepLength(BlockDiagonalMatrix &XCholesky,
vector<Vector> &eigenvalues,
vector<Vector> &workspace,
const SDPSolverParameters ¶meters) {
-
// XInvDX = L^{-1} dX L^{-1 T}, where X = L L^T
XInvDX.copyFrom(dX);
lowerTriangularInverseCongruence(XInvDX, XCholesky);
@@ -419,7 +428,7 @@ void SDPSolver::initializeSchurComplementSolver(const BlockDiagonalMatrix &Bilin
timers["schurblocks/cholesky"].stop();
// SchurUpdateLowRank = {{- 1, 0}, {E, G}}
timers["make schur update"].resume();
- SchurUpdateLowRank.copyFrom(sdp.FreeVarMatrix);
+ SchurUpdateLowRank.copyFrom(sdp.FreeVarMatrix);
blockMatrixLowerTriangularSolve(SchurBlocksCholesky, SchurUpdateLowRank);
int updateColumns = SchurUpdateLowRank.cols;
@@ -473,7 +482,7 @@ void SDPSolver::initializeSchurComplementSolver(const BlockDiagonalMatrix &Bilin
int c = stabilizeBlockUpdateColumn[j];
matrixSquareIntoBlock(stabilizeBlocks[b], Q, c, c);
for (int i = c; i < c + stabilizeBlocks[b].cols; i++)
- Q.elt(i,i) -= 1;
+ Q.elt(i, i) -= 1;
}
// LowerLeft(Q) = G^T U
@@ -500,7 +509,7 @@ void SDPSolver::initializeSchurComplementSolver(const BlockDiagonalMatrix &Bilin
# pragma omp parallel for schedule(static)
for (int c = 0; c < SchurUpdateLowRank.cols; c++)
for (int r = SchurUpdateLowRank.cols; r < Q.rows; r++)
- Q.elt(c,r) = Q.elt(r,c);
+ Q.elt(c, r) = Q.elt(r, c);
timers["make Q"].stop();
timers["LU of Q"].resume();
@@ -524,7 +533,7 @@ void SDPSolver::solveSchurComplementEquation(Vector &dx, Vector &dy) {
basicKernelCoords[n] = dy[n];
vectorScaleMatrixMultiplyTransposeAdd(-1, SchurUpdateLowRank, dx, 1, basicKernelCoords);
-
+
// k_2 = -G^T dx
for (unsigned int j = 0; j < stabilizeBlockIndices.size(); j++) {
int b = stabilizeBlockIndices[j];
@@ -534,7 +543,7 @@ void SDPSolver::solveSchurComplementEquation(Vector &dx, Vector &dy) {
for (int c = 0; c < stabilizeBlocks[b].cols; c++) {
basicKernelCoords[cTopLeft + c] = 0;
for (int r = 0; r < stabilizeBlocks[b].rows; r++)
- basicKernelCoords[cTopLeft + c] -= dx[pTopLeft + r] * stabilizeBlocks[b].elt(r,c);
+ basicKernelCoords[cTopLeft + c] -= dx[pTopLeft + r] * stabilizeBlocks[b].elt(r, c);
}
}
@@ -551,7 +560,7 @@ void SDPSolver::solveSchurComplementEquation(Vector &dx, Vector &dy) {
for (int c = 0; c < stabilizeBlocks[b].cols; c++)
for (int r = 0; r < stabilizeBlocks[b].rows; r++)
- dx[pTopLeft + r] += basicKernelCoords[cTopLeft + c] * stabilizeBlocks[b].elt(r,c);
+ dx[pTopLeft + r] += basicKernelCoords[cTopLeft + c] * stabilizeBlocks[b].elt(r, c);
}
// dx = SchurBlocksCholesky^{-T} dx
@@ -564,7 +573,6 @@ void SDPSolver::solveSchurComplementEquation(Vector &dx, Vector &dy) {
void SDPSolver::computeSearchDirection(const Real &beta,
const Real &mu,
const bool correctorPhase) {
-
blockDiagonalMatrixScaleMultiplyAdd(-1, X, Y, 0, R);
if (correctorPhase)
blockDiagonalMatrixScaleMultiplyAdd(-1, dX, dY, 1, R);
@@ -586,7 +594,7 @@ void SDPSolver::computeSearchDirection(const Real &beta,
// dX = R_p + sum_p F_p dx_p
constraintMatrixWeightedSum(sdp, dx, dX);
dX += PrimalResidues;
-
+
// dY = Symmetrize(X^{-1} (R - dX Y))
blockDiagonalMatrixMultiply(dX, Y, dY);
dY -= R;
@@ -608,9 +616,8 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
const path checkpointFile) {
Real primalStepLength;
Real dualStepLength;
-
- for (int iteration = 1;; iteration++) {
+ for (int iteration = 1;; iteration++) {
if (timers["Last checkpoint"].elapsed().wall >= parameters.checkpointInterval * 1000000000LL)
saveCheckpoint(checkpointFile);
if (timers["Solver runtime"].elapsed().wall >= parameters.maxRuntime * 1000000000LL)
@@ -621,8 +628,12 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
choleskyDecomposition(Y, YCholesky);
timers["cholesky"].stop();
timers["bilinear pairings"].resume();
- computeInvBilinearPairingsWithCholesky(XCholesky, sdp.bilinearBases, bilinearPairingsWorkspace, BilinearPairingsXInv);
- computeBilinearPairings(Y, sdp.bilinearBases, bilinearPairingsWorkspace, BilinearPairingsY);
+ computeInvBilinearPairingsWithCholesky(XCholesky, sdp.bilinearBases,
+ bilinearPairingsWorkspace,
+ BilinearPairingsXInv);
+ computeBilinearPairings(Y, sdp.bilinearBases,
+ bilinearPairingsWorkspace,
+ BilinearPairingsY);
timers["bilinear pairings"].stop();
// d_k = c_k - Tr(F_k Y) - (D y)_k
computeDualResidues(sdp, y, BilinearPairingsY, dualResidues);
@@ -654,7 +665,8 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
else if (iteration > parameters.maxIterations)
return MaxIterationsExceeded;
timers["initialize schur solver"].resume();
- initializeSchurComplementSolver(BilinearPairingsXInv, BilinearPairingsY, parameters.choleskyStabilizeThreshold);
+ initializeSchurComplementSolver(BilinearPairingsXInv, BilinearPairingsY,
+ parameters.choleskyStabilizeThreshold);
timers["initialize schur solver"].stop();
Real mu = frobeniusProductSymmetric(X, Y)/X.dim;
@@ -662,12 +674,14 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
return MaxComplementarityExceeded;
timers["predictor"].resume();
// Mehrotra predictor solution for (dx, dX, dY)
- Real betaPredictor = predictorCenteringParameter(parameters, isPrimalFeasible && isDualFeasible);
+ Real betaPredictor = predictorCenteringParameter(parameters,
+ isPrimalFeasible && isDualFeasible);
computeSearchDirection(betaPredictor, mu, false);
timers["predictor"].stop();
timers["corrector"].resume();
// Mehrotra corrector solution for (dx, dX, dY)
- Real betaCorrector = correctorCenteringParameter(parameters, X, dX, Y, dY, mu, isPrimalFeasible && isDualFeasible);
+ Real betaCorrector = correctorCenteringParameter(parameters, X, dX, Y, dY, mu,
+ isPrimalFeasible && isDualFeasible);
computeSearchDirection(betaCorrector, mu, true);
timers["corrector"].stop();
timers["step length"].resume();
@@ -682,7 +696,8 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
dualStepLength = primalStepLength;
}
- printSolverInfo(iteration, mu, status, primalStepLength, dualStepLength, betaCorrector, sdp.dualObjective.size(), Q.rows);
+ printSolverInfo(iteration, mu, status, primalStepLength, dualStepLength,
+ betaCorrector, sdp.dualObjective.size(), Q.rows);
// Update current point
scaleVector(dx, primalStepLength);
@@ -694,7 +709,7 @@ SDPSolverTerminateReason SDPSolver::run(const SDPSolverParameters ¶meters,
dY *= dualStepLength;
Y += dY;
}
-
+
// Never reached
return MaxIterationsExceeded;
}
diff --git a/src/SDPSolverIO.cpp b/src/SDPSolverIO.cpp
index cbcf20c..05b5f9c 100644
--- a/src/SDPSolverIO.cpp
+++ b/src/SDPSolverIO.cpp
@@ -44,7 +44,7 @@ void printSolverInfo(int iteration,
gmp_fprintf(stdout,
"%3d %s %-8.1Fe %-+11.2Fe %-+11.2Fe %-9.2Fe %-+10.2Fe %-+10.2Fe %-8.3Fg %-8.3Fg %-4.2Fg %d/%d",
iteration,
- ss.str().substr(0,8).c_str(),
+ ss.str().substr(0, 8).c_str(),
mu.get_mpf_t(),
status.primalObjective.get_mpf_t(),
status.dualObjective.get_mpf_t(),
@@ -85,7 +85,7 @@ ostream& operator<<(ostream& os, const SDPSolverParameters& p) {
}
ostream &operator<<(ostream& os, const SDPSolverTerminateReason& r) {
- switch(r) {
+ switch (r) {
case PrimalDualOptimal:
os << "found primal-dual optimal solution";
break;
@@ -149,15 +149,16 @@ void SDPSolver::loadCheckpoint(const path &checkpointFile) {
void SDPSolver::saveSolution(const SDPSolverTerminateReason terminateReason, const path &outFile) {
boost::filesystem::ofstream ofs(outFile);
+ float runtime = static_cast<float>(timers["Solver runtime"].elapsed().wall)/1000000000;
cout << "Saving solution to : " << outFile << endl;
- ofs.precision(int(status.primalObjective.get_prec() * 0.30102999566398114 + 5));
+ 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 = " << float(timers["Solver runtime"].elapsed().wall)/1000000000 << ";\n";
+ ofs << "runtime = " << runtime << ";\n";
ofs << "y = " << y << ";\n";
ofs << "Y = " << Y << ";\n";
ofs << "x = " << x << ";\n";
diff --git a/src/Timers.h b/src/Timers.h
index bd39d49..2817774 100644
--- a/src/Timers.h
+++ b/src/Timers.h
@@ -11,6 +11,7 @@
#include <iostream>
#include <ostream>
+#include <string>
#include <map>
#include "boost/timer/timer.hpp"
@@ -19,10 +20,10 @@ using std::string;
using std::ostream;
using boost::timer::cpu_timer;
-class Timers : public map<string,cpu_timer> {
-public:
+class Timers : public map<string, cpu_timer> {
+ public:
friend ostream& operator<<(ostream& os, const Timers& t) {
- for (map<string,cpu_timer>::const_iterator it = t.begin();
+ for (map<string, cpu_timer>::const_iterator it = t.begin();
it != t.end();
++it) {
os << it->first << "\t:" << it->second.format();
diff --git a/src/Vector.h b/src/Vector.h
index 2be8583..77eba24 100644
--- a/src/Vector.h
+++ b/src/Vector.h
@@ -9,9 +9,9 @@
#ifndef SDPB_VECTOR_H_
#define SDPB_VECTOR_H_
+#include <assert.h>
#include <algorithm>
#include <vector>
-#include <assert.h>
#include "types.h"
#include "util.h"
@@ -19,9 +19,13 @@ using std::vector;
typedef vector<Real> Vector;
+inline bool compareAbs(const Real &a, const Real &b) {
+ return abs(a) < abs(b);
+}
+
inline Real maxAbsVector(const Vector &v) {
return abs(*std::max_element(v.begin(), v.end(), compareAbs));
-}
+}
inline void fillVector(Vector &v, const Real &a) {
std::fill(v.begin(), v.end(), a);
diff --git a/src/main.cpp b/src/main.cpp
index 36a58f1..74cc365 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,10 +6,12 @@
//=======================================================================
+#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <ostream>
+#include <string>
#include "omp.h"
#include "boost/filesystem.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
@@ -38,9 +40,8 @@ int solveSDP(const path &sdpFile,
const path &outFile,
const path &checkpointFile,
SDPSolverParameters parameters) {
-
setDefaultPrecision(parameters.precision);
- cout.precision(min(int(parameters.precision * 0.30102999566398114 + 5), 30));
+ cout.precision(min(static_cast<int>(parameters.precision * 0.31 + 5), 30));
// Ensure all the Real parameters have the appropriate precision
parameters.resetPrecision();
omp_set_num_threads(parameters.maxThreads);
@@ -67,8 +68,8 @@ int solveSDP(const path &sdpFile,
SDPSolverTerminateReason reason = solver.run(parameters, checkpointFile);
timers["Solver runtime"].stop();
- cout << "-----" << setfill('-') << setw(116) << std::left << reason << endl << endl;
- cout << solver.status << endl;
+ cout << "-----" << setfill('-') << setw(116) << std::left << reason << endl;
+ cout << endl << solver.status << endl;
if (!parameters.noFinalCheckpoint)
solver.saveCheckpoint(checkpointFile);
@@ -81,7 +82,6 @@ int solveSDP(const path &sdpFile,
}
int main(int argc, char** argv) {
-
path sdpFile;
path outFile;
path checkpointFile;
@@ -192,7 +192,7 @@ int main(int argc, char** argv) {
po::value<Real>(¶meters.maxComplementarity)->default_value(Real("1e100")),
"Terminate if the complementarity mu = Tr(X Y)/dim(X) exceeds this value.")
;
-
+
po::options_description cmdLineOptions;
cmdLineOptions.add(basicOptions).add(solverParamsOptions);
@@ -225,9 +225,9 @@ int main(int argc, char** argv) {
}
} catch(po::error& e) {
cerr << "ERROR: " << e.what() << endl;
- cerr << cmdLineOptions << endl;
- return 1;
- }
+ cerr << cmdLineOptions << endl;
+ return 1;
+ }
return solveSDP(sdpFile, outFile, checkpointFile, parameters);
}
diff --git a/src/serialize.h b/src/serialize.h
index 7c4bb27..5f5708c 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -72,8 +72,8 @@ namespace boost {
ar & Y;
}
- } // namespace serialization
-} // namespace boost
+ } // namespace serialization
+} // namespace boost
BOOST_SERIALIZATION_SPLIT_FREE(Real)
diff --git a/src/util.h b/src/util.h
index 8906b65..a1d487b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -18,10 +18,6 @@
using std::ostream;
using std::vector;
-inline bool compareAbs(const Real &a, const Real &b) {
- return abs(a) < abs(b);
-}
-
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
@@ -34,16 +30,4 @@ ostream& operator<<(ostream& os, const vector<T>& v) {
return os;
}
-template<class Iter, class T>
-Iter binaryFind(Iter begin, Iter end, T val)
-{
- // Finds the lower bound in at most log(last - first) + 1 comparisons
- Iter i = std::lower_bound(begin, end, val);
-
- if (i != end && !(val < *i))
- return i; // found
- else
- return end; // not found
-}
-
#endif // SDPB_UTIL_H_
--
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