AntHocNet 2.6.1
Paper-faithful ant-colony ad hoc routing: the shared core and its adapters
Loading...
Searching...
No Matches
pheromone_engine.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT OR GPL-2.0-only
2// Copyright (C) 2026 Daniel Henrique Joppi
3
4/**
5 * PheromoneEngine: the reinforcement / evaporation math, lifted out of the
6 * NS-2 AntNest class so both simulators share identical routing dynamics.
7 *
8 * Operates on a PheromoneTable by reference; carries no simulator state.
9 */
10#ifndef ANTHOCNET_CORE_PHEROMONE_ENGINE_H
11#define ANTHOCNET_CORE_PHEROMONE_ENGINE_H
12
13#include <map>
14
19
20namespace anthocnet {
21namespace core {
22
24public:
25 explicit PheromoneEngine(const Config& config) : config_(config) {}
26
27 /// phValue - (1 - alpha) * phValue
28 double evaporate(double phValue) const;
29 /// gamma * phValue + (1 - gamma) * phUpdate
30 double reinforce(double phValue, double phUpdate) const;
31
32 /// Reinforce the (dest, neighbor) regular link travelled by an ant. Aging
33 /// of other links is handled separately by evaporateAll (ADR-0012).
35 double phUpdate) const;
36
37 /// Time-proportional aging of every regular AND virtual link by
38 /// alpha^(dt/interval), pruning links below minPheromone. Driven by the
39 /// maintenance tick. One clock for both tables (#262) keeps them
40 /// commensurable for virtual-vs-regular comparisons.
41 /// `rateMultiplier` (#572), when given, scales the decay per destination:
42 /// a destination in the map ages as if `m` times the elapsed time had
43 /// passed, in both tables (they must stay commensurable, #262). nullptr,
44 /// or a destination absent from the map, ages exactly as before.
45 void evaporateAll(PheromoneTable& table, double dtSeconds,
46 const std::map<NodeAddress, double>* rateMultiplier = nullptr) const;
47
48 /// Reinforce the virtual links advertised by a hello. Aging is handled by
49 /// evaporateAll, same as the regular table (#262).
50 void updateVirtual(PheromoneTable& table, const AntMessage& hello) const;
51 /// Same, adding `hopCost` (the cost of the link to the hello's sender, in
52 /// the metric's units) instead of the unloaded hop time (#181).
53 void updateVirtual(PheromoneTable& table, const AntMessage& hello, double hopCost) const;
54
55 /// Prune a vanished neighbour from both tables.
56 void cleanNeighbor(PheromoneTable& table, NodeAddress neighbor) const;
57
58 /// True if any neighbour still holds usable pheromone for this dest.
59 bool hasRegularDestination(const PheromoneTable& table, NodeAddress dest) const;
60
61private:
62 void cleanNeighbor(PheromoneTable& table, NodeAddress neighbor, bool regular) const;
63
64 const Config config_;
65};
66
67} // namespace core
68} // namespace anthocnet
69
70#endif // ANTHOCNET_CORE_PHEROMONE_ENGINE_H
double reinforce(double phValue, double phUpdate) const
gamma * phValue + (1 - gamma) * phUpdate
void updateRegular(PheromoneTable &table, NodeAddress dest, NodeAddress neighbor, double phUpdate) const
Reinforce the (dest, neighbor) regular link travelled by an ant.
double evaporate(double phValue) const
phValue - (1 - alpha) * phValue
void updateVirtual(PheromoneTable &table, const AntMessage &hello) const
Reinforce the virtual links advertised by a hello.
void cleanNeighbor(PheromoneTable &table, NodeAddress neighbor) const
Prune a vanished neighbour from both tables.
PheromoneEngine(const Config &config)
bool hasRegularDestination(const PheromoneTable &table, NodeAddress dest) const
True if any neighbour still holds usable pheromone for this dest.
void evaporateAll(PheromoneTable &table, double dtSeconds, const std::map< NodeAddress, double > *rateMultiplier=nullptr) const
Time-proportional aging of every regular AND virtual link by alpha^(dt/interval), pruning links below...
void updateVirtual(PheromoneTable &table, const AntMessage &hello, double hopCost) const
Same, adding hopCost (the cost of the link to the hello's sender, in the metric's units) instead of t...
std::int32_t NodeAddress
Network-layer node address.
Definition types.h:21
AntHistoryTracker: (src, seqNum) duplicate detection.
Definition ant_history.h:24
Complete, copyable description of an ant packet.
Definition ant_message.h:48