#ifndef LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H #define LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H #include "GraphBase.h" namespace PBQP { class SimpleEdge; class SimpleNode : public NodeBase { public: SimpleNode(const Vector &costs) : NodeBase(costs) {} }; class SimpleEdge : public EdgeBase { public: SimpleEdge(const NodeIterator &node1Itr, const NodeIterator &node2Itr, const Matrix &costs) : EdgeBase(node1Itr, node2Itr, costs) {} }; class SimpleGraph : public GraphBase { private: typedef GraphBase PGraph; void copyFrom(const SimpleGraph &other) { assert(other.areNodeIDsValid() && "Cannot copy from another graph unless IDs have been assigned."); std::vector newNodeItrs(other.getNumNodes()); for (ConstNodeIterator nItr = other.nodesBegin(), nEnd = other.nodesEnd(); nItr != nEnd; ++nItr) { newNodeItrs[other.getNodeID(nItr)] = addNode(other.getNodeCosts(nItr)); } for (ConstEdgeIterator eItr = other.edgesBegin(), eEnd = other.edgesEnd(); eItr != eEnd; ++eItr) { unsigned node1ID = other.getNodeID(other.getEdgeNode1Itr(eItr)), node2ID = other.getNodeID(other.getEdgeNode2Itr(eItr)); addEdge(newNodeItrs[node1ID], newNodeItrs[node2ID], other.getEdgeCosts(eItr)); } } void copyFrom(SimpleGraph &other) { if (!other.areNodeIDsValid()) { other.assignNodeIDs(); } copyFrom(const_cast(other)); } public: SimpleGraph() {} SimpleGraph(const SimpleGraph &other) : PGraph() { copyFrom(other); } SimpleGraph& operator=(const SimpleGraph &other) { clear(); copyFrom(other); return *this; } NodeIterator addNode(const Vector &costs) { return PGraph::addConstructedNode(SimpleNode(costs)); } EdgeIterator addEdge(const NodeIterator &node1Itr, const NodeIterator &node2Itr, const Matrix &costs) { return PGraph::addConstructedEdge(SimpleEdge(node1Itr, node2Itr, costs)); } }; } #endif // LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H