1 #ifndef LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H
2 #define LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H
10 class SimpleNode : public NodeBase<SimpleNode, SimpleEdge> {
12 SimpleNode(const Vector &costs) :
13 NodeBase<SimpleNode, SimpleEdge>(costs) {}
16 class SimpleEdge : public EdgeBase<SimpleNode, SimpleEdge> {
18 SimpleEdge(const NodeIterator &node1Itr, const NodeIterator &node2Itr,
19 const Matrix &costs) :
20 EdgeBase<SimpleNode, SimpleEdge>(node1Itr, node2Itr, costs) {}
23 class SimpleGraph : public GraphBase<SimpleNode, SimpleEdge> {
26 typedef GraphBase<SimpleNode, SimpleEdge> PGraph;
28 void copyFrom(const SimpleGraph &other) {
29 assert(other.areNodeIDsValid() &&
30 "Cannot copy from another graph unless IDs have been assigned.");
32 std::vector<NodeIterator> newNodeItrs(other.getNumNodes());
34 for (ConstNodeIterator nItr = other.nodesBegin(), nEnd = other.nodesEnd();
35 nItr != nEnd; ++nItr) {
36 newNodeItrs[other.getNodeID(nItr)] = addNode(other.getNodeCosts(nItr));
39 for (ConstEdgeIterator eItr = other.edgesBegin(), eEnd = other.edgesEnd();
40 eItr != eEnd; ++eItr) {
42 unsigned node1ID = other.getNodeID(other.getEdgeNode1Itr(eItr)),
43 node2ID = other.getNodeID(other.getEdgeNode2Itr(eItr));
45 addEdge(newNodeItrs[node1ID], newNodeItrs[node2ID],
46 other.getEdgeCosts(eItr));
50 void copyFrom(SimpleGraph &other) {
51 if (!other.areNodeIDsValid()) {
52 other.assignNodeIDs();
54 copyFrom(const_cast<const SimpleGraph&>(other));
62 SimpleGraph(const SimpleGraph &other) : PGraph() {
66 SimpleGraph& operator=(const SimpleGraph &other) {
72 NodeIterator addNode(const Vector &costs) {
73 return PGraph::addConstructedNode(SimpleNode(costs));
76 EdgeIterator addEdge(const NodeIterator &node1Itr,
77 const NodeIterator &node2Itr,
78 const Matrix &costs) {
79 return PGraph::addConstructedEdge(SimpleEdge(node1Itr, node2Itr, costs));
86 #endif // LLVM_CODEGEN_PBQP_SIMPLEGRAPH_H