it.unibo.alchemist.model.geometry.navigationgraph.BaseNavigationGraph.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alchemist-euclidean-geometry Show documentation
Show all versions of alchemist-euclidean-geometry Show documentation
Alchemist geometric components for Euclidean spaces
The 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.geometry.navigationgraph
import it.unibo.alchemist.model.geometry.ConvexShape
import it.unibo.alchemist.model.geometry.Transformation
import it.unibo.alchemist.model.geometry.Vector
import org.jgrapht.GraphType
import org.jgrapht.graph.AbstractBaseGraph
import org.jgrapht.graph.DefaultGraphType
import org.jgrapht.util.SupplierUtil
import java.util.function.Supplier
/**
* An implementation of [NavigationGraph], deriving from [AbstractBaseGraph].
* The user can specify the [GraphType] so as to obtain a custom graph (e.g. weighted or not,
* directed or undirected, etc). [AbstractBaseGraph] guarantees deterministic ordering for
* the collection it maintains, as stated in its api documentation.
* Note that vertices and edges are used as keys inside [AbstractBaseGraph], so when choosing
* their types, you must follow these rules:
* - You must follow the contract defined in java.lang.Object for both equals and hashCode.
* - In particular, if you override either equals or hashCode, you must override them both.
* - Your implementation for hashCode must produce a value which does not change over the
* lifetime of the object.
* Further information available [here](https://jgrapht.org/guide/VertexAndEdgeTypes).
*/
open class BaseNavigationGraph(
vertexSupplier: Supplier?,
edgeSupplier: Supplier?,
graphType: GraphType,
) : AbstractBaseGraph(vertexSupplier, edgeSupplier, graphType),
NavigationGraph
where V : Vector,
A : Transformation,
N : ConvexShape {
/*
* Allows to rapidly create a directed or undirected unweighted graph without
* self-loops and allowing multiple edges.
*/
constructor(edgeClass: Class, directed: Boolean) : this(
null,
SupplierUtil.createSupplier(edgeClass),
DefaultGraphType
.Builder()
.let {
when {
directed -> it.directed()
else -> it.undirected()
}
}.weighted(false)
.allowMultipleEdges(true)
.allowSelfLoops(false)
.build(),
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy