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

it.unibo.alchemist.model.cognitive.impact.ImpactModel.kt Maven / Gradle / Ivy

There is a newer version: 35.0.0
Show newest version
/*
 * Copyright (C) 2010-2020, Danilo Pianini and contributors
 * listed in the main project's alchemist/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.impact

import it.unibo.alchemist.model.cognitive.CognitiveModel
import it.unibo.alchemist.model.cognitive.impact.cognitive.BeliefDanger
import it.unibo.alchemist.model.cognitive.impact.cognitive.CognitiveCharacteristic
import it.unibo.alchemist.model.cognitive.impact.cognitive.DesireEvacuate
import it.unibo.alchemist.model.cognitive.impact.cognitive.DesireWalkRandomly
import it.unibo.alchemist.model.cognitive.impact.cognitive.Fear
import it.unibo.alchemist.model.cognitive.impact.cognitive.IntentionEvacuate
import it.unibo.alchemist.model.cognitive.impact.cognitive.IntentionWalkRandomly
import kotlin.reflect.KClass

/**
 * Path to the file containing characteristics parameters.
 */
const val PARAMETERS_FILE = "it/unibo/alchemist/model/cognitive/impact/config.toml"

/**
 * Agent-based evacuation model with social contagion mechanisms.
 * More information can be found [here](https://doi.org/10.1007/978-3-319-70647-4_11).
 */
class ImpactModel(
    compliance: Double,
    influencedBy: () -> List,
    environmentalFactors: () -> Double,
) : CognitiveModel {

    private val cognitiveCharacteristics = linkedMapOf, CognitiveCharacteristic>(
        BeliefDanger::class to
            BeliefDanger(environmentalFactors, { characteristicLevel() }, influencedBy),
        Fear::class to Fear(
            { characteristicLevel() },
            { characteristicLevel() },
            influencedBy,
        ),
        DesireEvacuate::class to DesireEvacuate(
            compliance,
            { characteristicLevel() },
            { characteristicLevel() },
        ),
        DesireWalkRandomly::class to DesireWalkRandomly(
            compliance,
            { characteristicLevel() },
            { characteristicLevel() },
        ),
        IntentionEvacuate::class to IntentionEvacuate(
            { characteristicLevel() },
            { characteristicLevel() },
        ),
        IntentionWalkRandomly::class to IntentionWalkRandomly(
            { characteristicLevel() },
            { characteristicLevel() },
        ),
    )

    override fun dangerBelief() = characteristicLevel()

    override fun fear() = characteristicLevel()

    override fun remainIntention(): Double = characteristicLevel()

    override fun escapeIntention(): Double = characteristicLevel()

    override fun update(frequency: Double) =
        cognitiveCharacteristics.values.forEach { it.update(frequency) }

    private inline fun  characteristicLevel(): Double =
        cognitiveCharacteristics[C::class]?.level() ?: 0.0
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy