From e1f3e21aa43a8e61c32dcb985be3860d0b2e6b62 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 20 Jun 2021 12:30:39 -0700 Subject: [PATCH] remove color_diff and color_diff_sum computation from node_distinct_coloring Neither of the callers of this function use the results returned in these output parameters. --- cmd/gvmap/make_map.c | 6 ++---- lib/edgepaint/edge_distinct_coloring.c | 7 +++---- lib/edgepaint/node_distinct_coloring.c | 28 +++++++++----------------- lib/edgepaint/node_distinct_coloring.h | 2 +- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index 3a8626fec..f40e4bb97 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -49,10 +49,8 @@ void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMat */ /*color: On input an array of size n*cdim, if NULL, will be allocated. On exit the final color assignment for node i is [cdim*i,cdim*(i+1)), in RGB (between 0 to 1) - color_diff: the minuimum color difference across all edges - color_diff_sum: the sum of min color dfference across all nodes */ - real *colors = NULL, color_diff, color_diff_sum; + real *colors = NULL; int n = A0->m, i, cdim; SparseMatrix A; @@ -69,7 +67,7 @@ void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMat SparseMatrix_export(stdout, A); } - node_distinct_coloring(color_scheme, lightness, weightedQ, A, accuracy, iter_max, seed, &cdim, &colors, &color_diff, &color_diff_sum); + node_distinct_coloring(color_scheme, lightness, weightedQ, A, accuracy, iter_max, seed, &cdim, &colors); if (A != A0){ SparseMatrix_delete(A); diff --git a/lib/edgepaint/edge_distinct_coloring.c b/lib/edgepaint/edge_distinct_coloring.c index 479bf607f..977441395 100644 --- a/lib/edgepaint/edge_distinct_coloring.c +++ b/lib/edgepaint/edge_distinct_coloring.c @@ -160,7 +160,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* int *irn, *jcn, nz, nz2 = 0; real cos_critical = cos(angle/180*3.14159), cos_a; int u1, v1, u2, v2, i, j; - real *colors = NULL, color_diff, color_diff_sum; + real *colors = NULL; int flag, ne; char **xsplines = NULL; int cdim; @@ -238,7 +238,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* #endif int weightedQ = FALSE; int iter_max = 100; - flag = node_distinct_coloring(color_scheme, lightness, weightedQ, C, accuracy, iter_max, seed, &cdim, &colors, &color_diff, &color_diff_sum); + flag = node_distinct_coloring(color_scheme, lightness, weightedQ, C, accuracy, iter_max, seed, &cdim, &colors); if (flag) goto RETURN; #ifdef TIME fprintf(stderr, "cpu for color assignmment =%10.3f\n", ((real) (clock() - start))/CLOCKS_PER_SEC); @@ -246,8 +246,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* } if (Verbose) - fprintf(stderr,"The edge conflict graph has %d nodes and %d edges, final color_diff=%f color_diff_sum = %f\n", - C->m, C->nz, color_diff, color_diff_sum); + fprintf(stderr,"The edge conflict graph has %d nodes and %d edges\n", C->m, C->nz); attach_edge_colors(g, cdim, colors); diff --git a/lib/edgepaint/node_distinct_coloring.c b/lib/edgepaint/node_distinct_coloring.c index f16995fdc..827e18057 100644 --- a/lib/edgepaint/node_distinct_coloring.c +++ b/lib/edgepaint/node_distinct_coloring.c @@ -158,8 +158,10 @@ static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weight } -static void node_distinct_coloring_internal(int scheme, QuadTree qt, int weightedQ, SparseMatrix A, int cdim, real accuracy, int iter_max, int seed, real *colors, real *color_diff0, real *color_diff_sum0){ +static void node_distinct_coloring_internal(int scheme, QuadTree qt, int weightedQ, SparseMatrix A, int cdim, real accuracy, int iter_max, int seed, real *colors){ int i; + real color_diff; + real color_diff_sum; if (seed < 0) { /* do multiple iterations and pick the best */ int iter, seed_max = -1; @@ -168,19 +170,18 @@ static void node_distinct_coloring_internal(int scheme, QuadTree qt, int weighte iter = -seed; for (i = 0; i < iter; i++){ seed = irand(100000); - node_distinct_coloring_internal2(scheme, qt, weightedQ, A, cdim, accuracy, iter_max, seed, colors, color_diff0, color_diff_sum0); - if (color_diff_max < *color_diff0){ - seed_max = seed; color_diff_max = *color_diff0; + node_distinct_coloring_internal2(scheme, qt, weightedQ, A, cdim, accuracy, iter_max, seed, colors, &color_diff, &color_diff_sum); + if (color_diff_max < color_diff){ + seed_max = seed; color_diff_max = color_diff; } } seed = seed_max; } - node_distinct_coloring_internal2(scheme, qt, weightedQ, A, cdim, accuracy, iter_max, seed, colors, color_diff0, color_diff_sum0); + node_distinct_coloring_internal2(scheme, qt, weightedQ, A, cdim, accuracy, iter_max, seed, colors, &color_diff, &color_diff_sum); } -int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A0, real accuracy, int iter_max, int seed, int *cdim0, real **colors, real *color_diff0, - real *color_diff_sum0){ +int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A0, real accuracy, int iter_max, int seed, int *cdim0, real **colors){ /* for a graph A, get a distinctive color of its nodes so that the color distance among all neighboring nodes are maximized. Here color distance on a node is defined as the minimum of color differences between a node and its neighbors (or the minimum of weighted color differences if weightedQ = true, @@ -196,15 +197,12 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S iter_max: max number of cdim: dimension of the color space color: On input an array of size n*cdim, if NULL, will be allocated. On exit the final color assignment for node i is [cdim*i,cdim*(i+1)), in RGB (between 0 to 1) - color_diff: the minuimum color difference across all edges - color_diff_sum: the sum of min color dfference across all nodes */ SparseMatrix B, A = A0; int ncomps, *comps = NULL, *comps_ptr = NULL; int nn, n; real *ctmp; int i, j, jj, nnodes = 0; - real color_diff = 0, color_diff_sum = 0; QuadTree qt = NULL; int cdim; int scheme = COLOR_LAB; @@ -243,7 +241,6 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S } - *color_diff0 = *color_diff_sum0 = -1; if (accuracy <= 0) accuracy = 0.0001; n = A->m; @@ -261,17 +258,11 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S SparseMatrix_weakly_connected_components(A, &ncomps, &comps, &comps_ptr); - *color_diff_sum0 = 0; for (i = 0; i < ncomps; i++){ nn = comps_ptr[i+1] - comps_ptr[i]; B = SparseMatrix_get_submatrix(A, nn, nn, &(comps[comps_ptr[i]]), &(comps[comps_ptr[i]])); - node_distinct_coloring_internal(scheme, qt, weightedQ, B, cdim, accuracy, iter_max, seed, ctmp, &color_diff, &color_diff_sum); - if (i == 0){ - *color_diff0 = color_diff; - } - *color_diff0 = MIN(*color_diff0, color_diff); + node_distinct_coloring_internal(scheme, qt, weightedQ, B, cdim, accuracy, iter_max, seed, ctmp); if (B->m > 2) { - *color_diff_sum0 = *color_diff_sum0 + color_diff_sum; nnodes += B->m; } @@ -282,7 +273,6 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S SparseMatrix_delete(B); } FREE(ctmp); - *color_diff_sum0 /= nnodes; if (A != A0) SparseMatrix_delete(A); return 0; diff --git a/lib/edgepaint/node_distinct_coloring.h b/lib/edgepaint/node_distinct_coloring.h index a371584b2..52d521a61 100644 --- a/lib/edgepaint/node_distinct_coloring.h +++ b/lib/edgepaint/node_distinct_coloring.h @@ -13,6 +13,6 @@ enum {COLOR_RGB, COLOR_GRAY, COLOR_LAB}; enum {ERROR_BAD_COLOR_SCHEME = -9}; -int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A, real accuracy, int iter_max, int seed, int *cdim, real **colors, real *color_diff, real *color_diff_sum); +int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A, real accuracy, int iter_max, int seed, int *cdim, real **colors); #endif -- 2.40.0