read edges from stdin instead of argv
This commit is contained in:
parent
ecc6296d85
commit
ca090daabe
2 changed files with 20 additions and 14 deletions
26
README.md
26
README.md
|
@ -11,25 +11,26 @@ Algorithm by R. Tarjan
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
python cycles.py 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" | python cycles.py
|
||||||
|
|
||||||
First argument is the number of vertices. Subsequent arguments are ordered
|
First argument is the number of vertices. Ordered pairs of space separated
|
||||||
pairs of comma separated vertices that make up the directed edges of the
|
vertices are given via standard input and make up the directed edges of the
|
||||||
graph.
|
graph.
|
||||||
|
|
||||||
DOT file input
|
DOT file input
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
For simplicity, there is no DOT file parser included but the following allows
|
For simplicity, there is no DOT file parser included but the following allows
|
||||||
to create a suitable argument string for simple DOT graphs.
|
to create a suitable argument string and standard input for simple DOT graphs.
|
||||||
|
|
||||||
Given a DOT file of a simple (no labels, colors, styles, only pairs of
|
Given a DOT file of a simple (no labels, colors, styles, only pairs of
|
||||||
vertices...) directed graph, the following line produces commandline
|
vertices...) directed graph, the following lines generate the number of
|
||||||
arguments in the above format for that graph.
|
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 works on DOT files like the following:
|
||||||
|
|
||||||
digraph G {
|
digraph G {
|
||||||
0;
|
0;
|
||||||
|
@ -42,6 +43,11 @@ The above line works on DOT files like the following:
|
||||||
2 -> 1;
|
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
|
||||||
|
|
|
@ -61,13 +61,13 @@ procedure circuit_enumeration;
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) != 2:
|
||||||
print "usage: %s num_vertices [v1,v2...]"%(sys.argv[0])
|
print "usage: echo \"v1 v2\nv1 v3\n...\" | %s num_vertices"%(sys.argv[0])
|
||||||
|
|
||||||
A = [[] for a in range(int(sys.argv[1]))]
|
A = [[] for a in range(int(sys.argv[1]))]
|
||||||
|
|
||||||
for edge in sys.argv[2:]:
|
for edge in sys.stdin.readlines():
|
||||||
v1,v2 = edge.split(',', 1)
|
v1,v2 = edge.split(' ', 1)
|
||||||
A[int(v1)].append(int(v2));
|
A[int(v1)].append(int(v2));
|
||||||
|
|
||||||
def print_point_stack():
|
def print_point_stack():
|
||||||
|
|
Loading…
Reference in a new issue