it.unibo.alchemist.model.cognitive.actions.CognitiveAgentArrive.kt Maven / Gradle / Ivy
Show all versions of alchemist-cognitive-agents Show documentation
/*
* Copyright (C) 2010-2023, Danilo Pianini and contributors
* listed, for each module, in the respective subproject's build.gradle.kts file.
*
* This file is part of Alchemist, and is distributed under the terms of the
* GNU General Public License, with a linking exception,
* as described in the file LICENSE in the Alchemist distribution's top directory.
*/
package it.unibo.alchemist.model.cognitive.actions
import it.unibo.alchemist.model.Environment
import it.unibo.alchemist.model.Node
import it.unibo.alchemist.model.Node.Companion.asProperty
import it.unibo.alchemist.model.Position
import it.unibo.alchemist.model.Reaction
import it.unibo.alchemist.model.cognitive.PedestrianProperty
import it.unibo.alchemist.model.cognitive.impact.individual.Speed
import it.unibo.alchemist.model.geometry.Transformation
import it.unibo.alchemist.model.geometry.Vector
/**
* Move the agent towards a target position.
* It is similar to [CognitiveAgentSeek] but attempts to arrive at the target position with a zero velocity.
*
* @param environment
* the environment inside which the node moves.
* @param reaction
* the reaction which executes this action.
* @param pedestrian
* the owner of this action.
* @param decelerationRadius
* the distance from which the node starts to decelerate.
* @param arrivalTolerance
* the distance at which the node is considered arrived to the target.
* @param target
* the position the node moves towards.
*/
open class CognitiveAgentArrive(
environment: Environment,
reaction: Reaction,
override val pedestrian: PedestrianProperty,
protected val decelerationRadius: Double,
protected val arrivalTolerance: Double,
protected val target: P,
) : AbstractSteeringActionWithTarget(environment, reaction, pedestrian, target)
where P : Position,
P : Vector
,
A : Transformation
{
constructor(
environment: Environment,
reaction: Reaction,
pedestrian: PedestrianProperty,
decelerationRadius: Double,
arrivalTolerance: Double,
vararg coordinates: Number,
) : this(
environment,
reaction,
pedestrian,
decelerationRadius,
arrivalTolerance,
environment.makePosition(*coordinates),
)
override val maxWalk: Double get() = with((currentPosition as Vector).distanceTo(target)) {
when {
this < arrivalTolerance -> 0.0
this < decelerationRadius -> Speed.default * this / decelerationRadius / reaction.rate
else -> node.asProperty>().speed() / reaction.rate
}
}
override fun cloneAction(node: Node, reaction: Reaction): CognitiveAgentArrive =
CognitiveAgentArrive(
environment,
reaction,
node.pedestrianProperty,
decelerationRadius,
arrivalTolerance,
target,
)
}