39#define ND_id(n) (((Agnodeinfo_t*)(n->base.data))->id)
43static double Hue2RGB(
double v1,
double v2,
double H)
50 return (v1 + (v2 - v1) * 6.0 * H);
54 return v1 + (v2 - v1) * (2.0 / 3.0 - H) * 6.0;
59 double v1, v2, lightness = .5, saturation = 1;
62 v2 = lightness + saturation - saturation * lightness;
64 v1 = 2.0 * lightness - v2;
66 red = (int) (255.0 *
Hue2RGB(v1, v2, hue + 1.0 / 3.0) + 0.5);
67 green = (int) (255.0 *
Hue2RGB(v1, v2, hue) + 0.5);
68 blue = (int) (255.0 *
Hue2RGB(v1, v2, hue - 1.0 / 3.0) + 0.5);
69 agxbprint(xb,
"#%02x%02x%02x", red, green, blue);
74 double * x,
int with_color,
int with_label,
int with_val)
92 fprintf (stderr,
"Warning: input matrix has no values, -c flag ignored\n");
96 fprintf (stderr,
"Warning: input has no coordinates, -c flag ignored\n");
101 if (
A->is_undirected) {
112 agxbprint (&xb,
"%s. %d nodes, %d edges.", name,
A->m,
A->nz);
116 for (i = 0; i <
A->m; i++) {
136 for (j = ia[i]; j < ia[i + 1]; j++) {
143 mindist = fmin(mindist,
color[j]);
146 maxdist = fmax(
color[j], maxdist);
149 for (j = ia[i]; j < ia[i + 1]; j++) {
150 if (val)
color[j] = fabs(val[j]);
157 mindist = fmin(mindist,
color[j]);
160 maxdist = fmax(
color[j], maxdist);
166 for (j = ia[i]; j < ia[i + 1]; j++) {
167 color[j] = (
color[j] - mindist) / fmax(maxdist - mindist, 0.000001);
174 for (j = ia[i]; j < ia[i + 1]; j++) {
195static char*
useString =
"Usage: %s [-uvcl] [-o file] matrix_market_filename\n\
196 -u - make graph undirected\n\
197 -U i - treat non-square matrix as a bipartite graph\n\
199 i = 1 if pattern unsymmetric (default)\n\
200 i = 2 if matrix unsymmetric\n\
202 -v - assign len to edges\n\
203 -c - assign color and wt to edges\n\
205 -o <file> - output file \n";
217 fprintf(stderr,
"Could not open %s for %s\n",
fname,
218 *
mode ==
'r' ?
"reading" :
"writing");
241 while ((c = getopt(argc, argv,
":o:uvclU:?")) != -1) {
268 fprintf(stderr,
"%s: option -%c missing argument - ignored\n",
cmd, optopt);
271 if (optopt ==
'\0' || optopt ==
'?')
275 "%s: option -%c unrecognized\n",
cmd,
293int main(
int argc,
char *argv[])
309 init(argc, argv, &pv);
315 fprintf (stderr,
"Unable to read input file \"%s\"\n", pv.
infile);
322 fprintf(stderr,
"cannot import from file %s\n", pv.
infile);
SparseMatrix SparseMatrix_to_square_matrix(SparseMatrix A, int bipartite_options)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_make_undirected(SparseMatrix A)
@ BIPARTITE_PATTERN_UNSYM
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
abstract graph C library, Cgraph API
static NORETURN void graphviz_exit(int status)
static int eval(Agraph_t *g, int root)
char * strip_dir(char *s)
double distance(double *x, int dim, int i, int j)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
int agxset(void *obj, Agsym_t *sym, const char *value)
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Agdesc_t Agundirected
undirected
Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
creates a new graph with the given name and kind
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Agdesc_t Agdirected
directed
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
static void color(Agraph_t *g)
static const char * usage
SparseMatrix SparseMatrix_import_matrix_market(FILE *f)
static char * hue2rgb(double hue, agxbuf *xb)
static void init(int argc, char **argv, parms_t *p)
static FILE * openF(char *fname, char *mode)
static Agraph_t * makeDotGraph(SparseMatrix A, char *name, int dim, double *x, int with_color, int with_label, int with_val)
static double Hue2RGB(double v1, double v2, double H)
implementation of Agrec_t