From d57d278ae588aa03db475163667816bd961cde93 Mon Sep 17 00:00:00 2001 From: Lakshmi Krishnamurthy Date: Mon, 26 Aug 2024 00:31:21 -0400 Subject: [PATCH] Features: - Graph Tree Add Standalone Vertex (1) - Abbsord Graph Tree and Edge (2, 3) - Graph Tree Edge Priority Queue (4, 5, 6) - Graph Tree Templated Vertex (7, 8, 9) - Directed Graph Untemplated Vertex #1 (10, 11, 12) - Directed Graph Untemplated Vertex #2 (13, 14, 15) - Directed Graph Untemplated Vertex #3 (16, 17, 18) - Directed Graph Untemplated Vertex #4 (19, 20, 21) - Directed Graph Untemplated Vertex #5 (22, 23, 24) - Directed Graph Untemplated Vertex #6 (25, 26, 27) - Directed Graph Untemplated Vertex #7 (28, 29, 30) - Directed Graph Untemplated Vertex #8 (31, 32, 33) - Directed Graph Untemplated Vertex #9 (34) - Core Graph N Dimensional Hypercube (38, 39, 40) - Greedy MST Graph Boruvka Forest (42, 43, 44) - Boruvka Optimal Spanning Forest Generator (45, 46) - Greedy MST Graph Kruskal Generator (47, 48) - Greedy MST Graph Prime Generator (49, 50) - Greedy MST Graph Reverse Delete Generator (51) - Tree Builder Capacitated MST Generator (52) - Tree Builder Degree Constrained MST Generator (53) - Tree Builder Directed MST Generator (54) - Tree Builder Dynamic MST Generator (55) - Tree Builder Dynamic Euclidean Generator (56) - Tree Builder Dynamic KSMT Generator (57) - K Optimal Spanning Forests Generator (58) - Optimal Bottleneck Spanning Tree Generator (59) - Builder Optimal Labeling Spanning Tree Generator (60) - Tree Builder Rectilinear MST Generator (61) - Builder Steiner Tree Generator (62) - Complete MST Random Graph Ensemble (63, 64, 65) - Complete MST Random Graph (66) - Bellman Ford Bannister Eppstein Path Generator (67) - Bellman Ford Edge Partition Generator (68) - Graph Shortest Optimal Path Generator (69) - Graph Shortest Path Vertex Augmentor (70) - Bellman Ford Edge Relaxation Path Generator (71) - Bellman Ford Yen Edge Relaxation Path Generator (72) - Bellman Ford Yen Reduced Relaxation Path Generator (73) - Bellman Ford Johnson Path Generator (73) - Bellman Ford Edge Partition (74, 75) - Dijkstra Shortest Path Generator (76) - Shortest Path Floyd Warshall (77) - Shortest Path Floyd Warshall Distance Metric (78) - Graph Search Breadth First (79) - Graph Search Depth First (80) - A Star Vertex Function (81) - A Star Vertex Context (82, 83) - A Star F Heuristic (84) - A Star Static Weight F Heuristic (85) - A Star Dynamic Weight F Heuristic (86) - A Star Mark Allard F Heuristic (87) - Graph Connectivity Kosaraju (88) Bug Fixes/Re-organization: - Graph Core Vertex R1 Remove (35, 36) - Graph Vertex R1 Function Remove (37) - Directed Graph R1 Remove (41) Samples: - MST Boruvka Maximum Forest Generator (89, 90) - MST Boruvka Minimum Forest Generator (91, 92) - MST Kruskal Maximum Forest Generator (93, 94) - MST Kruskal Minimum Forest Generator (95, 96) - MST Prim Maximum Forest Generator (97, 98) - MST Prim Minimum Forest Generator (99, 100) - MST Reverse Delete Maximum Forest Generator (101, 102) - MST Reverse Delete Minimum Forest Generator (103, 104) - Graph Properties (105) - Graph Complete Bipartite Properties (106, 107, 108) - Yen Reduced Relaxation Single Source (109) - Yen Reduced Relaxation Single Pair (110) - Yen Edge Partition Single Source (111) - Yen Edge Partition Single Pair (112) - Shortest Path Bannister Eppstein Single Source (113) - Shortest Path Bannister Eppstein Single Pair (114) - Shortest Path Bellman Ford Single Source (115) - Shortest Path Bellman Ford Single Pair (116) - Shortest Path Johnson Single Source (117) - Shortest Path Johnson Single Pair (118) - Shortest Path Johnson Single Source Negative Weight (119) - Connectivity Kosaraju Strongly Connected Components (120) IdeaDRIP: --- ReleaseNotes/04_02_2024.txt | 61 +++ ReleaseNotes/04_03_2024.txt | 92 +++++ .../graph/astar/DynamicWeightFHeuristic.java | 4 +- .../java/org/drip/graph/astar/FHeuristic.java | 12 +- .../graph/astar/MalikAllardFHeuristic.java | 2 +- .../graph/astar/StaticWeightFHeuristic.java | 2 +- .../org/drip/graph/astar/VertexContext.java | 18 +- .../org/drip/graph/astar/VertexFunction.java | 2 +- .../BannisterEppsteinPathGenerator.java | 4 +- .../drip/graph/bellmanford/EdgePartition.java | 24 +- .../bellmanford/EdgePartitionGenerator.java | 14 +- .../EdgeRelaxationPathGenerator.java | 6 +- .../bellmanford/JohnsonPathGenerator.java | 10 +- .../YenEdgePartitionPathGenerator.java | 6 +- .../YenReducedRelaxationPathGenerator.java | 2 +- .../org/drip/graph/connectivity/Kosaraju.java | 16 +- .../drip/graph/core/CompleteBipartite.java | 6 +- .../{DirectedGraph.java => Directed.java} | 356 ++++++------------ ...rectedGraphType.java => DirectedType.java} | 5 +- src/main/java/org/drip/graph/core/Forest.java | 24 +- .../graph/core/NDimensionalHypercube.java | 28 +- .../java/org/drip/graph/core/Network.java | 334 ++++++++-------- src/main/java/org/drip/graph/core/Tree.java | 216 ++++++----- src/main/java/org/drip/graph/core/Vertex.java | 39 +- .../drip/graph/mst/CompleteRandomGraph.java | 8 +- .../mst/CompleteRandomGraphEnsemble.java | 42 +-- .../drip/graph/mstgreedy/BoruvkaForest.java | 24 +- .../graph/mstgreedy/BoruvkaGenerator.java | 8 +- .../drip/graph/mstgreedy/KruskalForest.java | 4 +- .../graph/mstgreedy/KruskalGenerator.java | 8 +- .../drip/graph/mstgreedy/PrimGenerator.java | 22 +- .../mstgreedy/ReverseDeleteGenerator.java | 8 +- .../org/drip/graph/search/BreadthFirst.java | 10 +- .../org/drip/graph/search/DepthFirst.java | 12 +- .../shortestpath/DijkstraPathGenerator.java | 4 +- .../graph/shortestpath/FloydWarshall.java | 6 +- .../FloydWarshallDistanceMatrix.java | 2 +- .../shortestpath/OptimalPathGenerator.java | 6 +- .../graph/shortestpath/VertexAugmentor.java | 15 +- .../treebuilder/CapacitatedMSTGenerator.java | 2 +- .../DegreeConstrainedMSTGenerator.java | 2 +- .../DirectedGraphMSTGenerator.java | 2 +- .../treebuilder/DynamicMSTGenerator.java | 2 +- .../treebuilder/EuclideanMSTGenerator.java | 2 +- .../drip/graph/treebuilder/KMSTGenerator.java | 2 +- .../KOptimalSpanningForestsGenerator.java | 8 +- ...ptimalBottleneckSpanningTreeGenerator.java | 2 +- .../OptimalLabelingSpanningTreeGenerator.java | 2 +- .../OptimalSpanningForestGenerator.java | 8 +- .../treebuilder/RectilinearMSTGenerator.java | 2 +- .../treebuilder/SteinerTreeGenerator.java | 2 +- .../measure/crng/RandomMatrixGenerator.java | 31 ++ .../org/drip/numerical/eigen/EigenOutput.java | 11 + .../numerical/matrix/R1SquareEigenized.java | 279 ++++++++++++++ .../drip/sample/connectivity/KosarajuSCC.java | 4 +- .../graph/CompleteBipartiteProperties.java | 14 +- .../drip/sample/graph/GraphProperties.java | 4 +- .../org/drip/sample/graphsearch/BFS1.java | 4 +- .../org/drip/sample/graphsearch/BFS3.java | 4 +- .../org/drip/sample/graphsearch/DFS1.java | 4 +- .../org/drip/sample/graphsearch/DFS2.java | 4 +- .../org/drip/sample/graphsearch/DFS3.java | 4 +- .../mst/BoruvkaMaximumForestGenerator.java | 10 +- .../mst/BoruvkaMinimumForestGenerator.java | 10 +- .../mst/KruskalMaximumForestGenerator.java | 10 +- .../mst/KruskalMinimumForestGenerator.java | 10 +- .../mst/PrimMaximumForestGenerator.java | 10 +- .../mst/PrimMinimumForestGenerator.java | 10 +- .../ReverseDeleteMaximumForestGenerator.java | 10 +- .../ReverseDeleteMinimumForestGenerator.java | 10 +- .../BannisterEppsteinSinglePair.java | 4 +- .../BannisterEppsteinSingleSource.java | 4 +- .../shortestpath/BellmanFordSinglePair.java | 4 +- .../shortestpath/BellmanFordSingleSource.java | 4 +- .../shortestpath/DijkstraSinglePair.java | 4 +- .../shortestpath/DijkstraSingleSource.java | 4 +- .../shortestpath/JohnsonSinglePair.java | 6 +- .../shortestpath/JohnsonSingleSource.java | 6 +- .../JohnsonSingleSourceNegativeWeight.java | 6 +- .../YenEdgePartitionSinglePair.java | 4 +- .../YenEdgePartitionSingleSource.java | 4 +- .../YenReducedRelaxationSinglePair.java | 4 +- .../YenReducedRelaxationSingleSource.java | 4 +- 83 files changed, 1210 insertions(+), 789 deletions(-) create mode 100644 ReleaseNotes/04_02_2024.txt create mode 100644 ReleaseNotes/04_03_2024.txt rename src/main/java/org/drip/graph/core/{DirectedGraph.java => Directed.java} (58%) rename src/main/java/org/drip/graph/core/{DirectedGraphType.java => DirectedType.java} (97%) create mode 100644 src/main/java/org/drip/numerical/matrix/R1SquareEigenized.java diff --git a/ReleaseNotes/04_02_2024.txt b/ReleaseNotes/04_02_2024.txt new file mode 100644 index 000000000000..c77113cf9dbd --- /dev/null +++ b/ReleaseNotes/04_02_2024.txt @@ -0,0 +1,61 @@ + +Features: + + - R^1 Square Matrix Spectral Radius (1) + - Eigenized R^1 Square Matrix #1 (2, 3, 4) + - Eigenized R^1 Square Matrix #2 (5, 6, 7) + - Eigenized R^1 Square Matrix Constructor (8, 9) + - Eigenized R^1 Square Matrix Eigencomponent (10, 11, 12) + - Eigenized R^1 Square Matrix Eigenize (13, 14) + - Eigenized R^1 Square Matrix SVD (15, 16) + - Eigenized R^1 Square Matrix Multiplicity (17, 18) + - Eigenized R^1 Square Matrix Determinant (19, 20) + - Eigenized R^1 Square Matrix L2 Condition Number (21, 22) + - Eigenized R^1 Square Matrix Characteristic Polynomial (23, 24) + - Eigenized R^1 Square Matrix Spectral Radius (25, 26) + - Numerical Eigenvalue/Vector Output Dimension (27, 28) + - Eigenized R^1 Square Standard #1 (29, 30, 31) + - Eigenized R^1 Square Standard #2 (32, 33, 34) + - Eigenized R^1 Square Standard #3 (35, 36, 37) + - Eigenized R^1 Square Standard #4 (38, 39, 40) + - Eigenized R^1 Square Standard #5 (41, 42, 43) + - Eigenized R^1 Square Generator #1 (44, 45, 46) + - Eigenized R^1 Square Generator #2 (47, 48, 49) + - Graph Core R1 Vertex Shell (50, 51, 52) + - Graph Core R1 Vertex Node Value (53, 54) + - Graph Core R1 Vertex Constructor (55, 56, 57) + - Graph Core Vertex Function Shell (58, 59) + - Graph Core Vertex Function R1 -> R1 (60, 61) + - Graph Core Vertex Function Constructor (62, 63, 64) + - Graph Vertex Function R1 Evaluate (65, 66, 67) + - Graph Vertex Function R1 Bounded (68, 69, 70) + - Directed R1 Function Graph Shell (73, 74) + - Directed Graph R1 Function Constructor (75, 76) + - Templated Graph Vertex Node Value (77, 78, 79) + - Standard, Non-templated Instance of Vertex (80, 81, 82) + - Untemplated Vertex Node Graph Network (83, 84, 85) + - Directed Graph Untemplated Vertex Node (86, 87) + - Templated Graph Network Format #1 (88, 89, 90) + - Templated Graph Network Format #2 (91, 92, 93) + - Templated Graph Network Format #3 (94, 95, 96) + - Templated Graph Network Format #4 (97, 98, 99) + - Templated Graph Network Format #5 (100, 101, 102) + - Templated Graph Network Format #6 (103, 104, 105) + - Templated Instance of Vertex Value (106, 107, 108) + - Graph Network Add Vertex Edge (109, 110) + - Graph Network Vertex Value Map (111, 112) + - Network Edge Vertex Value Map (113, 114, 115) + - Graph Tree Templated Vertex #1 (116, 117) + - Graph Tree Templated Vertex #2 (118, 119) + - Graph Tree Add Standalone Vertex (120) + + +Bug Fixes/Re-organization: + + - Core Directed Graph Type (71) + - Core Directed Graph Rename (72) + + +Samples: + +IdeaDRIP: diff --git a/ReleaseNotes/04_03_2024.txt b/ReleaseNotes/04_03_2024.txt new file mode 100644 index 000000000000..d452b6fede5f --- /dev/null +++ b/ReleaseNotes/04_03_2024.txt @@ -0,0 +1,92 @@ + +Features: + + - Graph Tree Add Standalone Vertex (1) + - Abbsord Graph Tree and Edge (2, 3) + - Graph Tree Edge Priority Queue (4, 5, 6) + - Graph Tree Templated Vertex (7, 8, 9) + - Directed Graph Untemplated Vertex #1 (10, 11, 12) + - Directed Graph Untemplated Vertex #2 (13, 14, 15) + - Directed Graph Untemplated Vertex #3 (16, 17, 18) + - Directed Graph Untemplated Vertex #4 (19, 20, 21) + - Directed Graph Untemplated Vertex #5 (22, 23, 24) + - Directed Graph Untemplated Vertex #6 (25, 26, 27) + - Directed Graph Untemplated Vertex #7 (28, 29, 30) + - Directed Graph Untemplated Vertex #8 (31, 32, 33) + - Directed Graph Untemplated Vertex #9 (34) + - Core Graph N Dimensional Hypercube (38, 39, 40) + - Greedy MST Graph Boruvka Forest (42, 43, 44) + - Boruvka Optimal Spanning Forest Generator (45, 46) + - Greedy MST Graph Kruskal Generator (47, 48) + - Greedy MST Graph Prime Generator (49, 50) + - Greedy MST Graph Reverse Delete Generator (51) + - Tree Builder Capacitated MST Generator (52) + - Tree Builder Degree Constrained MST Generator (53) + - Tree Builder Directed MST Generator (54) + - Tree Builder Dynamic MST Generator (55) + - Tree Builder Dynamic Euclidean Generator (56) + - Tree Builder Dynamic KSMT Generator (57) + - K Optimal Spanning Forests Generator (58) + - Optimal Bottleneck Spanning Tree Generator (59) + - Builder Optimal Labeling Spanning Tree Generator (60) + - Tree Builder Rectilinear MST Generator (61) + - Builder Steiner Tree Generator (62) + - Complete MST Random Graph Ensemble (63, 64, 65) + - Complete MST Random Graph (66) + - Bellman Ford Bannister Eppstein Path Generator (67) + - Bellman Ford Edge Partition Generator (68) + - Graph Shortest Optimal Path Generator (69) + - Graph Shortest Path Vertex Augmentor (70) + - Bellman Ford Edge Relaxation Path Generator (71) + - Bellman Ford Yen Edge Relaxation Path Generator (72) + - Bellman Ford Yen Reduced Relaxation Path Generator (73) + - Bellman Ford Johnson Path Generator (73) + - Bellman Ford Edge Partition (74, 75) + - Dijkstra Shortest Path Generator (76) + - Shortest Path Floyd Warshall (77) + - Shortest Path Floyd Warshall Distance Metric (78) + - Graph Search Breadth First (79) + - Graph Search Depth First (80) + - A Star Vertex Function (81) + - A Star Vertex Context (82, 83) + - A Star F Heuristic (84) + - A Star Static Weight F Heuristic (85) + - A Star Dynamic Weight F Heuristic (86) + - A Star Mark Allard F Heuristic (87) + - Graph Connectivity Kosaraju (88) + + +Bug Fixes/Re-organization: + + - Graph Core Vertex R1 Remove (35, 36) + - Graph Vertex R1 Function Remove (37) + - Directed Graph R1 Remove (41) + + +Samples: + + - MST Boruvka Maximum Forest Generator (89, 90) + - MST Boruvka Minimum Forest Generator (91, 92) + - MST Kruskal Maximum Forest Generator (93, 94) + - MST Kruskal Minimum Forest Generator (95, 96) + - MST Prim Maximum Forest Generator (97, 98) + - MST Prim Minimum Forest Generator (99, 100) + - MST Reverse Delete Maximum Forest Generator (101, 102) + - MST Reverse Delete Minimum Forest Generator (103, 104) + - Graph Properties (105) + - Graph Complete Bipartite Properties (106, 107, 108) + - Yen Reduced Relaxation Single Source (109) + - Yen Reduced Relaxation Single Pair (110) + - Yen Edge Partition Single Source (111) + - Yen Edge Partition Single Pair (112) + - Shortest Path Bannister Eppstein Single Source (113) + - Shortest Path Bannister Eppstein Single Pair (114) + - Shortest Path Bellman Ford Single Source (115) + - Shortest Path Bellman Ford Single Pair (116) + - Shortest Path Johnson Single Source (117) + - Shortest Path Johnson Single Pair (118) + - Shortest Path Johnson Single Source Negative Weight (119) + - Connectivity Kosaraju Strongly Connected Components (120) + + +IdeaDRIP: diff --git a/src/main/java/org/drip/graph/astar/DynamicWeightFHeuristic.java b/src/main/java/org/drip/graph/astar/DynamicWeightFHeuristic.java index 283ff0c77adf..c51dd82d299a 100644 --- a/src/main/java/org/drip/graph/astar/DynamicWeightFHeuristic.java +++ b/src/main/java/org/drip/graph/astar/DynamicWeightFHeuristic.java @@ -158,7 +158,7 @@ public static final DynamicWeightFHeuristic Pohl1970 ( new org.drip.graph.astar.VertexFunction() { @Override public double evaluate ( - final org.drip.graph.core.Vertex vertex) + final org.drip.graph.core.Vertex vertex) throws java.lang.Exception { double wHeuristicValue = 1. - ( @@ -239,7 +239,7 @@ public org.drip.graph.astar.VertexFunction wHeuristic() } @Override public double evaluate ( - final org.drip.graph.core.Vertex vertex) + final org.drip.graph.core.Vertex vertex) throws java.lang.Exception { return gHeuristic().evaluate ( diff --git a/src/main/java/org/drip/graph/astar/FHeuristic.java b/src/main/java/org/drip/graph/astar/FHeuristic.java index 8be2a66f806e..b76fa0ac7396 100644 --- a/src/main/java/org/drip/graph/astar/FHeuristic.java +++ b/src/main/java/org/drip/graph/astar/FHeuristic.java @@ -168,7 +168,7 @@ public org.drip.graph.astar.VertexFunction hHeuristic() } @Override public double evaluate ( - final org.drip.graph.core.Vertex vertex) + final org.drip.graph.core.Vertex vertex) throws java.lang.Exception { return _gHeuristic.evaluate ( @@ -190,7 +190,7 @@ public org.drip.graph.astar.VertexFunction hHeuristic() */ public boolean isMonotone ( - final org.drip.graph.core.Network graph, + final org.drip.graph.core.Network graph, final org.drip.graph.core.Edge edge) throws java.lang.Exception { @@ -203,7 +203,7 @@ public boolean isMonotone ( ); } - java.util.Map vertexMap = graph.vertexMap(); + java.util.Map> vertexMap = graph.vertexMap(); return evaluate ( vertexMap.get ( @@ -228,7 +228,7 @@ public boolean isMonotone ( */ public boolean isConsistent ( - final org.drip.graph.core.Network graph, + final org.drip.graph.core.Network graph, final org.drip.graph.core.Edge edge) throws java.lang.Exception { @@ -250,7 +250,7 @@ public boolean isConsistent ( */ public double reducedWeight ( - final org.drip.graph.core.Network graph, + final org.drip.graph.core.Network graph, final org.drip.graph.core.Edge edge) throws java.lang.Exception { @@ -263,7 +263,7 @@ public double reducedWeight ( ); } - java.util.Map vertexMap = graph.vertexMap(); + java.util.Map> vertexMap = graph.vertexMap(); return edge.weight() + evaluate ( vertexMap.get ( diff --git a/src/main/java/org/drip/graph/astar/MalikAllardFHeuristic.java b/src/main/java/org/drip/graph/astar/MalikAllardFHeuristic.java index 979fe9304e79..29fb49085237 100644 --- a/src/main/java/org/drip/graph/astar/MalikAllardFHeuristic.java +++ b/src/main/java/org/drip/graph/astar/MalikAllardFHeuristic.java @@ -202,7 +202,7 @@ public double nearAdmissibleHFLoading() } @Override public double evaluate ( - final org.drip.graph.core.Vertex vertex) + final org.drip.graph.core.Vertex vertex) throws java.lang.Exception { return _foundationFLoading * _foundationFHeuristic.evaluate ( diff --git a/src/main/java/org/drip/graph/astar/StaticWeightFHeuristic.java b/src/main/java/org/drip/graph/astar/StaticWeightFHeuristic.java index 86cf1f373bcb..817f323c5746 100644 --- a/src/main/java/org/drip/graph/astar/StaticWeightFHeuristic.java +++ b/src/main/java/org/drip/graph/astar/StaticWeightFHeuristic.java @@ -165,7 +165,7 @@ public double epsilon() } @Override public double evaluate ( - final org.drip.graph.core.Vertex vertex) + final org.drip.graph.core.Vertex vertex) throws java.lang.Exception { return gHeuristic().evaluate ( diff --git a/src/main/java/org/drip/graph/astar/VertexContext.java b/src/main/java/org/drip/graph/astar/VertexContext.java index f3ac077f5836..fe3f764c20d5 100644 --- a/src/main/java/org/drip/graph/astar/VertexContext.java +++ b/src/main/java/org/drip/graph/astar/VertexContext.java @@ -118,9 +118,9 @@ public class VertexContext { - private org.drip.graph.core.Vertex _parent = null; - private org.drip.graph.core.Vertex _current = null; - private org.drip.graph.core.Vertex _mostRecentlyExpanded = null; + private org.drip.graph.core.Vertex _parent = null; + private org.drip.graph.core.Vertex _current = null; + private org.drip.graph.core.Vertex _mostRecentlyExpanded = null; /** * VertexContext Constructor @@ -133,9 +133,9 @@ public class VertexContext */ public VertexContext ( - final org.drip.graph.core.Vertex current, - final org.drip.graph.core.Vertex parent, - final org.drip.graph.core.Vertex mostRecentlyExpanded) + final org.drip.graph.core.Vertex current, + final org.drip.graph.core.Vertex parent, + final org.drip.graph.core.Vertex mostRecentlyExpanded) throws java.lang.Exception { if (null == (_current = current) || @@ -156,7 +156,7 @@ public VertexContext ( * @return The Current Vertex */ - public org.drip.graph.core.Vertex current() + public org.drip.graph.core.Vertex current() { return _current; } @@ -167,7 +167,7 @@ public org.drip.graph.core.Vertex current() * @return The Parent Vertex */ - public org.drip.graph.core.Vertex parent() + public org.drip.graph.core.Vertex parent() { return _parent; } @@ -178,7 +178,7 @@ public org.drip.graph.core.Vertex parent() * @return The Most Recently Expanded Vertex */ - public org.drip.graph.core.Vertex mostRecentlyExpanded() + public org.drip.graph.core.Vertex mostRecentlyExpanded() { return _mostRecentlyExpanded; } diff --git a/src/main/java/org/drip/graph/astar/VertexFunction.java b/src/main/java/org/drip/graph/astar/VertexFunction.java index 4d5d087a5efc..d7617efcf6c0 100644 --- a/src/main/java/org/drip/graph/astar/VertexFunction.java +++ b/src/main/java/org/drip/graph/astar/VertexFunction.java @@ -129,6 +129,6 @@ public interface VertexFunction */ public abstract double evaluate ( - final org.drip.graph.core.Vertex vertex) + final org.drip.graph.core.Vertex vertex) throws java.lang.Exception; } diff --git a/src/main/java/org/drip/graph/bellmanford/BannisterEppsteinPathGenerator.java b/src/main/java/org/drip/graph/bellmanford/BannisterEppsteinPathGenerator.java index c41ea2509b54..e39d0f24fff6 100644 --- a/src/main/java/org/drip/graph/bellmanford/BannisterEppsteinPathGenerator.java +++ b/src/main/java/org/drip/graph/bellmanford/BannisterEppsteinPathGenerator.java @@ -129,7 +129,7 @@ public class BannisterEppsteinPathGenerator */ public BannisterEppsteinPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -141,7 +141,7 @@ public BannisterEppsteinPathGenerator ( ); } - @Override public org.drip.graph.bellmanford.EdgePartition edgePartition() + @Override public org.drip.graph.bellmanford.EdgePartition edgePartition() { return org.drip.graph.bellmanford.EdgePartition.FromGraph ( graph(), diff --git a/src/main/java/org/drip/graph/bellmanford/EdgePartition.java b/src/main/java/org/drip/graph/bellmanford/EdgePartition.java index f1815b1cc1be..e5e80ef54f49 100644 --- a/src/main/java/org/drip/graph/bellmanford/EdgePartition.java +++ b/src/main/java/org/drip/graph/bellmanford/EdgePartition.java @@ -113,11 +113,11 @@ * @author Lakshmi Krishnamurthy */ -public class EdgePartition +public class EdgePartition { private java.util.List _vertexNameList = null; - private org.drip.graph.core.DirectedGraph _forwardDirectedGraph = null; - private org.drip.graph.core.DirectedGraph _backwardDirectedGraph = null; + private org.drip.graph.core.Directed _forwardDirectedGraph = null; + private org.drip.graph.core.Directed _backwardDirectedGraph = null; private java.util.Map _vertexIndexMap = null; private static final java.util.List ShuffleVertexNameCollection ( @@ -148,8 +148,8 @@ private static final java.util.List ShuffleVertexNameCollectio * @return EdgePartition from a Graph */ - public static final EdgePartition FromGraph ( - final org.drip.graph.core.DirectedGraph graph, + public static EdgePartition FromGraph ( + final org.drip.graph.core.Directed graph, final boolean randomizeVertexes) { if (null == graph) @@ -185,9 +185,9 @@ public static final EdgePartition FromGraph ( ); } - org.drip.graph.core.DirectedGraph forwardDirectedGraph = new org.drip.graph.core.DirectedGraph(); + org.drip.graph.core.Directed forwardDirectedGraph = new org.drip.graph.core.Directed(); - org.drip.graph.core.DirectedGraph backwardDirectedGraph = new org.drip.graph.core.DirectedGraph(); + org.drip.graph.core.Directed backwardDirectedGraph = new org.drip.graph.core.Directed(); for (org.drip.graph.core.Edge edge : graph.edgeMap().values()) { @@ -218,7 +218,7 @@ public static final EdgePartition FromGraph ( try { - return new EdgePartition ( + return new EdgePartition ( vertexIndexMap, vertexNameList, forwardDirectedGraph, @@ -247,8 +247,8 @@ public static final EdgePartition FromGraph ( public EdgePartition ( final java.util.Map vertexIndexMap, final java.util.List vertexNameList, - final org.drip.graph.core.DirectedGraph forwardDirectedGraph, - final org.drip.graph.core.DirectedGraph backwardDirectedGraph) + final org.drip.graph.core.Directed forwardDirectedGraph, + final org.drip.graph.core.Directed backwardDirectedGraph) throws java.lang.Exception { if (null == (_vertexIndexMap = vertexIndexMap) || @@ -302,7 +302,7 @@ public java.util.List vertexNameList() * @return The Forward Directed Graph */ - public org.drip.graph.core.DirectedGraph forwardDirectedGraph() + public org.drip.graph.core.Directed forwardDirectedGraph() { return _forwardDirectedGraph; } @@ -313,7 +313,7 @@ public org.drip.graph.core.DirectedGraph forwardDirectedGraph() * @return The Backward Directed Graph */ - public org.drip.graph.core.DirectedGraph backwardDirectedGraph() + public org.drip.graph.core.Directed backwardDirectedGraph() { return _backwardDirectedGraph; } diff --git a/src/main/java/org/drip/graph/bellmanford/EdgePartitionGenerator.java b/src/main/java/org/drip/graph/bellmanford/EdgePartitionGenerator.java index 53a701225b0e..56bb095c1efd 100644 --- a/src/main/java/org/drip/graph/bellmanford/EdgePartitionGenerator.java +++ b/src/main/java/org/drip/graph/bellmanford/EdgePartitionGenerator.java @@ -119,7 +119,7 @@ public abstract class EdgePartitionGenerator { private static final boolean ProcessVertex ( - final org.drip.graph.core.Vertex vertex, + final org.drip.graph.core.Vertex vertex, final org.drip.graph.shortestpath.VertexAugmentor vertexAugmentor, final boolean shortestPath) { @@ -153,7 +153,7 @@ private static final boolean ProcessVertex ( private static final boolean ProcessSubgraph ( final int vertexCount, final boolean forward, - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final java.util.List vertexNameList, final org.drip.graph.shortestpath.VertexAugmentor vertexAugmentor, final boolean shortestPath) @@ -161,7 +161,7 @@ private static final boolean ProcessSubgraph ( int vertexIndex = forward ? 0 : vertexCount - 1; int finalVertexIndex = forward ? vertexCount - 1 : 0; - java.util.Map forwardVertexMap = graph.vertexMap(); + java.util.Map> forwardVertexMap = graph.vertexMap(); while (vertexIndex != finalVertexIndex) { @@ -202,11 +202,11 @@ private static final boolean ProcessSubgraph ( final org.drip.graph.shortestpath.VertexAugmentor vertexAugmentor, final org.drip.graph.bellmanford.VertexRelaxationControl vertexRelaxationControl) { - org.drip.graph.bellmanford.EdgePartition edgePartition = edgePartition(); + org.drip.graph.bellmanford.EdgePartition edgePartition = edgePartition(); java.util.List vertexNameList = edgePartition.vertexNameList(); - org.drip.graph.core.DirectedGraph graph = graph(); + org.drip.graph.core.Directed graph = graph(); boolean shortestPath = shortestPath(); @@ -230,7 +230,7 @@ private static final boolean ProcessSubgraph ( } protected EdgePartitionGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -248,5 +248,5 @@ protected EdgePartitionGenerator ( * @return The Edge Partition */ - public abstract org.drip.graph.bellmanford.EdgePartition edgePartition(); + public abstract org.drip.graph.bellmanford.EdgePartition edgePartition(); } diff --git a/src/main/java/org/drip/graph/bellmanford/EdgeRelaxationPathGenerator.java b/src/main/java/org/drip/graph/bellmanford/EdgeRelaxationPathGenerator.java index 166ec1da5919..8a6553e0a182 100644 --- a/src/main/java/org/drip/graph/bellmanford/EdgeRelaxationPathGenerator.java +++ b/src/main/java/org/drip/graph/bellmanford/EdgeRelaxationPathGenerator.java @@ -159,7 +159,7 @@ protected boolean relaxEdges ( { boolean shortestPath = shortestPath(); - org.drip.graph.core.DirectedGraph graph = graph(); + org.drip.graph.core.Directed graph = graph(); java.util.Map edgeMap = graph.edgeMap(); @@ -211,7 +211,7 @@ protected boolean relaxEdges ( */ public EdgeRelaxationPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -233,7 +233,7 @@ public EdgeRelaxationPathGenerator ( boolean shortestPath = shortestPath(); - org.drip.graph.core.DirectedGraph graph = graph(); + org.drip.graph.core.Directed graph = graph(); java.util.Set vertexNameSet = graph.vertexNameSet(); diff --git a/src/main/java/org/drip/graph/bellmanford/JohnsonPathGenerator.java b/src/main/java/org/drip/graph/bellmanford/JohnsonPathGenerator.java index efea9665ff01..e0f07a8355ab 100644 --- a/src/main/java/org/drip/graph/bellmanford/JohnsonPathGenerator.java +++ b/src/main/java/org/drip/graph/bellmanford/JohnsonPathGenerator.java @@ -112,7 +112,7 @@ * @author Lakshmi Krishnamurthy */ -public class JohnsonPathGenerator +public class JohnsonPathGenerator extends org.drip.graph.shortestpath.OptimalPathGenerator { @@ -127,7 +127,7 @@ public class JohnsonPathGenerator */ public JohnsonPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -147,9 +147,9 @@ public JohnsonPathGenerator ( return null; } - org.drip.graph.core.DirectedGraph graph = graph(); + org.drip.graph.core.Directed graph = graph(); - org.drip.graph.core.DirectedGraph graphClone = graph.clone(); + org.drip.graph.core.Directed graphClone = graph.clone(); java.util.Set vertexNameSet = graph.vertexNameSet(); @@ -197,7 +197,7 @@ public JohnsonPathGenerator ( return null; } - org.drip.graph.core.DirectedGraph bellmanFordGraph = new org.drip.graph.core.DirectedGraph(); + org.drip.graph.core.Directed bellmanFordGraph = new org.drip.graph.core.Directed(); java.util.Map augmentedVertexMap = bellmanFordVertexAugmentor.augmentedVertexMap(); diff --git a/src/main/java/org/drip/graph/bellmanford/YenEdgePartitionPathGenerator.java b/src/main/java/org/drip/graph/bellmanford/YenEdgePartitionPathGenerator.java index 3fc24b707c03..c2c87c802092 100644 --- a/src/main/java/org/drip/graph/bellmanford/YenEdgePartitionPathGenerator.java +++ b/src/main/java/org/drip/graph/bellmanford/YenEdgePartitionPathGenerator.java @@ -117,7 +117,7 @@ public class YenEdgePartitionPathGenerator extends org.drip.graph.bellmanford.EdgePartitionGenerator { - private org.drip.graph.bellmanford.EdgePartition _edgePartition = null; + private org.drip.graph.bellmanford.EdgePartition _edgePartition = null; /** * YenEdgePartitionPathGenerator Constructor @@ -130,7 +130,7 @@ public class YenEdgePartitionPathGenerator */ public YenEdgePartitionPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -153,7 +153,7 @@ public YenEdgePartitionPathGenerator ( } } - @Override public org.drip.graph.bellmanford.EdgePartition edgePartition() + @Override public org.drip.graph.bellmanford.EdgePartition edgePartition() { return _edgePartition; } diff --git a/src/main/java/org/drip/graph/bellmanford/YenReducedRelaxationPathGenerator.java b/src/main/java/org/drip/graph/bellmanford/YenReducedRelaxationPathGenerator.java index 292ce956b70a..c2f4ba969d95 100644 --- a/src/main/java/org/drip/graph/bellmanford/YenReducedRelaxationPathGenerator.java +++ b/src/main/java/org/drip/graph/bellmanford/YenReducedRelaxationPathGenerator.java @@ -138,7 +138,7 @@ public class YenReducedRelaxationPathGenerator */ public YenReducedRelaxationPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception diff --git a/src/main/java/org/drip/graph/connectivity/Kosaraju.java b/src/main/java/org/drip/graph/connectivity/Kosaraju.java index 2027f982dbe7..e579980ead4a 100644 --- a/src/main/java/org/drip/graph/connectivity/Kosaraju.java +++ b/src/main/java/org/drip/graph/connectivity/Kosaraju.java @@ -117,16 +117,16 @@ public class Kosaraju { - private org.drip.graph.core.Network _graph = null; + private org.drip.graph.core.Network _graph = null; private boolean updateVisitation ( - final org.drip.graph.core.Vertex vertex, + final org.drip.graph.core.Vertex vertex, final java.util.Map vertexVisitationIndicatorMap, final java.util.List componentVertexNameList) { java.lang.String vertexName = vertex.name(); - java.util.Map vertexMap = _graph.vertexMap(); + java.util.Map> vertexMap = _graph.vertexMap(); if (!vertexVisitationIndicatorMap.containsKey ( vertexName @@ -166,7 +166,7 @@ private boolean updateVisitation ( } private boolean assignComponent ( - final org.drip.graph.core.Vertex vertex, + final org.drip.graph.core.Vertex vertex, final java.lang.String rootVertexName, final java.util.Map vertexRootComponentMap) { @@ -181,7 +181,7 @@ private boolean assignComponent ( rootVertexName ); - java.util.Map vertexMap = _graph.vertexMap(); + java.util.Map> vertexMap = _graph.vertexMap(); java.util.Set neighboringVertexNameSet = vertex.neighboringVertexNameSet(); @@ -215,7 +215,7 @@ private boolean assignComponent ( */ public Kosaraju ( - final org.drip.graph.core.Network graph) + final org.drip.graph.core.Network graph) throws java.lang.Exception { if (null == (_graph = graph)) @@ -232,7 +232,7 @@ public Kosaraju ( * @return The Network Graph */ - public org.drip.graph.core.Network graph() + public org.drip.graph.core.Network graph() { return _graph; } @@ -245,7 +245,7 @@ public org.drip.graph.core.Network graph() public java.util.Map vertexRootComponentMap() { - java.util.Map vertexMap = _graph.vertexMap(); + java.util.Map> vertexMap = _graph.vertexMap(); if (0 == vertexMap.size()) { diff --git a/src/main/java/org/drip/graph/core/CompleteBipartite.java b/src/main/java/org/drip/graph/core/CompleteBipartite.java index 75424023ee9d..5e49658bf50d 100644 --- a/src/main/java/org/drip/graph/core/CompleteBipartite.java +++ b/src/main/java/org/drip/graph/core/CompleteBipartite.java @@ -110,8 +110,8 @@ * @author Lakshmi Krishnamurthy */ -public class CompleteBipartite - extends org.drip.graph.core.DirectedGraph +public class CompleteBipartite + extends org.drip.graph.core.Directed { private java.util.Set _vertexNameSetP = null; private java.util.Set _vertexNameSetQ = null; @@ -271,7 +271,7 @@ public int q() @Override public int type() { - return org.drip.graph.core.DirectedGraphType.COMPLETE_BIPARTITE; + return org.drip.graph.core.DirectedType.COMPLETE_BIPARTITE; } @Override public double spanningTreeCount() diff --git a/src/main/java/org/drip/graph/core/DirectedGraph.java b/src/main/java/org/drip/graph/core/Directed.java similarity index 58% rename from src/main/java/org/drip/graph/core/DirectedGraph.java rename to src/main/java/org/drip/graph/core/Directed.java index 1ce1d317d247..98fcdd7fd3da 100644 --- a/src/main/java/org/drip/graph/core/DirectedGraph.java +++ b/src/main/java/org/drip/graph/core/Directed.java @@ -1,6 +1,18 @@ package org.drip.graph.core; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.drip.analytics.support.CaseInsensitiveHashMap; +import org.drip.function.matrix.Square; +import org.drip.graph.search.BreadthFirst; +import org.drip.graph.search.OrderedVertexGroup; + /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ @@ -76,8 +88,7 @@ */ /** - * DirectedGraph implements the Vertex/Edge Topology corresponding to a Directed Graph. The References - * are: + * Directed implements the Vertex/Edge Topology corresponding to a Directed Graph. The References are: * *

