/[ascend]/trunk/base/generic/system/graph.c
ViewVC logotype

Contents of /trunk/base/generic/system/graph.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1678 - (show annotations) (download) (as text)
Wed Dec 19 00:29:48 2007 UTC (16 years, 7 months ago) by jpye
File MIME type: text/x-csrc
File size: 2762 byte(s)
Removed references to MFGRAPH, seems better to use GraphViz directly.
Added configuration test for GraphViz.
Added configuration test for strdup, fixed mmio to not create its own strdup if other form is available already.

1 /* ASCEND modelling environment
2 Copyright (C) 2007 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//** @file
19 System graph output
20
21 Use variable and relation filters to generate a graph between the selected
22 vars and rels, by querying their incidence data. Write the graph in DOT
23 format to the provided FILE*.
24
25 by John Pye, March 2007
26 */
27 #include "graph.h"
28 #include "slv_client.h"
29 #include <utilities/ascMalloc.h>
30 #include <utilities/ascPanic.h>
31
32 #ifdef WITH_GRAPHVIZ
33 #include <graphviz/gvc.h>
34 #endif
35
36 int system_write_graph(slv_system_t sys
37 , FILE *fp
38 , const rel_filter_t *rfilter, const var_filter_t *vfilter
39 ){
40 int nr,nsr,nv,nsv,niv;
41 int i,j;
42 struct rel_relation **srels;
43 struct var_variable **svars, **ivars;
44 char *relname, *varname;
45
46 CONSOLE_DEBUG("Writing graph...");
47 asc_assert(fp!=NULL);
48
49 CONSOLE_DEBUG("FP = %p",fp);
50 fprintf(fp,"digraph G{\n");
51
52 /* first create nodes for the rels */
53 nr = slv_count_solvers_rels(sys,rfilter);
54 nsr = slv_get_num_solvers_rels(sys);
55 srels = slv_get_solvers_rel_list(sys);
56 fprintf(fp,"\n\n\t/* %d relations */\n\n",nr);
57 for(i=0; i<nsr; ++i){
58 if(rel_apply_filter(srels[i],rfilter)){
59 relname = rel_make_name(sys,srels[i]);
60 fprintf(fp,"\tr%d[shape=box,label=\"%s\"]\n",i,relname);
61 ASC_FREE(relname);
62 }
63 }
64
65 /* and the vars */
66 nsv = slv_get_num_solvers_vars(sys);
67 nv = slv_count_solvers_vars(sys,vfilter);
68 svars = slv_get_solvers_var_list(sys);
69 fprintf(fp,"\n\n\t/* %d variables */\n\n",nv);
70 for(j=0; j<nsv; ++j){
71 if(var_apply_filter(svars[j],vfilter)){
72 varname = var_make_name(sys,svars[j]);
73 fprintf(fp,"\tv%d[label=\"%s\"]\n",j,varname);
74 ASC_FREE(varname);
75 }
76 }
77
78 /* now output the edges between them */
79 fprintf(fp,"\n\n\t/* incidences */\n\n");
80 for(i=0; i<nsr; ++i){
81 if(!rel_apply_filter(srels[i],rfilter))continue;
82
83 ivars = rel_incidence_list(srels[i]);
84 niv = rel_n_incidences(srels[i]);
85
86 for(j=0; j<niv; ++j){
87 if(!var_apply_filter(ivars[j],vfilter))continue;
88
89 fprintf(fp,"\tv%d->r%d\n",var_sindex(ivars[j]),i);
90 }
91 }
92
93 fprintf(fp,"}\n");
94
95 CONSOLE_DEBUG("Completed graph output");
96 return 0;
97 }
98
99
100
101

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22