AntHocNet 2.6.1
Paper-faithful ant-colony ad hoc routing: the shared core and its adapters
Loading...
Searching...
No Matches
link_lifetime.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 * Link-lifetime prediction (#574): how long two nodes stay within radio range
6 * if both keep their current velocity -- the link expiration time (LET) of Su,
7 * Lee and Gerla, "Mobility prediction and routing in ad hoc wireless networks"
8 * (2001), in 3-D. Pure arithmetic over Kinematics (ADR-0025); the router turns
9 * it into a next-hop discount.
10 */
11#ifndef ANTHOCNET_CORE_LINK_LIFETIME_H
12#define ANTHOCNET_CORE_LINK_LIFETIME_H
13
14#include <cmath>
15#include <limits>
16
18
19namespace anthocnet {
20namespace core {
21
22/// Seconds until `a` and `b` are `range` metres apart, moving as they move
23/// now. +inf when they never separate (same velocity, or approaching for
24/// ever is impossible: a quadratic with a > 0 always has a root, so +inf
25/// means zero relative velocity inside range). 0 when they are already out
26/// of range.
27inline double linkExpiryTime(const Kinematics& a, const Kinematics& b, double range) {
28 const double dx = b.x - a.x, dy = b.y - a.y, dz = b.z - a.z;
29 const double vx = b.vx - a.vx, vy = b.vy - a.vy, vz = b.vz - a.vz;
30 const double c = dx * dx + dy * dy + dz * dz - range * range;
31 if (c > 0.0) return 0.0; // already beyond range
32 const double qa = vx * vx + vy * vy + vz * vz;
33 if (qa <= 0.0) return std::numeric_limits<double>::infinity();
34 const double qb = 2.0 * (dx * vx + dy * vy + dz * vz);
35 // c <= 0 and qa > 0: the discriminant is >= qb^2, so the larger root is
36 // the non-negative time the separation reaches `range`.
37 return (-qb + std::sqrt(qb * qb - 4.0 * qa * c)) / (2.0 * qa);
38}
39
40/// The next-hop weight for a link expected to live `let` seconds: 1 at or
41/// beyond `horizon`, falling linearly below it, never under `floor` (a short
42/// link is discouraged, not removed: if every link is short the choice among
43/// them is the pheromone's).
44inline double linkLifetimeWeight(double let, double horizon, double floor) {
45 if (!(horizon > 0.0) || let >= horizon) return 1.0;
46 const double w = let / horizon;
47 return w < floor ? floor : w;
48}
49
50} // namespace core
51} // namespace anthocnet
52
53#endif // ANTHOCNET_CORE_LINK_LIFETIME_H
double linkLifetimeWeight(double let, double horizon, double floor)
The next-hop weight for a link expected to live let seconds: 1 at or beyond horizon,...
double linkExpiryTime(const Kinematics &a, const Kinematics &b, double range)
Seconds until a and b are range metres apart, moving as they move now.
AntHistoryTracker: (src, seqNum) duplicate detection.
Definition ant_history.h:24
A node's position (m) and velocity (m/s) in the adapter's Cartesian frame (ADR-0025).
Definition types.h:32