Linkgraph: Split demand annotations from edge flow annotations

Use sparse storage format for demand annotations
This commit is contained in:
Jonathan G Rennison
2023-01-05 01:05:40 +00:00
parent 9bc5f69a19
commit 55473bc730
6 changed files with 74 additions and 65 deletions

View File

@@ -244,7 +244,8 @@ void AsymmetricScalerEq::SetDemands(LinkGraphJob &job, NodeID from_id, NodeID to
*/
inline void Scaler::SetDemands(LinkGraphJob &job, NodeID from_id, NodeID to_id, uint demand_forw)
{
job[from_id].DeliverSupply(to_id, demand_forw);
job[from_id].DeliverSupply(demand_forw);
job.demand_map[std::make_pair(from_id, to_id)] += demand_forw;
}
/**
@@ -476,4 +477,25 @@ DemandCalculator::DemandCalculator(LinkGraphJob &job) :
first_unseen++;
}
} while (first_unseen < size);
if (job.demand_map.size() > 0) {
job.demand_annotation_store.resize(job.demand_map.size());
size_t start_idx = 0;
size_t idx = 0;
NodeID last_from = job.demand_map.begin()->first.first;
auto flush = [&]() {
job[last_from].SetDemandAnnotations({ job.demand_annotation_store.data() + start_idx, idx - start_idx });
};
for (auto &iter : job.demand_map) {
if (iter.first.first != last_from) {
flush();
last_from = iter.first.first;
start_idx = idx;
}
job.demand_annotation_store[idx] = { iter.first.second, iter.second, iter.second };
idx++;
}
flush();
job.demand_map.clear();
}
}