Skip to content

Commit 459275f

Browse files
author
Jegors Čemisovs
committed
add graph2mermaid.awk
closes #50 Signed-off-by: Jegors Čemisovs <jegors_cemisovs@epam.com>
1 parent ca58066 commit 459275f

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

README.md

+23-15
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ can also see the [specifications](https://algorithms.jc.id.lv/docs/spock-reports
1414

1515
## Demo. Graph Shell
1616

17-
To demonstrate the work of search algorithms, I made a small console program '[Graph Shell](graph-shell/README.md)'. The program allows you to select [one of three build-in graph samples](#Graph-Samples) and search for a path using two algorithms. The source code of the program is located in `graph-shell` module.
17+
To demonstrate the work of search algorithms, I made a small console program '[Graph Shell](graph-shell/README.md)'. The program
18+
allows you to select [one of three build-in graph samples](#Graph-Samples) and search for a path using two algorithms. The source
19+
code of the program is located in `graph-shell` module.
1820

1921
[![asciicast](https://asciinema.org/a/468058.svg)](https://asciinema.org/a/468058)
2022

2123
### Usage in other projects
2224

2325
These algorithms used in the [Hypermetro](https://rabestro.github.io/hypermetro/) project, where they are
24-
utilized to find the optimal route in the metro schema.
26+
utilized to find the optimal route in the metro schema.
2527

2628

2729
## How to use the algorithms in your program
@@ -30,7 +32,11 @@ The first step is to create a graph structure. The Graph interface is generic, s
3032
and any [Number](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Number.html) type for distance.
3133

3234
### Example
33-
In the following Java code we create a graph structure with eight nodes. We use [Character](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Character.html) class for vertex identification and [Integer](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Integer.html) for the distance. You can see the graphic representation of the scheme [here](docs/assets/complex.gif).
35+
36+
In the following Java code we create a graph structure with eight nodes. We
37+
use [Character](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Character.html) class for vertex
38+
identification and [Integer](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Integer.html) for the
39+
distance. You can see the graphic representation of the scheme [here](docs/assets/complex.gif).
3440

3541
```java
3642
var graph = Graph.of(Map.of(
@@ -45,7 +51,7 @@ var graph = Graph.of(Map.of(
4551
));
4652
```
4753

48-
The second step is creating a search algorithm class. You can choose one of the two algorithms.
54+
The second step is creating a search algorithm class. You can choose one of the two algorithms.
4955

5056
### Example
5157

@@ -66,11 +72,11 @@ var routeOne = shortest.findPath(graph, source, target);
6672
var routeTwo = fastest.findPath(graph, source, target);
6773
```
6874

69-
As result, you get a list with the path.
75+
As result, you get a list with the path.
7076

7177
```java
72-
routeOne == ['D', 'C']
73-
routeTwo == ['D', 'E', 'F', 'G', 'C']
78+
routeOne==['D','C']
79+
routeTwo==['D','E','F','G','C']
7480
```
7581

7682
## Unit Tests
@@ -83,12 +89,15 @@ Tests are written in Groove language. For unit testing, the [Spock Framework](ht
8389

8490
```mermaid
8591
flowchart LR
86-
A --> |7| B
87-
A --> |2| C
88-
B --> |3| A
89-
B --> |5| C
90-
C --> |1| A
91-
C --> |3| B
92+
A((A))
93+
B((B))
94+
C((C))
95+
A -->|7| B
96+
A -->|2| C
97+
B -->|3| A
98+
B -->|5| C
99+
C -->|1| A
100+
C -->|3| B
92101
```
93102

94103
![Small Graph](docs/assets/small.gif)
@@ -127,5 +136,4 @@ flowchart LR
127136
H --> |3 | G
128137
```
129138

130-
![Complex Graph](docs/assets/complex.gif)
131-
139+
![Complex Graph](docs/assets/complex.gif)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env gawk --exec
2+
#
3+
# Copyright (c) 2023 Jegors Čemisovs
4+
# License: MIT License
5+
# Repository: https://github.com/rabestro/graph-pathfinding-algorithms
6+
#
7+
BEGIN {
8+
FS = "[ :,{}]+"
9+
print "flowchart LR"
10+
}
11+
{
12+
node = $1
13+
print node "((" node "))"
14+
15+
for (i = 2; i < NF; i += 2)
16+
printf "%s --> |%2d| %s\n", node, $(i + 1), $i
17+
}

graph-shell/src/script/graph2puml.awk

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/usr/bin/env gawk --exec
2+
#
3+
# Copyright (c) 2023 Jegors Čemisovs
4+
# License: MIT License
5+
# Repository: https://github.com/rabestro/graph-pathfinding-algorithms
6+
#
17
BEGIN {
28
FS = "[ :,{}]+"
39

@@ -17,4 +23,4 @@ BEGIN {
1723
END {
1824
print "}"
1925
print "@enddot"
20-
}
26+
}

0 commit comments

Comments
 (0)