tmp
authoryu.dongliang <18588496441@163.com>
Sat, 4 Nov 2023 04:01:58 +0000 (12:01 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 4 Nov 2023 04:01:58 +0000 (12:01 +0800)
ses_graph.h
ses_layout.c

index 5e96889a7b05d7f6001b887f98629f5acbf85313..459920eb1b37e2fa7938cf974fcdc01a8d0922ee 100644 (file)
@@ -43,10 +43,10 @@ static int ses_vertex_cmp(const void* v0, const void* v1)
        return -1;
 }
 
-static ses_vertex_t* ses_vertex_add(scf_vector_t* edges, void* data)
+static ses_vertex_t* ses_vertex_add(ses_graph_t* graph, void* data)
 {
        ses_vertex_t  tmp = {NULL, 0, data};
-       ses_vertex_t* v   = scf_vector_find_cmp(edges, &tmp, ses_vertex_cmp);
+       ses_vertex_t* v   = scf_vector_find_cmp(graph, &tmp, ses_vertex_cmp);
 
        if (!v) {
                v = ses_vertex_alloc();
@@ -54,7 +54,7 @@ static ses_vertex_t* ses_vertex_add(scf_vector_t* edges, void* data)
                        return NULL;
                v->data = data;
 
-               if (scf_vector_add(edges, v) < 0) {
+               if (scf_vector_add(graph, v) < 0) {
                        ses_vertex_free(v);
                        return NULL;
                }
index 0969759b10418b32e5d7c009619f510817f7c92d..fcb6f0f364e5ab61a6c7b31e4261d6a0a9d7239a 100644 (file)
@@ -343,6 +343,139 @@ int ses_lines_same_components(ScfEfunction* f)
        return 0;
 }
 
+int ses_lines_no_components(ScfEfunction* f, ses_graph_t* graph)
+{
+       if (!f || !graph)
+               return -EINVAL;
+
+       ses_vertex_t* v0;
+       ses_vertex_t* v1;
+
+       ScfEline*     el0;
+       ScfEline*     el1;
+       ScfEconn*     ec;
+
+       size_t i;
+       size_t j;
+       size_t k;
+
+       for (i = 0; i + 1 < f->n_elines; i++) {
+               el0           = f->elines[i];
+
+               v0 = ses_vertex_add(graph, el0);
+               if (!v0)
+                       return -ENOMEM;
+
+               for (j = i + 1; j < f->n_elines; j++) {
+                       el1           = f->elines[j];
+
+                       for (k = 0; k < el0->n_conns; k++) {
+                               ec =        el0->conns[k];
+
+                               if (el1->id == ec->lid)
+                                       break;
+                       }
+
+                       if (k < el0->n_conns)
+                               continue;
+
+                       v1 = ses_vertex_add(graph, el1);
+                       if (!v1)
+                               return -ENOMEM;
+
+                       if (ses_vertex_connect(v0, v1) < 0)
+                               return -ENOMEM;
+               }
+       }
+
+       scf_vector_qsort(graph, ses_vertex_cmp_edges);
+
+#if 1
+       for (i = 0; i < graph->size; i++) {
+               v0        = graph->data[i];
+
+               el0 = v0->data;
+               scf_logi("i: %ld, l%ld\n", i, el0->id);
+
+               for (j = 0; j < v0->edges->size; j++) {
+                       v1        = v0->edges->data[j];
+
+                       el1 = v1->data;
+                       scf_logi("j: %ld, l%ld\n", j, el1->id);
+               }
+       }
+#endif
+       return 0;
+}
+
+static int __ses_layout_lines3(ScfEfunction* f)
+{
+       ScfEline*      el;
+       ses_vertex_t*  v;
+
+       scf_vector_t*  graph  = scf_vector_alloc();
+       scf_vector_t*  colors = scf_vector_alloc();
+
+       intptr_t N = 2;
+       intptr_t i;
+       intptr_t j;
+
+       scf_loge("\n");
+       ses_lines_no_components(f, graph);
+
+       if (0  < graph->size) {
+               v  = graph->data[0];
+
+               N  = v->edges->size;
+       }
+
+       for (j = N; j >= 0; j--) {
+
+               for (i = 1; i <= j; i++)
+                       scf_vector_add(colors, (void*)i);
+
+               int ret = ses_graph_kcolor(graph, j, colors);
+               if (ret < 0) {
+                       scf_loge("**********\n");
+               }
+
+               for (i = 0; i < graph->size; i++) {
+                       v         = graph->data[i];
+
+                       if (v->color < 0) {
+                               el = v->data;
+                               scf_loge("j: %ld, i: %ld, l%ld->color: %ld\n", j, i, el->id, v->color);
+                               break;
+                       }
+               }
+
+               if (i < graph->size)
+                       break;
+
+               for (i = 0; i < graph->size; i++) {
+                       v         = graph->data[i];
+
+                       el        = v->data;
+                       el->color = v->color;
+                       v->color  = 0;
+               }
+
+               scf_vector_clear(colors, NULL);
+               printf("\n");
+       }
+
+       for (i = 0; i < graph->size; i++) {
+               v         = graph->data[i];
+
+               el = v->data;
+               scf_loge("i: %ld, l%ld->color: %ld\n", i, el->id, el->color);
+       }
+
+       scf_vector_clear(graph, ( void (*)(void*) )ses_vertex_free);
+       scf_vector_free(graph);
+       scf_vector_free(colors);
+}
+
 static int __ses_layout_lines2(ScfEfunction* f)
 {
        ScfEline* tmp;
@@ -1279,7 +1412,7 @@ int ses_cross(ScfEfunction* f, int d)
                vc        = graph->data[i];
 
                c = vc->data;
-               scf_logi("j: %ld, i: %ld, c%ld->color: %ld\n", j, i, c->id, c->color);
+               scf_logi("i: %ld, c%ld->color: %ld\n", i, c->id, c->color);
        }
 
        scf_vector_clear(graph, ( void (*)(void*) )ses_vertex_free);