85template<
class E,
class V,
class K>
99 typedef V* (*RefVehicleFactory)(
const K*, int);
165 myAppliedEffort.assign(space, std::numeric_limits<double>::quiet_NaN());
171 delete c->refVehicle;
175 delete item.second.refVehicle;
202 const std::pair<const K*, int> mapKey(key, period);
218 return it->second.metric.get();
254 std::vector<LiveMetric*>& slots =
myByKey[key];
264 const int id = e->getNumericalID();
280 const int id = e->getNumericalID();
305 if (
myQueried.exchange(
false, std::memory_order_acq_rel)
340 std::vector<const E*> accepted;
342 std::vector<const E*> stillPending;
344 const int id = e->getNumericalID();
351 const double hi =
MAX2(effNow, effApplied);
352 const double lo =
MIN2(effNow, effApplied);
356 accepted.push_back(e);
360 stillPending.push_back(e);
366 const int back = 1 - c->frontIndex;
367 const std::vector<unsigned>& front = c->weight[c->frontIndex];
377 if (c->metric[back] ==
nullptr || fullFill > 0) {
378 if (fullFill == 2 || c->metric[c->frontIndex] ==
nullptr) {
387 std::copy(front.begin(), front.end(), c->weight[back].begin());
388 for (
const E* e : accepted) {
394 if (c->metric[back] ==
nullptr) {
395 c->metric[back] = std::make_shared<RoutingKit::CustomizableContractionHierarchyMetric>(
398 c->metric[back]->customize();
407 std::vector<unsigned>& applied = c->weight[back];
409 unsigned changed = 0;
412 if (applied[a] != front[a]) {
413 applied[a] = front[a];
414 c->partial->update_arc(a);
419 for (
const E* e : accepted) {
422 if (newW != applied[a]) {
424 c->partial->update_arc(a);
430 if (changed * 64 > applied.size()) {
433 c->metric[back]->customize();
435 c->partial->customize(*c->metric[back]);
441 c->frontIndex = back;
442 c->front.store(c->metric[back].get(), std::memory_order_release);
464 std::memory_order_release);
472 const auto it =
myByKey.find(key);
480 myQueried.store(
true, std::memory_order_relaxed);
487 if (!
myQueried.load(std::memory_order_relaxed)) {
488 myQueried.store(
true, std::memory_order_relaxed);
513 return c->
front.load(std::memory_order_acquire);
538 void loadEdge(
const E* e,
double appliedEffort,
bool pending) {
547 std::vector<const K*> keys;
548 for (
const auto& item :
myByKey) {
549 keys.push_back(item.first);
561 void getLaggingArcs(
const K* key,
int slot,
double now, std::vector<int>& arcs, std::vector<int>& weights)
const {
566 std::vector<unsigned> fresh;
569 for (
unsigned a = 0; a < (unsigned)fresh.size(); a++) {
570 if (front[a] != fresh[a]) {
571 arcs.push_back((
int)a);
572 weights.push_back((
int)front[a]);
580 void loadMetric(
const K* key,
int slot,
double now,
const std::vector<int>& arcs,
const std::vector<int>& weights) {
587 for (
int i = 0; i < (int)arcs.size() && i < (int)weights.size(); i++) {
588 if (arcs[i] >= 0 && arcs[i] < (
int)c->
weight[0].size()) {
589 c->
weight[0][arcs[i]] = (unsigned)weights[i];
592 c->
metric[0] = std::make_shared<RoutingKit::CustomizableContractionHierarchyMetric>(
myGraph->
cch(), c->
weight[0]);
593 c->
metric[0]->customize();
596 c->
front.store(c->
metric[0].get(), std::memory_order_release);
605 std::shared_ptr<RoutingKit::CustomizableContractionHierarchyMetric>
metric[2];
606 std::atomic<const RoutingKit::CustomizableContractionHierarchyMetric*>
front{
nullptr};
613 std::shared_ptr<RoutingKit::CustomizableContractionHierarchyPartialCustomization>
partial;
621 std::unique_ptr<RoutingKit::CustomizableContractionHierarchyMetric>
metric;
630 std::vector<std::pair<unsigned, unsigned> >
patched;
658 const std::vector<unsigned> unpatched(sm.
weights);
660 for (
unsigned a = 0; a < (unsigned)sm.
weights.size(); a++) {
661 if (sm.
weights[a] != unpatched[a]) {
667 for (
const auto& p : sm.
patched) {
668 sm.
weights[p.first] = p.second;
674 static uint64_t
fnv1a(
const std::string& s) {
675 uint64_t h = 1469598103934665603ull;
676 for (
const char ch : s) {
677 h = (h ^ (
unsigned char)ch) * 1099511628211ull;
690 c->
partial = std::make_shared<RoutingKit::CustomizableContractionHierarchyPartialCustomization>(
myGraph->
cch());
729 std::map<const K*, std::vector<LiveMetric*> >
myByKey;
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
Metric-independent RoutingKit CCH topology over the PURE road graph.
unsigned edgeIdSpace() const
size of the edge numerical-id space the graph was built over (for callers keeping per-edge-id side ar...
unsigned arcCount() const
number of input arcs (== number of mapped connections)
double(* EffortOperation)(const E *const, const V *const, double)
effort callback signature, matching SUMOAbstractRouter::Operation
void fillInputWeights(EffortOperation effort, SUMOVehicleClass maskClass, const V *veh, double time, std::vector< unsigned > &weight) const
Fill a centisecond input-weight buffer for one vehicle class.
const RoutingKit::CustomizableContractionHierarchy & cch() const
the immutable CCH (share const& across clones)
const std::vector< unsigned > & arcsOfEdge(const E *e) const
the arcs whose weight depends on the given edge (arcs it heads plus arcs whose folded via chain conta...
unsigned computeArcWeight(unsigned a, EffortOperation effort, SUMOVehicleClass maskClass, const V *veh, double time) const
Recompute the input weight of one arc – the exact per-arc body of fillInputWeights (same masking,...
per-vehicle-type CCH metric store over a shared CCHGraph
std::map< const K *, std::vector< LiveMetric * > > myByKey
bool myStale
the efforts changed behind the cached metrics: refill and re-customize them all on the next get() (se...
MetricPtr get(const K *key, SUMOVehicleClass vClass, SUMOTime time, const V *veh)
the metric for (type key, period of time), built on the first query of the pair; nullptr before init....
void seedKey(const K *key)
allocate the metric state (all ensemble slots) for one type; call only while no query is in flight (s...
const Graph * myGraph
the immutable shared topology
EffortOperation myFillEffort
the effort the metrics are filled from
std::map< std::pair< const K *, int >, StaticMetric > myStaticMetrics
int periodOf(SUMOTime time) const
the weight period containing time: 0 is everything before begin and the whole run when the weights ar...
bool hasDeadband() const
whether the deadband can keep the metrics behind the efforts (then its state and the lagging arcs bel...
WeightPatch myPatch
post-fill weight hook (STATIC)
void loadMetric(const K *key, int slot, double now, const std::vector< int > &arcs, const std::vector< int > &weights)
publish the metric of a type and ensemble slot as a fresh fill at now with the given arcs overwritten...
const bool myLive
LIVE or STATIC (fixed at construction)
std::vector< LiveMetric * > myLiveMetrics
every type's state, in creation order (barrier iteration) and by key (query lookup; only mutated whil...
std::vector< const E * > myPendingList
void atBarrier(double now, bool effortsMoved)
the owner's customization barrier: bump the speed epoch when an effort moved and re-customize when it...
int myFullFillsPending
how many customize passes must replace a whole buffer after a permission flip: 2 = refill one,...
std::vector< double > myAppliedEffort
edge state for the sparse path, shared by both buffers: the gate effort each edge's arcs were last fi...
std::atomic< bool > myQueried
whether a query arrived since the last barrier (bootstraps type creation and re-arms after resets – s...
RefVehicleFactory myFactory
reference-vehicle factory (required LIVE, optional STATIC)
std::atomic< uint64_t > myPublishedEpoch
void customize(double now)
refill + customize + publish every type's metric from the live efforts and permissions....
void getLaggingArcs(const K *key, int slot, double now, std::vector< int > &arcs, std::vector< int > &weights) const
the arcs of the published metric of a type and ensemble slot whose weight differs from a fresh fill a...
std::vector< const K * > myWantedKeys
types that queried but have no metric yet (demand streams, so types can appear after seeding); querie...
V *(* RefVehicleFactory)(const K *, int)
builds an OWNED effort-reference vehicle for a type: never registered, counted or inserted – it exist...
CCHMetricFamily(const Graph *graph, EffortOperation fillEffort, SUMOTime begin, SUMOTime weightPeriod, RefVehicleFactory factory, WeightPatch patch)
construct a STATIC family (lazy build per (type, period))
std::vector< const E * > myLastAccepted
void fillStatic(StaticMetric &sm, int period, SUMOTime time, const V *ref, const V *veh)
(re)fill a STATIC metric's input weights from the live efforts. A weight-period grid evaluates at the...
CCHMetricFamily & operator=(const CCHMetricFamily &)=delete
bool empty() const
whether any type has live metric state yet
int getEnsembleSize() const
the number of metrics per type
void flagStale()
the efforts behind the cached metrics changed – a runtime permission change in the simulation (the ca...
const RoutingKit::CustomizableContractionHierarchyMetric * MetricPtr
std::vector< char > myPendingFlag
void invalidateEdge(const E *e)
a runtime permission change (closure / re-opening) hit this edge: queue it bypassing the deadband and...
std::atomic< uint64_t > mySpeedEpoch
barrier counter of the tracked efforts and the counter value the published metrics were customized fr...
CCHMetricFamily(const Graph *graph, EffortOperation fillEffort, EffortOperation gateEffort, double updateFactor, double updateConstant, RefVehicleFactory factory, int ensembleK=1)
construct a LIVE family (double-buffered, barrier-customized)
double getAppliedEffort(const E *e) const
the gate effort the edge was last applied with (NaN = never)
std::vector< const K * > getKeys() const
the type keys with metric state
std::atomic< bool > myMetricStale
a permission flip has not yet been customized into the published metrics (queries divert to the exact...
bool isPending(const E *e) const
whether the edge waits for the deadband
SUMOTime periodEnd(SUMOTime time) const
the end of the weight period containing the given time (SUMOTime_MAX when the weights are static); CC...
int myEnsembleK
frozen random-factor realizations per type (see the LIVE ctor)
EffortOperation myGateEffort
the type-independent effort of the LIVE deadband
Graph::EffortOperation EffortOperation
void loadEdge(const E *e, double appliedEffort, bool pending)
restore the deadband state of an edge (state loading)
MetricPtr published(const K *key, const std::string &vehID)
the published metric for a type key and querying vehicle id (the id picks the ensemble slot – see the...
void flagPermissionsStale()
flagStale() under the simulation's name for the permission case
static uint64_t fnv1a(const std::string &s)
stable 64-bit FNV-1a for the ensemble slot assignment
void markDirty(const E *e)
queue an edge whose gate effort changed (the deadband applies later, at the customize barrier)
void(* WeightPatch)(const Graph *, const V *, std::vector< unsigned > &)
post-fill hook on the input weights (STATIC mode), e.g. duarouter masking the edges that restrict a t...
LiveMetric * buildLiveMetric(const K *key, int slot)
allocate LIVE metric state for one (type, ensemble slot) (owner's thread only)
CCHMetricFamily(const CCHMetricFamily &)=delete
per-type LIVE metric state. Heap-owned: the atomic makes it non-movable, so it cannot live in a map b...
V * refVehicle
OWNED effort-reference vehicle (see RefVehicleFactory)
std::vector< unsigned > weight[2]
std::atomic< const RoutingKit::CustomizableContractionHierarchyMetric * > front
std::shared_ptr< RoutingKit::CustomizableContractionHierarchyPartialCustomization > partial
partial-customization worker (queue over the shared CCH); one per metric – its queue is drained by ev...
std::shared_ptr< RoutingKit::CustomizableContractionHierarchyMetric > metric[2]
per-(type, period) STATIC metric state. RoutingKit metrics BORROW their input-weight buffer,...
std::vector< unsigned > weights
V * refVehicle
OWNED reference vehicle (nullptr when filling with the querying vehicle)
std::vector< std::pair< unsigned, unsigned > > patched
the (arc, weight) pairs the patch wrote on the first fill, re-applied on every refill
bool filled
whether the first fill (which runs the patch) is done
std::unique_ptr< RoutingKit::CustomizableContractionHierarchyMetric > metric