Link graph: Use non-sparse matrix for accumulating demand totals
This commit is contained in:
@@ -244,8 +244,13 @@ 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)
|
inline void Scaler::SetDemands(LinkGraphJob &job, NodeID from_id, NodeID to_id, uint demand_forw)
|
||||||
{
|
{
|
||||||
|
if (demand_forw == 0) return;
|
||||||
|
|
||||||
job[from_id].DeliverSupply(demand_forw);
|
job[from_id].DeliverSupply(demand_forw);
|
||||||
job.demand_map[std::make_pair(from_id, to_id)] += demand_forw;
|
|
||||||
|
uint &demand = job.demand_matrix[(from_id * job.Size()) + to_id];
|
||||||
|
if (demand == 0) job.demand_matrix_count++;
|
||||||
|
demand += demand_forw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -437,6 +442,8 @@ DemandCalculator::DemandCalculator(LinkGraphJob &job) :
|
|||||||
}
|
}
|
||||||
uint first_unseen = 0;
|
uint first_unseen = 0;
|
||||||
std::vector<bool> reachable_nodes(size);
|
std::vector<bool> reachable_nodes(size);
|
||||||
|
job.demand_matrix.reset(new uint[size * size]{});
|
||||||
|
job.demand_matrix_count = 0;
|
||||||
do {
|
do {
|
||||||
reachable_nodes.assign(size, false);
|
reachable_nodes.assign(size, false);
|
||||||
std::vector<NodeID> queue;
|
std::vector<NodeID> queue;
|
||||||
@@ -480,24 +487,23 @@ DemandCalculator::DemandCalculator(LinkGraphJob &job) :
|
|||||||
}
|
}
|
||||||
} while (first_unseen < size);
|
} while (first_unseen < size);
|
||||||
|
|
||||||
if (job.demand_map.size() > 0) {
|
if (job.demand_matrix_count > 0) {
|
||||||
job.demand_annotation_store.resize(job.demand_map.size());
|
job.demand_annotation_store.resize(job.demand_matrix_count);
|
||||||
size_t start_idx = 0;
|
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
NodeID last_from = job.demand_map.begin()->first.first;
|
const uint *demand = job.demand_matrix.get();
|
||||||
auto flush = [&]() {
|
for (NodeID from = 0; from != size; from++) {
|
||||||
job[last_from].SetDemandAnnotations({ job.demand_annotation_store.data() + start_idx, idx - start_idx });
|
const size_t start_idx = idx;
|
||||||
};
|
for (NodeID to = 0; to != size; to++) {
|
||||||
for (auto &iter : job.demand_map) {
|
if (*demand != 0) {
|
||||||
if (iter.first.first != last_from) {
|
job.demand_annotation_store[idx] = { to, *demand, *demand };
|
||||||
flush();
|
|
||||||
last_from = iter.first.first;
|
|
||||||
start_idx = idx;
|
|
||||||
}
|
|
||||||
job.demand_annotation_store[idx] = { iter.first.second, iter.second, iter.second };
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
flush();
|
demand++;
|
||||||
job.demand_map.clear();
|
}
|
||||||
|
if (idx != start_idx) {
|
||||||
|
job[from].SetDemandAnnotations({ job.demand_annotation_store.data() + start_idx, idx - start_idx });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
job.demand_matrix.reset();
|
||||||
|
}
|
||||||
|
@@ -152,7 +152,8 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
btree::btree_map<std::pair<NodeID, NodeID>, uint> demand_map; ///< Demand map.
|
std::unique_ptr<uint[]> demand_matrix; ///< Demand matrix.
|
||||||
|
uint demand_matrix_count; ///< Count of non-zero entries in demand_matrix.
|
||||||
std::vector<DemandAnnotation> demand_annotation_store; ///< Demand annotation store.
|
std::vector<DemandAnnotation> demand_annotation_store; ///< Demand annotation store.
|
||||||
|
|
||||||
DynUniformArenaAllocator path_allocator; ///< Arena allocator used for paths
|
DynUniformArenaAllocator path_allocator; ///< Arena allocator used for paths
|
||||||
|
Reference in New Issue
Block a user