/[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 1349 - (show annotations) (download) (as text)
Tue Mar 13 07:26:43 2007 UTC (13 years ago) by jpye
File MIME type: text/x-csrc
File size: 2683 byte(s)
Fixed DOT graph output (system_write_graph), added very basic test case.
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 int system_write_graph(slv_system_t sys
33 , FILE *fp
34 , const rel_filter_t *rfilter, const var_filter_t *vfilter
35 ){
36 int nr,nsr,nv,nsv,niv;
37 int i,j;
38 struct rel_relation **srels;
39 struct var_variable **svars, **ivars;
40 char *relname, *varname;
41
42 CONSOLE_DEBUG("Writing graph...");
43 asc_assert(fp!=NULL);
44
45 fprintf(fp,"digraph G{\n");
46
47 /* first create nodes for the rels */
48 nr = slv_count_solvers_rels(sys,rfilter);
49 nsr = slv_get_num_solvers_rels(sys);
50 srels = slv_get_solvers_rel_list(sys);
51 fprintf(fp,"\n\n\t/* %d relations */\n\n",nr);
52 for(i=0; i<nsr; ++i){
53 if(rel_apply_filter(srels[i],rfilter)){
54 relname = rel_make_name(sys,srels[i]);
55 fprintf(fp,"\tr%d[shape=box,label=\"%s\"]\n",i,relname);
56 ASC_FREE(relname);
57 }
58 }
59
60 /* and the vars */
61 nsv = slv_get_num_solvers_vars(sys);
62 nv = slv_count_solvers_vars(sys,vfilter);
63 svars = slv_get_solvers_var_list(sys);
64 fprintf(fp,"\n\n\t/* %d variables */\n\n",nv);
65 for(j=0; j<nsv; ++j){
66 if(var_apply_filter(svars[j],vfilter)){
67 varname = var_make_name(sys,svars[j]);
68 fprintf(fp,"\tv%d[label=\"%s\"]\n",j,varname);
69 ASC_FREE(varname);
70 }
71 }
72
73 /* now output the edges between them */
74 fprintf(fp,"\n\n\t/* incidences */\n\n");
75 for(i=0; i<nsr; ++i){
76 if(!rel_apply_filter(srels[i],rfilter))continue;
77
78 ivars = rel_incidence_list(srels[i]);
79 niv = rel_n_incidences(srels[i]);
80
81 for(j=0; j<niv; ++j){
82 if(!var_apply_filter(ivars[j],vfilter))continue;
83
84 fprintf(fp,"\tv%d->r%d\n",var_sindex(ivars[j]),i);
85 }
86 }
87
88 fprintf(fp,"}\n");
89
90 CONSOLE_DEBUG("Completed graph output");
91 return 0;
92 }
93
94
95
96

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