All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.alchemist.model.cognitive.navigation.ReachDestination.kt Maven / Gradle / Ivy

There is a newer version: 35.0.0
Show newest version
/*
 * 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.navigation

import it.unibo.alchemist.model.cognitive.NavigationStrategy
import it.unibo.alchemist.model.cognitive.actions.NavigationAction2D
import it.unibo.alchemist.model.geometry.ConvexPolygon
import it.unibo.alchemist.model.geometry.Euclidean2DConvexShape
import it.unibo.alchemist.model.geometry.navigationgraph.Euclidean2DPassage
import it.unibo.alchemist.model.positions.Euclidean2DPosition

/**
 * A [NavigationStrategy] allowing to reach a (static) destination.
 * The client can specify a list of [knownDestinations] (see [Pursue]) and [unknownDestinations] (see
 * [GoalOrientedExploration]).
 * The pedestrian will try to reach the closest known destination for which a valid path leading there is
 * known, but in case another destination is found along the way (either known or unknown), the latter will
 * be approached instead of the chosen known destination. To put it in another way, this behavior mixes
 * [ReachKnownDestination] and [GoalOrientedExploration].
 *
 * @param T the concentration type.
 * @param L the type of landmarks of the pedestrian's cognitive map.
 * @param R the type of edges of the pedestrian's cognitive map, representing the [R]elations between landmarks.
 */
open class ReachDestination(
    action: NavigationAction2D,
    /**
     * Known destinations, can be empty.
     */
    private val knownDestinations: List,
    /**
     * Unknown destinations, defaults to an empty list.
     */
    private val unknownDestinations: List = emptyList(),
) : GoalOrientedExploration(
    action,
    /*
     * This may seem strange, but as stated above if we found a destination along the way (either known
     * or unknown), we want to approach it and leave the route we're following.
     */
    knownDestinations + unknownDestinations,
) {

    private val reachKnownDestination: ReachKnownDestination? =
        knownDestinations.takeIf { it.isNotEmpty() }?.let { ReachKnownDestination(action, it) }

    override fun inNewRoom(newRoom: ConvexPolygon) = when (reachKnownDestination) {
        null -> super.inNewRoom(newRoom)
        else -> reachUnknownDestination(newRoom, orElse = { reachKnownDestination.inNewRoom(newRoom) })
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy