Struct openrailwaymap_exporter::ai::TrainAgentAI
source · pub struct TrainAgentAI {
pub id: RailwayObjectId,
pub railway_graph: Option<RailwayGraph>,
pub current_node: Option<NodeId>,
pub target_node: Option<NodeId>,
pub agent_rl: TrainAgentRL,
pub trainer: Arc<RwLock<AgentTrainer<TrainAgentState>>>,
}
Expand description
A reinforcement learning agent that controls a train in the simulation.
Fields§
§id: RailwayObjectId
The id of the railway object
railway_graph: Option<RailwayGraph>
The railway graph representing the train network.
current_node: Option<NodeId>
The current node
target_node: Option<NodeId>
The target node
agent_rl: TrainAgentRL
The reinforcement learning agent responsible for controlling the train.
trainer: Arc<RwLock<AgentTrainer<TrainAgentState>>>
The trainer responsible for training the reinforcement learning agent.
Implementations§
source§impl TrainAgentAI
impl TrainAgentAI
sourcepub fn new(railway_graph: RailwayGraph, initial_state: TrainAgentState) -> Self
pub fn new(railway_graph: RailwayGraph, initial_state: TrainAgentState) -> Self
sourcepub fn train(&mut self, iterations: usize)
pub fn train(&mut self, iterations: usize)
Trains the reinforcement learning agent for the specified number of iterations.
Arguments
iterations
- The number of iterations to train the agent.
sourcepub fn best_action(&self, state: &TrainAgentState) -> Option<RailMovableAction>
pub fn best_action(&self, state: &TrainAgentState) -> Option<RailMovableAction>
sourcepub fn observe(
&mut self,
current_node: NodeId,
target_node: Option<NodeId>,
speed_mm_s: Option<i32>,
delta_distance_mm: Option<i32>
)
pub fn observe( &mut self, current_node: NodeId, target_node: Option<NodeId>, speed_mm_s: Option<i32>, delta_distance_mm: Option<i32> )
Updates the current edge, target node (optionally), and calculates the new state by updating its distance using the shortest path distance while keeping the current speed constant.
Arguments
current_edge
- The current edge on which the train agent is.target_node
- The optional target node the train agent is heading to.time_delta_ms
- The time delta in milliseconds since the last update.
Trait Implementations§
source§impl Clone for TrainAgentAI
impl Clone for TrainAgentAI
source§fn clone(&self) -> TrainAgentAI
fn clone(&self) -> TrainAgentAI
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for TrainAgentAI
impl Debug for TrainAgentAI
source§impl DecisionAgent for TrainAgentAI
impl DecisionAgent for TrainAgentAI
§type A = RailMovableAction
type A = RailMovableAction
The associated action type for this decision agent.
source§fn next_action(&self, _delta_time: Option<Duration>) -> Self::A
fn next_action(&self, _delta_time: Option<Duration>) -> Self::A
Returns the best action based on the current state of the simulation. Read more
source§fn observe(&mut self, environment: &SimulationEnvironment)
fn observe(&mut self, environment: &SimulationEnvironment)
Observes the current environment and updates the agent’s internal state. Read more
source§impl Default for TrainAgentAI
impl Default for TrainAgentAI
source§fn default() -> TrainAgentAI
fn default() -> TrainAgentAI
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl RefUnwindSafe for TrainAgentAI
impl Send for TrainAgentAI
impl Sync for TrainAgentAI
impl Unpin for TrainAgentAI
impl UnwindSafe for TrainAgentAI
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates
Self
using data from the given [World]source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self
to a value of a Properties
struct.§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self
to a value of a Properties
struct.