Skip to content

Commit 243dcf6

Browse files
Update README.md
1 parent af0194b commit 243dcf6

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

README.md

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -88,55 +88,53 @@ with the correct abstractions and utilities. The builtin algorithms are:
8888
#### 1. creating a very simple graph
8989

9090
```java
91+
SimpleDirectedGraph graph_triangle = new SimpleDirectedGraph();
9192

92-
SimpleDirectedGraph graph_triangle = new SimpleDirectedGraph();
93-
94-
Vertex v0 = new Vertex();
95-
Vertex v1 = new Vertex();
96-
Vertex v2 = new Vertex("tag_v2");
97-
98-
graph_triangle.addVertex(v0);
99-
graph_triangle.addVertex(v1);
100-
graph_triangle.addVertex(v2);
101-
102-
Edge e_0 = graph_triangle.addEdge(v0, v1);
103-
graph_triangle.addEdge(v1, v2);
104-
graph_triangle.addEdge(v2, v3);
105-
106-
graph_triangle.print();
107-
108-
// iterate the graph vertices directly
109-
for (IVertex vertex : graph_triangle) {
110-
System.out.println(vertex.toString());
111-
}
93+
Vertex v0 = new Vertex();
94+
Vertex v1 = new Vertex();
95+
Vertex v2 = new Vertex("tag_v2");
11296

113-
// iterate the edges of the graph
114-
for (Edge edge : graph_triangle.edges()) {
115-
System.out.println(edge.toString());
116-
}
97+
graph_triangle.addVertex(v0);
98+
graph_triangle.addVertex(v1);
99+
graph_triangle.addVertex(v2);
100+
101+
Edge e_0 = graph_triangle.addEdge(v0, v1);
102+
graph_triangle.addEdge(v1, v2);
103+
graph_triangle.addEdge(v2, v3);
104+
105+
graph_triangle.print();
106+
107+
// iterate the graph vertices directly
108+
for (IVertex vertex : graph_triangle) {
109+
System.out.println(vertex.toString());
110+
}
111+
112+
// iterate the edges of the graph
113+
for (Edge edge : graph_triangle.edges()) {
114+
System.out.println(edge.toString());
115+
}
117116

118-
// removing a vertex in any of the following ways will remove it's connected edges as well,
119-
// also removing any edge in similar fashion will update the graph :)
120-
graph_triangle.removeVertex(v0);
121-
graph_triangle.vertices().remove(v1);
122-
graph_triangle.vertices().iterator().remove();
117+
// removing a vertex in any of the following ways will remove it's connected edges as well,
118+
// also removing any edge in similar fashion will update the graph :)
119+
graph_triangle.removeVertex(v0);
120+
graph_triangle.vertices().remove(v1);
121+
graph_triangle.vertices().iterator().remove();
123122

124123
```
125124

126125
#### 2. use a factory for custom graph
127126
you can define your graph in terms of self loops, multi edges (per vertex) and
128127
a custom implementation of a graph engine.
129128
```java
129+
boolean allow_self_loops = true;
130+
boolean allow_multi_edges = true;
130131

131-
boolean allow_self_loops = true;
132-
boolean allow_multi_edges = true;
132+
UndirectedGraph graph_undirected = Erdos.newUndirectedGraphWithEngine(new AdjIncidenceGraphEngine(),
133+
allow_self_loops, allow_multi_edges);
133134

134-
UndirectedGraph graph_undirected = Erdos.newUndirectedGraphWithEngine(new AdjIncidenceGraphEngine(),
135-
allow_self_loops, allow_multi_edges);
136-
137-
DirectedGraph graph = Erdos.newGraphWithEngine(new AdjIncidenceGraphEngine(),
138-
Edge.EDGE_DIRECTION.DIRECTED,
139-
allow_self_loops, allow_multi_edges);
135+
DirectedGraph graph = Erdos.newGraphWithEngine(new AdjIncidenceGraphEngine(),
136+
Edge.EDGE_DIRECTION.DIRECTED,
137+
allow_self_loops, allow_multi_edges);
140138

141139
```
142140

@@ -197,16 +195,16 @@ private void BellmanFord()
197195
this example shows the simplicity of the framework (hopefully ;)) where we apply 5
198196
different algorithms sequentally
199197
```java
200-
// perform a breadth first search
201-
BFS.BreadthFirstTree breadthFirstTree = new BFS(graph, s).applyAlgorithm();
202-
// perform a depth first search
203-
DFS.DepthFirstForest depthFirstForest = new DFS(graph).applyAlgorithm();
204-
// extract the strongly connected components of the graph
205-
ArrayList<HashSet<IVertex>> hashSets = new SCC(graph).applyAlgorithm();
206-
// perform a topological sort on the graph
207-
LinkedList<IVertex> res_sort = new TopologicalSort(graph).applyAlgorithm();
208-
// compute all pairs shortest paths using the Floyd-Warshall algorithm
209-
AllPairsShortPathResult floyd_result = new FloydWarshall(graph).applyAlgorithm();
198+
// perform a breadth first search
199+
BFS.BreadthFirstTree breadthFirstTree = new BFS(graph, s).applyAlgorithm();
200+
// perform a depth first search
201+
DFS.DepthFirstForest depthFirstForest = new DFS(graph).applyAlgorithm();
202+
// extract the strongly connected components of the graph
203+
ArrayList<HashSet<IVertex>> hashSets = new SCC(graph).applyAlgorithm();
204+
// perform a topological sort on the graph
205+
LinkedList<IVertex> res_sort = new TopologicalSort(graph).applyAlgorithm();
206+
// compute all pairs shortest paths using the Floyd-Warshall algorithm
207+
AllPairsShortPathResult floyd_result = new FloydWarshall(graph).applyAlgorithm();
210208

211209
```
212210

0 commit comments

Comments
 (0)