From 4a96d9cad446ea405b51dfeebb01a1b6d7f6fb2b Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Tue, 27 Sep 2022 19:21:16 -0400 Subject: Add some interesting new things Adds a number of things based off of some of the notes I've made over time, plus a few papers I've read. More details to come later, whenever I decide to actually get serious about documentation and examples and the like --- base/src/main/java/bjc/utils/graph/AlgGraph.java | 88 ++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 base/src/main/java/bjc/utils/graph/AlgGraph.java (limited to 'base/src/main/java/bjc/utils/graph/AlgGraph.java') diff --git a/base/src/main/java/bjc/utils/graph/AlgGraph.java b/base/src/main/java/bjc/utils/graph/AlgGraph.java new file mode 100644 index 0000000..7c9d38d --- /dev/null +++ b/base/src/main/java/bjc/utils/graph/AlgGraph.java @@ -0,0 +1,88 @@ +package bjc.utils.graph; + +import bjc.functypes.Container; + +/** + * A directed algebraic graph + * + * (ref. Algebraic Graphs with Class, Andrey Mokhov} + * + * @author bjcul + * + * @param The type of the vertexes + * @param Containing type parameter + */ +public interface AlgGraph> extends Container> { + /** + * Create a empty algebraic graph. + * + * @param The type of the vertices + * + * @return A new empty graph. + */ + AlgGraph empty(); + + /** + * Create a algebraic graph with a single vertex + * + * @param val The value for the vertex + * + * @return A new graph with the given vertex + */ + AlgGraph vertex(B val); + + /** + * Overlay a graph onto this one, adding its vertices and edges. + * + * @param other The graph to overlay + */ + void overlay(AlgGraph other); + + /** + * Connect a graph to this one, adding its vertices and edges; as well as + * establishing an edge from each node in this graph, to each node in the other + * graph. + * + * @param other The graph to connect + */ + void connect(AlgGraph other); + + /** + * Overlay two graphs into a new graph. + * + * @param The type of the vertices. + * + * @param left The graph to overlay onto + * @param right The graph being overlaid + * + * @return The overlaid graph. + */ + public static > G overlay(G left, G right) { + @SuppressWarnings("unchecked") + // We know this cast is good, java just can't tell + G result = (G) left.empty(); + result.overlay(left); + result.overlay(right); + + return result; + } + + /** + * Connect two graphs into a new graph. + * + * @param The type of the vertices. + * + * @param left The graph to connect to + * @param right The graph being connected + * + * @return The connected graph. + */ + public static > G connect(G left, G right) { + @SuppressWarnings("unchecked") + // We know this cast is good, java just can't tell + G result = (G) left.empty(); + result.overlay(left); + result.connect(right); + return result; + } +} \ No newline at end of file -- cgit v1.2.3