28 for (
unsigned i = 2; i <= n; i++)
37 for (
unsigned i = 1; i < n; i++) {
38 for (
unsigned j = i + 1; j <= n; j++) {
46 fprintf(stderr,
"Warning: degenerate circle of %u vertices\n", n);
51 for (
unsigned i = 1; i < n; i++)
58 fprintf(stderr,
"Warning: degenerate star of %u vertices\n", n);
63 for (
unsigned i = 2; i <= n; i++)
69 fprintf(stderr,
"Warning: degenerate wheel of %u vertices\n", n);
76 for (
unsigned i = 2; i < n; i++)
82 for (
unsigned i = 1; i <= dim1; i++) {
83 for (
unsigned j = 1; j <= dim2; j++) {
90 for (
unsigned i = 1, n = 0; i <= dim1; i++) {
91 for (
unsigned j = 1; j < dim2; j++) {
92 ef( n + j, n + j + 1);
98 for (
unsigned i = 1; i <= dim2; i++) {
99 for (
unsigned j = 1; j < dim1; j++) {
100 ef( dim2 * (j - 1) + i, dim2 * j + i);
102 ef( i, dim2 * (dim1 - 1) + i);
108 for (
unsigned i = 0; i < dim1; i++) {
109 for (
unsigned j = 0; j < dim2; j++) {
110 unsigned li = (i + t1) % dim1;
111 unsigned lj = (j + 1) % dim2;
112 ef (i+j*dim1+1, li+lj*dim1+1);
115 lj = (j + t2) % dim2;
116 ef(i+j*dim1+1, li+lj*dim1+1);
122 for (
unsigned i = 1, n = 0; i <= dim1; i++) {
123 for (
unsigned j = 1; j < dim2; j++) {
124 ef( n + j, n + j + 1);
126 ef( n + 1, n + dim2);
130 for (
unsigned i = 1; i <= dim2; i++) {
131 for (
unsigned j = 1; j < dim1; j++) {
132 ef( dim2 * (j - 1) + i, dim2 * j + i);
137#define OUTE(h) if (tl < (hd=(h))) ef( tl, hd)
141 for (
unsigned i = 0; i < dim1; i++)
142 for (
unsigned j = 0; j < dim2; j++) {
144 const unsigned tl = i * dim2 + j + 1;
147 && (!partial || j < 2 * dim2 / 6 || j >= 4 * dim2 / 6
148 || i <= 2 * dim1 / 6 || i > 4 * dim1 / 6)) {
149 ef(tl, i * dim2 + j + 2);
152 ef(tl, (i + 1) * dim2 + j + 1);
154 if (connect_corners == 1) {
155 if (i == 0 && j == 0) {
156 OUTE((dim1 - 1) * dim2 + dim2);
157 }
else if (i + 1 == dim1 && j == 0) {
159 }
else if (i == 0 && j + 1 == dim2) {
160 OUTE((dim1 - 1) * dim2 + 1);
161 }
else if (i + 1 == dim1 && j + 1 == dim2) {
164 }
else if (connect_corners == 2) {
165 if (i == 0 && j == 0) {
167 }
else if (i + 1 == dim1 && j == 0) {
168 OUTE((dim1 - 1) * dim2 + dim2);
169 }
else if (i == 0 && j + 1 == dim2) {
171 }
else if (i + 1 == dim1 && j + 1 == dim2) {
172 OUTE((dim1 - 1) * dim2 + 1);
179 const double n = (pow(nary, depth) - 1) / (nary - 1);
182 for (
unsigned i = 1; i <= n; i++) {
183 for (
unsigned j = 0; j < nary; j++) {
190 const unsigned n = (1u << depth) - 1;
192 for (
unsigned i = 1; i <= n; i++) {
205 static unsigned last_used_node_name = 3;
208 const unsigned v4 = ++last_used_node_name;
209 const unsigned v5 = ++last_used_node_name;
210 const unsigned v6 = ++last_used_node_name;
238 const unsigned n = 3 * (1 + ((unsigned)(pow(3.0, depth) + 0.5) - 1) / 2);
241 unsigned *edges =
gv_calloc(4 * n,
sizeof(
unsigned));
243 for (
unsigned i = 1; i <= n; i++) {
244 graph[i].edges = edges;
251 for (
unsigned i = 1; i <= n; i++) {
253 for (
unsigned j = 0; j <
graph[i].nedges; j++) {
254 const unsigned nghbr =
graph[i].edges[j];
255 if (i < nghbr) ef( i, nghbr);
265 static unsigned last_used_node_name = 4;
268 const unsigned v5 = ++last_used_node_name;
269 const unsigned v6 = ++last_used_node_name;
270 const unsigned v7 = ++last_used_node_name;
271 const unsigned v8 = ++last_used_node_name;
272 const unsigned v9 = ++last_used_node_name;
273 const unsigned v10 = ++last_used_node_name;
310 const unsigned n = 4 + 2 * (((unsigned)(pow(4.0, depth) + 0.5) - 1));
313 unsigned *edges =
gv_calloc(6 * n,
sizeof(
unsigned));
315 for (
unsigned i = 1; i <= n; i++) {
316 graph[i].edges = edges;
323 for (
unsigned i = 1; i <= n; i++) {
325 for (
unsigned j = 0; j <
graph[i].nedges; j++) {
326 const unsigned nghbr =
graph[i].edges[j];
327 if (i < nghbr) ef( i, nghbr);
336 const unsigned n = 1u <<
dim;
338 for (
unsigned i = 0; i < n; i++) {
339 for (
unsigned j = 0; j <
dim; j++) {
340 const unsigned neighbor = (i ^ (1u << j)) + 1;
355 for (
unsigned i = 2; i < sz; i++) {
356 for (
unsigned j = 1; j <= i; j++) {
364 for (
unsigned j = 1; j < sz; j++) {
373 for (
unsigned i = 1; i <= h; i++)
376 const unsigned cap = w * h + 1;
377 for (
unsigned i = (w - 1) * h + 1; i <= w * h; i++)
386 srand((
unsigned)time(0));
387 const int type = rand() % 2;
406 for (
unsigned i = 3; i <= size; i++) {
407 for (
unsigned j = 1; j + 1 < i; j++) {
408 const unsigned th = (unsigned)rand() % (size * size);
409 if ((th <= w * w && (i < 5 || (i + 4 > h && j + 4 > h))) || th <= w)
417 fprintf(stderr,
"Warning: degenerate Moebius strip of %u vertices\n", w);
422 fprintf(stderr,
"Warning: degenerate Moebius strip of %u vertices\n", h);
427 for (
unsigned i = 0; i + 1 < w; i++) {
428 for (
unsigned j = 1; j < h; j++){
429 ef(j + i*h, j + (i+1)*h);
430 ef(j + i*h, j+1 + i*h);
434 for (
unsigned i = 1; i < h; i++){
435 ef (i + (w-1)*h, i+1 + (w-1)*h);
437 for (
unsigned i=1; i < w; i++) {
481 return tp->
p[tp->
root];
502 if (sz > 1) tp->
p[tp->
top] = tp->
top-1;
509 unsigned LS =
L + (J-1)*
M - 1;
510 for (
unsigned i =
L; i <= LS; i++) {
511 if ((i-
L)%
M == 0) tp->
p[i+
M] = LL;
512 else tp->
p[i+
M] = tp->
p[i] +
M;
521static
void push(int_stack_t *sp,
unsigned j,
unsigned d) {
522 int_stack_push_back(sp, j);
523 int_stack_push_back(sp, d);
529 const unsigned d = int_stack_pop_back(sp);
530 const unsigned j = int_stack_pop_back(sp);
538 unsigned*
T =
gv_calloc(NN + 1,
sizeof(
unsigned));
543 for (
unsigned D = 1;
D <= NLAST;
D++) {
544 unsigned I = NLAST + 1;
545 const unsigned TD =
T[
D] *
D;
546 for (
unsigned J = 1; J <= NLAST; J++) {
553 T[NLAST] = SUM/(NLAST-1);
567static void genTree(
unsigned NN,
unsigned *
T, int_stack_t *stack,
578 double Z = floor(v *
drand());
584 const unsigned TD =
D*
T[
D];
589 if (
M <
D + 1)
break;
612 if (
treeTop(TREE) == NN)
return;
622 for (
unsigned i = 2; i <= tp->
top; i++)
638 tg->
sp = (int_stack_t){0};
640 srand((
unsigned)time(0));
647 int_stack_clear(&tg->
sp);
657 int_stack_free(&tg->
sp);
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
static void * gv_alloc(size_t size)
static void treePop(tree_t *tp)
void makeTriMesh(unsigned sz, edgefn ef)
static unsigned prevRoot(tree_t *tp)
void makeHypercube(unsigned dim, edgefn ef)
static void addTree(tree_t *tp, unsigned sz)
static unsigned treeSize(tree_t *tp)
static double drand(void)
static void constructSierpinski(unsigned v1, unsigned v2, unsigned v3, unsigned depth, vtx_data *graph)
void makeCircle(unsigned n, edgefn ef)
void makeTree(unsigned depth, unsigned nary, edgefn ef)
static void writeTree(tree_t *tp, edgefn ef)
void makeWheel(unsigned n, edgefn ef)
void makeSquareGrid(unsigned dim1, unsigned dim2, int connect_corners, int partial, edgefn ef)
static void genTree(unsigned NN, unsigned *T, int_stack_t *stack, tree_t *TREE)
void makeBinaryTree(unsigned depth, edgefn ef)
static void constructTetrix(unsigned v1, unsigned v2, unsigned v3, unsigned v4, unsigned depth, vtx_data *graph)
void makeComplete(unsigned n, edgefn ef)
void makeMobius(unsigned w, unsigned h, edgefn ef)
treegen_t * makeTreeGen(unsigned N)
void makeCompleteB(unsigned dim1, unsigned dim2, edgefn ef)
static void push(int_stack_t *sp, unsigned j, unsigned d)
void makeBall(unsigned w, unsigned h, edgefn ef)
void makePath(unsigned n, edgefn ef)
static unsigned treeRoot(tree_t *tp)
static void resetTree(tree_t *tp)
void makeTetrix(unsigned depth, edgefn ef)
void makeCylinder(unsigned dim1, unsigned dim2, edgefn ef)
void makeStar(unsigned n, edgefn ef)
static void treeDup(tree_t *tp, unsigned J)
void freeTreeGen(treegen_t *tg)
void makeTorus(unsigned dim1, unsigned dim2, edgefn ef)
void makeTwistedTorus(unsigned dim1, unsigned dim2, unsigned t1, unsigned t2, edgefn ef)
void makeRandomTree(treegen_t *tg, edgefn ef)
void makeRandom(unsigned h, unsigned w, edgefn ef)
static unsigned * genCnt(unsigned NN)
static void freeTree(tree_t *tp)
void makeSierpinski(unsigned depth, edgefn ef)
static tree_t * mkTree(unsigned sz)
static unsigned treeTop(tree_t *tp)
Agraph_t * graph(char *name)
static Agedge_t * top(edge_stack_t *sp)
#define DEFINE_LIST(name, type)
#define neighbor(t, i, edim, elist)
static int nedges
total no. of edges used in routing
void(* edgefn)(Agraph_t *, Agedge_t *, glCompColor)