]> granicus.if.org Git - graphviz/commitdiff
Added generation of tetrix (3d sierpinski) graphs.
authorHan Kruiger <hankruiger@gmail.com>
Fri, 18 Nov 2016 10:32:05 +0000 (11:32 +0100)
committerHan Kruiger <hankruiger@gmail.com>
Fri, 18 Nov 2016 10:32:05 +0000 (11:32 +0100)
cmd/tools/graph_generator.c
cmd/tools/gvgen.c

index 81f37fa83a2170ecf07f772645d44656a00e13cd..be8439a9f669bc9ccc937682d5a48de9fd1e374b 100644 (file)
@@ -332,6 +332,93 @@ void makeSierpinski(int depth, edgefn ef)
     free(graph);
 }
 
+static void
+constructTetrix(int v1, int v2, int v3, int v4, int depth, vtx_data* graph)
+{
+    static int last_used_node_name = 4;
+    int v5, v6, v7, v8, v9, v10;
+
+    int nedges;
+
+    if (depth > 0) {
+        v5 = ++last_used_node_name;
+        v6 = ++last_used_node_name;
+        v7 = ++last_used_node_name;
+        v8 = ++last_used_node_name;
+        v9 = ++last_used_node_name;
+        v10 = ++last_used_node_name;
+        constructTetrix(v1, v5, v6, v8, depth - 1, graph);
+        constructTetrix(v2, v6, v7, v9, depth - 1, graph);
+        constructTetrix(v3, v5, v7, v10, depth - 1, graph);
+        constructTetrix(v4, v8, v9, v10, depth - 1, graph);
+        return;
+    }
+    // depth==0, Construct graph:
+    nedges = graph[v1].nedges;
+    graph[v1].edges[nedges++] = v2;
+    graph[v1].edges[nedges++] = v3;
+    graph[v1].edges[nedges++] = v4;
+    graph[v1].nedges = nedges;
+
+    nedges = graph[v2].nedges;
+    graph[v2].edges[nedges++] = v1;
+    graph[v2].edges[nedges++] = v3;
+    graph[v2].edges[nedges++] = v4;
+    graph[v2].nedges = nedges;
+
+    nedges = graph[v3].nedges;
+    graph[v3].edges[nedges++] = v1;
+    graph[v3].edges[nedges++] = v2;
+    graph[v3].edges[nedges++] = v4;
+    graph[v3].nedges = nedges;
+
+    nedges = graph[v4].nedges;
+    graph[v4].edges[nedges++] = v1;
+    graph[v4].edges[nedges++] = v2;
+    graph[v4].edges[nedges++] = v3;
+    graph[v4].nedges = nedges;
+
+    return;
+
+}
+
+void makeTetrix(int depth, edgefn ef)
+{
+    vtx_data* graph;
+    int* edges;
+    int n;
+    int nedges;
+    int i, j;
+
+    depth--;
+    n = 4 + 2 * (((int) (pow(4.0, (double) depth) + 0.5) - 1));
+
+    nedges = (int) (pow(6.0, depth + 1.0) + 0.5);
+
+    graph = N_NEW(n + 1, vtx_data);
+    edges = N_NEW(6 * n, int);
+
+    for (i = 1; i <= n; i++) {
+        graph[i].edges = edges;
+        edges += 6;
+        graph[i].nedges = 0;
+    }
+
+    constructTetrix(1, 2, 3, 4, depth, graph);
+
+    for (i = 1; i <= n; i++) {
+        int nghbr;
+        // write the neighbors of the node i
+        for (j = 0; j < graph[i].nedges; j++) {
+            nghbr = graph[i].edges[j];
+            if (i < nghbr) ef( i, nghbr);
+        }
+    }
+
+    free(graph[1].edges);
+    free(graph);
+}
+
 void makeHypercube(int dim, edgefn ef)
 {
     int i, j, n;
index 0a766bb6a797f4a74666d0cd4c393556aa2b76be..bdfcd34bb72912ce7fdbf3c4422c65fc35a9a00a 100644 (file)
@@ -34,7 +34,7 @@
 
 typedef enum { unknown, grid, circle, complete, completeb, 
     path, tree, torus, cylinder, mobius, randomg, randomt, ball,
-    sierpinski, hypercube, star, wheel, trimesh
+    sierpinski, tetrix, hypercube, star, wheel, trimesh
 } GraphType;
 
 typedef struct {
@@ -92,6 +92,7 @@ static char *Usage = "Usage: %s [-dv?] [options]\n\
  -R<n>         : random rooted tree on <n> vertices\n\
  -s<x>         : star\n\
  -S<x>         : sierpinski\n\
+ -X<x>         : tetrix (3d sierpinski)\n\
  -t<x>         : binary tree \n\
  -t<x>,<n>     : n-ary tree \n\
  -T<x,y>       : torus \n\
@@ -286,7 +287,7 @@ static char* setFold(char *s, opts_t* opts)
     return next;
 }
 
-static char *optList = ":i:M:m:n:N:c:C:dg:G:h:k:b:B:o:p:r:R:s:S:t:T:vw:";
+static char *optList = ":i:M:m:n:N:c:C:dg:G:h:k:b:B:o:p:r:R:s:S:X:t:T:vw:";
 
 static GraphType init(int argc, char *argv[], opts_t* opts)
 {
@@ -377,6 +378,11 @@ static GraphType init(int argc, char *argv[], opts_t* opts)
            if (setOne(optarg, opts))
                errexit(c);
            break;
+       case 'X':
+               graphType = tetrix;
+               if (setOne(optarg, opts))
+               errexit(c);
+               break;
        case 's':
            graphType = star;
            if (setOne(optarg, opts))
@@ -509,6 +515,9 @@ int main(int argc, char *argv[])
     case sierpinski:
        makeSierpinski(opts.graphSize1, ef);
        break;
+       case tetrix:
+       makeTetrix(opts.graphSize1, ef);
+       break;
     case complete:
        makeComplete(opts.graphSize1, ef);
        break;