997 OutEdgeIt(const Edge& e) : Edge(e) { } |
997 OutEdgeIt(const Edge& e) : Edge(e) { } |
998 OutEdgeIt(const Invalid& i) : Edge(i) { } |
998 OutEdgeIt(const Invalid& i) : Edge(i) { } |
999 protected: |
999 protected: |
1000 OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { |
1000 OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { |
1001 resG.gw.first(out, v); |
1001 resG.gw.first(out, v); |
1002 while( resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); } |
1002 while( resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); } |
1003 if (!resG.gw.valid(out)) { |
1003 if (!resG.gw.valid(out)) { |
1004 out_or_in=0; |
1004 out_or_in=0; |
1005 resG.gw.first(in, v); |
1005 resG.gw.first(in, v); |
1006 while( resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); } |
1006 while( resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); } |
1007 } |
1007 } |
1008 } |
1008 } |
1009 // public: |
1009 // public: |
1010 // OutEdgeIt& operator++() { |
1010 // OutEdgeIt& operator++() { |
1011 // if (out_or_in) { |
1011 // if (out_or_in) { |
1012 // Node v=/*resG->*/G->aNode(out); |
1012 // Node v=/*resG->*/G->aNode(out); |
1013 // ++out; |
1013 // ++out; |
1014 // while( out.valid() && !(Edge::free()>0) ) { ++out; } |
1014 // while( out.valid() && !(Edge::resCap()>0) ) { ++out; } |
1015 // if (!out.valid()) { |
1015 // if (!out.valid()) { |
1016 // out_or_in=0; |
1016 // out_or_in=0; |
1017 // G->first(in, v); |
1017 // G->first(in, v); |
1018 // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
1018 // while( in.valid() && !(Edge::resCap()>0) ) { ++in; } |
1019 // } |
1019 // } |
1020 // } else { |
1020 // } else { |
1021 // ++in; |
1021 // ++in; |
1022 // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
1022 // while( in.valid() && !(Edge::resCap()>0) ) { ++in; } |
1023 // } |
1023 // } |
1024 // return *this; |
1024 // return *this; |
1025 // } |
1025 // } |
1026 }; |
1026 }; |
1027 |
1027 |
1035 EdgeIt() { } |
1035 EdgeIt() { } |
1036 //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { } |
1036 //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { } |
1037 EdgeIt(const Invalid& i) : Edge(i) { } |
1037 EdgeIt(const Invalid& i) : Edge(i) { } |
1038 EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() { |
1038 EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() { |
1039 resG.gw.first(v); |
1039 resG.gw.first(v); |
1040 if (resG.gw.valid(v)) resG.gw.first(out, v); else out=/*OldOutEdgeIt*/(INVALID); |
1040 if (resG.gw.valid(v)) resG.gw.first(out, v); else out=INVALID; |
1041 while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); } |
1041 while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); } |
1042 while (resG.gw.valid(v) && !resG.gw.valid(out)) { |
1042 while (resG.gw.valid(v) && !resG.gw.valid(out)) { |
1043 resG.gw.next(v); |
1043 resG.gw.next(v); |
1044 if (resG.gw.valid(v)) resG.gw.first(out, v); |
1044 if (resG.gw.valid(v)) resG.gw.first(out, v); |
1045 while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); } |
1045 while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); } |
1046 } |
1046 } |
1047 if (!resG.gw.valid(out)) { |
1047 if (!resG.gw.valid(out)) { |
1048 out_or_in=0; |
1048 out_or_in=0; |
1049 resG.gw.first(v); |
1049 resG.gw.first(v); |
1050 if (resG.gw.valid(v)) resG.gw.first(in, v); else in=/*OldInEdgeIt*/(INVALID); |
1050 if (resG.gw.valid(v)) resG.gw.first(in, v); else in=INVALID; |
1051 while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); } |
1051 while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); } |
1052 while (resG.gw.valid(v) && !resG.gw.valid(in)) { |
1052 while (resG.gw.valid(v) && !resG.gw.valid(in)) { |
1053 resG.gw.next(v); |
1053 resG.gw.next(v); |
1054 if (resG.gw.valid(v)) resG.gw.first(in, v); |
1054 if (resG.gw.valid(v)) resG.gw.first(in, v); |
1055 while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); } |
1055 while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); } |
1056 } |
1056 } |
1057 } |
1057 } |
1058 } |
1058 } |
1059 // EdgeIt& operator++() { |
1059 // EdgeIt& operator++() { |
1060 // if (out_or_in) { |
1060 // if (out_or_in) { |
1061 // ++out; |
1061 // ++out; |
1062 // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
1062 // while (out.valid() && !(Edge::resCap()>0) ) { ++out; } |
1063 // while (v.valid() && !out.valid()) { |
1063 // while (v.valid() && !out.valid()) { |
1064 // ++v; |
1064 // ++v; |
1065 // if (v.valid()) G->first(out, v); |
1065 // if (v.valid()) G->first(out, v); |
1066 // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
1066 // while (out.valid() && !(Edge::resCap()>0) ) { ++out; } |
1067 // } |
1067 // } |
1068 // if (!out.valid()) { |
1068 // if (!out.valid()) { |
1069 // out_or_in=0; |
1069 // out_or_in=0; |
1070 // G->first(v); |
1070 // G->first(v); |
1071 // if (v.valid()) G->first(in, v); else in=OldInEdgeIt(); |
1071 // if (v.valid()) G->first(in, v); else in=OldInEdgeIt(); |
1072 // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
1072 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; } |
1073 // while (v.valid() && !in.valid()) { |
1073 // while (v.valid() && !in.valid()) { |
1074 // ++v; |
1074 // ++v; |
1075 // if (v.valid()) G->first(in, v); |
1075 // if (v.valid()) G->first(in, v); |
1076 // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
1076 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; } |
1077 // } |
1077 // } |
1078 // } |
1078 // } |
1079 // } else { |
1079 // } else { |
1080 // ++in; |
1080 // ++in; |
1081 // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
1081 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; } |
1082 // while (v.valid() && !in.valid()) { |
1082 // while (v.valid() && !in.valid()) { |
1083 // ++v; |
1083 // ++v; |
1084 // if (v.valid()) G->first(in, v); |
1084 // if (v.valid()) G->first(in, v); |
1085 // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
1085 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; } |
1086 // } |
1086 // } |
1087 // } |
1087 // } |
1088 // return *this; |
1088 // return *this; |
1089 // } |
1089 // } |
1090 }; |
1090 }; |
1103 |
1103 |
1104 OutEdgeIt& next(OutEdgeIt& e) const { |
1104 OutEdgeIt& next(OutEdgeIt& e) const { |
1105 if (e.out_or_in) { |
1105 if (e.out_or_in) { |
1106 Node v=gw.aNode(e.out); |
1106 Node v=gw.aNode(e.out); |
1107 gw.next(e.out); |
1107 gw.next(e.out); |
1108 while( gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); } |
1108 while( gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); } |
1109 if (!gw.valid(e.out)) { |
1109 if (!gw.valid(e.out)) { |
1110 e.out_or_in=0; |
1110 e.out_or_in=0; |
1111 gw.first(e.in, v); |
1111 gw.first(e.in, v); |
1112 while( gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
1112 while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } |
1113 } |
1113 } |
1114 } else { |
1114 } else { |
1115 gw.next(e.in); |
1115 gw.next(e.in); |
1116 while( gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
1116 while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } |
1117 } |
1117 } |
1118 return e; |
1118 return e; |
1119 } |
1119 } |
1120 |
1120 |
1121 EdgeIt& next(EdgeIt& e) const { |
1121 EdgeIt& next(EdgeIt& e) const { |
1122 if (e.out_or_in) { |
1122 if (e.out_or_in) { |
1123 gw.next(e.out); |
1123 gw.next(e.out); |
1124 while (gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); } |
1124 while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); } |
1125 while (gw.valid(e.v) && !gw.valid(e.out)) { |
1125 while (gw.valid(e.v) && !gw.valid(e.out)) { |
1126 gw.next(e.v); |
1126 gw.next(e.v); |
1127 if (gw.valid(e.v)) gw.first(e.out, e.v); |
1127 if (gw.valid(e.v)) gw.first(e.out, e.v); |
1128 while (gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); } |
1128 while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); } |
1129 } |
1129 } |
1130 if (!gw.valid(e.out)) { |
1130 if (!gw.valid(e.out)) { |
1131 e.out_or_in=0; |
1131 e.out_or_in=0; |
1132 gw.first(e.v); |
1132 gw.first(e.v); |
1133 if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=/*OldInEdgeIt*/(INVALID); |
1133 if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=INVALID; |
1134 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
1134 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } |
1135 while (gw.valid(e.v) && !gw.valid(e.in)) { |
1135 while (gw.valid(e.v) && !gw.valid(e.in)) { |
1136 gw.next(e.v); |
1136 gw.next(e.v); |
1137 if (gw.valid(e.v)) gw.first(e.in, e.v); |
1137 if (gw.valid(e.v)) gw.first(e.in, e.v); |
1138 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
1138 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } |
1139 } |
1139 } |
1140 } |
1140 } |
1141 } else { |
1141 } else { |
1142 gw.next(e.in); |
1142 gw.next(e.in); |
1143 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
1143 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } |
1144 while (gw.valid(e.v) && !gw.valid(e.in)) { |
1144 while (gw.valid(e.v) && !gw.valid(e.in)) { |
1145 gw.next(e.v); |
1145 gw.next(e.v); |
1146 if (gw.valid(e.v)) gw.first(e.in, e.v); |
1146 if (gw.valid(e.v)) gw.first(e.in, e.v); |
1147 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
1147 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } |
1148 } |
1148 } |
1149 } |
1149 } |
1150 return e; |
1150 return e; |
1151 } |
1151 } |
1152 |
1152 |
1191 flow->set(e.out, flow->get(e.out)+a); |
1191 flow->set(e.out, flow->get(e.out)+a); |
1192 else |
1192 else |
1193 flow->set(e.in, flow->get(e.in)-a); |
1193 flow->set(e.in, flow->get(e.in)-a); |
1194 } |
1194 } |
1195 |
1195 |
1196 Number free(const Edge& e) const { |
1196 Number resCap(const Edge& e) const { |
1197 if (e.out_or_in) |
1197 if (e.out_or_in) |
1198 return (capacity->get(e.out)-flow->get(e.out)); |
1198 return (capacity->get(e.out)-flow->get(e.out)); |
1199 else |
1199 else |
1200 return (flow->get(e.in)); |
1200 return (flow->get(e.in)); |
1201 } |
1201 } |
1202 |
1202 |
1203 Number free(OldOutEdgeIt out) const { |
1203 Number resCap(OldOutEdgeIt out) const { |
1204 return (capacity->get(out)-flow->get(out)); |
1204 return (capacity->get(out)-flow->get(out)); |
1205 } |
1205 } |
1206 |
1206 |
1207 Number free(OldInEdgeIt in) const { |
1207 Number resCap(OldInEdgeIt in) const { |
1208 return (flow->get(in)); |
1208 return (flow->get(in)); |
1209 } |
1209 } |
1210 |
1210 |
1211 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
1211 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
1212 // public: |
1212 // public: |
1243 return forward_map.get(e.out); |
1243 return forward_map.get(e.out); |
1244 else |
1244 else |
1245 return backward_map.get(e.in); |
1245 return backward_map.get(e.in); |
1246 } |
1246 } |
1247 }; |
1247 }; |
|
1248 }; |
|
1249 |
|
1250 //Subgraph on the same node-set and partial edge-set |
|
1251 template<typename GraphWrapper, typename FirstOutEdgesMap> |
|
1252 class ErasingFirstGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> { |
|
1253 protected: |
|
1254 FirstOutEdgesMap* first_out_edges; |
|
1255 public: |
|
1256 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; |
|
1257 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt; |
|
1258 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge; |
|
1259 typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt; |
|
1260 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt; |
|
1261 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt; |
|
1262 |
|
1263 ErasingFirstGraphWrapper(GraphWrapper _gw, FirstOutEdgesMap& _first_out_edges) : |
|
1264 GraphWrapperSkeleton<GraphWrapper>(_gw), first_out_edges(&_first_out_edges) { } |
|
1265 |
|
1266 template<typename I> I& first(I& i) const { |
|
1267 gw.first(i); |
|
1268 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } |
|
1269 return i; |
|
1270 } |
|
1271 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
|
1272 e=first_out_edges->get(n); |
|
1273 return e; |
|
1274 } |
|
1275 template<typename I, typename P> I& first(I& i, const P& p) const { |
|
1276 gw.first(i, p); |
|
1277 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } |
|
1278 return i; |
|
1279 } |
|
1280 |
|
1281 //template<typename I> I getNext(const I& i) const { |
|
1282 // return gw.getNext(i); |
|
1283 //} |
|
1284 template<typename I> I& next(I &i) const { |
|
1285 gw.next(i); |
|
1286 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } |
|
1287 return i; |
|
1288 } |
|
1289 |
|
1290 template< typename It > It first() const { |
|
1291 It e; this->first(e); return e; } |
|
1292 |
|
1293 template< typename It > It first(const Node& v) const { |
|
1294 It e; this->first(e, v); return e; } |
|
1295 |
|
1296 void erase(const OutEdgeIt& e) const { |
|
1297 OutEdgeIt f=e; |
|
1298 this->next(f); |
|
1299 first_out_edges->set(this->tail(e), f); |
|
1300 } |
1248 }; |
1301 }; |
1249 |
1302 |
1250 // template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
1303 // template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
1251 // class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
1304 // class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
1252 // protected: |
1305 // protected: |