Skip to content

Commit

Permalink
(svn r27611) -Codechange: Cache the calculated value of CapacityAnnot…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
ulfhermann committed Jul 10, 2016
1 parent 8f2461c commit 8d55666
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/linkgraph/mcf.cpp
Expand Up @@ -32,6 +32,11 @@ class DistanceAnnotation : public Path {
*/
inline uint GetAnnotation() const { return this->distance; }

/**
* Update the cached annotation value
*/
inline void UpdateAnnotation() { }

/**
* Comparator for std containers.
*/
Expand All @@ -47,6 +52,8 @@ class DistanceAnnotation : public Path {
* can only decrease or stay the same if you add more edges.
*/
class CapacityAnnotation : public Path {
int cached_annotation;

public:

/**
Expand All @@ -62,7 +69,15 @@ class CapacityAnnotation : public Path {
* Return the actual value of the annotation, in this case the capacity.
* @return Capacity.
*/
inline int GetAnnotation() const { return this->GetCapacityRatio(); }
inline int GetAnnotation() const { return this->cached_annotation; }

/**
* Update the cached annotation value
*/
inline void UpdateAnnotation()
{
this->cached_annotation = this->GetCapacityRatio();
}

/**
* Comparator for std containers.
Expand Down Expand Up @@ -246,6 +261,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
paths.resize(size, NULL);
for (NodeID node = 0; node < size; ++node) {
Tannotation *anno = new Tannotation(node, node == source_node);
anno->UpdateAnnotation();
annos.insert(anno);
paths[node] = anno;
}
Expand All @@ -270,6 +286,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
if (dest->IsBetter(source, capacity, capacity - edge.Flow(), distance)) {
annos.erase(dest);
dest->Fork(source, capacity, capacity - edge.Flow(), distance);
dest->UpdateAnnotation();
annos.insert(dest);
}
}
Expand Down

0 comments on commit 8d55666

Please sign in to comment.