/[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 1347 - (show annotations) (download) (as text)
Tue Mar 13 06:40:06 2007 UTC (13 years, 2 months ago) by jpye
File MIME type: text/x-csrc
File size: 2579 byte(s)
Added routine for outputting system as a DOT graph.
Changed an 'assert' to an 'asc_assert' in logrelation.c.
Changed logical relation in sequence.a4c (was causing a crash).
Added Simulation::write(FILE,char*) for outputting *stuff* from a simulation.
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
31 int system_write_graph(slv_system_t sys
32 , FILE *fp
33 , const rel_filter_t *rfilter, const var_filter_t *vfilter
34 ){
35 int nr,nsr,nv,nsv,niv;
36 int i,j;
37 struct rel_relation **srels;
38 struct var_variable **svars, **ivars;
39 char *relname, *varname;
40
41 fprintf(fp,"digraph G{\n");
42
43 /* first create nodes for the rels */
44 nr = slv_count_solvers_rels(sys,rfilter);
45 nsr = slv_get_num_solvers_rels(sys);
46 srels = slv_get_solvers_rel_list(sys);
47 fprintf(fp,"\n\n\t/* %d relations */\n\n",nr);
48 for(i=0; i<nsr; ++i){
49 if(rel_apply_filter(srels[i],rfilter)){
50 relname = rel_make_name(sys,srels[i]);
51 fprintf(fp,"\tr%d[shape=box,label=\"%s\"]\n",i,relname);
52 ASC_FREE(relname);
53 }
54 }
55
56 /* and the vars */
57 nsv = slv_get_num_solvers_vars(sys);
58 nv = slv_count_solvers_vars(sys,vfilter);
59 svars = slv_get_solvers_var_list(sys);
60 fprintf(fp,"\n\n\t/* %d variables */\n\n",nv);
61 for(j=0; j<nsv; ++j){
62 if(var_apply_filter(svars[j],vfilter)){
63 varname = var_make_name(sys,svars[j]);
64 fprintf(fp,"\tv%d[label=\"%s\"]\n",j,varname);
65 ASC_FREE(varname);
66 }
67 }
68
69 /* now output the edges between them */
70 fprintf(fp,"\n\n\t/* incidences */\n\n");
71 for(i=0; i<nsr; ++i){
72 if(!rel_apply_filter(srels[i],rfilter))continue;
73
74 ivars = rel_incidence_list(srels[i]);
75 niv = rel_n_incidences(srels[i]);
76
77 for(j=0; j<niv; ++j){
78 if(!var_apply_filter(ivars[j],vfilter))continue;
79
80 fprintf(fp,"\tv%d->r%d\n",var_sindex(ivars[j]),i);
81 }
82 }
83
84 fprintf(fp,"}\n");
85
86 CONSOLE_DEBUG("Completed graph output");
87 }
88
89
90
91

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