deep_causality/types/context_node_types/time/discrete_time/mod.rs
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6mod adjustable;
7mod display;
8mod identifiable;
9mod scalar_projector;
10mod temporable;
11
12use crate::{TimeKind, TimeScale};
13
14/// A time model representing **discrete, uniformly spaced ticks** instead of continuous physical time.
15///
16/// `DiscreteTime` is designed for systems that evolve in **fixed increments**, such as:
17/// - Simulation steps
18/// - Control loops
19/// - State machines
20/// - Reinforcement learning environments
21/// - Event-driven or digital logic systems
22///
23/// This model is ideal when:
24/// - You don’t need wall-clock time or sub-second resolution
25/// - You care only about the **order and progression** of steps
26/// - Time is measured in **counted ticks** or iterations
27///
28/// # Fields
29/// - `id`: Unique numeric identifier for the time point
30/// - `tick_scale`: Scale of the tick (e.g., `Milliseconds`, `Microseconds`, `Seconds`)
31/// - `tick_unit`: The current tick index (`u64`), typically monotonically increasing
32///
33/// # Examples
34///
35/// ```rust
36/// use deep_causality::{DiscreteTime, Temporal, TimeScale};
37///
38/// let t0 = DiscreteTime::new(1, TimeScale::Microseconds, 0);
39/// let t1 = DiscreteTime::new(2, TimeScale::Microseconds, 1);
40///
41/// assert!(t0.time_unit() < t1.time_unit());
42/// assert_eq!(t0.time_scale(), TimeScale::Microseconds);
43/// ```
44///
45/// # Trait Compatibility
46/// - Implements `Identifiable` via `id`
47/// - Implements `Temporal<u64>`, so it can be used in any time-aware causal context
48///
49/// # Use Cases
50/// - Agent-based simulations with fixed timesteps
51/// - Ticking state machines (e.g., embedded control)
52/// - Digital logic simulation
53/// - Environments where **temporal resolution** is implicit or constant
54///
55/// # Note
56/// While `tick_unit` is a `u64` and ordered, it does **not** imply any physical duration
57/// unless paired with a meaningful `TimeScale`. The interpretation of ticks is context-dependent.
58///
59/// # See also
60/// - `SymbolicTime` for non-numeric symbolic events
61/// - `LorentzianTime` or `ProperTime` for physical time
62#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
63pub struct DiscreteTime {
64 /// Unique identifier for this discrete time instance.
65 id: u64,
66
67 /// Semantic scale of the ticks (e.g., Steps, Cycles, Milliseconds).
68 tick_scale: TimeScale,
69
70 /// The actual tick count (monotonic unit of progression).
71 tick_unit: u64,
72}
73
74impl DiscreteTime {
75 pub fn new(id: u64, tick_scale: TimeScale, tick_unit: u64) -> Self {
76 Self {
77 id,
78 tick_scale,
79 tick_unit,
80 }
81 }
82}
83
84impl From<DiscreteTime> for TimeKind {
85 fn from(t: DiscreteTime) -> Self {
86 TimeKind::Discrete(t)
87 }
88}