//
// Heuristic PBQP solver. This solver is able to perform optimal reductions for
// nodes of degree 0, 1 or 2. For nodes of degree >2 a plugable heuristic is
-// used to select a node for reduction.
+// used to select a node for reduction.
//
//===----------------------------------------------------------------------===//
typedef std::list<Graph::EdgeId> SolverEdges;
public:
-
+
/// \brief Iterator type for edges in the solver graph.
typedef SolverEdges::iterator SolverEdgeItr;
unsigned getSolverDegree() const { return solverDegree; }
void clearSolverEdges() {
solverDegree = 0;
- solverEdges.clear();
+ solverEdges.clear();
}
-
+
private:
HeuristicNodeData hData;
unsigned solverDegree;
SolverEdges solverEdges;
};
-
+
class EdgeData {
public:
HeuristicEdgeData& getHeuristicData() { return hData; }
/// \brief Construct a heuristic solver implementation to solve the given
/// graph.
/// @param g The graph representing the problem instance to be solved.
- HeuristicSolverImpl(Graph &g) : g(g), h(*this) {}
+ HeuristicSolverImpl(Graph &g) : g(g), h(*this) {}
/// \brief Get the graph being solved by this solver.
/// @return The graph representing the problem instance being solved by this
/// the solver graph.
/// @param nItr Node iterator.
/// @return Begin iterator for the set of edges adjacent to the given node
- /// in the solver graph.
+ /// in the solver graph.
SolverEdgeItr solverEdgesBegin(Graph::NodeId nId) {
return getSolverNodeData(nId).solverEdgesBegin();
}
/// the solver graph.
/// @param nItr Node iterator.
/// @return End iterator for the set of edges adjacent to the given node in
- /// the solver graph.
+ /// the solver graph.
SolverEdgeItr solverEdgesEnd(Graph::NodeId nId) {
return getSolverNodeData(nId).solverEdgesEnd();
}
const Matrix &eCosts = g.getEdgeCosts(eId);
const Vector &xCosts = g.getNodeCosts(xnId);
-
+
// Duplicate a little to avoid transposing matrices.
if (xnId == g.getEdgeNode1(eId)) {
Graph::NodeId ynId = g.getEdgeNode2(eId);
unsigned xLen = xCosts.getLength(),
yLen = yxeCosts->getRows(),
zLen = zxeCosts->getRows();
-
+
Matrix delta(yLen, zLen);
for (unsigned i = 0; i < yLen; ++i) {
// If we modified the edge costs let the heuristic know.
h.postUpdateEdgeCosts(yzeId);
}
-
+
if (nullCostEdge) {
// If this edge ended up null remove it.
if (!addedEdge) {
/// \brief Record an application of the RN rule.
///
/// For use by the HeuristicBase.
- void recordRN() { s.recordRN(); }
+ void recordRN() { s.recordRN(); }
private:
bool tryToEliminateEdge(Graph::EdgeId eId) {
if (tryNormaliseEdgeMatrix(eId)) {
g.removeEdge(eId);
- return true;
+ return true;
}
return false;
}