Class DirectedWeightedGraph<V,W>
java.lang.Object
org.episteme.core.mathematics.discrete.DirectedWeightedGraph<V,W>
- All Implemented Interfaces:
Graph<V>, WeightedGraph<V,W>
- Direct Known Subclasses:
BayesianBeliefNetwork
Adjacency list implementation of a directed weighted graph.
Stores edges with weights using an adjacency list structure. Default weight is Real.ONE for backward compatibility.
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Nested Class Summary
Nested classes/interfaces inherited from interface Graph
Graph.Edge<V> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new directed weighted graph with Real.ONE as default weight.DirectedWeightedGraph(W defaultWeight) Creates a new directed weighted graph with specified default weight. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a weighted edge to the graph.booleanAdds a vertex to the graph.intReturns the degree (number of edges) of a vertex.Set<Graph.Edge<V>> edges()Returns all edges in this graph.Returns the default weight for unweighted edge additions.Returns the weight of an edge.Set<WeightedEdge<V, W>> Returns all weighted edges in the graph.Set<WeightedEdge<V, W>> getWeightedEdgesFrom(V vertex) Returns weighted edges originating from a vertex.booleanChecks if this graph is directed.Returns neighbors of a vertex.intReturns the number of vertices in the graph.vertices()Returns all vertices in this graph.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WeightedGraph
addEdge, hasEdge
-
Constructor Details
-
DirectedWeightedGraph
public DirectedWeightedGraph()Creates a new directed weighted graph with Real.ONE as default weight. -
DirectedWeightedGraph
Creates a new directed weighted graph with specified default weight.- Parameters:
defaultWeight- the default weight for unweighted edges
-
-
Method Details
-
vertices
-
vertexCount
public int vertexCount()Description copied from interface:GraphReturns the number of vertices in the graph.- Specified by:
vertexCountin interfaceGraph<V>- Returns:
- the number of vertices
-
edges
-
addVertex
-
addEdge
Description copied from interface:WeightedGraphAdds a weighted edge to the graph.Vertices are automatically added if not already present.
- Specified by:
addEdgein interfaceWeightedGraph<V,W> - Parameters:
source- the source vertextarget- the target vertexweight- the edge weight- Returns:
- true if the edge was added
-
getWeight
Description copied from interface:WeightedGraphReturns the weight of an edge.- Specified by:
getWeightin interfaceWeightedGraph<V,W> - Parameters:
source- the source vertextarget- the target vertex- Returns:
- the edge weight, or null if no such edge exists
-
getWeightedEdges
Description copied from interface:WeightedGraphReturns all weighted edges in the graph.- Specified by:
getWeightedEdgesin interfaceWeightedGraph<V,W> - Returns:
- unmodifiable set of weighted edges
-
getWeightedEdgesFrom
Description copied from interface:WeightedGraphReturns weighted edges originating from a vertex.- Specified by:
getWeightedEdgesFromin interfaceWeightedGraph<V,W> - Parameters:
vertex- the source vertex- Returns:
- set of weighted edges from vertex
-
neighbors
-
degree
-
isDirected
public boolean isDirected()Description copied from interface:GraphChecks if this graph is directed.- Specified by:
isDirectedin interfaceGraph<V>- Returns:
- true if directed, false if undirected
-
getDefaultWeight
Description copied from interface:WeightedGraphReturns the default weight for unweighted edge additions.Used when addEdge(V, V) is called without a weight. Subclasses should override to provide appropriate default.
- Specified by:
getDefaultWeightin interfaceWeightedGraph<V,W> - Returns:
- the default weight (e.g., 1.0, Real.ONE)
-