diff --git a/README.md b/README.md index 0d0ecc2..483928b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Usage ----- make - java de.normalisiert.utils.graphs.TestCycles 4 0,1 0,2 1,0 1,3 2,0 3,0 3,1 3,2 + echo "0 1\n0 2\n1 0\n1 3\n2 0\n3 0\n3 1\n3 2" | java de.normalisiert.utils.graphs.TestCycles 4 First argument is the number of vertices. Subsequent arguments are ordered pairs of comma separated vertices that make up the directed edges of the @@ -24,12 +24,13 @@ For simplicity, there is no DOT file parser included but the following allows to create a suitable argument string for simple DOT graphs. Given a DOT file of a simple (no labels, colors, styles, only pairs of -vertices...) directed graph, the following line produces commandline -arguments in the above format for that graph. +vertices...) directed graph, the following lines generate the number of +vertices as well as the edge list expected on standard input. - echo `sed -n -e '/^\s*[0-9]\+;$/p' graph.dot | wc -l` `sed -n -e 's/^\s*\([0-9]\) -> \([0-9]\);$/\1,\2/p' graph.dot` + sed -n -e '/^\s*[0-9]\+;$/p' graph.dot | wc -l + sed -n -e 's/^\s*\([0-9]\) -> \([0-9]\);$/\1 \2/p' graph.dot -The above line works on DOT files like the following: +The above lines work on DOT files like the following: digraph G { 0; @@ -42,6 +43,11 @@ The above line works on DOT files like the following: 2 -> 1; } -It would produce the following output: +They would produce the following output: - 3 0,1 0,2 1,0 2,0 2,1 + 3 + 0 1 + 0 2 + 1 0 + 2 0 + 2 1 diff --git a/de/normalisiert/utils/graphs/TestCycles.java b/de/normalisiert/utils/graphs/TestCycles.java index 6e636e3..a952df8 100644 --- a/de/normalisiert/utils/graphs/TestCycles.java +++ b/de/normalisiert/utils/graphs/TestCycles.java @@ -2,6 +2,7 @@ package de.normalisiert.utils.graphs; import java.util.List; +import java.io.*; /** @@ -15,9 +16,9 @@ public class TestCycles { /** * @param args */ - public static void main(String[] args) { - if (args.length < 2) { - System.out.println("usage: de.normalisiert.utils.graphs.TestCycles num_vertices [v1,v2...]"); + public static void main(String[] args) throws java.io.IOException { + if (args.length != 1) { + System.out.println("usage: echo \"v1 v2\nv1 v3\n...\" | de.normalisiert.utils.graphs.TestCycles num_vertices"); System.exit(1); } @@ -43,8 +44,11 @@ public class TestCycles { adjMatrix[7][9] = true; adjMatrix[9][6] = true;*/ - for (int i = 1; i < args.length; i++) { - String[] vertices = args[i].split(",", 2); + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + String line; + + while ((line = stdin.readLine()) != null && line.length()!= 0) { + String[] vertices = line.split(" ", 2); int v1 = Integer.parseInt(vertices[0]); int v2 = Integer.parseInt(vertices[1]); adjMatrix[v1][v2] = true;