Changeset 1025:c8fa41fcc4a7 in lemon-main for lemon/smart_graph.h
- Timestamp:
- 12/01/11 09:05:47 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note: See TracChangeset
for help on using the changeset viewer.