mcf.h

Go to the documentation of this file.
00001 
00003 #ifndef MCF_H
00004 #define MCF_H
00005 
00006 #include "linkgraph.h"
00007 #include <vector>
00008 
00014 class DistanceAnnotation : public Path {
00015 public:
00016 
00017   DistanceAnnotation(NodeID n, bool source = false) : Path(n, source) {}
00018 
00019   bool IsBetter(const DistanceAnnotation *base, uint cap, int free_cap, uint dist) const;
00020 
00025   inline uint GetAnnotation() const { return this->distance; }
00026 
00027   struct Comparator {
00028     bool operator()(const DistanceAnnotation *x, const DistanceAnnotation *y) const;
00029   };
00030 };
00031 
00038 class CapacityAnnotation : public Path {
00039 public:
00040 
00041   CapacityAnnotation(NodeID n, bool source = false) : Path(n, source) {}
00042 
00043   bool IsBetter(const CapacityAnnotation *base, uint cap, int free_cap, uint dist) const;
00044 
00049   inline int GetAnnotation() const { return this->GetCapacityRatio(); }
00050 
00051   struct Comparator {
00052     bool operator()(const CapacityAnnotation *x, const CapacityAnnotation *y) const;
00053   };
00054 };
00055 
00056 typedef std::vector<Path *> PathVector;
00057 
00061 class MultiCommodityFlow {
00062 protected:
00063   MultiCommodityFlow(LinkGraphJob *job) : job(job), graph(&job->Graph()),
00064       max_saturation(job->Settings().short_path_saturation)
00065   {}
00066 
00067   template<class Tannotation, class Tedge_iterator>
00068   void Dijkstra(NodeID from, PathVector &paths);
00069 
00070   uint PushFlow(EdgeAnnotation &edge, Path *path, uint accuracy, uint max_saturation);
00071 
00072   void CleanupPaths(NodeID source, PathVector &paths);
00073 
00074   LinkGraphJob *job;   
00075   LinkGraph *graph;    
00076   uint max_saturation; 
00077 };
00078 
00094 class MCF1stPass : public MultiCommodityFlow {
00095 private:
00096   bool EliminateCycles();
00097   bool EliminateCycles(PathVector &path, NodeID origin_id, NodeID next_id);
00098   void EliminateCycle(PathVector &path, Path *cycle_begin, uint flow);
00099   uint FindCycleFlow(const PathVector &path, const Path *cycle_begin);
00100 public:
00101   MCF1stPass(LinkGraphJob *job);
00102 };
00103 
00111 class MCF2ndPass : public MultiCommodityFlow {
00112 public:
00113   MCF2ndPass(LinkGraphJob *job);
00114 };
00115 
00120 template<class Tpass>
00121 class MCFHandler : public ComponentHandler {
00122 public:
00123 
00128   virtual void Run(LinkGraphJob *job) { Tpass pass(job); }
00129 
00130   virtual ~MCFHandler() {}
00131 };
00132 
00133 #endif /* MCF_H */