Changeset 1025:c8fa41fcc4a7 in lemon-main
- Timestamp:
- 12/01/11 09:05:47 (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/graph_extender.h
r1020 r1025 761 761 762 762 typedef typename Parent::Node Node; 763 typedef typename Parent::RedNode RedNode; 764 typedef typename Parent::BlueNode BlueNode; 763 765 typedef typename Parent::Arc Arc; 764 766 typedef typename Parent::Edge Edge; … … 766 768 // BpGraph extension 767 769 768 class RedNode : public Node {769 public:770 RedNode() {}771 RedNode(const RedNode& node) : Node(node) {}772 RedNode(Invalid) : Node(INVALID){}773 RedNode(const Node& node) : Node(node) {}774 };775 class BlueNode : public Node {776 public:777 BlueNode() {}778 BlueNode(const BlueNode& node) : Node(node) {}779 BlueNode(Invalid) : Node(INVALID){}780 BlueNode(const Node& node) : Node(node) {}781 };782 783 770 using Parent::first; 784 771 using Parent::next; 785 786 void first(RedNode& node) const {787 Parent::firstRed(node);788 }789 790 void next(RedNode& node) const {791 Parent::nextRed(node);792 }793 794 void first(BlueNode& node) const {795 Parent::firstBlue(node);796 }797 798 void next(BlueNode& node) const {799 Parent::nextBlue(node);800 }801 802 772 using Parent::id; 803 804 int id(const RedNode& node) const {805 return Parent::redId(node);806 }807 808 int id(const BlueNode& node) const {809 return Parent::blueId(node);810 }811 773 812 774 int maxId(Node) const { … … 863 825 } 864 826 827 RedNode asRedNode(const Node& node) const { 828 if (node == INVALID || Parent::blue(node)) { 829 return INVALID; 830 } else { 831 return Parent::asRedNodeUnsafe(node); 832 } 833 } 834 835 BlueNode asBlueNode(const Node& node) const { 836 if (node == INVALID || Parent::red(node)) { 837 return INVALID; 838 } else { 839 return Parent::asBlueNodeUnsafe(node); 840 } 841 } 842 843 std::pair<RedNode, BlueNode> asRedBlueNode(const Node& node) const { 844 if (node == INVALID) { 845 return std::make_pair(RedNode(INVALID), BlueNode(INVALID)); 846 } else if (Parent::red(node)) { 847 return std::make_pair(Parent::asRedNodeUnsafe(node), BlueNode(INVALID)); 848 } else { 849 return std::make_pair(RedNode(INVALID), Parent::asBlueNodeUnsafe(node)); 850 } 851 } 852 865 853 // Alterable extension 866 854 … … 926 914 }; 927 915 928 class RedIt : public Node {916 class RedIt : public RedNode { 929 917 const BpGraph* _graph; 930 918 public: … … 932 920 RedIt() {} 933 921 934 RedIt(Invalid i) : Node(i) { }922 RedIt(Invalid i) : RedNode(i) { } 935 923 936 924 explicit RedIt(const BpGraph& graph) : _graph(&graph) { 937 _graph->firstRed(static_cast<Node&>(*this)); 938 } 939 940 RedIt(const BpGraph& graph, const Node& node) 941 : Node(node), _graph(&graph) { 942 LEMON_DEBUG(_graph->red(node), "Node has to be red."); 943 } 925 _graph->first(static_cast<RedNode&>(*this)); 926 } 927 928 RedIt(const BpGraph& graph, const RedNode& node) 929 : RedNode(node), _graph(&graph) {} 944 930 945 931 RedIt& operator++() { 946 _graph->next Red(*this);947 return *this; 948 } 949 950 }; 951 952 class BlueIt : public Node {932 _graph->next(static_cast<RedNode&>(*this)); 933 return *this; 934 } 935 936 }; 937 938 class BlueIt : public BlueNode { 953 939 const BpGraph* _graph; 954 940 public: … … 956 942 BlueIt() {} 957 943 958 BlueIt(Invalid i) : Node(i) { }944 BlueIt(Invalid i) : BlueNode(i) { } 959 945 960 946 explicit BlueIt(const BpGraph& graph) : _graph(&graph) { 961 _graph->firstBlue(static_cast<Node&>(*this)); 962 } 963 964 BlueIt(const BpGraph& graph, const Node& node) 965 : Node(node), _graph(&graph) { 966 LEMON_DEBUG(_graph->blue(node), "Node has to be blue."); 967 } 947 _graph->first(static_cast<BlueNode&>(*this)); 948 } 949 950 BlueIt(const BpGraph& graph, const BlueNode& node) 951 : BlueNode(node), _graph(&graph) {} 968 952 969 953 BlueIt& operator++() { 970 _graph->next Blue(*this);954 _graph->next(static_cast<BlueNode&>(*this)); 971 955 return *this; 972 956 } … … 1259 1243 // Alteration extension 1260 1244 1261 Node addRedNode() {1262 Node node = Parent::addRedNode();1245 RedNode addRedNode() { 1246 RedNode node = Parent::addRedNode(); 1263 1247 notifier(RedNode()).add(node); 1264 1248 notifier(Node()).add(node); … … 1266 1250 } 1267 1251 1268 Node addBlueNode() {1269 Node node = Parent::addBlueNode();1252 BlueNode addBlueNode() { 1253 BlueNode node = Parent::addBlueNode(); 1270 1254 notifier(BlueNode()).add(node); 1271 1255 notifier(Node()).add(node); … … 1273 1257 } 1274 1258 1275 Edge addEdge(const Node& from, constNode& to) {1259 Edge addEdge(const RedNode& from, const BlueNode& to) { 1276 1260 Edge edge = Parent::addEdge(from, to); 1277 1261 notifier(Edge()).add(edge); … … 1318 1302 1319 1303 if (Parent::red(node)) { 1320 notifier(RedNode()).erase( node);1304 notifier(RedNode()).erase(this->asRedNodeUnsafe(node)); 1321 1305 } else { 1322 notifier(BlueNode()).erase( node);1306 notifier(BlueNode()).erase(this->asBlueNodeUnsafe(node)); 1323 1307 } 1324 1308 -
lemon/concepts/bpgraph.h
r1018 r1025 150 150 RedNode(Invalid) { } 151 151 152 /// Constructor for conversion from a node.153 154 /// Constructor for conversion from a node. The conversion can155 /// be invalid, since the Node can be member of the blue156 /// set.157 RedNode(const Node&) {}158 152 }; 159 153 … … 183 177 BlueNode(Invalid) { } 184 178 185 /// Constructor for conversion from a node.186 187 /// Constructor for conversion from a node. The conversion can188 /// be invalid, since the Node can be member of the red189 /// set.190 BlueNode(const Node&) {}191 179 }; 192 180 … … 200 188 /// for (BpGraph::RedNodeIt n(g); n!=INVALID; ++n) ++count; 201 189 ///\endcode 202 class RedIt : public Node {190 class RedIt : public RedNode { 203 191 public: 204 192 /// Default constructor … … 211 199 /// Copy constructor. 212 200 /// 213 RedIt(const RedIt& n) : Node(n) { }201 RedIt(const RedIt& n) : RedNode(n) { } 214 202 /// %Invalid constructor \& conversion. 215 203 … … 226 214 /// Sets the iterator to the given red node of the given 227 215 /// digraph. 228 RedIt(const BpGraph&, const Node&) { }216 RedIt(const BpGraph&, const RedNode&) { } 229 217 /// Next node. 230 218 … … 243 231 /// for (BpGraph::BlueNodeIt n(g); n!=INVALID; ++n) ++count; 244 232 ///\endcode 245 class BlueIt : public Node {233 class BlueIt : public BlueNode { 246 234 public: 247 235 /// Default constructor … … 254 242 /// Copy constructor. 255 243 /// 256 BlueIt(const BlueIt& n) : Node(n) { }244 BlueIt(const BlueIt& n) : BlueNode(n) { } 257 245 /// %Invalid constructor \& conversion. 258 246 … … 269 257 /// Sets the iterator to the given blue node of the given 270 258 /// digraph. 271 BlueIt(const BpGraph&, const Node&) { }259 BlueIt(const BpGraph&, const BlueNode&) { } 272 260 /// Next node. 273 261 … … 785 773 bool blue(const Node&) const { return true; } 786 774 775 /// \brief Converts the node to red node object. 776 /// 777 /// This class is converts unsafely the node to red node 778 /// object. It should be called only if the node is from the red 779 /// partition or INVALID. 780 RedNode asRedNodeUnsafe(const Node&) const { return RedNode(); } 781 782 /// \brief Converts the node to blue node object. 783 /// 784 /// This class is converts unsafely the node to blue node 785 /// object. It should be called only if the node is from the red 786 /// partition or INVALID. 787 BlueNode asBlueNodeUnsafe(const Node&) const { return BlueNode(); } 788 789 /// \brief Converts the node to red node object. 790 /// 791 /// This class is converts safely the node to red node 792 /// object. If the node is not from the red partition, then it 793 /// returns INVALID. 794 RedNode asRedNode(const Node&) const { return RedNode(); } 795 796 /// \brief Converts the node to blue node object. 797 /// 798 /// This class is converts unsafely the node to blue node 799 /// object. If the node is not from the blue partition, then it 800 /// returns INVALID. 801 BlueNode asBlueNode(const Node&) const { return BlueNode(); } 802 803 /// \brief Convert the node to either red or blue node. 804 /// 805 /// If the node is from the red partition then it is returned in 806 /// first and second is INVALID. If the node is from the blue 807 /// partition then it is returned in second and first is 808 /// INVALID. If the node INVALID then both first and second are 809 /// INVALID in the return value. 810 std::pair<RedNode, BlueNode> asRedBlueNode(const Node&) const { 811 return std::make_pair(RedNode(), BlueNode()); 812 } 813 787 814 /// \brief Gives back the red end node of the edge. 788 815 /// 789 816 /// Gives back the red end node of the edge. 790 Node redNode(const Edge&) const { returnNode(); }817 RedNode redNode(const Edge&) const { return RedNode(); } 791 818 792 819 /// \brief Gives back the blue end node of the edge. 793 820 /// 794 821 /// Gives back the blue end node of the edge. 795 Node blueNode(const Edge&) const { returnNode(); }822 BlueNode blueNode(const Edge&) const { return BlueNode(); } 796 823 797 824 /// \brief The first node of the edge. … … 823 850 /// 824 851 /// Returns the red ID of the given node. 825 int redId(Node) const { return -1; }826 827 /// \brief The red ID of the node.828 ///829 /// Returns the red ID of the given node.830 852 int id(RedNode) const { return -1; } 831 832 /// \brief The blue ID of the node.833 ///834 /// Returns the blue ID of the given node.835 int blueId(Node) const { return -1; }836 853 837 854 /// \brief The blue ID of the node. … … 929 946 void next(Node&) const {} 930 947 931 void firstRed( Node&) const {}932 void nextRed( Node&) const {}933 934 void firstBlue( Node&) const {}935 void nextBlue( Node&) const {}948 void firstRed(RedNode&) const {} 949 void nextRed(RedNode&) const {} 950 951 void firstBlue(BlueNode&) const {} 952 void nextBlue(BlueNode&) const {} 936 953 937 954 void first(Edge&) const {} -
lemon/concepts/graph_components.h
r1018 r1025 318 318 /// \brief Class to represent red nodes. 319 319 /// 320 /// This class represents the red nodes of the graph. It does 321 /// not supposed to be used directly, because the nodes can be 322 /// represented as Node instances. This class can be used as 323 /// template parameter for special map classes. 320 /// This class represents the red nodes of the graph. The red 321 /// nodes can be used also as normal nodes. 324 322 class RedNode : public Node { 325 323 typedef Node Parent; … … 345 343 /// \sa Invalid for more details. 346 344 RedNode(Invalid) {} 347 348 /// \brief Constructor for conversion from a node.349 ///350 /// Constructor for conversion from a node. The conversion can351 /// be invalid, since the Node can be member of the blue352 /// set.353 RedNode(const Node&) {}354 345 }; 355 346 356 347 /// \brief Class to represent blue nodes. 357 348 /// 358 /// This class represents the blue nodes of the graph. It does 359 /// not supposed to be used directly, because the nodes can be 360 /// represented as Node instances. This class can be used as 361 /// template parameter for special map classes. 349 /// This class represents the blue nodes of the graph. The blue 350 /// nodes can be used also as normal nodes. 362 351 class BlueNode : public Node { 363 352 typedef Node Parent; … … 405 394 /// 406 395 /// Gives back the red end node of the edge. 407 Node redNode(const Edge&) const { returnNode(); }396 RedNode redNode(const Edge&) const { return RedNode(); } 408 397 409 398 /// \brief Gives back the blue end node of the edge. 410 399 /// 411 400 /// Gives back the blue end node of the edge. 412 Node blueNode(const Edge&) const { return Node(); } 401 BlueNode blueNode(const Edge&) const { return BlueNode(); } 402 403 /// \brief Converts the node to red node object. 404 /// 405 /// This class is converts unsafely the node to red node 406 /// object. It should be called only if the node is from the red 407 /// partition or INVALID. 408 RedNode asRedNodeUnsafe(const Node&) const { return RedNode(); } 409 410 /// \brief Converts the node to blue node object. 411 /// 412 /// This class is converts unsafely the node to blue node 413 /// object. It should be called only if the node is from the red 414 /// partition or INVALID. 415 BlueNode asBlueNodeUnsafe(const Node&) const { return BlueNode(); } 416 417 /// \brief Converts the node to red node object. 418 /// 419 /// This class is converts safely the node to red node 420 /// object. If the node is not from the red partition, then it 421 /// returns INVALID. 422 RedNode asRedNode(const Node&) const { return RedNode(); } 423 424 /// \brief Converts the node to blue node object. 425 /// 426 /// This class is converts unsafely the node to blue node 427 /// object. If the node is not from the blue partition, then it 428 /// returns INVALID. 429 BlueNode asBlueNode(const Node&) const { return BlueNode(); } 430 431 /// \brief Convert the node to either red or blue node. 432 /// 433 /// If the node is from the red partition then it is returned in 434 /// first and second is INVALID. If the node is from the blue 435 /// partition then it is returned in second and first is 436 /// INVALID. If the node INVALID then both first and second are 437 /// INVALID in the return value. 438 std::pair<RedNode, BlueNode> asRedBlueNode(const Node&) const { 439 return std::make_pair(RedNode(), BlueNode()); 440 } 413 441 414 442 template <typename _BpGraph> … … 426 454 { 427 455 Node n; 428 RedNode rn = n; 429 BlueNode bn = bn; 456 RedNode rn; 457 BlueNode bn; 458 Node rnan = rn; 459 Node bnan = bn; 430 460 Edge e; 431 461 bool b; 432 b = bpgraph.red(n); 433 b = bpgraph.blue(n); 434 ignore_unused_variable_warning(b); 435 n = bpgraph.redNode(e); 436 n = bpgraph.blueNode(e); 437 rn = n; 438 bn = n; 462 b = bpgraph.red(rnan); 463 b = bpgraph.blue(bnan); 464 rn = bpgraph.redNode(e); 465 bn = bpgraph.blueNode(e); 466 rn = bpgraph.asRedNodeUnsafe(rnan); 467 bn = bpgraph.asBlueNodeUnsafe(bnan); 468 rn = bpgraph.asRedNode(rnan); 469 bn = bpgraph.asBlueNode(bnan); 470 std::pair<RedNode, BlueNode> p = bpgraph.asRedBlueNode(rnan); 471 ignore_unused_variable_warning(b,p); 439 472 } 440 473 } … … 600 633 /// 601 634 /// Return a unique integer id for the given node in the red set. 602 int redId(const Node&) const { return -1; }603 604 /// \brief Return the same value as redId().605 ///606 /// Return the same value as redId().607 635 int id(const RedNode&) const { return -1; } 608 636 … … 610 638 /// 611 639 /// Return a unique integer id for the given node in the blue set. 612 int blueId(const Node&) const { return -1; }613 614 /// \brief Return the same value as blueId().615 ///616 /// Return the same value as blueId().617 640 int id(const BlueNode&) const { return -1; } 618 641 … … 639 662 typename _BpGraph::RedNode red; 640 663 typename _BpGraph::BlueNode blue; 641 int rid = bpgraph.redId(node); 642 int bid = bpgraph.blueId(node); 643 rid = bpgraph.id(red); 644 bid = bpgraph.id(blue); 664 int rid = bpgraph.id(red); 665 int bid = bpgraph.id(blue); 645 666 rid = bpgraph.maxRedId(); 646 667 bid = bpgraph.maxBlueId(); … … 1138 1159 typedef BAS Base; 1139 1160 typedef typename Base::Node Node; 1161 typedef typename Base::RedNode RedNode; 1162 typedef typename Base::BlueNode BlueNode; 1140 1163 typedef typename Base::Arc Arc; 1141 1164 typedef typename Base::Edge Edge; 1142 1143 1165 1144 1166 typedef IterableBpGraphComponent BpGraph; 1145 1167 1168 using IterableGraphComponent<BAS>::first; 1169 using IterableGraphComponent<BAS>::next; 1170 1146 1171 /// \name Base Iteration 1147 1172 /// … … 1153 1178 /// 1154 1179 /// This function gives back the first red node in the iteration order. 1155 void first Red(Node&) const {}1180 void first(RedNode&) const {} 1156 1181 1157 1182 /// \brief Return the next red node. 1158 1183 /// 1159 1184 /// This function gives back the next red node in the iteration order. 1160 void next Red(Node&) const {}1185 void next(RedNode&) const {} 1161 1186 1162 1187 /// \brief Return the first blue node. 1163 1188 /// 1164 1189 /// This function gives back the first blue node in the iteration order. 1165 void first Blue(Node&) const {}1190 void first(BlueNode&) const {} 1166 1191 1167 1192 /// \brief Return the next blue node. 1168 1193 /// 1169 1194 /// This function gives back the next blue node in the iteration order. 1170 void next Blue(Node&) const {}1195 void next(BlueNode&) const {} 1171 1196 1172 1197 … … 1182 1207 /// 1183 1208 /// This iterator goes through each red node. 1184 typedef GraphItemIt<BpGraph, Node> RedIt;1209 typedef GraphItemIt<BpGraph, RedNode> RedIt; 1185 1210 1186 1211 /// \brief This iterator goes through each blue node. 1187 1212 /// 1188 1213 /// This iterator goes through each blue node. 1189 typedef GraphItemIt<BpGraph, Node> BlueIt;1214 typedef GraphItemIt<BpGraph, BlueNode> BlueIt; 1190 1215 1191 1216 /// @} … … 1196 1221 checkConcept<IterableGraphComponent<Base>, _BpGraph>(); 1197 1222 1198 typename _BpGraph::Node node(INVALID); 1199 bpgraph.firstRed(node); 1200 bpgraph.nextRed(node); 1201 bpgraph.firstBlue(node); 1202 bpgraph.nextBlue(node); 1203 1204 checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::Node>, 1223 typename _BpGraph::RedNode rn(INVALID); 1224 bpgraph.first(rn); 1225 bpgraph.next(rn); 1226 typename _BpGraph::BlueNode bn(INVALID); 1227 bpgraph.first(bn); 1228 bpgraph.next(bn); 1229 1230 checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::RedNode>, 1205 1231 typename _BpGraph::RedIt>(); 1206 checkConcept<GraphItemIt<_BpGraph, typename _BpGraph:: Node>,1232 checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::BlueNode>, 1207 1233 typename _BpGraph::BlueIt>(); 1208 1234 } … … 1791 1817 { // int map test 1792 1818 typedef typename _BpGraph::template RedMap<int> IntRedMap; 1793 checkConcept<GraphMap<_BpGraph, typename _BpGraph:: Node, int>,1819 checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, int>, 1794 1820 IntRedMap >(); 1795 1821 } { // bool map test 1796 1822 typedef typename _BpGraph::template RedMap<bool> BoolRedMap; 1797 checkConcept<GraphMap<_BpGraph, typename _BpGraph:: Node, bool>,1823 checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, bool>, 1798 1824 BoolRedMap >(); 1799 1825 } { // Dummy map test 1800 1826 typedef typename _BpGraph::template RedMap<Dummy> DummyRedMap; 1801 checkConcept<GraphMap<_BpGraph, typename _BpGraph:: Node, Dummy>,1827 checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, Dummy>, 1802 1828 DummyRedMap >(); 1803 1829 } … … 1805 1831 { // int map test 1806 1832 typedef typename _BpGraph::template BlueMap<int> IntBlueMap; 1807 checkConcept<GraphMap<_BpGraph, typename _BpGraph:: Node, int>,1833 checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, int>, 1808 1834 IntBlueMap >(); 1809 1835 } { // bool map test 1810 1836 typedef typename _BpGraph::template BlueMap<bool> BoolBlueMap; 1811 checkConcept<GraphMap<_BpGraph, typename _BpGraph:: Node, bool>,1837 checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, bool>, 1812 1838 BoolBlueMap >(); 1813 1839 } { // Dummy map test 1814 1840 typedef typename _BpGraph::template BlueMap<Dummy> DummyBlueMap; 1815 checkConcept<GraphMap<_BpGraph, typename _BpGraph:: Node, Dummy>,1841 checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, Dummy>, 1816 1842 DummyBlueMap >(); 1817 1843 } … … 1924 1950 typedef BAS Base; 1925 1951 typedef typename Base::Node Node; 1952 typedef typename Base::RedNode RedNode; 1953 typedef typename Base::BlueNode BlueNode; 1926 1954 typedef typename Base::Edge Edge; 1927 1955 … … 1929 1957 /// 1930 1958 /// This function adds a red new node to the digraph. 1931 Node addRedNode() {1959 RedNode addRedNode() { 1932 1960 return INVALID; 1933 1961 } … … 1936 1964 /// 1937 1965 /// This function adds a blue new node to the digraph. 1938 Node addBlueNode() {1966 BlueNode addBlueNode() { 1939 1967 return INVALID; 1940 1968 } … … 1945 1973 /// of the graph. The first node has to be a red node, and the 1946 1974 /// second one a blue node. 1947 Edge addEdge(const Node&, constNode&) {1975 Edge addEdge(const RedNode&, const BlueNode&) { 1948 1976 return INVALID; 1949 1977 } 1978 Edge addEdge(const BlueNode&, const RedNode&) { 1979 return INVALID; 1980 } 1950 1981 1951 1982 template <typename _BpGraph> … … 1953 1984 void constraints() { 1954 1985 checkConcept<Base, _BpGraph>(); 1955 typename _BpGraph::Node red_node, blue_node; 1986 typename _BpGraph::RedNode red_node; 1987 typename _BpGraph::BlueNode blue_node; 1956 1988 red_node = bpgraph.addRedNode(); 1957 1989 blue_node = bpgraph.addBlueNode(); 1958 1990 typename _BpGraph::Edge edge; 1959 1991 edge = bpgraph.addEdge(red_node, blue_node); 1992 edge = bpgraph.addEdge(blue_node, red_node); 1960 1993 } 1961 1994 -
lemon/core.h
r1022 r1025 551 551 template <typename From, typename NodeRefMap, typename EdgeRefMap> 552 552 static void copy(const From& from, Graph &to, 553 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 553 NodeRefMap& nodeRefMap, 554 EdgeRefMap& edgeRefMap) { 554 555 to.build(from, nodeRefMap, edgeRefMap); 555 556 } … … 558 559 template <typename BpGraph, typename Enable = void> 559 560 struct BpGraphCopySelector { 560 template <typename From, typename NodeRefMap, typename EdgeRefMap> 561 template <typename From, typename RedNodeRefMap, 562 typename BlueNodeRefMap, typename EdgeRefMap> 561 563 static void copy(const From& from, BpGraph &to, 562 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 564 RedNodeRefMap& redNodeRefMap, 565 BlueNodeRefMap& blueNodeRefMap, 566 EdgeRefMap& edgeRefMap) { 563 567 to.clear(); 564 568 for (typename From::RedIt it(from); it != INVALID; ++it) { 565 nodeRefMap[it] = to.addRedNode();569 redNodeRefMap[it] = to.addRedNode(); 566 570 } 567 571 for (typename From::BlueIt it(from); it != INVALID; ++it) { 568 nodeRefMap[it] = to.addBlueNode();572 blueNodeRefMap[it] = to.addBlueNode(); 569 573 } 570 574 for (typename From::EdgeIt it(from); it != INVALID; ++it) { 571 edgeRefMap[it] = to.addEdge( nodeRefMap[from.redNode(it)],572 nodeRefMap[from.blueNode(it)]);575 edgeRefMap[it] = to.addEdge(redNodeRefMap[from.redNode(it)], 576 blueNodeRefMap[from.blueNode(it)]); 573 577 } 574 578 } … … 580 584 typename enable_if<typename BpGraph::BuildTag, void>::type> 581 585 { 582 template <typename From, typename NodeRefMap, typename EdgeRefMap> 586 template <typename From, typename RedNodeRefMap, 587 typename BlueNodeRefMap, typename EdgeRefMap> 583 588 static void copy(const From& from, BpGraph &to, 584 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 585 to.build(from, nodeRefMap, edgeRefMap); 589 RedNodeRefMap& redNodeRefMap, 590 BlueNodeRefMap& blueNodeRefMap, 591 EdgeRefMap& edgeRefMap) { 592 to.build(from, redNodeRefMap, blueNodeRefMap, edgeRefMap); 586 593 } 587 594 }; … … 1183 1190 1184 1191 typedef typename To::Node TNode; 1192 typedef typename To::RedNode TRedNode; 1193 typedef typename To::BlueNode TBlueNode; 1185 1194 typedef typename To::Arc TArc; 1186 1195 typedef typename To::Edge TEdge; 1187 1196 1188 typedef typename From::template NodeMap<TNode> NodeRefMap; 1197 typedef typename From::template RedMap<TRedNode> RedNodeRefMap; 1198 typedef typename From::template BlueMap<TBlueNode> BlueNodeRefMap; 1189 1199 typedef typename From::template EdgeMap<TEdge> EdgeRefMap; 1200 1201 struct NodeRefMap { 1202 NodeRefMap(const From& from, const RedNodeRefMap& red_node_ref, 1203 const BlueNodeRefMap& blue_node_ref) 1204 : _from(from), _red_node_ref(red_node_ref), 1205 _blue_node_ref(blue_node_ref) {} 1206 1207 typedef typename From::Node Key; 1208 typedef typename To::Node Value; 1209 1210 Value operator[](const Key& key) const { 1211 std::pair<RedNode, BlueNode> red_blue_pair = _from.asRedBlueNode(key); 1212 if (red_blue_pair.first != INVALID) { 1213 return _red_node_ref[red_blue_pair.first]; 1214 } else { 1215 return _blue_node_ref[red_blue_pair.second]; 1216 } 1217 } 1218 1219 const From& _from; 1220 const RedNodeRefMap& _red_node_ref; 1221 const BlueNodeRefMap& _blue_node_ref; 1222 }; 1190 1223 1191 1224 struct ArcRefMap { … … 1293 1326 BpGraphCopy& redRef(RedRef& map) { 1294 1327 _red_maps.push_back(new _core_bits::RefCopy<From, RedNode, 1295 NodeRefMap, RedRef>(map));1328 RedNodeRefMap, RedRef>(map)); 1296 1329 return *this; 1297 1330 } … … 1307 1340 BpGraphCopy& redCrossRef(RedCrossRef& map) { 1308 1341 _red_maps.push_back(new _core_bits::CrossRefCopy<From, RedNode, 1309 NodeRefMap, RedCrossRef>(map));1342 RedNodeRefMap, RedCrossRef>(map)); 1310 1343 return *this; 1311 1344 } … … 1322 1355 BpGraphCopy& redMap(const FromMap& map, ToMap& tmap) { 1323 1356 _red_maps.push_back(new _core_bits::MapCopy<From, RedNode, 1324 NodeRefMap, FromMap, ToMap>(map, tmap)); 1357 RedNodeRefMap, FromMap, ToMap>(map, tmap)); 1358 return *this; 1359 } 1360 1361 /// \brief Make a copy of the given red node. 1362 /// 1363 /// This function makes a copy of the given red node. 1364 BpGraphCopy& redNode(const RedNode& node, TRedNode& tnode) { 1365 _red_maps.push_back(new _core_bits::ItemCopy<From, RedNode, 1366 RedNodeRefMap, TRedNode>(node, tnode)); 1325 1367 return *this; 1326 1368 } … … 1335 1377 BpGraphCopy& blueRef(BlueRef& map) { 1336 1378 _blue_maps.push_back(new _core_bits::RefCopy<From, BlueNode, 1337 NodeRefMap, BlueRef>(map));1379 BlueNodeRefMap, BlueRef>(map)); 1338 1380 return *this; 1339 1381 } … … 1349 1391 BpGraphCopy& blueCrossRef(BlueCrossRef& map) { 1350 1392 _blue_maps.push_back(new _core_bits::CrossRefCopy<From, BlueNode, 1351 NodeRefMap, BlueCrossRef>(map));1393 BlueNodeRefMap, BlueCrossRef>(map)); 1352 1394 return *this; 1353 1395 } … … 1364 1406 BpGraphCopy& blueMap(const FromMap& map, ToMap& tmap) { 1365 1407 _blue_maps.push_back(new _core_bits::MapCopy<From, BlueNode, 1366 NodeRefMap, FromMap, ToMap>(map, tmap)); 1408 BlueNodeRefMap, FromMap, ToMap>(map, tmap)); 1409 return *this; 1410 } 1411 1412 /// \brief Make a copy of the given blue node. 1413 /// 1414 /// This function makes a copy of the given blue node. 1415 BpGraphCopy& blueNode(const BlueNode& node, TBlueNode& tnode) { 1416 _blue_maps.push_back(new _core_bits::ItemCopy<From, BlueNode, 1417 BlueNodeRefMap, TBlueNode>(node, tnode)); 1367 1418 return *this; 1368 1419 } … … 1471 1522 /// copying of the assigned data. 1472 1523 void run() { 1473 NodeRefMap nodeRefMap(_from); 1524 RedNodeRefMap redNodeRefMap(_from); 1525 BlueNodeRefMap blueNodeRefMap(_from); 1526 NodeRefMap nodeRefMap(_from, redNodeRefMap, blueNodeRefMap); 1474 1527 EdgeRefMap edgeRefMap(_from); 1475 1528 ArcRefMap arcRefMap(_from, _to, edgeRefMap); 1476 1529 _core_bits::BpGraphCopySelector<To>:: 1477 copy(_from, _to, nodeRefMap, edgeRefMap);1530 copy(_from, _to, redNodeRefMap, blueNodeRefMap, edgeRefMap); 1478 1531 for (int i = 0; i < int(_node_maps.size()); ++i) { 1479 1532 _node_maps[i]->copy(_from, nodeRefMap); 1480 1533 } 1481 1534 for (int i = 0; i < int(_red_maps.size()); ++i) { 1482 _red_maps[i]->copy(_from, nodeRefMap);1535 _red_maps[i]->copy(_from, redNodeRefMap); 1483 1536 } 1484 1537 for (int i = 0; i < int(_blue_maps.size()); ++i) { 1485 _blue_maps[i]->copy(_from, nodeRefMap);1538 _blue_maps[i]->copy(_from, blueNodeRefMap); 1486 1539 } 1487 1540 for (int i = 0; i < int(_edge_maps.size()); ++i) { … … 1501 1554 _node_maps; 1502 1555 1503 std::vector<_core_bits::MapCopyBase<From, RedNode, NodeRefMap>* >1556 std::vector<_core_bits::MapCopyBase<From, RedNode, RedNodeRefMap>* > 1504 1557 _red_maps; 1505 1558 1506 std::vector<_core_bits::MapCopyBase<From, BlueNode, NodeRefMap>* >1559 std::vector<_core_bits::MapCopyBase<From, BlueNode, BlueNodeRefMap>* > 1507 1560 _blue_maps; 1508 1561 -
lemon/full_graph.h
r1024 r1025 652 652 }; 653 653 654 class RedNode : public Node { 655 friend class FullBpGraphBase; 656 protected: 657 658 explicit RedNode(int pid) : Node(pid) {} 659 660 public: 661 RedNode() {} 662 RedNode(const RedNode& node) : Node(node) {} 663 RedNode(Invalid) : Node(INVALID){} 664 }; 665 666 class BlueNode : public Node { 667 friend class FullBpGraphBase; 668 protected: 669 670 explicit BlueNode(int pid) : Node(pid) {} 671 672 public: 673 BlueNode() {} 674 BlueNode(const BlueNode& node) : Node(node) {} 675 BlueNode(Invalid) : Node(INVALID){} 676 }; 677 654 678 class Edge { 655 679 friend class FullBpGraphBase; … … 718 742 bool blue(Node n) const { return n._id >= _red_num; } 719 743 744 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n._id); } 745 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n._id); } 746 720 747 Node source(Arc a) const { 721 748 if (a._id & 1) { … … 733 760 } 734 761 735 Node redNode(Edge e) const {736 return Node(e._id % _red_num);737 } 738 Node blueNode(Edge e) const {739 return Node(e._id / _red_num + _red_num);762 RedNode redNode(Edge e) const { 763 return RedNode(e._id % _red_num); 764 } 765 BlueNode blueNode(Edge e) const { 766 return BlueNode(e._id / _red_num + _red_num); 740 767 } 741 768 … … 756 783 } 757 784 758 void first Red(Node& node) const {785 void first(RedNode& node) const { 759 786 node._id = _red_num - 1; 760 787 } 761 788 762 static void next Red(Node& node) {789 static void next(RedNode& node) { 763 790 --node._id; 764 791 } 765 792 766 void first Blue(Node& node) const {793 void first(BlueNode& node) const { 767 794 if (_red_num == _node_num) node._id = -1; 768 795 else node._id = _node_num - 1; 769 796 } 770 797 771 void next Blue(Node& node) const {798 void next(BlueNode& node) const { 772 799 if (node._id == _red_num) node._id = -1; 773 800 else --node._id; … … 843 870 } 844 871 845 static int id(Node v) { return v._id; } 846 int redId(Node v) const { 847 LEMON_DEBUG(v._id < _red_num, "Node has to be red"); 848 return v._id; 849 } 850 int blueId(Node v) const { 851 LEMON_DEBUG(v._id >= _red_num, "Node has to be blue"); 852 return v._id - _red_num; 853 } 872 static int id(const Node& v) { return v._id; } 873 int id(const RedNode& v) const { return v._id; } 874 int id(const BlueNode& v) const { return v._id - _red_num; } 854 875 static int id(Arc e) { return e._id; } 855 876 static int id(Edge e) { return e._id; } … … 869 890 } 870 891 871 Node redNode(int index) const {872 return Node(index);873 } 874 875 int redIndex(Node n) const {892 RedNode redNode(int index) const { 893 return RedNode(index); 894 } 895 896 int index(RedNode n) const { 876 897 return n._id; 877 898 } 878 899 879 Node blueNode(int index) const {880 return Node(index + _red_num);881 } 882 883 int blueIndex(Node n) const {900 BlueNode blueNode(int index) const { 901 return BlueNode(index + _red_num); 902 } 903 904 int index(BlueNode n) const { 884 905 return n._id - _red_num; 885 906 } … … 1001 1022 /// with integers from the range <tt>[0..redNum()-1]</tt>. 1002 1023 /// \sa redIndex() 1003 Node redNode(int index) const { return Parent::redNode(index); }1024 RedNode redNode(int index) const { return Parent::redNode(index); } 1004 1025 1005 1026 /// \brief Returns the index of the given red node. … … 1010 1031 /// 1011 1032 /// \sa operator()() 1012 int redIndex(Node node) const { return Parent::redIndex(node); }1033 int index(RedNode node) const { return Parent::index(node); } 1013 1034 1014 1035 /// \brief Returns the blue node with the given index. … … 1018 1039 /// with integers from the range <tt>[0..blueNum()-1]</tt>. 1019 1040 /// \sa blueIndex() 1020 Node blueNode(int index) const { return Parent::blueNode(index); }1041 BlueNode blueNode(int index) const { return Parent::blueNode(index); } 1021 1042 1022 1043 /// \brief Returns the index of the given blue node. … … 1027 1048 /// 1028 1049 /// \sa operator()() 1029 int blueIndex(Node node) const { return Parent::blueIndex(node); }1050 int index(BlueNode node) const { return Parent::index(node); } 1030 1051 1031 1052 /// \brief Returns the edge which connects the given nodes. -
lemon/list_graph.h
r1021 r1025 1648 1648 }; 1649 1649 1650 class RedNode : public Node { 1651 friend class ListBpGraphBase; 1652 protected: 1653 1654 explicit RedNode(int pid) : Node(pid) {} 1655 1656 public: 1657 RedNode() {} 1658 RedNode(const RedNode& node) : Node(node) {} 1659 RedNode(Invalid) : Node(INVALID){} 1660 }; 1661 1662 class BlueNode : public Node { 1663 friend class ListBpGraphBase; 1664 protected: 1665 1666 explicit BlueNode(int pid) : Node(pid) {} 1667 1668 public: 1669 BlueNode() {} 1670 BlueNode(const BlueNode& node) : Node(node) {} 1671 BlueNode(Invalid) : Node(INVALID){} 1672 }; 1673 1650 1674 class Edge { 1651 1675 friend class ListBpGraphBase; … … 1693 1717 bool blue(Node n) const { return !nodes[n.id].red; } 1694 1718 1719 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n.id); } 1720 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n.id); } 1721 1695 1722 int maxNodeId() const { return nodes.size()-1; } 1696 1723 int maxRedId() const { return max_red; } … … 1702 1729 Node target(Arc e) const { return Node(arcs[e.id].target); } 1703 1730 1704 Node redNode(Edge e) const { return Node(arcs[2 * e.id].target); } 1705 Node blueNode(Edge e) const { return Node(arcs[2 * e.id + 1].target); } 1731 RedNode redNode(Edge e) const { 1732 return RedNode(arcs[2 * e.id].target); 1733 } 1734 BlueNode blueNode(Edge e) const { 1735 return BlueNode(arcs[2 * e.id + 1].target); 1736 } 1706 1737 1707 1738 static bool direction(Arc e) { … … 1721 1752 } 1722 1753 1723 void first Red(Node& node) const {1754 void first(RedNode& node) const { 1724 1755 node.id = first_red; 1725 1756 } 1726 1757 1727 void next Red(Node& node) const {1758 void next(RedNode& node) const { 1728 1759 node.id = nodes[node.id].partition_next; 1729 1760 } 1730 1761 1731 void first Blue(Node& node) const {1762 void first(BlueNode& node) const { 1732 1763 node.id = first_blue; 1733 1764 } 1734 1765 1735 void next Blue(Node& node) const {1766 void next(BlueNode& node) const { 1736 1767 node.id = nodes[node.id].partition_next; 1737 1768 } … … 1836 1867 1837 1868 static int id(Node v) { return v.id; } 1838 int redId(Node v) const { 1839 LEMON_DEBUG(nodes[v.id].red, "Node has to be red"); 1840 return nodes[v.id].partition_index; 1841 } 1842 int blueId(Node v) const { 1843 LEMON_DEBUG(!nodes[v.id].red, "Node has to be blue"); 1844 return nodes[v.id].partition_index; 1845 } 1869 int id(RedNode v) const { return nodes[v.id].partition_index; } 1870 int id(BlueNode v) const { return nodes[v.id].partition_index; } 1846 1871 static int id(Arc e) { return e.id; } 1847 1872 static int id(Edge e) { return e.id; } … … 1866 1891 } 1867 1892 1868 Node addRedNode() {1893 RedNode addRedNode() { 1869 1894 int n; 1870 1895 … … 1891 1916 nodes[n].first_out = -1; 1892 1917 1893 return Node(n);1894 } 1895 1896 Node addBlueNode() {1918 return RedNode(n); 1919 } 1920 1921 BlueNode addBlueNode() { 1897 1922 int n; 1898 1923 … … 1919 1944 nodes[n].first_out = -1; 1920 1945 1921 return Node(n);1946 return BlueNode(n); 1922 1947 } 1923 1948 … … 2030 2055 protected: 2031 2056 2032 void changeRed(Edge e, Node n) { 2033 LEMON_DEBUG(nodes[n].red, "Node has to be red"); 2057 void changeRed(Edge e, RedNode n) { 2034 2058 if(arcs[(2 * e.id) | 1].next_out != -1) { 2035 2059 arcs[arcs[(2 * e.id) | 1].next_out].prev_out = … … 2053 2077 } 2054 2078 2055 void changeBlue(Edge e, Node n) { 2056 LEMON_DEBUG(nodes[n].red, "Node has to be blue"); 2057 if(arcs[2 * e.id].next_out != -1) { 2079 void changeBlue(Edge e, BlueNode n) { 2080 if(arcs[2 * e.id].next_out != -1) { 2058 2081 arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out; 2059 2082 } … … 2120 2143 /// This function adds a red new node to the graph. 2121 2144 /// \return The new node. 2122 Node addRedNode() { return Parent::addRedNode(); }2145 RedNode addRedNode() { return Parent::addRedNode(); } 2123 2146 2124 2147 /// \brief Add a new blue node to the graph. … … 2126 2149 /// This function adds a blue new node to the graph. 2127 2150 /// \return The new node. 2128 Node addBlueNode() { return Parent::addBlueNode(); }2151 BlueNode addBlueNode() { return Parent::addBlueNode(); } 2129 2152 2130 2153 /// \brief Add a new edge to the graph. … … 2134 2157 /// node \c v. 2135 2158 /// \return The new edge. 2136 Edge addEdge(Node u, Node v) { 2159 Edge addEdge(RedNode u, BlueNode v) { 2160 return Parent::addEdge(u, v); 2161 } 2162 Edge addEdge(BlueNode v, RedNode u) { 2137 2163 return Parent::addEdge(u, v); 2138 2164 } … … 2189 2215 ///\warning This functionality cannot be used together with the 2190 2216 ///Snapshot feature. 2191 void changeRed(Edge e, Node n) {2192 Parent::changeRed(e, n);2217 void changeRed(Edge e, RedNode n) { 2218 Parent::changeRed(e, n); 2193 2219 } 2194 2220 /// \brief Change the blue node of an edge. … … 2203 2229 ///\warning This functionality cannot be used together with the 2204 2230 ///Snapshot feature. 2205 void changeBlue(Edge e, Node n) {2206 Parent::changeBlue(e, n);2231 void changeBlue(Edge e, BlueNode n) { 2232 Parent::changeBlue(e, n); 2207 2233 } 2208 2234 -
lemon/smart_graph.h
r1023 r1025 855 855 }; 856 856 857 class RedNode : public Node { 858 friend class SmartBpGraphBase; 859 protected: 860 861 explicit RedNode(int pid) : Node(pid) {} 862 863 public: 864 RedNode() {} 865 RedNode(const RedNode& node) : Node(node) {} 866 RedNode(Invalid) : Node(INVALID){} 867 }; 868 869 class BlueNode : public Node { 870 friend class SmartBpGraphBase; 871 protected: 872 873 explicit BlueNode(int pid) : Node(pid) {} 874 875 public: 876 BlueNode() {} 877 BlueNode(const BlueNode& node) : Node(node) {} 878 BlueNode(Invalid) : Node(INVALID){} 879 }; 880 857 881 class Edge { 858 882 friend class SmartBpGraphBase; … … 914 938 bool blue(Node n) const { return !nodes[n._id].red; } 915 939 940 static RedNode asRedNodeUnsafe(Node n) { return RedNode(n._id); } 941 static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n._id); } 942 916 943 Node source(Arc a) const { return Node(arcs[a._id ^ 1].target); } 917 944 Node target(Arc a) const { return Node(arcs[a._id].target); } 918 945 919 Node redNode(Edge e) const { return Node(arcs[2 * e._id].target); } 920 Node blueNode(Edge e) const { return Node(arcs[2 * e._id + 1].target); } 946 RedNode redNode(Edge e) const { 947 return RedNode(arcs[2 * e._id].target); 948 } 949 BlueNode blueNode(Edge e) const { 950 return BlueNode(arcs[2 * e._id + 1].target); 951 } 921 952 922 953 static bool direction(Arc a) { … … 936 967 } 937 968 938 void first Red(Node& node) const {969 void first(RedNode& node) const { 939 970 node._id = first_red; 940 971 } 941 972 942 void next Red(Node& node) const {973 void next(RedNode& node) const { 943 974 node._id = nodes[node._id].partition_next; 944 975 } 945 976 946 void first Blue(Node& node) const {977 void first(BlueNode& node) const { 947 978 node._id = first_blue; 948 979 } 949 980 950 void next Blue(Node& node) const {981 void next(BlueNode& node) const { 951 982 node._id = nodes[node._id].partition_next; 952 983 } … … 1006 1037 1007 1038 static int id(Node v) { return v._id; } 1008 int redId(Node v) const { 1009 LEMON_DEBUG(nodes[v._id].red, "Node has to be red"); 1010 return nodes[v._id].partition_index; 1011 } 1012 int blueId(Node v) const { 1013 LEMON_DEBUG(!nodes[v._id].red, "Node has to be blue"); 1014 return nodes[v._id].partition_index; 1015 } 1039 int id(RedNode v) const { return nodes[v._id].partition_index; } 1040 int id(BlueNode v) const { return nodes[v._id].partition_index; } 1016 1041 static int id(Arc e) { return e._id; } 1017 1042 static int id(Edge e) { return e._id; } … … 1031 1056 } 1032 1057 1033 Node addRedNode() {1058 RedNode addRedNode() { 1034 1059 int n = nodes.size(); 1035 1060 nodes.push_back(NodeT()); … … 1040 1065 first_red = n; 1041 1066 1042 return Node(n);1043 } 1044 1045 Node addBlueNode() {1067 return RedNode(n); 1068 } 1069 1070 BlueNode addBlueNode() { 1046 1071 int n = nodes.size(); 1047 1072 nodes.push_back(NodeT()); … … 1052 1077 first_blue = n; 1053 1078 1054 return Node(n);1055 } 1056 1057 Edge addEdge( Node u,Node v) {1079 return BlueNode(n); 1080 } 1081 1082 Edge addEdge(RedNode u, BlueNode v) { 1058 1083 int n = arcs.size(); 1059 1084 arcs.push_back(ArcT()); … … 1125 1150 /// This function adds a red new node to the graph. 1126 1151 /// \return The new node. 1127 Node addRedNode() { return Parent::addRedNode(); }1152 RedNode addRedNode() { return Parent::addRedNode(); } 1128 1153 1129 1154 /// \brief Add a new blue node to the graph. … … 1131 1156 /// This function adds a blue new node to the graph. 1132 1157 /// \return The new node. 1133 Node addBlueNode() { return Parent::addBlueNode(); }1158 BlueNode addBlueNode() { return Parent::addBlueNode(); } 1134 1159 1135 1160 /// \brief Add a new edge to the graph. … … 1139 1164 /// node \c v. 1140 1165 /// \return The new edge. 1141 Edge addEdge(Node red, Node blue) { 1142 LEMON_DEBUG(Parent::red(red) && Parent::blue(blue), 1143 "Edge has to be formed by a red and a blue nodes"); 1144 return Parent::addEdge(red, blue); 1166 Edge addEdge(RedNode u, BlueNode v) { 1167 return Parent::addEdge(u, v); 1168 } 1169 Edge addEdge(BlueNode v, RedNode u) { 1170 return Parent::addEdge(u, v); 1145 1171 } 1146 1172 … … 1238 1264 max_red = -1; 1239 1265 } 1240 Parent::notifier(RedNode()).erase( node);1266 Parent::notifier(RedNode()).erase(asRedNodeUnsafe(node)); 1241 1267 } else { 1242 1268 first_blue = nodes[n].partition_next; … … 1246 1272 max_blue = -1; 1247 1273 } 1248 Parent::notifier(BlueNode()).erase( node);1274 Parent::notifier(BlueNode()).erase(asBlueNodeUnsafe(node)); 1249 1275 } 1250 1276 Parent::notifier(Node()).erase(node); -
test/bpgraph_test.cc
r1021 r1025 42 42 G.reserveEdge(3); 43 43 44 Node44 RedNode 45 45 rn1 = G.addRedNode(); 46 46 checkGraphNodeList(G, 1); … … 50 50 checkGraphArcList(G, 0); 51 51 52 Node52 BlueNode 53 53 bn1 = G.addBlueNode(), 54 54 bn2 = G.addBlueNode(); … … 77 77 78 78 Edge 79 e2 = G.addEdge( rn1, bn1),79 e2 = G.addEdge(bn1, rn1), 80 80 e3 = G.addEdge(rn1, bn2); 81 81 … … 113 113 114 114 BpGraph G; 115 Node 116 n1 = G.addRedNode(), n2 = G.addBlueNode(), 117 n3 = G.addBlueNode(), n4 = G.addRedNode(); 115 RedNode 116 n1 = G.addRedNode(), n4 = G.addRedNode(); 117 BlueNode 118 n2 = G.addBlueNode(), n3 = G.addBlueNode(); 118 119 Edge 119 120 e1 = G.addEdge(n1, n2), e2 = G.addEdge(n1, n3), … … 160 161 161 162 BpGraph G; 162 Node 163 n1 = G.addRedNode(), n2 = G.addBlueNode(), 164 n3 = G.addBlueNode(), n4 = G.addRedNode(); 163 RedNode 164 n1 = G.addRedNode(), n4 = G.addRedNode(); 165 BlueNode 166 n2 = G.addBlueNode(), n3 = G.addBlueNode(); 165 167 Edge 166 168 e1 = G.addEdge(n1, n2), e2 = G.addEdge(n1, n3), … … 210 212 211 213 BpGraph G; 212 Node 213 n1 = G.addRedNode(), 214 RedNode 215 n1 = G.addRedNode(); 216 BlueNode 214 217 n2 = G.addBlueNode(), 215 218 n3 = G.addBlueNode(); … … 226 229 typename BpGraph::Snapshot snapshot(G); 227 230 228 Node n4 = G.addRedNode();231 RedNode n4 = G.addRedNode(); 229 232 G.addEdge(n4, n2); 230 233 G.addEdge(n4, n3); … … 293 296 BpGraph g; 294 297 295 Node 296 n1 = g.addRedNode(), 298 RedNode 299 n1 = g.addRedNode(); 300 BlueNode 297 301 n2 = g.addBlueNode(), 298 302 n3 = g.addBlueNode(); … … 397 401 for (int i = 0; i < G.redNum(); ++i) { 398 402 check(G.red(G.redNode(i)), "Wrong node"); 399 check(G. redIndex(G.redNode(i)) == i, "Wrong index");403 check(G.index(G.redNode(i)) == i, "Wrong index"); 400 404 } 401 405 402 406 for (int i = 0; i < G.blueNum(); ++i) { 403 407 check(G.blue(G.blueNode(i)), "Wrong node"); 404 check(G. blueIndex(G.blueNode(i)) == i, "Wrong index");408 check(G.index(G.blueNode(i)) == i, "Wrong index"); 405 409 } 406 410 -
test/graph_copy_test.cc
r1022 r1025 222 222 SmartBpGraph::EdgeMap<int> fem(from); 223 223 SmartBpGraph::Node fn = INVALID; 224 SmartBpGraph::RedNode frn = INVALID; 225 SmartBpGraph::BlueNode fbn = INVALID; 224 226 SmartBpGraph::Arc fa = INVALID; 225 227 SmartBpGraph::Edge fe = INVALID; 226 228 227 std::vector<SmartBpGraph:: Node> frnv;228 for (int i = 0; i < nn; ++i) { 229 SmartBpGraph:: Node node = from.addRedNode();229 std::vector<SmartBpGraph::RedNode> frnv; 230 for (int i = 0; i < nn; ++i) { 231 SmartBpGraph::RedNode node = from.addRedNode(); 230 232 frnv.push_back(node); 231 233 fnm[node] = i * i; 232 234 frnm[node] = i + i; 233 if (i == 0) fn = node; 234 } 235 236 std::vector<SmartBpGraph::Node> fbnv; 237 for (int i = 0; i < nn; ++i) { 238 SmartBpGraph::Node node = from.addBlueNode(); 235 if (i == 0) { 236 fn = node; 237 frn = node; 238 } 239 } 240 241 std::vector<SmartBpGraph::BlueNode> fbnv; 242 for (int i = 0; i < nn; ++i) { 243 SmartBpGraph::BlueNode node = from.addBlueNode(); 239 244 fbnv.push_back(node); 240 245 fnm[node] = i * i; 241 246 fbnm[node] = i + i; 247 if (i == 0) fbn = node; 242 248 } 243 249 … … 261 267 typename GR::template EdgeMap<int> tem(to); 262 268 typename GR::Node tn; 269 typename GR::RedNode trn; 270 typename GR::BlueNode tbn; 263 271 typename GR::Arc ta; 264 272 typename GR::Edge te; 265 273 266 274 SmartBpGraph::NodeMap<typename GR::Node> nr(from); 267 SmartBpGraph::RedMap<typename GR:: Node> rnr(from);268 SmartBpGraph::BlueMap<typename GR:: Node> bnr(from);275 SmartBpGraph::RedMap<typename GR::RedNode> rnr(from); 276 SmartBpGraph::BlueMap<typename GR::BlueNode> bnr(from); 269 277 SmartBpGraph::ArcMap<typename GR::Arc> ar(from); 270 278 SmartBpGraph::EdgeMap<typename GR::Edge> er(from); 271 279 272 280 typename GR::template NodeMap<SmartBpGraph::Node> ncr(to); 273 typename GR::template RedMap<SmartBpGraph:: Node> rncr(to);274 typename GR::template BlueMap<SmartBpGraph:: Node> bncr(to);281 typename GR::template RedMap<SmartBpGraph::RedNode> rncr(to); 282 typename GR::template BlueMap<SmartBpGraph::BlueNode> bncr(to); 275 283 typename GR::template ArcMap<SmartBpGraph::Arc> acr(to); 276 284 typename GR::template EdgeMap<SmartBpGraph::Edge> ecr(to); … … 283 291 nodeCrossRef(ncr).redCrossRef(rncr).blueCrossRef(bncr). 284 292 arcCrossRef(acr).edgeCrossRef(ecr). 285 node(fn, tn).arc(fa, ta).edge(fe, te).run(); 293 node(fn, tn).redNode(frn, trn).blueNode(fbn, tbn). 294 arc(fa, ta).edge(fe, te).run(); 286 295 287 296 check(countNodes(from) == countNodes(to), "Wrong copy."); … … 294 303 check(ncr[nr[it]] == it, "Wrong copy."); 295 304 check(fnm[it] == tnm[nr[it]], "Wrong copy."); 296 if (from.red(it)) { 297 check(rnr[it] == nr[it], "Wrong copy."); 298 check(rncr[rnr[it]] == it, "Wrong copy."); 299 check(frnm[it] == trnm[rnr[it]], "Wrong copy."); 300 check(to.red(rnr[it]), "Wrong copy."); 301 } else { 302 check(bnr[it] == nr[it], "Wrong copy."); 303 check(bncr[bnr[it]] == it, "Wrong copy."); 304 check(fbnm[it] == tbnm[bnr[it]], "Wrong copy."); 305 check(to.blue(bnr[it]), "Wrong copy."); 306 } 305 } 306 307 for (SmartBpGraph::RedIt it(from); it != INVALID; ++it) { 308 check(ncr[nr[it]] == it, "Wrong copy."); 309 check(fnm[it] == tnm[nr[it]], "Wrong copy."); 310 check(rnr[it] == nr[it], "Wrong copy."); 311 check(rncr[rnr[it]] == it, "Wrong copy."); 312 check(frnm[it] == trnm[rnr[it]], "Wrong copy."); 313 check(to.red(rnr[it]), "Wrong copy."); 314 } 315 316 for (SmartBpGraph::BlueIt it(from); it != INVALID; ++it) { 317 check(ncr[nr[it]] == it, "Wrong copy."); 318 check(fnm[it] == tnm[nr[it]], "Wrong copy."); 319 check(bnr[it] == nr[it], "Wrong copy."); 320 check(bncr[bnr[it]] == it, "Wrong copy."); 321 check(fbnm[it] == tbnm[bnr[it]], "Wrong copy."); 322 check(to.blue(bnr[it]), "Wrong copy."); 307 323 } 308 324 … … 343 359 } 344 360 check(tn == nr[fn], "Wrong copy."); 361 check(trn == rnr[frn], "Wrong copy."); 362 check(tbn == bnr[fbn], "Wrong copy."); 345 363 check(ta == ar[fa], "Wrong copy."); 346 364 check(te == er[fe], "Wrong copy."); -
test/graph_test.h
r1019 r1025 47 47 for(int i=0;i<cnt;i++) { 48 48 check(n!=INVALID,"Wrong red Node list linking."); 49 check(G.red(n),"Wrong node set check."); 50 check(!G.blue(n),"Wrong node set check."); 51 typename Graph::Node nn = n; 52 check(G.asRedNodeUnsafe(nn) == n,"Wrong node conversion."); 53 check(G.asRedNode(nn) == n,"Wrong node conversion."); 54 check(G.asBlueNode(nn) == INVALID,"Wrong node conversion."); 55 std::pair<typename Graph::RedNode, typename Graph::BlueNode> rbn = 56 G.asRedBlueNode(nn); 57 check(rbn.first == n,"Wrong node conversion."); 58 check(rbn.second == INVALID,"Wrong node conversion."); 49 59 ++n; 50 60 } … … 59 69 for(int i=0;i<cnt;i++) { 60 70 check(n!=INVALID,"Wrong blue Node list linking."); 71 check(G.blue(n),"Wrong node set check."); 72 check(!G.red(n),"Wrong node set check."); 73 typename Graph::Node nn = n; 74 check(G.asBlueNodeUnsafe(nn) == n,"Wrong node conversion."); 75 check(G.asBlueNode(nn) == n,"Wrong node conversion."); 76 check(G.asRedNode(nn) == INVALID,"Wrong node conversion."); 77 std::pair<typename Graph::RedNode, typename Graph::BlueNode> rbn = 78 G.asRedBlueNode(nn); 79 check(rbn.first == INVALID,"Wrong node conversion."); 80 check(rbn.second == n,"Wrong node conversion."); 61 81 ++n; 62 82 } … … 208 228 for (typename Graph::RedIt n(G); n != INVALID; ++n) { 209 229 check(G.red(n), "Wrong partition"); 210 check(G.redId(n) == G.id(RedNode(n)), "Wrong id"); 211 check(values.find(G.redId(n)) == values.end(), "Wrong id"); 212 check(G.redId(n) <= G.maxRedId(), "Wrong maximum id"); 230 check(values.find(G.id(n)) == values.end(), "Wrong id"); 231 check(G.id(n) <= G.maxRedId(), "Wrong maximum id"); 213 232 values.insert(G.id(n)); 214 233 } … … 222 241 for (typename Graph::BlueIt n(G); n != INVALID; ++n) { 223 242 check(G.blue(n), "Wrong partition"); 224 check(G.blueId(n) == G.id(BlueNode(n)), "Wrong id"); 225 check(values.find(G.blueId(n)) == values.end(), "Wrong id"); 226 check(G.blueId(n) <= G.maxBlueId(), "Wrong maximum id"); 243 check(values.find(G.id(n)) == values.end(), "Wrong id"); 244 check(G.id(n) <= G.maxBlueId(), "Wrong maximum id"); 227 245 values.insert(G.id(n)); 228 246 }
Note: See TracChangeset
for help on using the changeset viewer.