Package net.automatalib.graph
Class SimpleMapGraph<N>
- java.lang.Object
-
- net.automatalib.graph.SimpleMapGraph<N>
-
- Type Parameters:
N
- node type
- All Implemented Interfaces:
Iterable<N>
,FiniteRepresentation
,Graph<N,N>
,IndefiniteGraph<N,N>
,IndefiniteSimpleGraph<N>
,MutableGraph<N,N,N,Void>
,ShrinkableGraph<N,N>
,SimpleGraph<N>
,UniversalGraph<N,N,N,Void>
,UniversalIndefiniteGraph<N,N,N,Void>
public class SimpleMapGraph<@Nullable N> extends Object implements MutableGraph<N,N,N,Void>, ShrinkableGraph<N,N>
A very simple graph realization, where nodes can be arbitrary Java objects. This graph does not support edge properties.This class provides maximum flexibility, but should only be used if performance is not a major concern.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.automatalib.graph.Graph
Graph.IntAbstraction<E>
-
Nested classes/interfaces inherited from interface net.automatalib.graph.MutableGraph
MutableGraph.IntAbstraction<E,NP,EP>
-
-
Constructor Summary
Constructors Constructor Description SimpleMapGraph()
SimpleMapGraph(Supplier<? extends Collection<@Nullable N>> adjCollSupplier)
Initializes a graph where the adjacency structure is stored using aHashMap
, and adjacency information for a single node is stored in data structures created via the provided supplier.SimpleMapGraph(Map<@Nullable N,Collection<@Nullable N>> structureMap)
Initializes a graph using the given adjacency structure, and adjacency information for a single node is stored usingHashSet
s.SimpleMapGraph(Map<@Nullable N,Collection<@Nullable N>> structureMap, Supplier<? extends Collection<@Nullable N>> adjCollSupplier)
Initializes a graph using the given adjacency structure, and adjacency information for a single node is stored in data structures created via the provided supplier.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description N
addNode(@Nullable N property)
Adds a new node to the graph.N
connect(@Nullable N source, @Nullable N target, Void property)
Inserts an edge in the graph.Collection<N>
getAdjacentNodes(@Nullable N node)
Retrieves, for a given node, the (finite) collection of all adjacent nodes.Iterator<N>
getAdjacentNodesIterator(@Nullable N node)
Retrieves, for a given node, all adjacent nodes.Void
getEdgeProperty(@Nullable N edge)
Retrieves the property of a given edge.N
getNodeProperty(@Nullable N node)
Retrieves the property of a given node.Set<N>
getNodes()
Retrieves an (unmodifiable) collection of the nodes in this graph.Collection<N>
getOutgoingEdges(@Nullable N node)
Retrieves, for a given node, the (finite) collection of all outgoing edges.N
getTarget(@Nullable N edge)
Retrieves, for a given edge, its target node.Iterator<N>
iterator()
void
removeEdge(@Nullable N node, @Nullable N edge)
Removes an outgoing edge from the given node.void
removeNode(@Nullable N node, @Nullable N replacement)
Removes a node from this graph, and redirects all incoming edges to the given replacement node (node that outgoing edges are still removed).void
setEdgeProperty(@Nullable N edge, Void property)
Sets the edge property of the given edge.void
setNodeProperty(@Nullable N node, @Nullable N property)
Deprecated.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.automatalib.graph.Graph
getOutgoingEdgesIterator, getVisualizationHelper
-
Methods inherited from interface net.automatalib.graph.IndefiniteGraph
getEdgesBetween
-
Methods inherited from interface net.automatalib.graph.IndefiniteSimpleGraph
createDynamicNodeMapping, createStaticNodeMapping, isConnected
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface net.automatalib.graph.MutableGraph
addNode, connect
-
Methods inherited from interface net.automatalib.graph.ShrinkableGraph
removeNode
-
Methods inherited from interface net.automatalib.graph.SimpleGraph
nodeIDs, size
-
-
-
-
Constructor Detail
-
SimpleMapGraph
public SimpleMapGraph()
-
SimpleMapGraph
public SimpleMapGraph(Supplier<? extends Collection<@Nullable N>> adjCollSupplier)
Initializes a graph where the adjacency structure is stored using aHashMap
, and adjacency information for a single node is stored in data structures created via the provided supplier.- Parameters:
adjCollSupplier
- the supplier for per-node adjacency collections
-
SimpleMapGraph
public SimpleMapGraph(Map<@Nullable N,Collection<@Nullable N>> structureMap)
Initializes a graph using the given adjacency structure, and adjacency information for a single node is stored usingHashSet
s.- Parameters:
structureMap
- the map for the overall graph structure
-
SimpleMapGraph
public SimpleMapGraph(Map<@Nullable N,Collection<@Nullable N>> structureMap, Supplier<? extends Collection<@Nullable N>> adjCollSupplier)
Initializes a graph using the given adjacency structure, and adjacency information for a single node is stored in data structures created via the provided supplier.- Parameters:
structureMap
- the map for the overall graph structureadjCollSupplier
- the supplier for per-node adjacency collections
-
-
Method Detail
-
getAdjacentNodes
public Collection<N> getAdjacentNodes(@Nullable N node)
Description copied from interface:Graph
Retrieves, for a given node, the (finite) collection of all adjacent nodes.- Specified by:
getAdjacentNodes
in interfaceGraph<N,N>
- Parameters:
node
- the node- Returns:
- a collection containing the outgoing edges
-
getAdjacentNodesIterator
public Iterator<N> getAdjacentNodesIterator(@Nullable N node)
Description copied from interface:IndefiniteSimpleGraph
Retrieves, for a given node, all adjacent nodes.- Specified by:
getAdjacentNodesIterator
in interfaceIndefiniteGraph<N,N>
- Specified by:
getAdjacentNodesIterator
in interfaceIndefiniteSimpleGraph<N>
- Parameters:
node
- the node- Returns:
- an iterator over the adjacent nodes
-
getOutgoingEdges
public Collection<N> getOutgoingEdges(@Nullable N node)
Description copied from interface:Graph
Retrieves, for a given node, the (finite) collection of all outgoing edges.- Specified by:
getOutgoingEdges
in interfaceGraph<N,N>
- Parameters:
node
- the node- Returns:
- a collection containing the outgoing edges
-
getTarget
public N getTarget(@Nullable N edge)
Description copied from interface:IndefiniteGraph
Retrieves, for a given edge, its target node.- Specified by:
getTarget
in interfaceIndefiniteGraph<N,N>
- Parameters:
edge
- the edge.- Returns:
- the target node of the given edge.
-
getNodes
public Set<N> getNodes()
Description copied from interface:SimpleGraph
Retrieves an (unmodifiable) collection of the nodes in this graph.- Specified by:
getNodes
in interfaceSimpleGraph<N>
- Returns:
- the nodes in this graph
-
getNodeProperty
public N getNodeProperty(@Nullable N node)
Description copied from interface:UniversalIndefiniteGraph
Retrieves the property of a given node.- Specified by:
getNodeProperty
in interfaceUniversalIndefiniteGraph<N,N,N,Void>
- Parameters:
node
- the node- Returns:
- the property of the specified node
-
getEdgeProperty
public Void getEdgeProperty(@Nullable N edge)
Description copied from interface:UniversalIndefiniteGraph
Retrieves the property of a given edge.- Specified by:
getEdgeProperty
in interfaceUniversalIndefiniteGraph<N,N,N,Void>
- Parameters:
edge
- the edge- Returns:
- the property of the specified edge
-
addNode
public N addNode(@Nullable N property)
Description copied from interface:MutableGraph
Adds a new node to the graph.
-
connect
public N connect(@Nullable N source, @Nullable N target, Void property)
Description copied from interface:MutableGraph
Inserts an edge in the graph.
-
setNodeProperty
@Deprecated public void setNodeProperty(@Nullable N node, @Nullable N property)
Deprecated.Description copied from interface:MutableGraph
Sets the node property of the given node.- Specified by:
setNodeProperty
in interfaceMutableGraph<N,N,N,Void>
- Parameters:
node
- the nodeproperty
- the property to set
-
setEdgeProperty
public void setEdgeProperty(@Nullable N edge, Void property)
Description copied from interface:MutableGraph
Sets the edge property of the given edge.- Specified by:
setEdgeProperty
in interfaceMutableGraph<N,N,N,Void>
- Parameters:
edge
- the edgeproperty
- the property to set
-
removeNode
public void removeNode(@Nullable N node, @Nullable N replacement)
Description copied from interface:ShrinkableGraph
Removes a node from this graph, and redirects all incoming edges to the given replacement node (node that outgoing edges are still removed). If anull
replacement is specified, then this function behaves equivalently to the aboveShrinkableGraph.removeNode(Object)
.- Specified by:
removeNode
in interfaceShrinkableGraph<N,N>
- Parameters:
node
- the node to removereplacement
- the replacement node for incoming edges
-
removeEdge
public void removeEdge(@Nullable N node, @Nullable N edge)
Description copied from interface:ShrinkableGraph
Removes an outgoing edge from the given node.- Specified by:
removeEdge
in interfaceShrinkableGraph<N,N>
- Parameters:
node
- the nodeedge
- the edge to remove
-
-