OKlibrary  0.2.1.6
InputOutput.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 27.12.2007 (Swansea) */
00002 /* Copyright 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00022 /* ***************************************
00023    * Printing graphs in dot-format       *
00024    ***************************************
00025 */
00026 
00027 /* Functions for converting vertices into a string: */
00028 element_label(i) := sconcat("e",i)$
00029 string_vertex(v) := xreduce(sconcat, map(element_label, v))$
00030 print_vertices(V) := for v in V do print(sconcat(string_vertex(v), ";"))$
00031 
00032 /* Functions for converting set-edges into a string: */
00033 print_edge(e) := block(
00034  [le : listify(e)], 
00035   print(sconcat(string_vertex(le[1]), " -- ", string_vertex(le[2]), ";")))$
00036 print_edges(E) := for e in E do print_edge(e)$
00037 
00038 /* Printing out a graph in the dot-format: */
00039 print_graph_dot(G) := (
00040  print(sconcat("graph G {")), 
00041  print_vertices(G[1]), 
00042  print_edges(G[2]), 
00043  print("}")
00044 )$
00045 /* Output a graph g to file n: */
00046 output_graph(g,n) := with_stdout(n, print_graph(g))$
00047