*
    @@ -111,15 +122,14 @@ * @author Lakshmi Krishnamurthy */ -public class DirectedGraph - extends org.drip.graph.core.Network +public class Directed extends Network { /** - * DirectedGraph Constructor + * Directed Constructor */ - public DirectedGraph() + public Directed() { super(); } @@ -133,27 +143,20 @@ public DirectedGraph() */ public boolean addGraph ( - final org.drip.graph.core.DirectedGraph graph) + final Directed graph) { - if (null == graph) - { + if (null == graph) { return false; } - java.util.Collection edgeCollection = - graph.edgeMap().values(); + Collection edgeCollection = graph.edgeMap().values(); - if (null == edgeCollection || 0 == edgeCollection.size()) - { + if (null == edgeCollection || 0 == edgeCollection.size()) { return true; } - for (org.drip.graph.core.Edge edge : edgeCollection) - { - if (!addEdge ( - edge - )) - { + for (Edge edge : edgeCollection) { + if (!addEdge (edge)) { return false; } } @@ -167,18 +170,14 @@ public boolean addGraph ( * @return The Cloned Graph */ - public DirectedGraph clone() + public Directed clone() { - DirectedGraph clone = new DirectedGraph(); + Directed clone = new Directed(); - java.util.Collection edgeCollection = edgeMap().values(); + Collection edgeCollection = edgeMap().values(); - for (org.drip.graph.core.Edge edge : edgeCollection) - { - if (!clone.addEdge ( - edge - )) - { + for (Edge edge : edgeCollection) { + if (!clone.addEdge (edge)) { return null; } } @@ -194,30 +193,19 @@ public DirectedGraph clone() public boolean isConnected() { - if (_vertexMap.isEmpty()) - { + if (_vertexMap.isEmpty()) { return false; } - java.util.Set vertexNameSet = _vertexMap.keySet(); + Set vertexNameSet = _vertexMap.keySet(); - org.drip.graph.search.OrderedVertexGroup orderedSearch = - new org.drip.graph.search.OrderedVertexGroup(); + OrderedVertexGroup orderedSearch = new OrderedVertexGroup(); - try - { - if (!new org.drip.graph.search.BreadthFirst ( - this - ).nonRecursive ( - initialVertexName(), - orderedSearch - )) - { + try { + if (!new BreadthFirst (this).nonRecursive (initialVertexName(), orderedSearch)) { return false; } - } - catch (java.lang.Exception e) - { + } catch (Exception e) { e.printStackTrace(); } @@ -233,34 +221,24 @@ public boolean isConnected() */ public boolean isTreeSpanning ( - final org.drip.graph.core.Tree tree) + final Tree tree) { - if (null == tree) - { + if (null == tree) { return false; } - java.util.Set graphVertexNameSet = new java.util.HashSet(); + Set graphVertexNameSet = new HashSet(); - for (org.drip.graph.core.Vertex graphVertex : _vertexMap.values()) - { - graphVertexNameSet.add ( - graphVertex.name() - ); + for (Vertex graphVertex : _vertexMap.values()) { + graphVertexNameSet.add (graphVertex.name()); } - for (java.lang.String treeVertexName : tree.vertexMap().keySet()) - { - if (!graphVertexNameSet.contains ( - treeVertexName - )) - { + for (String treeVertexName : tree.vertexMap().keySet()) { + if (!graphVertexNameSet.contains (treeVertexName)) { return false; } - graphVertexNameSet.remove ( - treeVertexName - ); + graphVertexNameSet.remove (treeVertexName); } return 0 == graphVertexNameSet.size(); @@ -274,31 +252,21 @@ public boolean isTreeSpanning ( * @return Set of the Fundamental Cycles using the Spanning Tree */ - public java.util.Set fundamentalCycleEdgeSet ( - final org.drip.graph.core.Tree tree) + public Set fundamentalCycleEdgeSet ( + final Tree tree) { - if (null == tree) - { + if (null == tree) { return null; } - java.util.Set edgeSet = - new java.util.HashSet ( - _edgeMap.values() - ); + Set edgeSet =new HashSet (_edgeMap.values()); - for (org.drip.graph.core.Edge edge : tree.edgeMap().values()) - { - if (!containsEdge ( - edge - )) - { + for (Edge edge : tree.edgeMap().values()) { + if (!containsEdge (edge)) { return null; } - edgeSet.remove ( - edge - ); + edgeSet.remove (edge); } return edgeSet; @@ -310,18 +278,13 @@ public java.util.Set fundamentalCycleEdgeSet ( * @return List of the Leaf Vertex Names */ - public java.util.List leafVertexNameList() + public List leafVertexNameList() { - java.util.List leafVertexNameList = new java.util.ArrayList(); + List leafVertexNameList = new ArrayList(); - for (java.util.Map.Entry vertexMapEntry : - _vertexMap.entrySet()) - { - if (vertexMapEntry.getValue().isLeaf()) - { - leafVertexNameList.add ( - vertexMapEntry.getKey() - ); + for (Map.Entry> vertexMapEntry : _vertexMap.entrySet()) { + if (vertexMapEntry.getValue().isLeaf()) { + leafVertexNameList.add (vertexMapEntry.getKey()); } } @@ -336,37 +299,24 @@ public java.util.List leafVertexNameList() public boolean containsCycle() { - java.util.List leafVertexNameList = leafVertexNameList(); + List leafVertexNameList = leafVertexNameList(); - if (null == leafVertexNameList || 0 == leafVertexNameList.size()) - { + if (null == leafVertexNameList || 0 == leafVertexNameList.size()) { return true; } - for (java.lang.String leafVertexName : leafVertexNameList) - { - org.drip.graph.search.OrderedVertexGroup orderedSearch = - new org.drip.graph.search.OrderedVertexGroup(); - - try - { - if (!new org.drip.graph.search.BreadthFirst ( - this - ).nonRecursive ( - leafVertexName, - orderedSearch - )) - { + for (String leafVertexName : leafVertexNameList) { + OrderedVertexGroup orderedSearch = new OrderedVertexGroup(); + + try { + if (!new BreadthFirst (this).nonRecursive (leafVertexName, orderedSearch)) { return false; } - } - catch (java.lang.Exception e) - { + } catch (Exception e) { e.printStackTrace(); } - if (orderedSearch.containsCycle()) - { + if (orderedSearch.containsCycle()) { return true; } } @@ -382,7 +332,7 @@ public boolean containsCycle() public boolean isCyclical() { - java.util.List leafVertexNameList = leafVertexNameList(); + List leafVertexNameList = leafVertexNameList(); return null == leafVertexNameList || 0 == leafVertexNameList.size() ? true : false; } @@ -406,25 +356,15 @@ public boolean isTree() public boolean isComplete() { - java.util.Set graphVertexNameSet = _vertexMap.keySet(); + Set graphVertexNameSet = _vertexMap.keySet(); - for (java.util.Map.Entry vertexMapEntry : - _vertexMap.entrySet()) - { - java.lang.String vertexName = vertexMapEntry.getKey(); - - java.util.Set neighborSet = - vertexMapEntry.getValue().neighboringVertexNameSet(); - - for (java.lang.String graphVertexName : graphVertexNameSet) - { - if (!neighborSet.contains ( - vertexName - ) && !graphVertexName.equalsIgnoreCase ( - vertexName - ) - ) - { + for (Map.Entry> vertexMapEntry : _vertexMap.entrySet()) { + String vertexName = vertexMapEntry.getKey(); + + Set neighborSet = vertexMapEntry.getValue().neighboringVertexNameSet(); + + for (String graphVertexName : graphVertexNameSet) { + if (!neighborSet.contains (vertexName) && !graphVertexName.equalsIgnoreCase (vertexName)) { return false; } } @@ -443,13 +383,7 @@ public boolean isDense() { int vertexCount = _vertexMap.size(); - return 0.5 * _edgeMap.size() >= vertexCount * java.lang.Math.log ( - java.lang.Math.log ( - java.lang.Math.log ( - vertexCount - ) - ) - ); + return 0.5 * _edgeMap.size() >= vertexCount * Math.log (Math.log (Math.log (vertexCount))); } /** @@ -458,16 +392,12 @@ public boolean isDense() * @return Map of the Vertex Adjacency Degree */ - public java.util.Map vertexDegreeMap() + public Map vertexDegreeMap() { - java.util.Map vertexDegreeMap = - new org.drip.analytics.support.CaseInsensitiveHashMap(); + Map vertexDegreeMap = new CaseInsensitiveHashMap(); - for (java.util.Map.Entry vertexMapEntry : - _vertexMap.entrySet()) - { - java.util.Set neighboringVertexNameSet = - vertexMapEntry.getValue().neighboringVertexNameSet(); + for (Map.Entry> vertexMapEntry : _vertexMap.entrySet()) { + Set neighboringVertexNameSet = vertexMapEntry.getValue().neighboringVertexNameSet(); vertexDegreeMap.put ( vertexMapEntry.getKey(), @@ -488,8 +418,8 @@ public java.util.Map vertexDegreeMap() */ public boolean areVertexesAdjacent ( - final java.lang.String vertexName1, - final java.lang.String vertexName2) + final String vertexName1, + final String vertexName2) { if (null == vertexName1 || vertexName1.isEmpty() || null == vertexName2 || vertexName2.isEmpty()) @@ -497,9 +427,7 @@ public boolean areVertexesAdjacent ( return false; } - return _edgeMap.containsKey ( - vertexName1 + "_" + vertexName2 - ); + return _edgeMap.containsKey (vertexName1 + "_" + vertexName2); } /** @@ -510,22 +438,19 @@ public boolean areVertexesAdjacent ( public int type() { - if (isTree()) - { - return org.drip.graph.core.DirectedGraphType.TREE; + if (isTree()) { + return DirectedType.TREE; } - if (isCyclical()) - { - return org.drip.graph.core.DirectedGraphType.CYCLICAL; + if (isCyclical()) { + return DirectedType.CYCLICAL; } - if (isComplete()) - { - return org.drip.graph.core.DirectedGraphType.COMPLETE; + if (isComplete()) { + return DirectedType.COMPLETE; } - return org.drip.graph.core.DirectedGraphType.UNSPECIFIED; + return DirectedType.UNSPECIFIED; } /** @@ -536,47 +461,32 @@ public int type() public double kirchoffSpanningTreeCount() { - java.util.Map vertexDegreeMap = vertexDegreeMap(); + Map vertexDegreeMap = vertexDegreeMap(); - java.util.Set vertexNameSetI = vertexDegreeMap.keySet(); + Set vertexNameSetI = vertexDegreeMap.keySet(); - java.util.Set vertexNameSetJ = vertexDegreeMap.keySet(); + Set vertexNameSetJ = vertexDegreeMap.keySet(); int vertexCount = vertexDegreeMap.size(); double[][] laplacianMatrix = new double[vertexCount][vertexCount]; double[][] laplacianMatrixCoFactor = new double[vertexCount - 1][vertexCount - 1]; - for (int vertexIndexI = 0; - vertexIndexI < vertexCount; - ++vertexIndexI) - { - for (int vertexIndexJ = 0; - vertexIndexJ < vertexCount; - ++vertexIndexJ) - { + for (int vertexIndexI = 0; vertexIndexI < vertexCount; ++vertexIndexI) { + for (int vertexIndexJ = 0; vertexIndexJ < vertexCount; ++vertexIndexJ) { laplacianMatrix[vertexIndexI][vertexIndexJ] = 0.; } } int vertexIndexI = 0; - for (java.lang.String vertexNameI : vertexNameSetI) - { + for (String vertexNameI : vertexNameSetI) { int vertexIndexJ = 0; - for (java.lang.String vertexNameJ : vertexNameSetJ) - { - if (vertexNameI.equalsIgnoreCase ( - vertexNameJ - )) - { - laplacianMatrix[vertexIndexI][vertexIndexJ] = vertexDegreeMap.get ( - vertexNameI - ); - } - else - { + for (String vertexNameJ : vertexNameSetJ) { + if (vertexNameI.equalsIgnoreCase (vertexNameJ)) { + laplacianMatrix[vertexIndexI][vertexIndexJ] = vertexDegreeMap.get (vertexNameI); + } else { laplacianMatrix[vertexIndexI][vertexIndexJ] = areVertexesAdjacent ( vertexNameI, vertexNameJ @@ -589,27 +499,16 @@ public double kirchoffSpanningTreeCount() ++vertexIndexI; } - for (vertexIndexI = 0; - vertexIndexI < vertexCount - 1; - ++vertexIndexI) - { - for (int vertexIndexJ = 0; - vertexIndexJ < vertexCount - 1; - ++vertexIndexJ) - { + for (vertexIndexI = 0; vertexIndexI < vertexCount - 1; ++vertexIndexI) { + for (int vertexIndexJ = 0; vertexIndexJ < vertexCount - 1; ++vertexIndexJ) { laplacianMatrixCoFactor[vertexIndexI][vertexIndexJ] = laplacianMatrix[vertexIndexI][vertexIndexJ]; } } - try - { - return new org.drip.function.matrix.Square ( - laplacianMatrixCoFactor - ).determinant(); - } - catch (java.lang.Exception e) - { + try { + return new Square (laplacianMatrixCoFactor).determinant(); + } catch (Exception e) { e.printStackTrace(); } @@ -624,31 +523,24 @@ public double kirchoffSpanningTreeCount() public double spanningTreeCount() { - if (!isConnected()) - { + if (!isConnected()) { return 0; } int type = type(); - if (type == org.drip.graph.core.DirectedGraphType.TREE) - { + if (type == DirectedType.TREE) { return 1; } - if (type == org.drip.graph.core.DirectedGraphType.CYCLICAL) - { + if (type == DirectedType.CYCLICAL) { return _vertexMap.size(); } - if (type == org.drip.graph.core.DirectedGraphType.COMPLETE) - { + if (type == DirectedType.COMPLETE) { int n = _vertexMap.size(); - return java.lang.Math.pow ( - n, - n - 2 - ); + return Math.pow (n, n - 2); } return kirchoffSpanningTreeCount(); @@ -660,36 +552,24 @@ public double spanningTreeCount() * @return The Transposed Graph */ - public DirectedGraph Transpose() + public Directed Transpose() { - java.util.Collection edgeCollection = _edgeMap.values(); + Collection edgeCollection = _edgeMap.values(); - DirectedGraph directedGraphTranspose = new DirectedGraph(); + Directed directedGraphTranspose = new Directed(); - if (!edgeCollection.isEmpty()) - { - for (org.drip.graph.core.Edge edge : edgeCollection) - { - if (!directedGraphTranspose.addEdge ( - edge.invert() - )) - { + if (!edgeCollection.isEmpty()) { + for (Edge edge : edgeCollection) { + if (!directedGraphTranspose.addEdge (edge.invert())) { return null; } } - } - else - { - java.util.Collection vertexCollection = _vertexMap.values(); - - if (!vertexCollection.isEmpty()) - { - for (org.drip.graph.core.Vertex vertex : vertexCollection) - { - if (!directedGraphTranspose.addVertex ( - vertex.name() - )) - { + } else { + Collection> vertexCollection = _vertexMap.values(); + + if (!vertexCollection.isEmpty()) { + for (Vertex vertex : vertexCollection) { + if (!directedGraphTranspose.addVertex (vertex.name())) { return null; } } diff --git a/src/main/java/org/drip/graph/core/DirectedGraphType.java b/src/main/java/org/drip/graph/core/DirectedType.java similarity index 97% rename from src/main/java/org/drip/graph/core/DirectedGraphType.java rename to src/main/java/org/drip/graph/core/DirectedType.java index 23d592d2c53a..b1263407aaf8 100644 --- a/src/main/java/org/drip/graph/core/DirectedGraphType.java +++ b/src/main/java/org/drip/graph/core/DirectedType.java @@ -76,7 +76,7 @@ */ /** - * DirectedGraphType holds the Pre-specified Directed Graph Types. The References are: + * DirectedType holds the Pre-specified Directed Graph Types. The References are: * *

    *
      @@ -110,7 +110,7 @@ * @author Lakshmi Krishnamurthy */ -public class DirectedGraphType +public class DirectedType { /** @@ -148,5 +148,4 @@ public class DirectedGraphType */ public static final int N_DIMENSIONAL_HYPERCUBE = 16; - } diff --git a/src/main/java/org/drip/graph/core/Forest.java b/src/main/java/org/drip/graph/core/Forest.java index 460fc5edd65a..53d60a10eac0 100644 --- a/src/main/java/org/drip/graph/core/Forest.java +++ b/src/main/java/org/drip/graph/core/Forest.java @@ -110,10 +110,10 @@ * @author Lakshmi Krishnamurthy */ -public class Forest +public class Forest { private java.util.Set _vertexSet = null; - private java.util.Map _treeMap = null; + private java.util.Map> _treeMap = null; private java.util.Map _containingTreeNameMap = null; /** @@ -124,7 +124,7 @@ public Forest() { _vertexSet = new java.util.HashSet(); - _treeMap = new org.drip.analytics.support.CaseInsensitiveHashMap(); + _treeMap = new org.drip.analytics.support.CaseInsensitiveHashMap>(); _containingTreeNameMap = new org.drip.analytics.support.CaseInsensitiveHashMap(); } @@ -135,7 +135,7 @@ public Forest() * @return Map of Trees in the Forest */ - public java.util.Map treeMap() + public java.util.Map> treeMap() { return _treeMap; } @@ -173,7 +173,7 @@ public java.util.Set vertexSet() public boolean unitVertexTree ( final java.lang.String vertexName, - final org.drip.graph.core.DirectedGraph graph) + final org.drip.graph.core.Directed graph) { if (null == vertexName || vertexName.isEmpty() || null == graph) @@ -181,7 +181,7 @@ public boolean unitVertexTree ( return false; } - org.drip.graph.core.Tree tree = new org.drip.graph.core.Tree(); + org.drip.graph.core.Tree tree = new org.drip.graph.core.Tree(); if (!tree.addStandaloneVertex ( vertexName @@ -215,8 +215,8 @@ public boolean unitVertexTree ( public boolean addTree ( final java.lang.String treeName, - final org.drip.graph.core.Tree tree, - final org.drip.graph.core.DirectedGraph graph) + final org.drip.graph.core.Tree tree, + final org.drip.graph.core.Directed graph) { if (null == treeName || _treeMap.containsKey ( treeName @@ -284,7 +284,7 @@ public boolean containsVertex ( * @return Tree that contains the specified Vertex */ - public org.drip.graph.core.Tree containingTree ( + public org.drip.graph.core.Tree containingTree ( final java.lang.String vertexName) { return containsVertex ( @@ -307,7 +307,7 @@ public org.drip.graph.core.Tree containingTree ( public boolean conditionalMerge ( final org.drip.graph.core.Edge edge, - final org.drip.graph.core.DirectedGraph graph) + final org.drip.graph.core.Directed graph) { if (null == edge || null == graph) @@ -344,7 +344,7 @@ public boolean conditionalMerge ( return true; } - org.drip.graph.core.Tree destinationTree = _treeMap.get ( + org.drip.graph.core.Tree destinationTree = _treeMap.get ( destinationTreeName ); @@ -385,7 +385,7 @@ public double length() { double length = 0.; - for (org.drip.graph.core.Tree tree : _treeMap.values()) + for (org.drip.graph.core.Tree tree : _treeMap.values()) { length = length + tree.length(); } diff --git a/src/main/java/org/drip/graph/core/NDimensionalHypercube.java b/src/main/java/org/drip/graph/core/NDimensionalHypercube.java index 2f92a8dc6896..49236dfd50cf 100644 --- a/src/main/java/org/drip/graph/core/NDimensionalHypercube.java +++ b/src/main/java/org/drip/graph/core/NDimensionalHypercube.java @@ -1,6 +1,8 @@ package org.drip.graph.core; +import org.drip.numerical.common.NumberUtil; + /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ @@ -110,8 +112,7 @@ * @author Lakshmi Krishnamurthy */ -public class NDimensionalHypercube - extends org.drip.graph.core.DirectedGraph +public class NDimensionalHypercube extends Directed { /** @@ -145,7 +146,7 @@ public NDimensionalHypercube() @Override public int type() { - return org.drip.graph.core.DirectedGraphType.N_DIMENSIONAL_HYPERCUBE; + return DirectedType.N_DIMENSIONAL_HYPERCUBE; } @Override public double spanningTreeCount() @@ -154,25 +155,10 @@ public NDimensionalHypercube() double spanningTreeCount = 1.; - for (int k = 2; - k <= n; - ++k) - { - spanningTreeCount = spanningTreeCount * java.lang.Math.pow ( - k, - org.drip.numerical.common.NumberUtil.NCK ( - n, - k - ) - ); + for (int k = 2; k <= n; ++k) { + spanningTreeCount = spanningTreeCount * Math.pow (k, NumberUtil.NCK (n, k)); } - return spanningTreeCount * java.lang.Math.pow ( - 2, - java.lang.Math.pow ( - 2, - n - ) - n - 1 - ); + return spanningTreeCount * Math.pow (2, Math.pow (2, n) - n - 1); } } diff --git a/src/main/java/org/drip/graph/core/Network.java b/src/main/java/org/drip/graph/core/Network.java index 58def084b9b2..cf4060445235 100644 --- a/src/main/java/org/drip/graph/core/Network.java +++ b/src/main/java/org/drip/graph/core/Network.java @@ -1,6 +1,13 @@ package org.drip.graph.core; +import java.util.Map; +import java.util.Set; + +import org.drip.analytics.support.CaseInsensitiveHashMap; +import org.drip.graph.heap.BinomialTreePriorityQueue; +import org.drip.graph.heap.PriorityQueue; + /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ @@ -111,89 +118,91 @@ * @author Lakshmi Krishnamurthy */ -abstract public class Network +abstract public class Network { - private java.lang.String _initialVertexName = ""; + private String _initialVertexName = ""; - protected java.util.Map _edgeMap = null; - protected java.util.Map _vertexMap = null; + protected Map _edgeMap = null; + protected Map> _vertexMap = null; - protected java.lang.String addVertexEdge ( - final org.drip.graph.core.Edge edge) + protected String addVertexEdge ( + final Edge edge) { - java.lang.String edgeKey = ""; + String edgeKey = ""; - java.lang.String sourceVertexName = edge.sourceVertexName(); + String sourceVertexName = edge.sourceVertexName(); - java.lang.String destinationVertexName = edge.destinationVertexName(); + String destinationVertexName = edge.destinationVertexName(); - if (_vertexMap.containsKey ( - sourceVertexName - )) - { - edgeKey = _vertexMap.get ( - sourceVertexName - ).addEdge ( - edge - ); - } - else - { - try - { - org.drip.graph.core.Vertex vertex = new org.drip.graph.core.Vertex ( - sourceVertexName - ); - - edgeKey = vertex.addEdge ( - edge - ); - - _vertexMap.put ( - sourceVertexName, - vertex - ); + if (_vertexMap.containsKey (sourceVertexName)) { + edgeKey = _vertexMap.get (sourceVertexName).addEdge (edge); + } else { + try { + Vertex vertex = Vertex.Standard (sourceVertexName); + + edgeKey = vertex.addEdge (edge); + + _vertexMap.put (sourceVertexName, vertex); + } catch (Exception e) { + e.printStackTrace(); + + return null; } - catch (java.lang.Exception e) - { + } + + if (!_vertexMap.containsKey (destinationVertexName)) { + addVertex (destinationVertexName); + } + + return edgeKey; + } + + protected String addVertexEdge ( + final Edge edge, + final Map vertexValueMap) + { + String edgeKey = ""; + + String sourceVertexName = edge.sourceVertexName(); + + String destinationVertexName = edge.destinationVertexName(); + + if (_vertexMap.containsKey (sourceVertexName)) { + edgeKey = _vertexMap.get (sourceVertexName).addEdge (edge); + } else { + try { + Vertex vertex = new Vertex (sourceVertexName, vertexValueMap.get (sourceVertexName)); + + edgeKey = vertex.addEdge (edge); + + _vertexMap.put (sourceVertexName, vertex); + } catch (Exception e) { e.printStackTrace(); return null; } } - if (!_vertexMap.containsKey ( - destinationVertexName - )) - { - addVertex ( - destinationVertexName - ); + if (!_vertexMap.containsKey (destinationVertexName)) { + addVertex (destinationVertexName, vertexValueMap.get (destinationVertexName)); } return edgeKey; } protected boolean removeVertexEdge ( - final java.lang.String vertexName, - final java.lang.String edgeKey) + final String vertexName, + final String edgeKey) { - return _vertexMap.containsKey ( - vertexName - ) ? _vertexMap.get ( - vertexName - ).removeEdge ( - edgeKey - ) : true; + return _vertexMap.containsKey (vertexName) ? + _vertexMap.get (vertexName).removeEdge (edgeKey) : true; } protected Network() { - _edgeMap = - new org.drip.analytics.support.CaseInsensitiveHashMap(); + _edgeMap = new CaseInsensitiveHashMap(); - _vertexMap = - new org.drip.analytics.support.CaseInsensitiveHashMap(); + _vertexMap = new CaseInsensitiveHashMap>(); } /** @@ -202,7 +211,7 @@ protected Network() * @return The Vertex Map */ - public java.util.Map vertexMap() + public Map> vertexMap() { return _vertexMap; } @@ -213,7 +222,7 @@ public java.util.Map vertexMap() * @return The Edge Map */ - public java.util.Map edgeMap() + public Map edgeMap() { return _edgeMap; } @@ -224,7 +233,7 @@ public java.util.Map edgeMap() * @return The Initial Vertex Name */ - public java.lang.String initialVertexName() + public String initialVertexName() { return _initialVertexName; } @@ -257,7 +266,7 @@ public int vertexCount() * @return The Set of Vertex Names */ - public java.util.Set vertexNameSet() + public Set vertexNameSet() { return _vertexMap.keySet(); } @@ -271,33 +280,51 @@ public java.util.Set vertexNameSet() */ public boolean addVertex ( - final java.lang.String vertexName) + final String vertexName) { - if (null == vertexName || vertexName.isEmpty() || - _vertexMap.containsKey ( - vertexName - ) - ) - { + if (null == vertexName || vertexName.isEmpty() || _vertexMap.containsKey (vertexName)) { return false; } - if (_initialVertexName.isEmpty()) - { + if (_initialVertexName.isEmpty()) { _initialVertexName = vertexName; } - try - { - _vertexMap.put ( - vertexName, - new org.drip.graph.core.Vertex ( - vertexName - ) - ); + try { + _vertexMap.put (vertexName, Vertex.Standard (vertexName)); + } catch (Exception e) { + e.printStackTrace(); + + return false; } - catch (java.lang.Exception e) - { + + return true; + } + + /** + * Add a Vertex to the Network + * + * @param vertexName The Vertex Name + * @param vertexValue The Vertex Value + * + * @return TRUE - The Vertex successfully added to the Network + */ + + public boolean addVertex ( + final String vertexName, + final V vertexValue) + { + if (null == vertexName || vertexName.isEmpty() || _vertexMap.containsKey (vertexName)) { + return false; + } + + if (_initialVertexName.isEmpty()) { + _initialVertexName = vertexName; + } + + try { + _vertexMap.put (vertexName, new Vertex (vertexName, vertexValue)); + } catch (Exception e) { e.printStackTrace(); return false; @@ -315,51 +342,87 @@ public boolean addVertex ( */ public boolean addEdge ( - final org.drip.graph.core.Edge edge) + final Edge edge) { - if (null == edge) - { + if (null == edge) { return false; } - java.lang.String edgeKey = addVertexEdge ( - edge - ); + String edgeKey = addVertexEdge (edge); - if (null == edgeKey || edgeKey.isEmpty()) - { + if (null == edgeKey || edgeKey.isEmpty()) { return false; } - if (_initialVertexName.isEmpty()) - { + if (_initialVertexName.isEmpty()) { _initialVertexName = edge.sourceVertexName(); } - _edgeMap.put ( - edgeKey, - edge - ); + _edgeMap.put (edgeKey, edge); return true; } + /** + * Add an Edge to the Network + * + * @param edge The Edge + * @param vertexValueMap Vertex Value Map + * + * @return TRUE - The Edge successfully added + */ + + public boolean addEdge ( + final Edge edge, + final Map vertexValueMap) + { + if (null == edge) { + return false; + } + + String edgeKey = addVertexEdge (edge, vertexValueMap); + + if (null == edgeKey || edgeKey.isEmpty()) { + return false; + } + + if (_initialVertexName.isEmpty()) { + _initialVertexName = edge.sourceVertexName(); + } + + _edgeMap.put (edgeKey, edge); + + return true; + } + + /** + * Add a Bidirectional Edge to the Network + * + * @param edge The Bidirectional Edge + * + * @return TRUE - The Bidirectional Edge successfully added + */ + + public boolean addBidirectionalEdge ( + final Edge edge) + { + return addEdge (edge) && addEdge (edge.invert()); + } + /** * Add a Bidirectional Edge to the Network * * @param edge The Bidirectional Edge + * @param vertexValueMap Vertex Value Map * * @return TRUE - The Bidirectional Edge successfully added */ public boolean addBidirectionalEdge ( - final org.drip.graph.core.Edge edge) + final Edge edge, + final Map vertexValueMap) { - return addEdge ( - edge - ) && addEdge ( - edge.invert() - ); + return addEdge (edge, vertexValueMap) && addEdge (edge.invert(), vertexValueMap); } /** @@ -371,30 +434,15 @@ public boolean addBidirectionalEdge ( */ public boolean removeEdge ( - final java.lang.String edgeKey) + final String edgeKey) { - if (null == edgeKey || - !_edgeMap.containsKey ( - edgeKey - ) - ) - { - return false; - } - - if (!removeVertexEdge ( - _edgeMap.get ( - edgeKey - ).sourceVertexName(), - edgeKey - )) + if (null == edgeKey || !_edgeMap.containsKey (edgeKey) || + !removeVertexEdge (_edgeMap.get (edgeKey).sourceVertexName(), edgeKey)) { return false; } - _edgeMap.remove ( - edgeKey - ); + _edgeMap.remove (edgeKey); return true; } @@ -407,21 +455,14 @@ public boolean removeEdge ( * @return The Edge Priority Queue */ - public org.drip.graph.heap.PriorityQueue edgePriorityQueue ( + public PriorityQueue edgePriorityQueue ( final boolean minHeap) { - org.drip.graph.heap.PriorityQueue edgePriorityQueue = - new org.drip.graph.heap.BinomialTreePriorityQueue ( - minHeap - ); + PriorityQueue edgePriorityQueue = + new BinomialTreePriorityQueue (minHeap); - for (java.util.Map.Entry edgeMapEntry : - _edgeMap.entrySet()) - { - edgePriorityQueue.insert ( - edgeMapEntry.getValue().weight(), - edgeMapEntry.getKey() - ); + for (Map.Entry edgeMapEntry : _edgeMap.entrySet()) { + edgePriorityQueue.insert (edgeMapEntry.getValue().weight(), edgeMapEntry.getKey()); } return edgePriorityQueue; @@ -447,11 +488,9 @@ public boolean isEmpty() */ public boolean containsVertex ( - final java.lang.String vertexName) + final String vertexName) { - return null != vertexName && _vertexMap.containsKey ( - vertexName - ); + return null != vertexName && _vertexMap.containsKey (vertexName); } /** @@ -464,8 +503,7 @@ public double length() { double length = 0.; - for (org.drip.graph.core.Edge edge : _edgeMap.values()) - { + for (Edge edge : _edgeMap.values()) { length = length + edge.weight(); } @@ -481,13 +519,10 @@ public double length() */ public boolean isEdgeACycle ( - final org.drip.graph.core.Edge edge) + final Edge edge) { - return null == edge ? false : _vertexMap.containsKey ( - edge.sourceVertexName() - ) && _vertexMap.containsKey ( - edge.destinationVertexName() - ); + return null != edge && _vertexMap.containsKey (edge.sourceVertexName()) && + _vertexMap.containsKey (edge.destinationVertexName()); } /** @@ -499,19 +534,14 @@ public boolean isEdgeACycle ( */ public boolean containsEdge ( - final org.drip.graph.core.Edge edgeOther) + final Edge edgeOther) { - if (null == edgeOther) - { + if (null == edgeOther) { return false; } - for (org.drip.graph.core.Edge edge : _edgeMap.values()) - { - if (edge.compareWith ( - edgeOther - )) - { + for (Edge edge : _edgeMap.values()) { + if (edge.compareWith (edgeOther)) { return true; } } diff --git a/src/main/java/org/drip/graph/core/Tree.java b/src/main/java/org/drip/graph/core/Tree.java index 1c2a1a2f40b4..b5a291cf4385 100644 --- a/src/main/java/org/drip/graph/core/Tree.java +++ b/src/main/java/org/drip/graph/core/Tree.java @@ -1,6 +1,12 @@ package org.drip.graph.core; +import java.util.Collection; +import java.util.Map; + +import org.drip.graph.heap.BinomialTreePriorityQueue; +import org.drip.graph.heap.PriorityQueue; + /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ @@ -110,8 +116,7 @@ * @author Lakshmi Krishnamurthy */ -public class Tree - extends org.drip.graph.core.Network +public class Tree extends Network { /** @@ -132,27 +137,45 @@ public Tree() */ public boolean addStandaloneVertex ( - final java.lang.String vertexName) + final String vertexName) { - if (null == vertexName || vertexName.isEmpty() || - !_vertexMap.isEmpty() || - !_edgeMap.isEmpty() - ) - { + if (null == vertexName || vertexName.isEmpty() || !_vertexMap.isEmpty() || !_edgeMap.isEmpty()) { return false; } - try - { - _vertexMap.put ( - vertexName, - new org.drip.graph.core.Vertex ( - vertexName - ) - ); + try { + _vertexMap.put (vertexName, Vertex.Standard (vertexName)); + } catch (Exception e) { + e.printStackTrace(); + + return false; } - catch (java.lang.Exception e) + + return true; + } + + /** + * Add a Stand-alone Vertex to the Network + * + * @param vertexName The Stand-alone Vertex Name + * @param vertexValueMap Vertex Value Map + * + * @return TRUE - The Stand-alone Vertex successfully added to the Network + */ + + public boolean addStandaloneVertex ( + final String vertexName, + final Map vertexValueMap) + { + if (null == vertexName || vertexName.isEmpty() || !_vertexMap.isEmpty() || !_edgeMap.isEmpty() | + null == vertexValueMap) { + return false; + } + + try { + _vertexMap.put (vertexName, new Vertex (vertexName, vertexValueMap.get (vertexName))); + } catch (Exception e) { e.printStackTrace(); return false; @@ -171,31 +194,55 @@ public boolean addStandaloneVertex ( */ public boolean absorbTreeAndEdge ( - final org.drip.graph.core.Tree tree, - final org.drip.graph.core.Edge edge) + final Tree tree, + final Edge edge) { - if (null == tree || - !addEdge ( - edge - ) - ) - { + if (null == tree || !addEdge (edge)) { return false; } - java.util.Collection treeEdgeCollection = tree.edgeMap().values(); + Collection treeEdgeCollection = tree.edgeMap().values(); - if (null == treeEdgeCollection || 0 == treeEdgeCollection.size()) - { + if (null == treeEdgeCollection || 0 == treeEdgeCollection.size()) { return true; } - for (org.drip.graph.core.Edge treeEdge : treeEdgeCollection) - { - if (!addEdge ( - treeEdge - )) - { + for (Edge treeEdge : treeEdgeCollection) { + if (!addEdge (treeEdge)) { + return false; + } + } + + return true; + } + + /** + * Absorb the Specified Tree and Edge + * + * @param tree The Tree + * @param edge The Edge + * @param vertexValueMap Vertex Value Map + * + * @return TRUE - The Tree and Edge successfully absorbed + */ + + public boolean absorbTreeAndEdge ( + final Tree tree, + final Edge edge, + final Map vertexValueMap) + { + if (null == tree || !addEdge (edge, vertexValueMap)) { + return false; + } + + Collection treeEdgeCollection = tree.edgeMap().values(); + + if (null == treeEdgeCollection || 0 == treeEdgeCollection.size()) { + return true; + } + + for (Edge treeEdge : treeEdgeCollection) { + if (!addEdge (treeEdge, vertexValueMap)) { return false; } } @@ -206,71 +253,52 @@ public boolean absorbTreeAndEdge ( /** * Construct and Retrieve the Edge Priority Queue from the Graph * - * @param graph The Graph + * @param network The Graph Network * @param minHeap TRUE - The Edge Priority Queue is in the Descending Order of Distance * * @return The Tree Adjacency Map */ - public org.drip.graph.heap.PriorityQueue edgePriorityQueue ( - final org.drip.graph.core.DirectedGraph graph, + public PriorityQueue edgePriorityQueue ( + final Network network, final boolean minHeap) { - if (null == graph) - { + if (null == network) { return null; } - java.util.Map graphEdgeMap = graph.edgeMap(); + Map graphEdgeMap = network.edgeMap(); - java.util.Map graphVertexMap = graph.vertexMap(); + Map> graphVertexMap = network.vertexMap(); - org.drip.graph.heap.PriorityQueue edgePriorityQueue = - new org.drip.graph.heap.BinomialTreePriorityQueue ( - minHeap - ); + PriorityQueue edgePriorityQueue = + new BinomialTreePriorityQueue (minHeap); - for (java.lang.String vertexName : _vertexMap.keySet()) - { - if (!graphVertexMap.containsKey ( - vertexName - )) - { + for (String vertexName : _vertexMap.keySet()) { + if (!graphVertexMap.containsKey (vertexName)) { return null; } - org.drip.graph.core.Vertex vertex = graphVertexMap.get ( - vertexName - ); + Vertex vertex = graphVertexMap.get (vertexName); - if (vertex.isLeaf()) - { + if (vertex.isLeaf()) { continue; } - for (java.lang.String graphEdgeKey : vertex.edgeMap().keySet()) - { - org.drip.graph.core.Edge graphEdge = graphEdgeMap.get ( - graphEdgeKey - ); + for (String graphEdgeKey : vertex.edgeMap().keySet()) { + Edge graphEdge = graphEdgeMap.get (graphEdgeKey); - java.lang.String sourceVertexName = graphEdge.sourceVertexName(); + String sourceVertexName = graphEdge.sourceVertexName(); - java.lang.String destinationVertexName = graphEdge.destinationVertexName(); + String destinationVertexName = graphEdge.destinationVertexName(); - if (_vertexMap.containsKey ( - sourceVertexName - ) && _vertexMap.containsKey ( - destinationVertexName - )) + if (_vertexMap.containsKey (sourceVertexName) && + _vertexMap.containsKey (destinationVertexName)) { continue; } - edgePriorityQueue.insert ( - graphEdge.weight(), - graphEdge - ); + edgePriorityQueue.insert (graphEdge.weight(), graphEdge); } } @@ -283,27 +311,21 @@ public org.drip.graph.heap.PriorityQueue edgeMap = edgeMap(); + Map edgeMap = edgeMap(); - if (null == edgeMap || 0 == edgeMap.size()) - { + if (null == edgeMap || 0 == edgeMap.size()) { return null; } - org.drip.graph.core.Edge bottleneckEdge = null; + Edge bottleneckEdge = null; - for (org.drip.graph.core.Edge edge : edgeMap.values()) - { - if (null == bottleneckEdge) - { + for (Edge edge : edgeMap.values()) { + if (null == bottleneckEdge) { bottleneckEdge = edge; - } - else - { - if (edge.weight() > bottleneckEdge.weight()) - { + } else { + if (edge.weight() > bottleneckEdge.weight()) { bottleneckEdge = edge; } } @@ -318,27 +340,21 @@ public org.drip.graph.core.Edge maximumBottleneckEdge() * @return The Minimum Bottleneck Edge of the Tree */ - public org.drip.graph.core.Edge minimumBottleneckEdge() + public Edge minimumBottleneckEdge() { - java.util.Map edgeMap = edgeMap(); + Map edgeMap = edgeMap(); - if (null == edgeMap || 0 == edgeMap.size()) - { + if (null == edgeMap || 0 == edgeMap.size()) { return null; } - org.drip.graph.core.Edge bottleneckEdge = null; + Edge bottleneckEdge = null; - for (org.drip.graph.core.Edge edge : edgeMap.values()) - { - if (null == bottleneckEdge) - { + for (Edge edge : edgeMap.values()) { + if (null == bottleneckEdge) { bottleneckEdge = edge; - } - else - { - if (edge.weight() < bottleneckEdge.weight()) - { + } else { + if (edge.weight() < bottleneckEdge.weight()) { bottleneckEdge = edge; } } diff --git a/src/main/java/org/drip/graph/core/Vertex.java b/src/main/java/org/drip/graph/core/Vertex.java index 23f59300862f..b41f606bc7af 100644 --- a/src/main/java/org/drip/graph/core/Vertex.java +++ b/src/main/java/org/drip/graph/core/Vertex.java @@ -111,12 +111,32 @@ * @author Lakshmi Krishnamurthy */ -public class Vertex +public class Vertex { + private V _value = null; private java.lang.String _name = ""; private java.util.Map _edgeMap = null; private java.util.Map _destinationCounterMap = null; + /** + * Construct a Standard, Non-templated Instance of Vertex + * + * @param name Vertex Name + * + * @return Standard, Non-templated Instance of Vertex + */ + + public static Vertex Standard ( + final String name) + { + try { + return new Vertex<> (name, null); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } private int incrementDestinationEdgeCounterMap ( final java.lang.String destinationVertexName) @@ -175,12 +195,14 @@ private boolean decrementDestinationEdgeCounterMap ( * Vertex Constructor * * @param name The Vertex Name + * @param value The Vertex Value * * @throws java.lang.Exception Thrown if the Inputs are Invalid */ public Vertex ( - final java.lang.String name) + final java.lang.String name, + final V value) throws java.lang.Exception { if (null == (_name = name) || _name.isEmpty()) @@ -190,6 +212,8 @@ public Vertex ( ); } + _value = value; + _edgeMap = new org.drip.analytics.support.CaseInsensitiveHashMap(); _destinationCounterMap = new org.drip.analytics.support.CaseInsensitiveHashMap(); @@ -206,6 +230,17 @@ public java.lang.String name() return _name; } + /** + * Retrieve the Vertex Value + * + * @return The Vertex Value + */ + + public V value() + { + return _value; + } + /** * Retrieve the Destination Edge Counter Map * diff --git a/src/main/java/org/drip/graph/mst/CompleteRandomGraph.java b/src/main/java/org/drip/graph/mst/CompleteRandomGraph.java index 319430b415fd..228e40f9ac70 100644 --- a/src/main/java/org/drip/graph/mst/CompleteRandomGraph.java +++ b/src/main/java/org/drip/graph/mst/CompleteRandomGraph.java @@ -116,8 +116,8 @@ * @author Lakshmi Krishnamurthy */ -public class CompleteRandomGraph - extends org.drip.graph.core.DirectedGraph +public class CompleteRandomGraph + extends org.drip.graph.core.Directed { private org.drip.measure.crng.RandomNumberGenerator _randomNumberGenerator = null; @@ -129,12 +129,12 @@ public class CompleteRandomGraph * @return Uniform Instance of the Complete Random Graph */ - public static final CompleteRandomGraph Uniform ( + public static CompleteRandomGraph Uniform ( final int vertexCount) { try { - return new CompleteRandomGraph ( + return new CompleteRandomGraph ( vertexCount, new org.drip.measure.crng.RandomNumberGenerator() ); diff --git a/src/main/java/org/drip/graph/mst/CompleteRandomGraphEnsemble.java b/src/main/java/org/drip/graph/mst/CompleteRandomGraphEnsemble.java index 2e4f5c26b412..73823ca9ba76 100644 --- a/src/main/java/org/drip/graph/mst/CompleteRandomGraphEnsemble.java +++ b/src/main/java/org/drip/graph/mst/CompleteRandomGraphEnsemble.java @@ -115,9 +115,9 @@ * @author Lakshmi Krishnamurthy */ -public class CompleteRandomGraphEnsemble +public class CompleteRandomGraphEnsemble { - private org.drip.graph.mst.CompleteRandomGraph _completeRandomGraph = null; + private org.drip.graph.mst.CompleteRandomGraph _completeRandomGraph = null; private org.drip.graph.treebuilder.OptimalSpanningForestGenerator _minimumSpanningForestGenerator = null; /** @@ -128,14 +128,14 @@ public class CompleteRandomGraphEnsemble * @return The CompleteRandomGraphEnsemble Instance */ - public static final CompleteRandomGraphEnsemble Prim ( - final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) + public static CompleteRandomGraphEnsemble Prim ( + final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) { try { - return new CompleteRandomGraphEnsemble ( + return new CompleteRandomGraphEnsemble ( completeRandomGraph, - new org.drip.graph.mstgreedy.PrimGenerator ( + new org.drip.graph.mstgreedy.PrimGenerator ( completeRandomGraph, false ) @@ -157,14 +157,14 @@ public static final CompleteRandomGraphEnsemble Prim ( * @return The CompleteRandomGraphEnsemble Instance */ - public static final CompleteRandomGraphEnsemble Kruskal ( - final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) + public static CompleteRandomGraphEnsemble Kruskal ( + final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) { try { - return new CompleteRandomGraphEnsemble ( + return new CompleteRandomGraphEnsemble ( completeRandomGraph, - new org.drip.graph.mstgreedy.KruskalGenerator ( + new org.drip.graph.mstgreedy.KruskalGenerator ( completeRandomGraph, false ) @@ -186,14 +186,14 @@ public static final CompleteRandomGraphEnsemble Kruskal ( * @return The CompleteRandomGraphEnsemble Instance */ - public static final CompleteRandomGraphEnsemble ReverseDelete ( - final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) + public static CompleteRandomGraphEnsemble ReverseDelete ( + final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) { try { - return new CompleteRandomGraphEnsemble ( + return new CompleteRandomGraphEnsemble ( completeRandomGraph, - new org.drip.graph.mstgreedy.ReverseDeleteGenerator ( + new org.drip.graph.mstgreedy.ReverseDeleteGenerator ( completeRandomGraph, false ) @@ -215,14 +215,14 @@ public static final CompleteRandomGraphEnsemble ReverseDelete ( * @return The CompleteRandomGraphEnsemble Instance */ - public static final CompleteRandomGraphEnsemble Boruvka ( - final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) + public static CompleteRandomGraphEnsemble Boruvka ( + final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph) { try { - return new CompleteRandomGraphEnsemble ( + return new CompleteRandomGraphEnsemble ( completeRandomGraph, - new org.drip.graph.mstgreedy.BoruvkaGenerator ( + new org.drip.graph.mstgreedy.BoruvkaGenerator ( completeRandomGraph, false ) @@ -246,7 +246,7 @@ public static final CompleteRandomGraphEnsemble Boruvka ( */ public CompleteRandomGraphEnsemble ( - final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph, + final org.drip.graph.mst.CompleteRandomGraph completeRandomGraph, final org.drip.graph.treebuilder.OptimalSpanningForestGenerator minimumSpanningForestGenerator) throws java.lang.Exception { @@ -266,7 +266,7 @@ public CompleteRandomGraphEnsemble ( * @return The Underlying Complete Random Graph */ - public org.drip.graph.mst.CompleteRandomGraph completeRandomGraph() + public org.drip.graph.mst.CompleteRandomGraph completeRandomGraph() { return _completeRandomGraph; } @@ -293,7 +293,7 @@ public org.drip.graph.treebuilder.OptimalSpanningForestGenerator minimumSpanning public double length() throws java.lang.Exception { - org.drip.graph.core.Forest minimumSpanningForest = + org.drip.graph.core.Forest minimumSpanningForest = _minimumSpanningForestGenerator.optimalSpanningForest(); if (null == minimumSpanningForest) diff --git a/src/main/java/org/drip/graph/mstgreedy/BoruvkaForest.java b/src/main/java/org/drip/graph/mstgreedy/BoruvkaForest.java index 551731e1ec13..494a293528dc 100644 --- a/src/main/java/org/drip/graph/mstgreedy/BoruvkaForest.java +++ b/src/main/java/org/drip/graph/mstgreedy/BoruvkaForest.java @@ -111,17 +111,17 @@ * @author Lakshmi Krishnamurthy */ -public class BoruvkaForest - extends org.drip.graph.mstgreedy.KruskalForest +public class BoruvkaForest + extends org.drip.graph.mstgreedy.KruskalForest { private java.util.Map _treeNameDistanceMap = null; - private org.drip.graph.heap.PriorityQueue + private org.drip.graph.heap.PriorityQueue> _orderedTreePriorityQueue = null; private boolean updateOrderedTreeMap ( final java.lang.String treeName, - final org.drip.graph.core.Tree tree, - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Tree tree, + final org.drip.graph.core.Directed graph, final boolean descending) { org.drip.graph.heap.PriorityQueue edgePriorityQueue = @@ -151,7 +151,7 @@ private boolean updateOrderedTreeMap ( private boolean updateOrderedTreeMap ( final java.lang.String sourceTreeName, final java.lang.String destinationTreeName, - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean minHeap) { _orderedTreePriorityQueue.delete ( @@ -170,7 +170,7 @@ private boolean updateOrderedTreeMap ( destinationTreeName ); - org.drip.graph.core.Tree sourceTree = treeMap().get ( + org.drip.graph.core.Tree sourceTree = treeMap().get ( sourceTreeName ); @@ -212,7 +212,7 @@ public BoruvkaForest ( _treeNameDistanceMap = new org.drip.analytics.support.CaseInsensitiveHashMap(); _orderedTreePriorityQueue = - new org.drip.graph.heap.BinomialTreePriorityQueue ( + new org.drip.graph.heap.BinomialTreePriorityQueue> ( minHeap ); } @@ -228,7 +228,7 @@ public BoruvkaForest ( public boolean unitVertexTree ( final java.lang.String vertexName, - final org.drip.graph.core.DirectedGraph graph) + final org.drip.graph.core.Directed graph) { return super.unitVertexTree ( vertexName, @@ -256,8 +256,8 @@ public boolean unitVertexTree ( public boolean addTree ( final java.lang.String treeName, - final org.drip.graph.core.Tree tree, - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Tree tree, + final org.drip.graph.core.Directed graph, final boolean descending) { return super.addTree ( @@ -282,7 +282,7 @@ public boolean addTree ( */ public boolean conditionalBoruvkaMerge ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) { org.drip.graph.core.Edge edge = _orderedTreePriorityQueue.extremum().item().edgePriorityQueue ( diff --git a/src/main/java/org/drip/graph/mstgreedy/BoruvkaGenerator.java b/src/main/java/org/drip/graph/mstgreedy/BoruvkaGenerator.java index e9382c1c4dbc..3e6906c2c2b8 100644 --- a/src/main/java/org/drip/graph/mstgreedy/BoruvkaGenerator.java +++ b/src/main/java/org/drip/graph/mstgreedy/BoruvkaGenerator.java @@ -116,7 +116,7 @@ * @author Lakshmi Krishnamurthy */ -public class BoruvkaGenerator +public class BoruvkaGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { @@ -130,7 +130,7 @@ public class BoruvkaGenerator */ public BoruvkaGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { @@ -140,13 +140,13 @@ public BoruvkaGenerator ( ); } - @Override public org.drip.graph.core.Forest optimalSpanningForest() + @Override public org.drip.graph.core.Forest optimalSpanningForest() { java.util.Set vertexNameSet = _graph.vertexMap().keySet(); boolean maximum = maximum(); - org.drip.graph.mstgreedy.BoruvkaForest forest = new org.drip.graph.mstgreedy.BoruvkaForest ( + org.drip.graph.mstgreedy.BoruvkaForest forest = new org.drip.graph.mstgreedy.BoruvkaForest ( !maximum ); diff --git a/src/main/java/org/drip/graph/mstgreedy/KruskalForest.java b/src/main/java/org/drip/graph/mstgreedy/KruskalForest.java index e8b83349fbbd..4716e8c9d6f6 100644 --- a/src/main/java/org/drip/graph/mstgreedy/KruskalForest.java +++ b/src/main/java/org/drip/graph/mstgreedy/KruskalForest.java @@ -111,8 +111,8 @@ * @author Lakshmi Krishnamurthy */ -public class KruskalForest - extends org.drip.graph.core.Forest +public class KruskalForest + extends org.drip.graph.core.Forest { /** diff --git a/src/main/java/org/drip/graph/mstgreedy/KruskalGenerator.java b/src/main/java/org/drip/graph/mstgreedy/KruskalGenerator.java index 15034007a7b4..9bab84d32ffe 100644 --- a/src/main/java/org/drip/graph/mstgreedy/KruskalGenerator.java +++ b/src/main/java/org/drip/graph/mstgreedy/KruskalGenerator.java @@ -114,7 +114,7 @@ * @author Lakshmi Krishnamurthy */ -public class KruskalGenerator +public class KruskalGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { @@ -128,7 +128,7 @@ public class KruskalGenerator */ public KruskalGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { @@ -138,9 +138,9 @@ public KruskalGenerator ( ); } - @Override public org.drip.graph.core.Forest optimalSpanningForest() + @Override public org.drip.graph.core.Forest optimalSpanningForest() { - org.drip.graph.core.Forest forest = new org.drip.graph.mstgreedy.KruskalForest(); + org.drip.graph.core.Forest forest = new org.drip.graph.mstgreedy.KruskalForest(); for (java.lang.String vertexName : _graph.vertexMap().keySet()) { diff --git a/src/main/java/org/drip/graph/mstgreedy/PrimGenerator.java b/src/main/java/org/drip/graph/mstgreedy/PrimGenerator.java index 4e2de23f7be6..3daceeb71e0b 100644 --- a/src/main/java/org/drip/graph/mstgreedy/PrimGenerator.java +++ b/src/main/java/org/drip/graph/mstgreedy/PrimGenerator.java @@ -119,7 +119,7 @@ * @author Lakshmi Krishnamurthy */ -public class PrimGenerator +public class PrimGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { @@ -129,7 +129,7 @@ private boolean updateEdgePriorityQueue ( final java.util.Set visitedVertexSet, final java.lang.String currentVertexName) { - org.drip.graph.core.Vertex currentVertex = _graph.vertexMap().get ( + org.drip.graph.core.Vertex currentVertex = _graph.vertexMap().get ( currentVertexName ); @@ -155,7 +155,7 @@ private boolean updateEdgePriorityQueue ( } private java.lang.String uncoveredVertex ( - final org.drip.graph.core.Forest forest) + final org.drip.graph.core.Forest forest) { java.util.Set graphVertexNameSet = _graph.vertexNameSet(); @@ -184,7 +184,7 @@ private java.lang.String uncoveredVertex ( */ public PrimGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { @@ -202,7 +202,7 @@ public PrimGenerator ( * @return The Minimum Spanning Tree */ - public org.drip.graph.core.Tree minimumSpanningTree ( + public org.drip.graph.core.Tree minimumSpanningTree ( final java.lang.String initialVertexName) { if (null == initialVertexName || initialVertexName.isEmpty()) @@ -210,7 +210,7 @@ public org.drip.graph.core.Tree minimumSpanningTree ( return null; } - org.drip.graph.core.Tree minimumSpanningTree = new org.drip.graph.core.Tree(); + org.drip.graph.core.Tree minimumSpanningTree = new org.drip.graph.core.Tree(); java.util.Set visitedVertexSet = new java.util.HashSet(); @@ -266,10 +266,10 @@ public org.drip.graph.core.Tree minimumSpanningTree ( * @return The Minimum Spanning Forest */ - public org.drip.graph.core.Forest minimumSpanningForest ( + public org.drip.graph.core.Forest minimumSpanningForest ( final java.lang.String initialVertexName) { - org.drip.graph.core.Tree minimumSpanningTreeInitial = minimumSpanningTree ( + org.drip.graph.core.Tree minimumSpanningTreeInitial = minimumSpanningTree ( initialVertexName ); @@ -278,7 +278,7 @@ public org.drip.graph.core.Forest minimumSpanningForest ( return null; } - org.drip.graph.core.Forest forest = new org.drip.graph.core.Forest(); + org.drip.graph.core.Forest forest = new org.drip.graph.core.Forest(); if (!forest.addTree ( initialVertexName, @@ -295,7 +295,7 @@ public org.drip.graph.core.Forest minimumSpanningForest ( while (!uncoveredVertex.isEmpty()) { - org.drip.graph.core.Tree minimumSpanningTree = minimumSpanningTree ( + org.drip.graph.core.Tree minimumSpanningTree = minimumSpanningTree ( initialVertexName ); @@ -318,7 +318,7 @@ public org.drip.graph.core.Forest minimumSpanningForest ( return forest; } - @Override public org.drip.graph.core.Forest optimalSpanningForest() + @Override public org.drip.graph.core.Forest optimalSpanningForest() { java.lang.String initialVertexName = _graph.initialVertexName(); diff --git a/src/main/java/org/drip/graph/mstgreedy/ReverseDeleteGenerator.java b/src/main/java/org/drip/graph/mstgreedy/ReverseDeleteGenerator.java index 6726c8795cbe..f5352be4c292 100644 --- a/src/main/java/org/drip/graph/mstgreedy/ReverseDeleteGenerator.java +++ b/src/main/java/org/drip/graph/mstgreedy/ReverseDeleteGenerator.java @@ -113,7 +113,7 @@ * @author Lakshmi Krishnamurthy */ -public class ReverseDeleteGenerator +public class ReverseDeleteGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { @@ -127,7 +127,7 @@ public class ReverseDeleteGenerator */ public ReverseDeleteGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { @@ -137,7 +137,7 @@ public ReverseDeleteGenerator ( ); } - @Override public org.drip.graph.core.Forest optimalSpanningForest() + @Override public org.drip.graph.core.Forest optimalSpanningForest() { if (!_graph.isConnected()) { @@ -178,7 +178,7 @@ public ReverseDeleteGenerator ( try { - return new org.drip.graph.mstgreedy.KruskalGenerator ( + return new org.drip.graph.mstgreedy.KruskalGenerator ( _graph, maximum ).optimalSpanningForest(); diff --git a/src/main/java/org/drip/graph/search/BreadthFirst.java b/src/main/java/org/drip/graph/search/BreadthFirst.java index 86a47b73ee34..53642097df2b 100644 --- a/src/main/java/org/drip/graph/search/BreadthFirst.java +++ b/src/main/java/org/drip/graph/search/BreadthFirst.java @@ -114,7 +114,7 @@ public class BreadthFirst { - private org.drip.graph.core.Network _network = null; + private org.drip.graph.core.Network _network = null; /** * BreadthFirst Constructor @@ -125,7 +125,7 @@ public class BreadthFirst */ public BreadthFirst ( - final org.drip.graph.core.Network network) + final org.drip.graph.core.Network network) throws java.lang.Exception { if (null == (_network = network)) @@ -142,7 +142,7 @@ public BreadthFirst ( * @return The Graph Network */ - public org.drip.graph.core.Network network() + public org.drip.graph.core.Network network() { return _network; } @@ -174,7 +174,7 @@ public boolean nonRecursive ( vertexName ); - java.util.Map vertexMap = _network.vertexMap(); + java.util.Map> vertexMap = _network.vertexMap(); while (!processVertexList.isEmpty()) { @@ -189,7 +189,7 @@ public boolean nonRecursive ( return false; } - org.drip.graph.core.Vertex currentVertex = vertexMap.get ( + org.drip.graph.core.Vertex currentVertex = vertexMap.get ( currentVertexName ); diff --git a/src/main/java/org/drip/graph/search/DepthFirst.java b/src/main/java/org/drip/graph/search/DepthFirst.java index 82856aa4171f..0535044d3940 100644 --- a/src/main/java/org/drip/graph/search/DepthFirst.java +++ b/src/main/java/org/drip/graph/search/DepthFirst.java @@ -115,7 +115,7 @@ public class DepthFirst { - private org.drip.graph.core.Network _network = null; + private org.drip.graph.core.Network _network = null; /** * DepthFirst Constructor @@ -126,7 +126,7 @@ public class DepthFirst */ public DepthFirst ( - final org.drip.graph.core.Network network) + final org.drip.graph.core.Network network) throws java.lang.Exception { if (null == (_network = network)) @@ -143,7 +143,7 @@ public DepthFirst ( * @return The Graph Network */ - public org.drip.graph.core.Network network() + public org.drip.graph.core.Network network() { return _network; } @@ -173,7 +173,7 @@ public boolean recursive ( vertexName ); - org.drip.graph.core.Vertex vertex = _network.vertexMap().get ( + org.drip.graph.core.Vertex vertex = _network.vertexMap().get ( vertexName ); @@ -237,7 +237,7 @@ public boolean nonRecursive ( vertexName ); - java.util.Map vertexMap = _network.vertexMap(); + java.util.Map> vertexMap = _network.vertexMap(); while (!processVertexList.isEmpty()) { @@ -258,7 +258,7 @@ public boolean nonRecursive ( return false; } - org.drip.graph.core.Vertex currentVertex = vertexMap.get ( + org.drip.graph.core.Vertex currentVertex = vertexMap.get ( currentVertexName ); diff --git a/src/main/java/org/drip/graph/shortestpath/DijkstraPathGenerator.java b/src/main/java/org/drip/graph/shortestpath/DijkstraPathGenerator.java index 85a6b997d2b4..a4be8d0f8392 100644 --- a/src/main/java/org/drip/graph/shortestpath/DijkstraPathGenerator.java +++ b/src/main/java/org/drip/graph/shortestpath/DijkstraPathGenerator.java @@ -130,7 +130,7 @@ public class DijkstraPathGenerator */ public DijkstraPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -158,7 +158,7 @@ public DijkstraPathGenerator ( boolean shortestPath = shortestPath(); - java.util.Map vertexMap = graph().vertexMap(); + java.util.Map> vertexMap = graph().vertexMap(); org.drip.graph.shortestpath.VertexAugmentor vertexAugmentor = null; diff --git a/src/main/java/org/drip/graph/shortestpath/FloydWarshall.java b/src/main/java/org/drip/graph/shortestpath/FloydWarshall.java index 76d24a138423..20b3f20c23b8 100644 --- a/src/main/java/org/drip/graph/shortestpath/FloydWarshall.java +++ b/src/main/java/org/drip/graph/shortestpath/FloydWarshall.java @@ -117,7 +117,7 @@ public class FloydWarshall { private boolean _shortestPath = false; - private org.drip.graph.core.DirectedGraph _graph = null; + private org.drip.graph.core.Directed _graph = null; private org.drip.graph.astar.FHeuristic _fHeuristic = null; /** @@ -131,7 +131,7 @@ public class FloydWarshall */ public FloydWarshall ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -153,7 +153,7 @@ public FloydWarshall ( * @return Graph underlying the Path Generator */ - public org.drip.graph.core.DirectedGraph graph() + public org.drip.graph.core.Directed graph() { return _graph; } diff --git a/src/main/java/org/drip/graph/shortestpath/FloydWarshallDistanceMatrix.java b/src/main/java/org/drip/graph/shortestpath/FloydWarshallDistanceMatrix.java index 39022c9a326a..8fb9fbee85bc 100644 --- a/src/main/java/org/drip/graph/shortestpath/FloydWarshallDistanceMatrix.java +++ b/src/main/java/org/drip/graph/shortestpath/FloydWarshallDistanceMatrix.java @@ -128,7 +128,7 @@ public class FloydWarshallDistanceMatrix */ public static final FloydWarshallDistanceMatrix FromGraph ( - final org.drip.graph.core.DirectedGraph graph) + final org.drip.graph.core.Directed graph) { if (null == graph || graph.isEmpty()) { diff --git a/src/main/java/org/drip/graph/shortestpath/OptimalPathGenerator.java b/src/main/java/org/drip/graph/shortestpath/OptimalPathGenerator.java index 8c19b7cdad56..90cafeb8bab5 100644 --- a/src/main/java/org/drip/graph/shortestpath/OptimalPathGenerator.java +++ b/src/main/java/org/drip/graph/shortestpath/OptimalPathGenerator.java @@ -116,11 +116,11 @@ public abstract class OptimalPathGenerator { private boolean _shortestPath = false; - private org.drip.graph.core.DirectedGraph _graph = null; + private org.drip.graph.core.Directed _graph = null; private org.drip.graph.astar.FHeuristic _fHeuristic = null; protected OptimalPathGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic) throws java.lang.Exception @@ -142,7 +142,7 @@ protected OptimalPathGenerator ( * @return Graph underlying the Path Generator */ - public org.drip.graph.core.DirectedGraph graph() + public org.drip.graph.core.Directed graph() { return _graph; } diff --git a/src/main/java/org/drip/graph/shortestpath/VertexAugmentor.java b/src/main/java/org/drip/graph/shortestpath/VertexAugmentor.java index 7f92036e71ec..befd1e78c336 100644 --- a/src/main/java/org/drip/graph/shortestpath/VertexAugmentor.java +++ b/src/main/java/org/drip/graph/shortestpath/VertexAugmentor.java @@ -119,7 +119,7 @@ public class VertexAugmentor private boolean _shortestPath = false; private java.lang.String _sourceVertexName = ""; private org.drip.graph.astar.FHeuristic _fHeuristic = null; - private java.util.Map _vertexMap = null; + private java.util.Map> _vertexMap = null; private java.util.Map _augmentedVertexMap = null; @@ -147,7 +147,7 @@ public VertexAugmentor ( final java.lang.String sourceVertexName, final boolean shortestPath, final org.drip.graph.astar.FHeuristic fHeuristic, - final java.util.Map vertexMap) + final java.util.Map> vertexMap) throws java.lang.Exception { if (null == (_sourceVertexName = sourceVertexName) || _sourceVertexName.isEmpty()) @@ -166,14 +166,15 @@ public VertexAugmentor ( } else { - org.drip.graph.core.Vertex sourceVertex = (_vertexMap = vertexMap).get ( + org.drip.graph.core.Vertex sourceVertex = (_vertexMap = vertexMap).get ( sourceVertexName ); sourceAugmentedVertex = new org.drip.graph.shortestpath.AugmentedVertex ( _fHeuristic.gHeuristic().evaluate ( sourceVertex - ), _fHeuristic.hHeuristic().evaluate ( + ), + _fHeuristic.hHeuristic().evaluate ( sourceVertex ) ); @@ -250,7 +251,7 @@ public org.drip.graph.astar.FHeuristic fHeuristic() * @return The Underlying Graph Vertex Map */ - public java.util.Map vertexMap() + public java.util.Map> vertexMap() { return _vertexMap; } @@ -287,7 +288,7 @@ public boolean initializeVertexNameSet ( } else { - org.drip.graph.core.Vertex augmentedGraphVertex = _vertexMap.get ( + org.drip.graph.core.Vertex augmentedGraphVertex = _vertexMap.get ( vertexName ); @@ -372,7 +373,7 @@ public boolean updateAugmentedVertex ( } else { - org.drip.graph.core.Vertex augmentedGraphVertex = _vertexMap.get ( + org.drip.graph.core.Vertex augmentedGraphVertex = _vertexMap.get ( augmentedVertexName ); diff --git a/src/main/java/org/drip/graph/treebuilder/CapacitatedMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/CapacitatedMSTGenerator.java index f488ae2b8b0a..e5b26c2037b9 100644 --- a/src/main/java/org/drip/graph/treebuilder/CapacitatedMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/CapacitatedMSTGenerator.java @@ -122,7 +122,7 @@ public abstract class CapacitatedMSTGenerator private int _c = -1; protected CapacitatedMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum, final int c) throws java.lang.Exception diff --git a/src/main/java/org/drip/graph/treebuilder/DegreeConstrainedMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/DegreeConstrainedMSTGenerator.java index dd3b71a3b8d3..a8e0f879f686 100644 --- a/src/main/java/org/drip/graph/treebuilder/DegreeConstrainedMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/DegreeConstrainedMSTGenerator.java @@ -122,7 +122,7 @@ public abstract class DegreeConstrainedMSTGenerator private int _d = -1; protected DegreeConstrainedMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum, final int d) throws java.lang.Exception diff --git a/src/main/java/org/drip/graph/treebuilder/DirectedGraphMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/DirectedGraphMSTGenerator.java index ef2902842e62..e8f5c36b230a 100644 --- a/src/main/java/org/drip/graph/treebuilder/DirectedGraphMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/DirectedGraphMSTGenerator.java @@ -120,7 +120,7 @@ public abstract class DirectedGraphMSTGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { protected DirectedGraphMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { diff --git a/src/main/java/org/drip/graph/treebuilder/DynamicMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/DynamicMSTGenerator.java index eb6c3e9700b4..fdf65cb438b3 100644 --- a/src/main/java/org/drip/graph/treebuilder/DynamicMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/DynamicMSTGenerator.java @@ -120,7 +120,7 @@ public abstract class DynamicMSTGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { protected DynamicMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { diff --git a/src/main/java/org/drip/graph/treebuilder/EuclideanMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/EuclideanMSTGenerator.java index 4666c56c501f..d30050717ee4 100644 --- a/src/main/java/org/drip/graph/treebuilder/EuclideanMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/EuclideanMSTGenerator.java @@ -120,7 +120,7 @@ public abstract class EuclideanMSTGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { protected EuclideanMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { diff --git a/src/main/java/org/drip/graph/treebuilder/KMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/KMSTGenerator.java index 709a71547717..16f330ca3cd1 100644 --- a/src/main/java/org/drip/graph/treebuilder/KMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/KMSTGenerator.java @@ -122,7 +122,7 @@ public abstract class KMSTGenerator private int _k = -1; protected KMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum, final int k) throws java.lang.Exception diff --git a/src/main/java/org/drip/graph/treebuilder/KOptimalSpanningForestsGenerator.java b/src/main/java/org/drip/graph/treebuilder/KOptimalSpanningForestsGenerator.java index 8c1b73a1e982..1e5c999d0e8e 100644 --- a/src/main/java/org/drip/graph/treebuilder/KOptimalSpanningForestsGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/KOptimalSpanningForestsGenerator.java @@ -120,10 +120,10 @@ public abstract class KOptimalSpanningForestsGenerator { private int _k = -1; private boolean _maximum = false; - protected org.drip.graph.core.DirectedGraph _graph = null; + protected org.drip.graph.core.Directed _graph = null; protected KOptimalSpanningForestsGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum, final int k) throws java.lang.Exception @@ -151,7 +151,7 @@ protected KOptimalSpanningForestsGenerator ( * @return The Graph */ - public org.drip.graph.core.DirectedGraph graph() + public org.drip.graph.core.Directed graph() { return _graph; } @@ -184,5 +184,5 @@ public int k() * @return List of the Smallest Spanning Forests */ - public abstract java.util.List smallestSpanningForestList(); + public abstract java.util.List> smallestSpanningForestList(); } diff --git a/src/main/java/org/drip/graph/treebuilder/OptimalBottleneckSpanningTreeGenerator.java b/src/main/java/org/drip/graph/treebuilder/OptimalBottleneckSpanningTreeGenerator.java index 9ee337e209bd..0d405c7d117c 100644 --- a/src/main/java/org/drip/graph/treebuilder/OptimalBottleneckSpanningTreeGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/OptimalBottleneckSpanningTreeGenerator.java @@ -120,7 +120,7 @@ public abstract class OptimalBottleneckSpanningTreeGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { protected OptimalBottleneckSpanningTreeGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { diff --git a/src/main/java/org/drip/graph/treebuilder/OptimalLabelingSpanningTreeGenerator.java b/src/main/java/org/drip/graph/treebuilder/OptimalLabelingSpanningTreeGenerator.java index bc745265e728..1f57d67589ae 100644 --- a/src/main/java/org/drip/graph/treebuilder/OptimalLabelingSpanningTreeGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/OptimalLabelingSpanningTreeGenerator.java @@ -120,7 +120,7 @@ public abstract class OptimalLabelingSpanningTreeGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { protected OptimalLabelingSpanningTreeGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { diff --git a/src/main/java/org/drip/graph/treebuilder/OptimalSpanningForestGenerator.java b/src/main/java/org/drip/graph/treebuilder/OptimalSpanningForestGenerator.java index c9bb4c56251b..9d7341652845 100644 --- a/src/main/java/org/drip/graph/treebuilder/OptimalSpanningForestGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/OptimalSpanningForestGenerator.java @@ -122,10 +122,10 @@ public abstract class OptimalSpanningForestGenerator { private boolean _maximum = false; - protected org.drip.graph.core.DirectedGraph _graph = null; + protected org.drip.graph.core.Directed _graph = null; protected OptimalSpanningForestGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { @@ -145,7 +145,7 @@ protected OptimalSpanningForestGenerator ( * @return The Graph */ - public org.drip.graph.core.DirectedGraph graph() + public org.drip.graph.core.Directed graph() { return _graph; } @@ -167,5 +167,5 @@ public boolean maximum() * @return Optimal Spanning Forest */ - public abstract org.drip.graph.core.Forest optimalSpanningForest(); + public abstract org.drip.graph.core.Forest optimalSpanningForest(); } diff --git a/src/main/java/org/drip/graph/treebuilder/RectilinearMSTGenerator.java b/src/main/java/org/drip/graph/treebuilder/RectilinearMSTGenerator.java index 909dd85193b2..330bd1160a48 100644 --- a/src/main/java/org/drip/graph/treebuilder/RectilinearMSTGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/RectilinearMSTGenerator.java @@ -120,7 +120,7 @@ public abstract class RectilinearMSTGenerator extends org.drip.graph.treebuilder.OptimalSpanningForestGenerator { protected RectilinearMSTGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum) throws java.lang.Exception { diff --git a/src/main/java/org/drip/graph/treebuilder/SteinerTreeGenerator.java b/src/main/java/org/drip/graph/treebuilder/SteinerTreeGenerator.java index 3b7c73390d5f..158af992286a 100644 --- a/src/main/java/org/drip/graph/treebuilder/SteinerTreeGenerator.java +++ b/src/main/java/org/drip/graph/treebuilder/SteinerTreeGenerator.java @@ -122,7 +122,7 @@ public abstract class SteinerTreeGenerator private java.util.Set _vertexNameSet = null; protected SteinerTreeGenerator ( - final org.drip.graph.core.DirectedGraph graph, + final org.drip.graph.core.Directed graph, final boolean maximum, final java.util.Set vertexNameSet) throws java.lang.Exception diff --git a/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java b/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java index 786765a5998f..0a63caddbaeb 100644 --- a/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java +++ b/src/main/java/org/drip/measure/crng/RandomMatrixGenerator.java @@ -1,6 +1,8 @@ package org.drip.measure.crng; +import org.drip.numerical.eigen.EigenOutput; +import org.drip.numerical.matrix.R1SquareEigenized; import org.drip.numerical.matrix.R1Triangular; /* @@ -403,4 +405,33 @@ public static final R1Triangular AtomicUpperTriangular ( return R1Triangular.Standard (r2Array); } + + /** + * Construct an Eigenized Square Matrix of Random Elements up to the Maximum Value + * + * @param elementCount Number of Elements in the Array + * @param maximumElement Maximum Element + * @param isEntryInteger TRUE - Entry is an Integer + * + * @return Eigenized Square Matrix of Random Elements up to the Maximum Value + */ + + public static final R1SquareEigenized EigenizedR1Square ( + final int elementCount, + final double maximumElement, + final boolean isEntryInteger) + { + try { + return R1SquareEigenized.Standard ( + new EigenOutput ( + RdRandomSequence.TwoD (elementCount, maximumElement, isEntryInteger), + RdRandomSequence.OneD (elementCount, maximumElement, isEntryInteger) + ) + ); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } } diff --git a/src/main/java/org/drip/numerical/eigen/EigenOutput.java b/src/main/java/org/drip/numerical/eigen/EigenOutput.java index 943dc79da351..651a9aef8512 100644 --- a/src/main/java/org/drip/numerical/eigen/EigenOutput.java +++ b/src/main/java/org/drip/numerical/eigen/EigenOutput.java @@ -162,6 +162,17 @@ public double[] eigenValueArray() return _eigenValueArray; } + /** + * Retrieve the Eigen-Dimension + * + * @return The Eigen-Dimension + */ + + public int dimension() + { + return _eigenValueArray.length; + } + /** * Retrieve the Eigenvalue Multiplicity Map * diff --git a/src/main/java/org/drip/numerical/matrix/R1SquareEigenized.java b/src/main/java/org/drip/numerical/matrix/R1SquareEigenized.java new file mode 100644 index 000000000000..f2b664d2e6fc --- /dev/null +++ b/src/main/java/org/drip/numerical/matrix/R1SquareEigenized.java @@ -0,0 +1,279 @@ + +package org.drip.numerical.matrix; + +import java.util.Map; + +import org.drip.function.definition.R1ToR1; +import org.drip.numerical.eigen.EigenOutput; +import org.drip.numerical.linearalgebra.R1MatrixUtil; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2025 Lakshmi Krishnamurthy + * + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, + * graph builder/navigator, and computational support. + * + * https://lakshmidrip.github.io/DROP/ + * + * DROP is composed of three modules: + * + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ + * + * DROP Product Core implements libraries for the following: + * - Fixed Income Analytics + * - Loan Analytics + * - Transaction Cost Analytics + * + * DROP Portfolio Core implements libraries for the following: + * - Asset Allocation Analytics + * - Asset Liability Management Analytics + * - Capital Estimation Analytics + * - Exposure Analytics + * - Margin Analytics + * - XVA Analytics + * + * DROP Computational Core implements libraries for the following: + * - Algorithm Support + * - Computation Support + * - Function Analysis + * - Graph Algorithm + * - Model Validation + * - Numerical Analysis + * - Numerical Optimizer + * - Spline Builder + * - Statistical Learning + * + * Documentation for DROP is Spread Over: + * + * - Main => https://lakshmidrip.github.io/DROP/ + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki + * - GitHub => https://github.com/lakshmiDRIP/DROP + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * R1SquareEigenized implements an R1 Square Matrix with its Pre-computed Eigen-values and + * Eigen-vectors. The References are: + * + *

      + *
        + *
      • + * Dunford, N., and J. Schwartz (1963): Linear Operators II: Spectral Theory: Self-adjoint + * Operators in the Hilbert Space Wiley Interscience Hoboken NJ + *
      • + *
      • + * Gradshteyn, I. S., I. M. Ryzhik, Y. V. Geronimus, M. Y. Tseytlin, and A. Jeffrey (2015): + * Tables of Integrals, Series, and Products Academic Press Cambridge MA + *
      • + *
      • + * Guo, J. M., Z. W. Wang, and X. Li (2019): Sharp Upper Bounds of the Spectral Radius of a Graph + * Discrete Mathematics 342 (9) 2559-2563 + *
      • + *
      • + * Lax, P. D. (2002): Functional Analysis Wiley Interscience Hoboken NJ + *
      • + *
      • + * Wikipedia (2024): Spectral Radius https://en.wikipedia.org/wiki/Spectral_radius + *
      • + *
      + * + *

      + * + *

      + * + * @author Lakshmi Krishnamurthy + */ + +public class R1SquareEigenized extends R1Square +{ + private EigenOutput _eigenOutput = null; + + /** + * Construct a Standard Instance of R1SquareEigenized from the EigenOutput + * + * @param eigenOutput The EigenOutput Instance + * + * @return Standard Instance of R1SquareEigenized + */ + + public static final R1SquareEigenized Standard ( + final EigenOutput eigenOutput) + { + if (null == eigenOutput) { + return null; + } + + int dimension = eigenOutput.dimension(); + + double[][] eigenValueMatrix = new double[dimension][]; + double[][] eigenVectorMatrix = new double[dimension][]; + + double[] eigenValueArray = eigenOutput.eigenValueArray(); + + double[][] eigenVectorArray = eigenOutput.eigenVectorArray(); + + for (int i = 0; i < dimension; ++i) { + eigenVectorMatrix[i] = eigenVectorArray[i]; + } + + for (int i = 0; i < dimension; ++i) { + for (int j = 0; j < dimension; ++j) { + eigenValueMatrix[i][j] = i == j ? eigenValueArray[i] : 0.; + } + } + + double[][] r1Grid = R1MatrixUtil.Product ( + eigenValueMatrix, + R1MatrixUtil.InvertUsingGaussianElimination (eigenVectorMatrix) + ); + + r1Grid = null == r1Grid ? null : R1MatrixUtil.Product ( + eigenVectorMatrix, + eigenValueMatrix + ); + + return null == r1Grid ? null : new R1SquareEigenized ( + r1Grid, + eigenOutput + ); + } + + protected R1SquareEigenized ( + final double[][] r1Grid, + final EigenOutput eigenOutput) + { + super (r1Grid); + + _eigenOutput = eigenOutput; + } + + /** + * Retrieve the Eigen Components and the Eigen Vectors + * + * @return Eigen Components and the Eigen Vectors + */ + + public EigenOutput eigenOutput() + { + return _eigenOutput; + } + + /** + * Eigenize and Extract the Components of the Specified Matrix + * + * @return The EigenComponents + */ + + public EigenOutput eigenize() + { + return _eigenOutput; + } + + /** + * Perform Singular Value Decomposition and Extract the Components of the Specified Matrix + * + * @return The Singular Value Decomposition Components + */ + + public EigenOutput svd() + { + return _eigenOutput; + } + + /** + * Retrieve the Eigenvalue Multiplicity Map + * + * @return Eigenvalue Multiplicity Map + */ + + public Map eigenValueMultiplicityMap() + { + return _eigenOutput.eigenValueMultiplicityMap(); + } + + /** + * Compute the Determinant of the Matrix + * + * @return Determinant of the Matrix + * + * @throws Exception Thrown if the Determinant cannot be calculated + */ + + public double determinant() + throws Exception + { + return _eigenOutput.determinant(); + } + + /** + * Compute the L2 Condition Number of the Matrix + * + * @return L2 Condition Number of the Matrix + * + * @throws Exception Thrown if the Condition Number cannot be calculated + */ + + public double conditionNumberL2() + throws Exception + { + return _eigenOutput.conditionNumber(); + } + + /** + * Retrieve the Characteristic Polynomial of the Eigenvalues + * + * @return Characteristic Polynomial of the Eigenvalues + */ + + public R1ToR1 characteristicPolynomial() + { + return _eigenOutput.characteristicPolynomial(); + } + + /** + * Compute the Spectral Radius of the Matrix + * + * @return Spectral Radius of the Matrix + * + * @throws Exception Thrown if the Spectral Radius cannot be calculated + */ + + public double spectralRadius() + throws Exception + { + return _eigenOutput.spectralRadius(); + } +} diff --git a/src/main/java/org/drip/sample/connectivity/KosarajuSCC.java b/src/main/java/org/drip/sample/connectivity/KosarajuSCC.java index ac79bcd1a3d5..5c2dd9ac8655 100644 --- a/src/main/java/org/drip/sample/connectivity/KosarajuSCC.java +++ b/src/main/java/org/drip/sample/connectivity/KosarajuSCC.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.connectivity.Kosaraju; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.service.env.EnvManager; @@ -155,7 +155,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/graph/CompleteBipartiteProperties.java b/src/main/java/org/drip/sample/graph/CompleteBipartiteProperties.java index a1fb2ac31d6a..5f8774125d5a 100644 --- a/src/main/java/org/drip/sample/graph/CompleteBipartiteProperties.java +++ b/src/main/java/org/drip/sample/graph/CompleteBipartiteProperties.java @@ -8,7 +8,7 @@ import org.drip.analytics.support.CaseInsensitiveHashMap; import org.drip.graph.core.Edge; import org.drip.graph.core.CompleteBipartite; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.KruskalGenerator; import org.drip.graph.mstgreedy.PrimGenerator; @@ -276,7 +276,7 @@ public static final void main ( 1782. ); - DirectedGraph graph = new CompleteBipartite ( + Directed graph = new CompleteBipartite ( VertexNameSet ( vertexNameArrayP ), @@ -340,14 +340,14 @@ public static final void main ( System.out.println(); - KruskalGenerator kruskal = new KruskalGenerator ( + KruskalGenerator kruskal = new KruskalGenerator ( graph, false ); - Map minimumSpanningForest = kruskal.optimalSpanningForest().treeMap(); + Map> minimumSpanningForest = kruskal.optimalSpanningForest().treeMap(); - for (Tree minimumSpanningTree : minimumSpanningForest.values()) + for (Tree minimumSpanningTree : minimumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" @@ -383,14 +383,14 @@ public static final void main ( System.out.println(); - PrimGenerator prim = new PrimGenerator ( + PrimGenerator prim = new PrimGenerator ( graph, false ); minimumSpanningForest = prim.optimalSpanningForest().treeMap(); - for (Tree minimumSpanningTree : minimumSpanningForest.values()) + for (Tree minimumSpanningTree : minimumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/graph/GraphProperties.java b/src/main/java/org/drip/sample/graph/GraphProperties.java index 59a07c207248..5fe681d048b6 100644 --- a/src/main/java/org/drip/sample/graph/GraphProperties.java +++ b/src/main/java/org/drip/sample/graph/GraphProperties.java @@ -2,7 +2,7 @@ package org.drip.sample.graph; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.service.env.EnvManager; /* @@ -147,7 +147,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/graphsearch/BFS1.java b/src/main/java/org/drip/sample/graphsearch/BFS1.java index 4c740653d86e..27915979597d 100644 --- a/src/main/java/org/drip/sample/graphsearch/BFS1.java +++ b/src/main/java/org/drip/sample/graphsearch/BFS1.java @@ -2,7 +2,7 @@ package org.drip.sample.graphsearch; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.search.BreadthFirst; import org.drip.graph.search.OrderedVertexGroup; import org.drip.service.env.EnvManager; @@ -137,7 +137,7 @@ public static final void main ( "" ); - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/graphsearch/BFS3.java b/src/main/java/org/drip/sample/graphsearch/BFS3.java index 09d78dcb0304..b21350e4b553 100644 --- a/src/main/java/org/drip/sample/graphsearch/BFS3.java +++ b/src/main/java/org/drip/sample/graphsearch/BFS3.java @@ -2,7 +2,7 @@ package org.drip.sample.graphsearch; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.search.BreadthFirst; import org.drip.graph.search.OrderedVertexGroup; import org.drip.service.env.EnvManager; @@ -150,7 +150,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/graphsearch/DFS1.java b/src/main/java/org/drip/sample/graphsearch/DFS1.java index c1e86dc0cea5..cf7e7c4b05fa 100644 --- a/src/main/java/org/drip/sample/graphsearch/DFS1.java +++ b/src/main/java/org/drip/sample/graphsearch/DFS1.java @@ -2,7 +2,7 @@ package org.drip.sample.graphsearch; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.search.DepthFirst; import org.drip.graph.search.OrderedVertexGroup; import org.drip.service.env.EnvManager; @@ -138,7 +138,7 @@ public static final void main ( "" ); - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/graphsearch/DFS2.java b/src/main/java/org/drip/sample/graphsearch/DFS2.java index b9f9cd573704..cd2af2840aab 100644 --- a/src/main/java/org/drip/sample/graphsearch/DFS2.java +++ b/src/main/java/org/drip/sample/graphsearch/DFS2.java @@ -2,7 +2,7 @@ package org.drip.sample.graphsearch; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.search.DepthFirst; import org.drip.graph.search.OrderedVertexGroup; import org.drip.service.env.EnvManager; @@ -138,7 +138,7 @@ public static final void main ( "" ); - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/graphsearch/DFS3.java b/src/main/java/org/drip/sample/graphsearch/DFS3.java index 0bfe4798ab70..9340b6cbd455 100644 --- a/src/main/java/org/drip/sample/graphsearch/DFS3.java +++ b/src/main/java/org/drip/sample/graphsearch/DFS3.java @@ -2,7 +2,7 @@ package org.drip.sample.graphsearch; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.search.DepthFirst; import org.drip.graph.search.OrderedVertexGroup; import org.drip.service.env.EnvManager; @@ -144,7 +144,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/mst/BoruvkaMaximumForestGenerator.java b/src/main/java/org/drip/sample/mst/BoruvkaMaximumForestGenerator.java index ff76876ef979..66b3f5b01c4f 100644 --- a/src/main/java/org/drip/sample/mst/BoruvkaMaximumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/BoruvkaMaximumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.BoruvkaGenerator; import org.drip.service.env.EnvManager; @@ -156,7 +156,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -254,14 +254,14 @@ public static final void main ( ) ); - BoruvkaGenerator boruvka = new BoruvkaGenerator ( + BoruvkaGenerator boruvka = new BoruvkaGenerator ( graph, true ); - Map maximumSpanningForest = boruvka.optimalSpanningForest().treeMap(); + Map> maximumSpanningForest = boruvka.optimalSpanningForest().treeMap(); - for (Tree maximumSpanningTree : maximumSpanningForest.values()) + for (Tree maximumSpanningTree : maximumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/BoruvkaMinimumForestGenerator.java b/src/main/java/org/drip/sample/mst/BoruvkaMinimumForestGenerator.java index a259b4370da8..774361de1232 100644 --- a/src/main/java/org/drip/sample/mst/BoruvkaMinimumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/BoruvkaMinimumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.BoruvkaGenerator; import org.drip.service.env.EnvManager; @@ -156,7 +156,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -254,14 +254,14 @@ public static final void main ( ) ); - BoruvkaGenerator boruvka = new BoruvkaGenerator ( + BoruvkaGenerator boruvka = new BoruvkaGenerator ( graph, false ); - Map minimumSpanningForest = boruvka.optimalSpanningForest().treeMap(); + Map> minimumSpanningForest = boruvka.optimalSpanningForest().treeMap(); - for (Tree minimumSpanningTree : minimumSpanningForest.values()) + for (Tree minimumSpanningTree : minimumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/KruskalMaximumForestGenerator.java b/src/main/java/org/drip/sample/mst/KruskalMaximumForestGenerator.java index a1e8ddf6611b..09fe58cd2312 100644 --- a/src/main/java/org/drip/sample/mst/KruskalMaximumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/KruskalMaximumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.KruskalGenerator; import org.drip.service.env.EnvManager; @@ -154,7 +154,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -252,14 +252,14 @@ public static final void main ( ) ); - KruskalGenerator kruskal = new KruskalGenerator ( + KruskalGenerator kruskal = new KruskalGenerator ( graph, true ); - Map maximumSpanningForest = kruskal.optimalSpanningForest().treeMap(); + Map> maximumSpanningForest = kruskal.optimalSpanningForest().treeMap(); - for (Tree maximumSpanningTree : maximumSpanningForest.values()) + for (Tree maximumSpanningTree : maximumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/KruskalMinimumForestGenerator.java b/src/main/java/org/drip/sample/mst/KruskalMinimumForestGenerator.java index 9e549fa562a9..05caf07104bb 100644 --- a/src/main/java/org/drip/sample/mst/KruskalMinimumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/KruskalMinimumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.KruskalGenerator; import org.drip.service.env.EnvManager; @@ -154,7 +154,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -252,14 +252,14 @@ public static final void main ( ) ); - KruskalGenerator kruskal = new KruskalGenerator ( + KruskalGenerator kruskal = new KruskalGenerator ( graph, false ); - Map minimumSpanningForest = kruskal.optimalSpanningForest().treeMap(); + Map> minimumSpanningForest = kruskal.optimalSpanningForest().treeMap(); - for (Tree minimumSpanningTree : minimumSpanningForest.values()) + for (Tree minimumSpanningTree : minimumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/PrimMaximumForestGenerator.java b/src/main/java/org/drip/sample/mst/PrimMaximumForestGenerator.java index 95dc57186bab..bc05f992d4df 100644 --- a/src/main/java/org/drip/sample/mst/PrimMaximumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/PrimMaximumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.PrimGenerator; import org.drip.service.env.EnvManager; @@ -159,7 +159,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -257,14 +257,14 @@ public static final void main ( ) ); - PrimGenerator prim = new PrimGenerator ( + PrimGenerator prim = new PrimGenerator ( graph, true ); - Map maximumSpanningForest = prim.optimalSpanningForest().treeMap(); + Map> maximumSpanningForest = prim.optimalSpanningForest().treeMap(); - for (Tree maximumSpanningTree : maximumSpanningForest.values()) + for (Tree maximumSpanningTree : maximumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/PrimMinimumForestGenerator.java b/src/main/java/org/drip/sample/mst/PrimMinimumForestGenerator.java index 960d070f8c0a..6b5965a50e65 100644 --- a/src/main/java/org/drip/sample/mst/PrimMinimumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/PrimMinimumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.PrimGenerator; import org.drip.service.env.EnvManager; @@ -159,7 +159,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -257,14 +257,14 @@ public static final void main ( ) ); - PrimGenerator prim = new PrimGenerator ( + PrimGenerator prim = new PrimGenerator ( graph, false ); - Map minimumSpanningForest = prim.optimalSpanningForest().treeMap(); + Map> minimumSpanningForest = prim.optimalSpanningForest().treeMap(); - for (Tree minimumSpanningTree : minimumSpanningForest.values()) + for (Tree minimumSpanningTree : minimumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/ReverseDeleteMaximumForestGenerator.java b/src/main/java/org/drip/sample/mst/ReverseDeleteMaximumForestGenerator.java index 738f710a0d15..e89d4c388dac 100644 --- a/src/main/java/org/drip/sample/mst/ReverseDeleteMaximumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/ReverseDeleteMaximumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.ReverseDeleteGenerator; import org.drip.service.env.EnvManager; @@ -153,7 +153,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -251,14 +251,14 @@ public static final void main ( ) ); - ReverseDeleteGenerator reverseDelete = new ReverseDeleteGenerator ( + ReverseDeleteGenerator reverseDelete = new ReverseDeleteGenerator ( graph, true ); - Map maximumSpanningForest = reverseDelete.optimalSpanningForest().treeMap(); + Map> maximumSpanningForest = reverseDelete.optimalSpanningForest().treeMap(); - for (Tree maximumSpanningTree : maximumSpanningForest.values()) + for (Tree maximumSpanningTree : maximumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/mst/ReverseDeleteMinimumForestGenerator.java b/src/main/java/org/drip/sample/mst/ReverseDeleteMinimumForestGenerator.java index 85aa3d08a5b0..4ab81c1e6497 100644 --- a/src/main/java/org/drip/sample/mst/ReverseDeleteMinimumForestGenerator.java +++ b/src/main/java/org/drip/sample/mst/ReverseDeleteMinimumForestGenerator.java @@ -4,7 +4,7 @@ import java.util.Map; import org.drip.graph.core.Edge; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Tree; import org.drip.graph.mstgreedy.ReverseDeleteGenerator; import org.drip.service.env.EnvManager; @@ -153,7 +153,7 @@ public static final void main ( "jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -251,14 +251,14 @@ public static final void main ( ) ); - ReverseDeleteGenerator reverseDelete = new ReverseDeleteGenerator ( + ReverseDeleteGenerator reverseDelete = new ReverseDeleteGenerator ( graph, false ); - Map minimumSpanningForest = reverseDelete.optimalSpanningForest().treeMap(); + Map> minimumSpanningForest = reverseDelete.optimalSpanningForest().treeMap(); - for (Tree minimumSpanningTree : minimumSpanningForest.values()) + for (Tree minimumSpanningTree : minimumSpanningForest.values()) { System.out.println ( "\t|-----------------------------------------------------------------------------------|" diff --git a/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSinglePair.java b/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSinglePair.java index 0557a3271d1c..97be49413fe0 100644 --- a/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSinglePair.java +++ b/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSinglePair.java @@ -2,7 +2,7 @@ package org.drip.sample.shortestpath; import org.drip.graph.bellmanford.BannisterEppsteinPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -155,7 +155,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSingleSource.java b/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSingleSource.java index 195882ac3848..6cf5e5fbe925 100644 --- a/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSingleSource.java +++ b/src/main/java/org/drip/sample/shortestpath/BannisterEppsteinSingleSource.java @@ -4,7 +4,7 @@ import java.util.List; import org.drip.graph.bellmanford.BannisterEppsteinPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -157,7 +157,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/BellmanFordSinglePair.java b/src/main/java/org/drip/sample/shortestpath/BellmanFordSinglePair.java index 265ef7e6ef7e..8b5e9adf499b 100644 --- a/src/main/java/org/drip/sample/shortestpath/BellmanFordSinglePair.java +++ b/src/main/java/org/drip/sample/shortestpath/BellmanFordSinglePair.java @@ -2,7 +2,7 @@ package org.drip.sample.shortestpath; import org.drip.graph.bellmanford.EdgeRelaxationPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.service.common.FormatUtil; @@ -153,7 +153,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/BellmanFordSingleSource.java b/src/main/java/org/drip/sample/shortestpath/BellmanFordSingleSource.java index 1df7f3e93177..82c3d595ddb8 100644 --- a/src/main/java/org/drip/sample/shortestpath/BellmanFordSingleSource.java +++ b/src/main/java/org/drip/sample/shortestpath/BellmanFordSingleSource.java @@ -4,7 +4,7 @@ import java.util.List; import org.drip.graph.bellmanford.EdgeRelaxationPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.service.common.FormatUtil; @@ -157,7 +157,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/DijkstraSinglePair.java b/src/main/java/org/drip/sample/shortestpath/DijkstraSinglePair.java index df83de254845..8eef9c3e034b 100644 --- a/src/main/java/org/drip/sample/shortestpath/DijkstraSinglePair.java +++ b/src/main/java/org/drip/sample/shortestpath/DijkstraSinglePair.java @@ -1,7 +1,7 @@ package org.drip.sample.shortestpath; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.DijkstraPathGenerator; @@ -155,7 +155,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/DijkstraSingleSource.java b/src/main/java/org/drip/sample/shortestpath/DijkstraSingleSource.java index 9f0f29112d12..e69661e41f70 100644 --- a/src/main/java/org/drip/sample/shortestpath/DijkstraSingleSource.java +++ b/src/main/java/org/drip/sample/shortestpath/DijkstraSingleSource.java @@ -3,7 +3,7 @@ import java.util.List; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.DijkstraPathGenerator; @@ -157,7 +157,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/JohnsonSinglePair.java b/src/main/java/org/drip/sample/shortestpath/JohnsonSinglePair.java index e0ecd0fbf450..b565b044263d 100644 --- a/src/main/java/org/drip/sample/shortestpath/JohnsonSinglePair.java +++ b/src/main/java/org/drip/sample/shortestpath/JohnsonSinglePair.java @@ -2,7 +2,7 @@ package org.drip.sample.shortestpath; import org.drip.graph.bellmanford.JohnsonPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -153,7 +153,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -255,7 +255,7 @@ public static final void main ( "\t|-----------------------------------------------------------------------------------------------------" ); - OptimalPathGenerator optimalPathGenerator = new JohnsonPathGenerator ( + OptimalPathGenerator optimalPathGenerator = new JohnsonPathGenerator ( graph, true, null diff --git a/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSource.java b/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSource.java index 09a0065479b7..e5a170123aa2 100644 --- a/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSource.java +++ b/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSource.java @@ -4,7 +4,7 @@ import java.util.List; import org.drip.graph.bellmanford.JohnsonPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -155,7 +155,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( @@ -257,7 +257,7 @@ public static final void main ( "\t|-----------------------------------------------------------------------------------------------------" ); - OptimalPathGenerator optimalPathGenerator = new JohnsonPathGenerator ( + OptimalPathGenerator optimalPathGenerator = new JohnsonPathGenerator ( graph, true, null diff --git a/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSourceNegativeWeight.java b/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSourceNegativeWeight.java index fd4c9d91b787..e1865806ac34 100644 --- a/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSourceNegativeWeight.java +++ b/src/main/java/org/drip/sample/shortestpath/JohnsonSingleSourceNegativeWeight.java @@ -4,7 +4,7 @@ import java.util.List; import org.drip.graph.bellmanford.JohnsonPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -141,7 +141,7 @@ public static final void main ( "" ); - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addEdge ( new Edge ( @@ -203,7 +203,7 @@ public static final void main ( "\t|-----------------------------------------------------------------------------------------------------" ); - OptimalPathGenerator optimalPathGenerator = new JohnsonPathGenerator ( + OptimalPathGenerator optimalPathGenerator = new JohnsonPathGenerator ( graph, true, null diff --git a/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSinglePair.java b/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSinglePair.java index 8675403fa00f..bdb967567ef7 100644 --- a/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSinglePair.java +++ b/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSinglePair.java @@ -2,7 +2,7 @@ package org.drip.sample.shortestpath; import org.drip.graph.bellmanford.YenEdgePartitionPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -155,7 +155,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSingleSource.java b/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSingleSource.java index b11787142464..43182852e7cc 100644 --- a/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSingleSource.java +++ b/src/main/java/org/drip/sample/shortestpath/YenEdgePartitionSingleSource.java @@ -4,7 +4,7 @@ import java.util.List; import org.drip.graph.bellmanford.YenEdgePartitionPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -157,7 +157,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSinglePair.java b/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSinglePair.java index 6802fdaa0086..ed4aca69067d 100644 --- a/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSinglePair.java +++ b/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSinglePair.java @@ -2,7 +2,7 @@ package org.drip.sample.shortestpath; import org.drip.graph.bellmanford.YenReducedRelaxationPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -155,7 +155,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge ( diff --git a/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSingleSource.java b/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSingleSource.java index e5241c4cad71..4533eab4a73c 100644 --- a/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSingleSource.java +++ b/src/main/java/org/drip/sample/shortestpath/YenReducedRelaxationSingleSource.java @@ -4,7 +4,7 @@ import java.util.List; import org.drip.graph.bellmanford.YenReducedRelaxationPathGenerator; -import org.drip.graph.core.DirectedGraph; +import org.drip.graph.core.Directed; import org.drip.graph.core.Edge; import org.drip.graph.core.Path; import org.drip.graph.shortestpath.OptimalPathGenerator; @@ -159,7 +159,7 @@ public static final void main ( "Jaipur " }; - DirectedGraph graph = new DirectedGraph(); + Directed graph = new Directed(); graph.addBidirectionalEdge ( new Edge (