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

it.unibo.alchemist.model.linkingrules.CombinedLinkingRule.kt Maven / Gradle / Ivy

The 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.linkingrules

import it.unibo.alchemist.model.Environment
import it.unibo.alchemist.model.LinkingRule
import it.unibo.alchemist.model.Node
import it.unibo.alchemist.model.Position
import it.unibo.alchemist.model.neighborhoods.Neighborhoods

/**
 * A meta-rule that combines multiple [subRules].
 * If any mandates a link, such link is created (union of all links).
 */
class CombinedLinkingRule>(
    val subRules: List>,
) : LinkingRule {

    private val isConsistent by lazy { subRules.all { it.isLocallyConsistent } }

    override fun computeNeighborhood(center: Node, environment: Environment) = Neighborhoods.make(
        environment,
        center,
        // Add all neigbours as per subrule
        subRules.asSequence().flatMap { it.computeNeighborhood(center, environment).neighbors }.asIterable(),
    )

    override fun isLocallyConsistent() = isConsistent
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy