nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
a_star: don't crash on deserialization errors and limit static types
[nit.git]
/
lib
/
graphs
/
digraph.nit
diff --git
a/lib/graphs/digraph.nit
b/lib/graphs/digraph.nit
index
0b74c4c
..
65e0162
100644
(file)
--- a/
lib/graphs/digraph.nit
+++ b/
lib/graphs/digraph.nit
@@
-369,20
+369,31
@@
interface Digraph[V: Object]
fun to_dot: String
do
var s = "digraph \{\n"
fun to_dot: String
do
var s = "digraph \{\n"
+ var id_set = new HashMap[V, Int]
# Writing the vertices
# Writing the vertices
- for u in vertices_iterator do
- s += " \"{u.to_s.escape_to_dot}\" "
+ for u in vertices_iterator, i in [0 .. vertices.length[ do
+ id_set[u] = i
+ s += " \"{i}\" "
s += "[label=\"{u.to_s.escape_to_dot}\"];\n"
end
# Writing the arcs
for arc in arcs do
s += "[label=\"{u.to_s.escape_to_dot}\"];\n"
end
# Writing the arcs
for arc in arcs do
- s += " {arc[0].to_s.escape_to_dot} "
- s += "-> {arc[1].to_s.escape_to_dot};"
+ s += " {id_set[arc[0]]} "
+ s += "-> {id_set[arc[1]]};"
end
s += "\}"
return s
end
end
s += "\}"
return s
end
+ # Open Graphviz with `self.to_dot`.
+ #
+ # Mainly used for debugging.
+ fun show_dot do
+ var f = new ProcessWriter("dot", "-Txlib")
+ f.write to_dot
+ f.close
+ end
+
## ------------ ##
## Neighborhood ##
## ------------ ##
## ------------ ##
## Neighborhood ##
## ------------ ##