1
0
Fork 0

(svn r27611) -Codechange: Cache the calculated value of CapacityAnnotation

release/1.7
fonsinchen 2016-07-10 11:53:43 +00:00
parent 14533f073b
commit bcdae9a093
1 changed files with 18 additions and 1 deletions

View File

@ -32,6 +32,11 @@ public:
*/ */
inline uint GetAnnotation() const { return this->distance; } inline uint GetAnnotation() const { return this->distance; }
/**
* Update the cached annotation value
*/
inline void UpdateAnnotation() { }
/** /**
* Comparator for std containers. * Comparator for std containers.
*/ */
@ -47,6 +52,8 @@ public:
* can only decrease or stay the same if you add more edges. * can only decrease or stay the same if you add more edges.
*/ */
class CapacityAnnotation : public Path { class CapacityAnnotation : public Path {
int cached_annotation;
public: public:
/** /**
@ -62,7 +69,15 @@ public:
* Return the actual value of the annotation, in this case the capacity. * Return the actual value of the annotation, in this case the capacity.
* @return 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. * Comparator for std containers.
@ -246,6 +261,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
paths.resize(size, NULL); paths.resize(size, NULL);
for (NodeID node = 0; node < size; ++node) { for (NodeID node = 0; node < size; ++node) {
Tannotation *anno = new Tannotation(node, node == source_node); Tannotation *anno = new Tannotation(node, node == source_node);
anno->UpdateAnnotation();
annos.insert(anno); annos.insert(anno);
paths[node] = anno; paths[node] = anno;
} }
@ -270,6 +286,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
if (dest->IsBetter(source, capacity, capacity - edge.Flow(), distance)) { if (dest->IsBetter(source, capacity, capacity - edge.Flow(), distance)) {
annos.erase(dest); annos.erase(dest);
dest->Fork(source, capacity, capacity - edge.Flow(), distance); dest->Fork(source, capacity, capacity - edge.Flow(), distance);
dest->UpdateAnnotation();
annos.insert(dest); annos.insert(dest);
} }
} }