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();
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;
}
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;
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);