COIN-OR::LEMON - Graph Library

Changeset 269:07af3069c0b8 in lemon-0.x for src/work/marci


Ignore:
Timestamp:
03/31/04 17:50:21 (20 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@375
Message:

Working on-the-fly with wrappers

Location:
src/work/marci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/marci/edmonds_karp_demo.cc

    r268 r269  
    9191
    9292  {
    93     //std::cout << "SmartGraph..." << std::endl;
    9493    typedef TrivGraphWrapper<const Graph> GW;
    9594    GW gw(G);
     
    123122
    124123  {
    125     //std::cout << "SmartGraph..." << std::endl;
    126124    typedef TrivGraphWrapper<const Graph> GW;
    127125    GW gw(G);
     
    154152  }
    155153
    156 //   {
    157 //     std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
    158 //     Graph::EdgeMap<int> flow(G); //0 flow
    159 
    160 //     Timer ts;
    161 //     ts.reset();
    162 
    163 //     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
    164 //     int i=0;
    165 //     while (max_flow_test.augmentOnBlockingFlow2()) {
    166 // //     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
    167 // //       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
    168 // //     }
    169 // //     std::cout<<std::endl;
    170 //       ++i;
    171 //     }
    172 
    173 // //   std::cout << "maximum flow: "<< std::endl;
    174 // //   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
    175 // //     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
    176 // //   }
    177 // //   std::cout<<std::endl;
    178 //     std::cout << "elapsed time: " << ts << std::endl;
    179 //     std::cout << "number of augmentation phases: " << i << std::endl;
    180 //     std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
    181 //   }
     154  {
     155    typedef TrivGraphWrapper<const Graph> GW;
     156    GW gw(G);
     157    std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
     158    GW::EdgeMap<int> flow(G); //0 flow
     159
     160    Timer ts;
     161    ts.reset();
     162
     163    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
     164    EMW cw(cap);
     165    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
     166    int i=0;
     167    while (max_flow_test.augmentOnBlockingFlow2()) {
     168//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
     169//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
     170//     }
     171//     std::cout<<std::endl;
     172      ++i;
     173    }
     174
     175//   std::cout << "maximum flow: "<< std::endl;
     176//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
     177//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
     178//   }
     179//   std::cout<<std::endl;
     180    std::cout << "elapsed time: " << ts << std::endl;
     181    std::cout << "number of augmentation phases: " << i << std::endl;
     182    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
     183  }
    182184
    183185  {
     
    190192    ts.reset();
    191193
    192     //CM cm;
    193194    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
    194195    EMW cw(cap);
  • src/work/marci/graph_wrapper.h

    r266 r269  
    10001000      OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
    10011001        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); }
    10031003        if (!resG.gw.valid(out)) {
    10041004          out_or_in=0;
    10051005          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); }
    10071007        }
    10081008      }
     
    10121012//        Node v=/*resG->*/G->aNode(out);
    10131013//        ++out;
    1014 //        while( out.valid() && !(Edge::free()>0) ) { ++out; }
     1014//        while( out.valid() && !(Edge::resCap()>0) ) { ++out; }
    10151015//        if (!out.valid()) {
    10161016//          out_or_in=0;
    10171017//          G->first(in, v);
    1018 //          while( in.valid() && !(Edge::free()>0) ) { ++in; }
     1018//          while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
    10191019//        }
    10201020//      } else {
    10211021//        ++in;
    1022 //        while( in.valid() && !(Edge::free()>0) ) { ++in; }
     1022//        while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
    10231023//      }
    10241024//      return *this;
     
    10381038      EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() {
    10391039        resG.gw.first(v);
    1040         if (resG.gw.valid(v)) resG.gw.first(out, v); else out=/*OldOutEdgeIt*/(INVALID);
    1041         while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); }
     1040        if (resG.gw.valid(v)) resG.gw.first(out, v); else out=INVALID;
     1041        while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
    10421042        while (resG.gw.valid(v) && !resG.gw.valid(out)) {
    10431043          resG.gw.next(v);
    10441044          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); }
    10461046        }
    10471047        if (!resG.gw.valid(out)) {
    10481048          out_or_in=0;
    10491049          resG.gw.first(v);
    1050           if (resG.gw.valid(v)) resG.gw.first(in, v); else in=/*OldInEdgeIt*/(INVALID);
    1051           while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); }
     1050          if (resG.gw.valid(v)) resG.gw.first(in, v); else in=INVALID;
     1051          while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
    10521052          while (resG.gw.valid(v) && !resG.gw.valid(in)) {
    10531053            resG.gw.next(v);
    10541054            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); }
    10561056          }
    10571057        }
     
    10601060//      if (out_or_in) {
    10611061//        ++out;
    1062 //        while (out.valid() && !(Edge::free()>0) ) { ++out; }
     1062//        while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
    10631063//        while (v.valid() && !out.valid()) {
    10641064//          ++v;
    10651065//          if (v.valid()) G->first(out, v);
    1066 //          while (out.valid() && !(Edge::free()>0) ) { ++out; }
     1066//          while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
    10671067//        }
    10681068//        if (!out.valid()) {
     
    10701070//          G->first(v);
    10711071//          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; }
    10731073//          while (v.valid() && !in.valid()) {
    10741074//            ++v;
    10751075//            if (v.valid()) G->first(in, v);
    1076 //            while (in.valid() && !(Edge::free()>0) ) { ++in; }
     1076//            while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
    10771077//          } 
    10781078//        }
    10791079//      } else {
    10801080//        ++in;
    1081 //        while (in.valid() && !(Edge::free()>0) ) { ++in; }
     1081//        while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
    10821082//        while (v.valid() && !in.valid()) {
    10831083//          ++v;
    10841084//          if (v.valid()) G->first(in, v);
    1085 //          while (in.valid() && !(Edge::free()>0) ) { ++in; }
     1085//          while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
    10861086//        }
    10871087//      }
     
    11061106        Node v=gw.aNode(e.out);
    11071107        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); }
    11091109        if (!gw.valid(e.out)) {
    11101110          e.out_or_in=0;
    11111111          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); }
    11131113        }
    11141114      } else {
    11151115        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); }
    11171117      }
    11181118      return e;
     
    11221122      if (e.out_or_in) {
    11231123        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); }
    11251125          while (gw.valid(e.v) && !gw.valid(e.out)) {
    11261126            gw.next(e.v);
    11271127            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); }
    11291129          }
    11301130          if (!gw.valid(e.out)) {
    11311131            e.out_or_in=0;
    11321132            gw.first(e.v);
    1133             if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=/*OldInEdgeIt*/(INVALID);
    1134             while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
     1133            if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=INVALID;
     1134            while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
    11351135            while (gw.valid(e.v) && !gw.valid(e.in)) {
    11361136              gw.next(e.v);
    11371137              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); }
    11391139            } 
    11401140          }
    11411141        } else {
    11421142          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); }
    11441144          while (gw.valid(e.v) && !gw.valid(e.in)) {
    11451145            gw.next(e.v);
    11461146            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); }
    11481148          }
    11491149        }
     
    11941194    }
    11951195
    1196     Number free(const Edge& e) const {
     1196    Number resCap(const Edge& e) const {
    11971197      if (e.out_or_in)
    11981198        return (capacity->get(e.out)-flow->get(e.out));
     
    12011201    }
    12021202
    1203     Number free(OldOutEdgeIt out) const {
     1203    Number resCap(OldOutEdgeIt out) const {
    12041204      return (capacity->get(out)-flow->get(out));
    12051205    }
    12061206   
    1207     Number free(OldInEdgeIt in) const {
     1207    Number resCap(OldInEdgeIt in) const {
    12081208      return (flow->get(in));
    12091209    }
     
    12461246      }
    12471247    };
     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    }
    12481301  };
    12491302
Note: See TracChangeset for help on using the changeset viewer.