-
+
should return an empty path if can't find a route
-
+
Return
diff --git a/docs/spock-reports/lv.id.jc.algorithm.graph.GraphSpec.html b/docs/spock-reports/lv.id.jc.algorithm.graph.GraphSpec.html
index 0105e4b..f83fed4 100644
--- a/docs/spock-reports/lv.id.jc.algorithm.graph.GraphSpec.html
+++ b/docs/spock-reports/lv.id.jc.algorithm.graph.GraphSpec.html
@@ -27,6 +27,10 @@
font-style: italic;
}
+.return-toc {
+ float: right; font-size: 60%;
+}
+
table.features-table {
width: 800px;
}
@@ -191,6 +195,11 @@
background: white !important;
}
+.ex-time {
+ font-style: italic;
+ font-size: smaller;
+}
+
.ex-pass {
color: darkgreen;
}
@@ -251,7 +260,7 @@ Report for lv.id.jc.algorithm.graph.GraphSpec
Summary:
- Created on Thu Jan 06 23:11:33 EET 2022 by jegors.cemisovs
+ Created on Sun Oct 16 12:33:47 EEST 2022 by jegors
@@ -272,7 +281,7 @@ Summary:
0 |
0 |
100.0% |
-0.047 seconds |
+0.032 seconds |
@@ -307,8 +316,9 @@ Features:
should return edges for a given node
-
+
Return
+(0)
|
@@ -362,17 +372,26 @@ Features:
A |
[B:7, C:2] |
-OK |
+
+OK
+(0)
+ |
B |
[A:3, C:5] |
-OK |
+
+OK
+(0)
+ |
C |
[A:1, B:3] |
-OK |
+
+OK
+(0)
+ |
@@ -386,8 +405,9 @@ Features:
should calculate distance for a path
-
+
Return
+(0)
|
@@ -454,42 +474,66 @@ Features:
[A] |
0 |
-OK |
+
+OK
+(0)
+ |
[A, B] |
5 |
-OK |
+
+OK
+(0)
+ |
[B, A] |
5 |
-OK |
+
+OK
+(0)
+ |
[A, B, A] |
10 |
-OK |
+
+OK
+(0)
+ |
[A, B, A, B] |
15 |
-OK |
+
+OK
+(0)
+ |
[C, D] |
3 |
-OK |
+
+OK
+(0)
+ |
[D, C] |
20 |
-OK |
+
+OK
+(0)
+ |
[D, E, F, G, C] |
19 |
-OK |
+
+OK
+(0)
+ |
@@ -503,8 +547,9 @@ Features:
should be zero distance for an empty path
-
+
Return
+(0.020 seconds)
|
@@ -541,8 +586,9 @@ Features:
should be zero distance for any one node path
-
+
Return
+(0)
|
@@ -598,23 +644,38 @@ Features:
[A] |
-OK |
+
+OK
+(0)
+ |
[B] |
-OK |
+
+OK
+(0)
+ |
[2] |
-OK |
+
+OK
+(0)
+ |
[X] |
-OK |
+
+OK
+(0)
+ |
[12.56] |
-OK |
+
+OK
+(0)
+ |
@@ -628,8 +689,9 @@ Features:
should throw NPE for incorrect path
-
+
Return
+(0)
|
@@ -705,15 +767,24 @@ Features:
[E, D] |
-OK |
+
+OK
+(0)
+ |
[A, C] |
-OK |
+
+OK
+(0)
+ |
[A, B, D] |
-OK |
+
+OK
+(0)
+ |
diff --git a/docs/spock-reports/lv.id.jc.algorithm.graph.SearchAlgorithmSpec.html b/docs/spock-reports/lv.id.jc.algorithm.graph.SearchAlgorithmsSpec.html
similarity index 76%
rename from docs/spock-reports/lv.id.jc.algorithm.graph.SearchAlgorithmSpec.html
rename to docs/spock-reports/lv.id.jc.algorithm.graph.SearchAlgorithmsSpec.html
index c36de8c..3210ffe 100644
--- a/docs/spock-reports/lv.id.jc.algorithm.graph.SearchAlgorithmSpec.html
+++ b/docs/spock-reports/lv.id.jc.algorithm.graph.SearchAlgorithmsSpec.html
@@ -27,6 +27,10 @@
font-style: italic;
}
+.return-toc {
+ float: right; font-size: 60%;
+}
+
table.features-table {
width: 800px;
}
@@ -191,6 +195,11 @@
background: white !important;
}
+.ex-time {
+ font-style: italic;
+ font-size: smaller;
+}
+
.ex-pass {
color: darkgreen;
}
@@ -244,14 +253,14 @@
- Report for lv.id.jc.algorithm.graph.SearchAlgorithmSpec
+ Report for lv.id.jc.algorithm.graph.SearchAlgorithmsSpec
Summary:
- Created on Thu Jan 06 23:11:33 EET 2022 by jegors.cemisovs
+ Created on Sun Oct 16 12:33:47 EEST 2022 by jegors
@@ -272,12 +281,29 @@ Summary:
0 |
0 |
100.0% |
-0.012 seconds |
+0.005 seconds |
Comparison of two algorithms
+
Features:
@@ -294,8 +320,9 @@ Features:
should find a route for a complex graph
-
+
Return
+(0)
|
@@ -305,6 +332,12 @@ Features:
Given:
+ a complex graph with eight nodes
+ |
+
+
+ |
+
def graph = Graph.of([
A: [B: 5, H: 2],
B: [A: 5, C: 7],
@@ -322,6 +355,12 @@ Features:
When:
|
+ we use Breadth First Search algorithm for the first route
+ |
+
+
+ |
+
def routeOne = bfsAlgorithm.findPath(graph, source, target)
|
@@ -330,6 +369,12 @@ Features:
And:
+ we use Dijkstra's algorithm for the second route
+ |
+
+
+ |
+
def routeTwo = dijkstras.findPath(graph, source, target)
|
@@ -338,6 +383,12 @@ Features:
Then:
+ the first route is the shortest
+ |
+
+
+ |
+
routeOne == shortest
|
@@ -346,6 +397,12 @@ Features:
And:
+ the second route is the fastest
+ |
+
+
+ |
+
routeTwo == fastest
|
@@ -354,8 +411,14 @@ Features:
And:
-graph.getDistance(routeOne) == d1 as double
-graph.getDistance(routeTwo) == d2 as double
+the distance calculated correctly
+ |
+
+
+ |
+
+graph.getDistance(routeOne) == t1 as double
+graph.getDistance(routeTwo) == t2 as double
|
@@ -369,9 +432,9 @@ Features:
-
+
-
+
@@ -383,7 +446,10 @@ Features:
[A] |
0 |
[A] |
-OK |
+
+OK
+(0)
+ |
B |
@@ -392,7 +458,10 @@ Features:
[B] |
0 |
[B] |
-OK |
+
+OK
+(0)
+ |
A |
@@ -401,7 +470,10 @@ Features:
[A, B] |
5 |
[A, B] |
-OK |
+
+OK
+(0)
+ |
B |
@@ -410,7 +482,10 @@ Features:
[B, A] |
5 |
[B, A] |
-OK |
+
+OK
+(0)
+ |
A |
@@ -419,7 +494,10 @@ Features:
[A, B, C] |
9 |
[A, H, G, C] |
-OK |
+
+OK
+(0)
+ |
C |
@@ -428,7 +506,10 @@ Features:
[C, B, A] |
12 |
[C, B, A] |
-OK |
+
+OK
+(0)
+ |
A |
@@ -437,7 +518,10 @@ Features:
[A, H, G] |
5 |
[A, H, G] |
-OK |
+
+OK
+(0)
+ |
C |
@@ -446,7 +530,10 @@ Features:
[C, D] |
3 |
[C, D] |
-OK |
+
+OK
+(0)
+ |
D |
@@ -455,7 +542,10 @@ Features:
[D, C] |
19 |
[D, E, F, G, C] |
-OK |
+
+OK
+(0)
+ |
B |
@@ -464,7 +554,10 @@ Features:
[B, C, D] |
10 |
[B, C, D] |
-OK |
+
+OK
+(0)
+ |
D |
@@ -473,7 +566,10 @@ Features:
[D, C, B] |
26 |
[D, E, F, G, C, B] |
-OK |
+
+OK
+(0)
+ |
D |
@@ -482,7 +578,10 @@ Features:
[D, C, B, A, H] |
33 |
[D, E, F, G, C, B, A, H] |
-OK |
+
+OK
+(0)
+ |
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 2e6e589..ae04661 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
old mode 100644
new mode 100755
index c53aefa..1b6c787
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
#!/bin/sh
#
-# Copyright © 2015-2021 the original authors.
+# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
-# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
-# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
-# * compound commands having a testable exit status, especially «case»;
-# * various built-in commands including «command», «set», and «ulimit».
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
diff --git a/graph-shell/README.md b/graph-shell/README.md
new file mode 100644
index 0000000..ee363c1
--- /dev/null
+++ b/graph-shell/README.md
@@ -0,0 +1,109 @@
+---
+title: "Sample application: Graph Shell"
+---
+
+## About
+
+To demonstrate the work of search algorithms, I made a small console program. The program allows you to select one of three graph samples and search for a path using two algorithms. The source code of the program is located in `graph-shell` module.
+
+## Build & Run
+
+To compile the program, use the command:
+
+```shell
+$ gradle assemble
+```
+
+This command will create an executable jar, so in Linux or macOS you may run the application by
+
+```shell
+$ ./build/libs/graph-shell-1.0-SNAPSHOT.jar
+```
+
+On the Windows machine you should run the application using java:
+
+```shell
+$ java -jar ./build/libs/graph-shell-1.0-SNAPSHOT.jar
+```
+
+## Using Graph Shell
+
+The application has build-in three graph schemas: `simple`, `medium`, `complex`. By default the `complex` scheme is loaded. You may specify the schema in the `application.properties` file:
+
+```properties
+graph=simple
+```
+
+Alternatively you may specify the command line parameter when you run the application:
+
+```shell
+$ ./build/libs/graph-shell-1.0-SNAPSHOT.jar --graph=medium
+```
+
+After starting the program you will see the banner and the prompt indicating the current graph scheme.
+
+```shell
+$ ./build/libs/graph-shell-1.0-SNAPSHOT.jar
+
+ _____ _ _____ _ _ _
+ / ____| | | / ____| | | | | | |
+ | | __ _ __ __ _ _ __ | |__ | (___ | |__ ___ | | | |
+ | | |_ | | '__| / _` | | '_ \ | '_ \ \___ \ | '_ \ / _ \ | | | |
+ | |__| | | | | (_| | | |_) | | | | | ____) | | | | | | __/ | | | |
+ \_____| |_| \__,_| | .__/ |_| |_| |_____/ |_| |_| \___| |_| |_|
+ | |
+ |_|
+
+complex:>
+```
+
+The command help will show all available commands with short description.
+
+```shell
+complex:> help
+AVAILABLE COMMANDS
+
+Built-In Commands
+ clear: Clear the shell screen.
+ exit, quit: Exit the shell.
+ help: Display help about available commands.
+ history: Display or save the history of previously run commands
+ script: Read and execute commands from a file.
+ stacktrace: Display the full stacktrace of the last error.
+
+Commands
+ distance: prints distance for the path
+ fastest: finds the fastest path by using Dijkstra's Algorithm
+ schema: prints schema of the graph
+ shortest: finds the shortest path by using Breadth First Search Algorithm
+```
+
+Typing `help ` you will get more detailed information about each command.
+
+```shell
+complex:> help fastest
+
+
+NAME
+ fastest - finds the fastest path by using Dijkstra's Algorithm
+
+SYNOPSYS
+ fastest [--source] string [--target] string
+
+OPTIONS
+ --source string
+
+ [Mandatory]
+ [this vertex was not found in the graph diagram]
+
+ --target string
+
+ [Mandatory]
+ [this vertex was not found in the graph diagram]
+```
+
+The program supports scripts. I provide one script `test1.script` to demonstrate the difference between two algorithms.
+
+
+
+
diff --git a/graph-shell/build.gradle b/graph-shell/build.gradle
new file mode 100644
index 0000000..dbba16f
--- /dev/null
+++ b/graph-shell/build.gradle
@@ -0,0 +1,30 @@
+plugins {
+ id 'java'
+ id 'org.springframework.boot' version '2.7.1'
+ id 'io.spring.dependency-management' version '1.0.11.RELEASE'
+}
+
+repositories {
+ mavenCentral()
+ maven { url 'https://repo.spring.io/release' }
+ maven { url 'https://repo.spring.io/libs-snapshot-local' }
+ maven { url 'https://repo.spring.io/libs-milestone-local' }
+}
+
+dependencies {
+ implementation project(':algorithm')
+ implementation 'org.springframework.boot:spring-boot-starter'
+ implementation 'org.springframework.shell:spring-shell-starter:2.1.3'
+
+ // YAML
+ implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4.2'
+ implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4'
+}
+
+bootJar {
+ launchScript()
+}
+
+group 'lv.id.jc'
+version '1.0-SNAPSHOT'
+
diff --git a/graph-shell/docs/complex.png b/graph-shell/docs/complex.png
new file mode 100644
index 0000000..ba793eb
Binary files /dev/null and b/graph-shell/docs/complex.png differ
diff --git a/graph-shell/docs/complex.puml b/graph-shell/docs/complex.puml
new file mode 100644
index 0000000..759f9ce
--- /dev/null
+++ b/graph-shell/docs/complex.puml
@@ -0,0 +1,29 @@
+@startdot
+digraph complex {
+fontname="Helvetica,Arial,sans-serif"
+node [fontname="Helvetica,Arial,sans-serif"]
+edge [fontname="Helvetica,Arial,sans-serif"]
+node [color=lightblue2, style=filled, shape=circle];
+A
+A -> B [label=5];
+A -> H [label=2];
+B
+B -> A [label=5];
+B -> C [label=7];
+C
+C -> B [label=7];
+C -> D [label=3];
+C -> G [label=4];
+D
+D -> C [label=20];
+D -> E [label=4];
+E
+E -> F [label=5];
+F
+F -> G [label=6];
+G
+G -> C [label=4];
+H
+H -> G [label=3];
+}
+@enddot
diff --git a/graph-shell/docs/medium.puml b/graph-shell/docs/medium.puml
new file mode 100644
index 0000000..4e53de8
--- /dev/null
+++ b/graph-shell/docs/medium.puml
@@ -0,0 +1,20 @@
+@startdot
+digraph medium {
+fontname="Helvetica,Arial,sans-serif"
+node [fontname="Helvetica,Arial,sans-serif"]
+edge [fontname="Helvetica,Arial,sans-serif"]
+node [color=lightblue2, style=filled, shape=circle];
+A
+A -> B [label=5];
+B
+B -> A [label=5];
+B -> C [label=10];
+C
+C -> B [label=20];
+C -> D [label=5];
+D
+D -> E [label=5];
+E
+E -> B [label=5];
+}
+@enddot
diff --git a/graph-shell/docs/simple.puml b/graph-shell/docs/simple.puml
new file mode 100644
index 0000000..5205658
--- /dev/null
+++ b/graph-shell/docs/simple.puml
@@ -0,0 +1,17 @@
+@startdot
+digraph simple {
+fontname="Helvetica,Arial,sans-serif"
+node [fontname="Helvetica,Arial,sans-serif"]
+edge [fontname="Helvetica,Arial,sans-serif"]
+node [color=lightblue2, style=filled, shape=circle];
+A
+A -> B [label=7];
+A -> C [label=2];
+B
+B -> A [label=3];
+B -> C [label=5];
+C
+C -> A [label=1];
+C -> B [label=3];
+}
+@enddot
diff --git a/graph-shell/src/main/java/lv/id/jc/graph/cli/Commands.java b/graph-shell/src/main/java/lv/id/jc/graph/cli/Commands.java
new file mode 100644
index 0000000..17bb0bf
--- /dev/null
+++ b/graph-shell/src/main/java/lv/id/jc/graph/cli/Commands.java
@@ -0,0 +1,76 @@
+package lv.id.jc.graph.cli;
+
+import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
+import lv.id.jc.algorithm.graph.BreadthFirstSearch;
+import lv.id.jc.algorithm.graph.DijkstrasAlgorithm;
+import lv.id.jc.algorithm.graph.Graph;
+import lv.id.jc.algorithm.graph.SearchAlgorithm;
+import org.jline.utils.AttributedString;
+import org.jline.utils.AttributedStyle;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.shell.jline.PromptProvider;
+import org.springframework.shell.standard.ShellComponent;
+import org.springframework.shell.standard.ShellMethod;
+
+import javax.annotation.PostConstruct;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.NotEmpty;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+@ShellComponent
+public class Commands implements PromptProvider, ConstraintValidator {
+ private final SearchAlgorithm bfgAlgorithm = new BreadthFirstSearch<>();
+ private final SearchAlgorithm dijkstrasAlgorithm = new DijkstrasAlgorithm<>();
+
+ @Value("${graph:complex}")
+ private String graphName;
+
+ private Graph graph;
+
+ @PostConstruct
+ public void loadGraph() throws IOException {
+ var resource = new ClassPathResource(graphName + ".yaml");
+ var schema = new YAMLMapper().readValue(resource.getInputStream(), Map.class);
+ graph = Graph.of(schema);
+ }
+
+ @Override
+ public AttributedString getPrompt() {
+ return new AttributedString(graphName + ":> ", AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW));
+ }
+
+ @Override
+ public boolean isValid(String vertex, ConstraintValidatorContext context) {
+ return graph.schema().containsKey(vertex);
+ }
+
+ @ShellMethod("Find the shortest path by using Breadth First Search Algorithm.")
+ public List shortest(@Vertex String source, @Vertex String target) {
+ return bfgAlgorithm.findPath(graph, source, target);
+ }
+
+ @ShellMethod("Find the fastest path by using Dijkstra's Algorithm.")
+ public List fastest(@Vertex String source, @Vertex String target) {
+ return dijkstrasAlgorithm.findPath(graph, source, target);
+ }
+
+ @ShellMethod("Print the edges of the given vertex.")
+ public Map edges(@Vertex String vertex) {
+ return graph.edges(vertex);
+ }
+
+ @ShellMethod("Print schema of the graph.")
+ public Map> schema() {
+ return graph.schema();
+ }
+
+ @ShellMethod("Calculate the distance for the given path.")
+ public double distance(@NotEmpty List path) {
+ return graph.getDistance(path);
+ }
+
+}
diff --git a/graph-shell/src/main/java/lv/id/jc/graph/cli/GraphShell.java b/graph-shell/src/main/java/lv/id/jc/graph/cli/GraphShell.java
new file mode 100644
index 0000000..ef9b391
--- /dev/null
+++ b/graph-shell/src/main/java/lv/id/jc/graph/cli/GraphShell.java
@@ -0,0 +1,12 @@
+package lv.id.jc.graph.cli;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class GraphShell {
+
+ public static void main(String[] args) {
+ SpringApplication.run(GraphShell.class, args);
+ }
+}
diff --git a/graph-shell/src/main/java/lv/id/jc/graph/cli/Vertex.java b/graph-shell/src/main/java/lv/id/jc/graph/cli/Vertex.java
new file mode 100644
index 0000000..bd7511d
--- /dev/null
+++ b/graph-shell/src/main/java/lv/id/jc/graph/cli/Vertex.java
@@ -0,0 +1,20 @@
+package lv.id.jc.graph.cli;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.PARAMETER;
+
+@Target({PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+@Constraint(validatedBy = {Commands.class})
+public @interface Vertex {
+ String message() default "must be present in the graph scheme";
+
+ Class>[] groups() default {};
+
+ Class extends Payload>[] payload() default {};
+}
diff --git a/graph-shell/src/main/java/lv/id/jc/graph/cli/package-info.java b/graph-shell/src/main/java/lv/id/jc/graph/cli/package-info.java
new file mode 100644
index 0000000..d0b00b7
--- /dev/null
+++ b/graph-shell/src/main/java/lv/id/jc/graph/cli/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * The package contains a simple shell program to demonstrate the work of search algorithms.
+ */
+package lv.id.jc.graph.cli;
\ No newline at end of file
diff --git a/graph-shell/src/main/resources/application.properties b/graph-shell/src/main/resources/application.properties
new file mode 100644
index 0000000..c080813
--- /dev/null
+++ b/graph-shell/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+spring.main.allow-circular-references=true
+logging.level.root=WARN
diff --git a/graph-shell/src/main/resources/banner.txt b/graph-shell/src/main/resources/banner.txt
new file mode 100644
index 0000000..c51d47b
--- /dev/null
+++ b/graph-shell/src/main/resources/banner.txt
@@ -0,0 +1,9 @@
+
+ _____ _ _____ _ _ _
+ / ____| | | / ____| | | | | | |
+ | | __ _ __ __ _ _ __ | |__ | (___ | |__ ___ | | | |
+ | | |_ | | '__| / _` | | '_ \ | '_ \ \___ \ | '_ \ / _ \ | | | |
+ | |__| | | | | (_| | | |_) | | | | | ____) | | | | | | __/ | | | |
+ \_____| |_| \__,_| | .__/ |_| |_| |_____/ |_| |_| \___| |_| |_|
+ | |
+ |_|
diff --git a/graph-shell/src/main/resources/complex.yaml b/graph-shell/src/main/resources/complex.yaml
new file mode 100644
index 0000000..64332c4
--- /dev/null
+++ b/graph-shell/src/main/resources/complex.yaml
@@ -0,0 +1,8 @@
+A: { B: 5, H: 2 }
+B: { A: 5, C: 7 }
+C: { B: 7, D: 3, G: 4 }
+D: { C: 20, E: 4 }
+E: { F: 5 }
+F: { G: 6 }
+G: { C: 4 }
+H: { G: 3 }
diff --git a/graph-shell/src/main/resources/medium.yaml b/graph-shell/src/main/resources/medium.yaml
new file mode 100644
index 0000000..5c95ddf
--- /dev/null
+++ b/graph-shell/src/main/resources/medium.yaml
@@ -0,0 +1,5 @@
+A: { B: 5 }
+B: { A: 5, C: 10 }
+C: { B: 20, D: 5 }
+D: { E: 5 }
+E: { B: 5 }
diff --git a/graph-shell/src/main/resources/simple.yaml b/graph-shell/src/main/resources/simple.yaml
new file mode 100644
index 0000000..b22e0b0
--- /dev/null
+++ b/graph-shell/src/main/resources/simple.yaml
@@ -0,0 +1,3 @@
+A: { B: 7, C: 2 }
+B: { A: 3, C: 5 }
+C: { A: 1, B: 3 }
diff --git a/graph-shell/src/script/graph2mermaid.awk b/graph-shell/src/script/graph2mermaid.awk
new file mode 100644
index 0000000..32d8aef
--- /dev/null
+++ b/graph-shell/src/script/graph2mermaid.awk
@@ -0,0 +1,17 @@
+#!/usr/bin/env gawk --exec
+#
+# Copyright (c) 2023 Jegors ÄŒemisovs
+# License: MIT License
+# Repository: https://github.com/rabestro/graph-pathfinding-algorithms
+#
+BEGIN {
+ FS = "[ :,{}]+"
+ print "flowchart LR"
+}
+{
+ node = $1
+ print node "((" node "))"
+
+ for (i = 2; i < NF; i += 2)
+ printf "%s --> |%2d| %s\n", node, $(i + 1), $i
+}
\ No newline at end of file
diff --git a/graph-shell/src/script/graph2puml.awk b/graph-shell/src/script/graph2puml.awk
new file mode 100644
index 0000000..8f7da75
--- /dev/null
+++ b/graph-shell/src/script/graph2puml.awk
@@ -0,0 +1,26 @@
+#!/usr/bin/env gawk --exec
+#
+# Copyright (c) 2023 Jegors ÄŒemisovs
+# License: MIT License
+# Repository: https://github.com/rabestro/graph-pathfinding-algorithms
+#
+BEGIN {
+ FS = "[ :,{}]+"
+
+ match(FILENAME, /([^/]+)\.yaml/, GraphName)
+ print "@startdot"
+ print "digraph", GraphName[1], "{"
+ print "fontname=\"Helvetica,Arial,sans-serif\""
+ print "node [fontname=\"Helvetica,Arial,sans-serif\"]"
+ print "edge [fontname=\"Helvetica,Arial,sans-serif\"]"
+ print "node [color=lightblue2, style=filled, shape=circle];"
+}
+{
+ print $1
+ for (i = 2; i < NF; i += 2)
+ print $1, "->", $i, "[label=" $(i + 1) "];"
+}
+END {
+ print "}"
+ print "@enddot"
+}
\ No newline at end of file
diff --git a/graph-shell/test1.script b/graph-shell/test1.script
new file mode 100644
index 0000000..a150925
--- /dev/null
+++ b/graph-shell/test1.script
@@ -0,0 +1,14 @@
+// The simple test is demonstrate the difference between two algorithms
+// By default the application loads the complex graph
+
+// We make a search by using Breadth First Search algorithm
+shortest D B
+
+// The path is shortest and we check the distance/time
+distance D,C,B
+
+// For second search we use Dijkstras algorithm
+fastest D B
+
+// For the same source and target the path is longer but it requires less time
+distance D,E,F,G,C,B
diff --git a/sample-groovy/build.gradle b/sample-groovy/build.gradle
index a95ad88..18b78ad 100644
--- a/sample-groovy/build.gradle
+++ b/sample-groovy/build.gradle
@@ -11,7 +11,7 @@ repositories {
}
dependencies {
- implementation 'org.codehaus.groovy:groovy-all:3.0.8'
+ implementation 'org.codehaus.groovy:groovy-all:3.0.12'
implementation project(':algorithm')
}
diff --git a/sample-java/build.gradle b/sample-java/build.gradle
index 7a1e561..3fe74e7 100644
--- a/sample-java/build.gradle
+++ b/sample-java/build.gradle
@@ -6,6 +6,10 @@ java {
sourceCompatibility = JavaVersion.VERSION_17
}
+repositories {
+ mavenCentral()
+}
+
dependencies {
implementation project(':algorithm')
}
@@ -14,3 +18,7 @@ application {
mainModule = 'lv.id.jc.sample'
mainClass = 'lv.id.jc.sample.GraphApp'
}
+
+run {
+ standardInput = System.in
+}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 3c86329..2daba11 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1,2 @@
rootProject.name = 'algorithms'
-include 'algorithm', 'sample-java', 'sample-groovy'
+include 'algorithm', 'sample-java', 'sample-groovy', 'graph-shell'
|