Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
cluster.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12#include "../tools/openFile.h"
13#include <cgraph/unreachable.h>
14#include <stdio.h>
15#include <stdlib.h>
16#define STANDALONE
17#include <sparse/general.h>
18#include <sparse/QuadTree.h>
19#include <time.h>
20#include <sparse/SparseMatrix.h>
21#include <getopt.h>
22#include <string.h>
23#include "make_map.h"
26#include <neatogen/overlap.h>
27#include <sparse/clustering.h>
28#include <cgraph/ingraphs.h>
29#include <sparse/DotIO.h>
30#include <sparse/colorutil.h>
31
32typedef struct {
33 FILE* outfp;
34 char** infiles;
37} opts_t;
38
39static const char usestr[] =
40" -C k - generate no more than k clusters (0)\n\
41 0 : no limit\n\
42 -c k - use clustering method k (0)\n\
43 0 : use modularity\n\
44 1 : use modularity quality\n\
45 -o <outfile> - output file (stdout)\n\
46 -v - verbose mode\n\
47 -? - print usage\n";
48
49static void usage(char* cmd, int eval)
50{
51 fprintf(stderr, "Usage: %s <options> graphfile\n", cmd);
52 fputs (usestr, stderr);
54}
55
56static void init(int argc, char *argv[], opts_t* opts) {
57 char* cmd = argv[0];
58 int c;
59 int v;
60
61 opts->maxcluster = 0;
62 opts->outfp = stdout;
63 Verbose = 0;
64
66 while ((c = getopt(argc, argv, ":vC:c:o:?")) != -1) {
67 switch (c) {
68 case 'c':
69 if (sscanf(optarg, "%d", &v) == 0 || v < 0) {
70 usage(cmd,1);
71 }
72 else opts->clustering_method = v;
73 break;
74 case 'C':
75 if (sscanf(optarg, "%d", &v) == 0 || v < 0) {
76 usage(cmd,1);
77 }
78 else opts->maxcluster = v;
79 break;
80 case 'o':
81 opts->outfp = openFile(cmd, optarg, "w");
82 break;
83 case 'v':
84 Verbose = 1;
85 break;
86 case '?':
87 if (optopt == '\0' || optopt == '?')
88 usage(cmd, 0);
89 else {
90 fprintf(stderr, " option -%c unrecognized\n",
91 optopt);
92 usage(cmd, 1);
93 }
94 break;
95 default:
97 }
98 }
99
100 argv += optind;
101 argc -= optind;
102 if (argc)
103 opts->infiles = argv;
104 else
105 opts->infiles = NULL;
106}
107
108static void clusterGraph (Agraph_t* g, int maxcluster, int clustering_method){
109 initDotIO(g);
110 attached_clustering(g, maxcluster, clustering_method);
111}
112
113int main(int argc, char *argv[])
114{
115 Agraph_t *g = 0, *prevg = 0;
116 ingraph_state ig;
117 opts_t opts;
118
119 init(argc, argv, &opts);
120
121 newIngraph(&ig, opts.infiles);
122
123 while ((g = nextGraph (&ig)) != 0) {
124 if (prevg) agclose (prevg);
126 agwrite(g, opts.outfp);
127 prevg = g;
128 }
129
130 graphviz_exit(0);
131}
void initDotIO(Agraph_t *g)
Definition DotIO.c:654
void attached_clustering(Agraph_t *g, int maxcluster, int clustering_scheme)
Definition DotIO.c:568
@ CLUSTERING_MODULARITY
Definition clustering.h:39
static const char usestr[]
Definition cluster.c:39
static void init(int argc, char *argv[], opts_t *opts)
Definition cluster.c:56
static void clusterGraph(Agraph_t *g, int maxcluster, int clustering_method)
Definition cluster.c:108
static char * cmd
Definition acyclic.c:40
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
static int eval(Agraph_t *g, int root)
Definition gc.c:269
static int Verbose
Definition gml2gv.c:22
node NULL
Definition grammar.y:149
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:96
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:708
static opts_t opts
Definition gvgen.c:394
static const char * usage
Definition gvpr.c:53
Agraph_t * nextGraph(ingraph_state *sp)
Definition ingraphs.c:61
ingraph_state * newIngraph(ingraph_state *sp, char **files)
Definition ingraphs.c:140
supports user-supplied data
static FILE * openFile(const char *argv0, const char *name, const char *mode)
Definition openFile.h:8
graph or subgraph
Definition cgraph.h:425
int maxcluster
Definition cluster.c:35
int clustering_method
Definition cluster.c:36
FILE * outfp
Definition cluster.c:33
char ** infiles
Definition cluster.c:34
int main()
#define UNREACHABLE()
Definition unreachable.h:30