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 FORCEINLINE 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 FORCEINLINE int GetAnnotation() const {return this->GetCapacityRatio();}
00050
00051 struct Comparator {
00052 bool operator()(const CapacityAnnotation *x, const CapacityAnnotation *y) const;
00053 };
00054 };
00055
00056
00057 typedef std::vector<Path *> PathVector;
00058
00062 class MultiCommodityFlow {
00063 protected:
00064 MultiCommodityFlow(LinkGraphComponent *graph) : graph(graph) {}
00065
00066 template<class ANNOTATION> void Dijkstra(NodeID from, PathVector &paths, bool create_new_paths);
00067
00068 uint PushFlow(Edge &edge, Path *path, uint accuracy, bool positive_cap);
00069
00070 void CleanupPaths(NodeID source, PathVector &paths);
00071
00072 LinkGraphComponent *graph;
00073 };
00074
00090 class MCF1stPass : public MultiCommodityFlow {
00091 private:
00092 bool EliminateCycles();
00093 bool EliminateCycles(PathVector &path, NodeID origin_id, NodeID next_id);
00094 void EliminateCycle(PathVector &path, Path *cycle_begin, uint flow);
00095 uint FindCycleFlow(const PathVector &path, const Path *cycle_begin);
00096 public:
00097 MCF1stPass(LinkGraphComponent *graph);
00098 };
00099
00107 class MCF2ndPass : public MultiCommodityFlow {
00108 public:
00109 MCF2ndPass(LinkGraphComponent *graph);
00110 };
00111
00116 template<class Tpass>
00117 class MCFHandler : public ComponentHandler {
00118 public:
00119
00124 virtual void Run(LinkGraphComponent *graph) {Tpass pass(graph);}
00125
00126 virtual ~MCFHandler() {}
00127 };
00128
00129 #endif