Indexing algorithm tested on the 50-cell skeleton of great circles

without any deadlocks or label mismatches
feature-120-cell-index
Mike Lynch 2023-08-28 08:31:45 +10:00
parent 43ed181d75
commit c093c89ce6
3 changed files with 249 additions and 99 deletions

View File

@ -7,3 +7,14 @@ export const get_colours = (basis) => {
return scheme.colors().map((cs) => parseInt('0x' + cs)); return scheme.colors().map((cs) => parseInt('0x' + cs));
} }
export const get_plain_colours = (basis) => {
return [
basis,
0xffffff,
0x00ff00,
0xff0000,
0x0000ff,
0xff9900,
0x000000,
]
}

View File

@ -370,79 +370,68 @@ function manual_label_120cell(nodes, links) {
} }
function meridian_label_120cell(nodes, links) { function meridian_label_120cell(nodes) {
const DODECAS = [ const MERIDIAN_COLOURED ={"1":[27,38,49,61,68,74,87,105,120,126,131,140,149,156,165,174,179,185,200,207,210,218,223,226,231,234,239,241,253,258,263,265,272,274,279,284,285,289,296,300,301,306,311,313,320,324,325,331,334,339,342,347,350,356,357,367,369,376,378,383,388,389,393,400,413,414,419,420,425,440,449,453,458,460,469,471,473,474,487,488,490,494,499,503,511,512,513,514,525,527,530,532,539,543,546,550,555,558,563,566,572,573,580,581,592,593],"2":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,21,22,23,24,25,28,30,31,34,35,37,40,41,46,47,50,51,53,56,57,60,62,63,66,67,69,72,73,76,78,83,85,88,90,93,97,103,106,107,109,112,113,116,118,119,122,123,125,129,132,134,135,138,139,141,144,145,148,150,151,155,157,160,161,164,166,167,170,171,173,177,180,182,183,187,189,192,193,196,198,202,203,205,208,209,212,214,215],"3":[26,39,45,52,64,65,94,99,108,117,127,130,137,152,153,168,175,178,188,197,206,211,219,222,227,230,235,238,245,251,268,269,273,280,283,286,292,293,299,302,305,312,316,317,321,328,330,335,349,355,358,363,366,370,375,377,384,385,392,394,399,404,405,415,416,417,418,426,437,439,441,445,452,456,457,459,470,472,475,485,486,491,495,498,502,509,510,515,516,526,529,531,538,542,547,551,554,559,562,567,569,576,577,584,588,597],"4":[32,33,43,54,58,71,77,84,101,110,115,121,136,143,146,159,162,169,184,204,213,220,221,228,229,236,237,249,260,261,271,276,277,281,288,290,295,297,304,308,309,315,318,322,327,329,336,340,341,351,354,359,361,368,371,374,379,382,387,390,396,397,409,410,423,424,430,433,435,443,447,450,454,461,463,466,468,477,478,483,484,489,493,500,504,507,508,517,518,522,533,535,540,544,545,549,553,560,561,568,570,583,587,590,595,598],"5":[29,36,42,55,59,70,80,81,89,111,114,133,142,147,163,181,191,194,201,216,217,224,225,232,233,240,243,246,255,267,270,275,278,282,287,291,294,298,303,307,310,314,319,323,326,332,333,337,344,345,352,353,360,364,365,372,373,380,381,395,398,402,407,411,412,421,422,429,436,442,446,451,455,462,464,465,467,479,481,482,492,496,497,501,505,506,519,520,521,523,534,536,537,541,548,552,556,557,564,565,574,579,586,591,594,599]};
[
313, 1, 317, 221, 217, 417,
341, 421, 165, 161, 465, 469,
37, 269, 33, 113, 117, 517,
365, 513
],
[
513, 365, 517, 117, 113, 577,
15, 581, 565, 561, 397, 399,
85, 389, 81, 301, 303, 213,
293, 209
],
[
301, 209, 293, 213, 303,
211, 309, 294, 311, 215,
310, 210, 214, 312, 295,
212, 302, 304, 216, 296
],
[
304, 302, 212, 296, 216, 400,
398, 84, 392, 88, 16, 580,
564, 568, 584, 368, 516, 116,
120, 520
],
[
368, 516, 116, 120, 520, 272,
36, 468, 472, 40, 164, 420,
344, 424, 168, 220, 316, 4,
320, 224
],
[
316, 4, 320, 224, 220, 412,
340, 416, 160, 156, 460, 464,
32, 268, 28, 108, 112, 512,
364, 508
],
[
508, 364, 512, 112, 108, 572,
14, 576, 560, 556, 394, 396,
80, 388, 76, 298, 300, 208,
292, 204
],
[
300, 298, 204, 292, 208,
206, 202, 306, 291, 308,
290, 305, 203, 207, 307,
289, 201, 297, 299, 205
],
[
299, 297, 201, 289, 205, 395,
393, 73, 385, 77, 13, 569,
553, 557, 573, 361, 505, 105,
109, 509
],
[
361, 505, 105, 109, 509, 265,
25, 457, 461, 29, 153, 409,
337, 413, 157, 217, 313, 1,
317, 221
]
]
let col = 1;
for( const dd of DODECAS ) { for( const cstr in MERIDIAN_COLOURED ) {
label_nodes(nodes, dd, 5); label_nodes(nodes, MERIDIAN_COLOURED[cstr], Number(cstr));
col++; }
if( col > 5 ) {
col = 1; //label_nodes(nodes, [313], 6);
} }
}
function arctic_label_120cell(nodes) {
const ARCTIC_COLOURED ={
'1': [
49, 105, 131, 149, 165, 223,
241, 253, 265, 279, 301, 313,
325, 347, 367, 389, 413, 425,
449, 453, 469, 473, 487, 513,
581, 593
],
'2': [
1, 5, 7, 15, 19, 25, 35,
37, 41, 53, 69, 85, 93, 97,
109, 113, 129, 135, 145, 155, 157,
161, 167, 173, 177, 209
],
'3': [
39, 45, 65, 117, 153, 219,
245, 251, 269, 293, 317, 321,
349, 375, 399, 417, 437, 441,
445, 457, 485, 509, 515, 529,
577, 597
],
'4': [
33, 101, 159, 169, 213, 221,
229, 249, 271, 277, 329, 341,
351, 361, 397, 409, 433, 461,
477, 483, 517, 533, 545, 549,
561, 583
],
'5': [
29, 81, 89, 133, 163, 181,
217, 225, 255, 267, 303, 333,
337, 345, 365, 373, 421, 429,
465, 481, 497, 501, 505, 519,
565, 579
]
}
for( const cstr in ARCTIC_COLOURED ) {
label_nodes(nodes, ARCTIC_COLOURED[cstr], Number(cstr));
}
}
function link_labels(nodes, link) {
const n1 = nodes.filter((n) => n.id === link.source);
const n2 = nodes.filter((n) => n.id === link.target);
return [ n1[0].label, n2[0].label ];
} }
@ -451,7 +440,12 @@ export const cell120 = () => {
const nodes = make_120cell_vertices(); const nodes = make_120cell_vertices();
const links = auto_detect_edges(nodes, 4); const links = auto_detect_edges(nodes, 4);
meridian_label_120cell(nodes, links); meridian_label_120cell(nodes);
// const links = links_all.filter((l) => {
// const labels = link_labels(nodes, l);
// return ( labels[0] > 0 && labels[1] > 0 );
// });
return { return {
nodes: nodes, nodes: nodes,

View File

@ -471,7 +471,6 @@ function find_adjacent_nodes(links, nid) {
function colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextdd) { function colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextdd) {
const lastvs = dodecahedron_vertices(dd); const lastvs = dodecahedron_vertices(dd);
const nextvs = dodecahedron_vertices(nextdd); const nextvs = dodecahedron_vertices(nextdd);
console.log(`maybe: vertices = ${nextvs}`);
// get the initial colour permutations from the existing labels; // get the initial colour permutations from the existing labels;
const p = []; const p = [];
for( i = 0; i < 5; i ++ ) { for( i = 0; i < 5; i ++ ) {
@ -487,9 +486,9 @@ function colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextd
const nextcol = nlabels[nextns[0]]; const nextcol = nlabels[nextns[0]];
if( lastcol === nextcol ) { if( lastcol === nextcol ) {
// one node in the adjoining face has two same-coloured neighbours // one node in the adjoining face has two same-coloured neighbours
console.log('chirality mismatch'); // console.log('chirality mismatch');
console.log(` test node ${n}`); // console.log(` test node ${n}`);
console.log(` neighbours ${lastns[0]} ${nextns[0]}`); // console.log(` neighbours ${lastns[0]} ${nextns[0]}`);
return false; return false;
} }
return nlabels; return nlabels;
@ -499,23 +498,56 @@ function colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextd
function meridian(nodes, links, faces, startf, startn, dir=11, max=10) {
const o = face_plus_to_dodecahedron(faces, startf, startn);
const colours = colour_dodecahedron_from_face(o, [ 1, 2, 3, 4, 5 ] );
const dds = follow_meridian(nodes, links, faces, colours, o, dir, max);
const labels = { 1: [], 2:[], 3:[], 4:[], 5:[] };
for( const vstr in colours ) {
labels[colours[vstr]].push(Number(vstr));
}
return { dodecahedra: dds, labels: labels };
}
function all_meridians(nodes, links, faces, startf, startn) {
const o = face_plus_to_dodecahedron(faces, startf, startn);
const colours = colour_dodecahedron_from_face(o, [ 1, 2, 3, 4, 5 ] );
// first meridian
const dds = follow_meridian(nodes, links, faces, colours, o, 11, 10);
for ( const f of [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ) {
follow_meridian(nodes, links, faces, colours, o, f, 4);
}
const labels = { 1: [], 2:[], 3:[], 4:[], 5:[] };
for( const vstr in colours ) {
labels[colours[vstr]].push(Number(vstr));
}
return labels;
}
// go along a meridian // go along a meridian
// modifies colours
function meridian(nodes, links, faces, startf, startn, max) { function follow_meridian(nodes, links, faces, colours, odd, dir, max) {
console.log(startf);
const dds = [ face_plus_to_dodecahedron(faces, startf, startn) ];
// colour first cell
const colours = colour_dodecahedron_from_face(dds[0], [ 1, 2, 3, 4, 5 ] );
const vs = dodecahedron_vertices(dds[0]);
console.log(`vertices: ${vs}`);
let ncolours = {}; let ncolours = {};
const dds = [ odd ];
while( ncolours && dds.length < max ) { while( ncolours && dds.length < max ) {
const dd = dds[dds.length - 1]; const dd = dds[dds.length - 1];
const nextf = dd[11]; // opposite to startf const nextf = dds.length === 1 ? dd[dir] : dd[11];
let nextdd = follow_face_to_dodeca(faces, dd, nextf); let nextdd = follow_face_to_dodeca(faces, dd, nextf);
ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextdd); ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextdd);
@ -523,20 +555,52 @@ function meridian(nodes, links, faces, startf, startn, max) {
if( !ncolours ) { if( !ncolours ) {
nextdd = follow_face_to_dodeca(faces, dd, nextf, true); nextdd = follow_face_to_dodeca(faces, dd, nextf, true);
ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextdd); ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextdd);
if( !ncolours ) {
console.log("*** two mismatches");
}
}
for( const vertex in ncolours ) {
if( vertex in colours ) {
if( colours[vertex] !== ncolours[vertex] ) {
console.log(`*** label mismatch at ${vertex}: ${colours[vertex]}/${ncolours[vertex]}`);
}
} else {
colours[vertex] = ncolours[vertex];
}
}
dds.push(nextdd);
}
return dds;
}
// "arctic circle" - this one works
function arctic(nodes, links, faces, startf, startn, max) {
console.log(startf);
const pole = face_plus_to_dodecahedron(faces, startf, startn);
const dds = [ pole ];
// colour first cell
const colours = colour_dodecahedron_from_face(dds[0], [ 1, 2, 3, 4, 5 ] );
const vs = dodecahedron_vertices(dds[0]);
let ncolours = {};
for( const face of pole ) {
let nextdd = follow_face_to_dodeca(faces, pole, face);
ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, pole, face, nextdd);
if( !ncolours ) {
nextdd = follow_face_to_dodeca(faces, pole, face, true);
ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, pole, face, nextdd);
if( !ncolours ) { if( !ncolours ) {
console.log("two mismatches"); console.log("two mismatches");
} }
} }
// const nextvs = dodecahedron_vertices(nextdd);
// // get the initial colour permutations from the existing labels;
// const p = [];
// for( i = 0; i < 5; i ++ ) {
// p[i] = labels[nextvs[i]];
// }
// console.log(`vertices: ${nextvs}`);
// console.log(`Next colour permutation ${p}`);
// const nlabels = colour_dodecahedron_from_face(nextdd, p);
for( const vertex in ncolours ) { for( const vertex in ncolours ) {
if( vertex in colours ) { if( vertex in colours ) {
if( colours[vertex] !== ncolours[vertex] ) { if( colours[vertex] !== ncolours[vertex] ) {
@ -564,8 +628,64 @@ function meridian(nodes, links, faces, startf, startn, max) {
// this one breaks but I don't know if it's because of the traversal
// algorithm or the indexing algorithm
function whole_120_cell(nodes, links, faces, startf, startn, max) {
const pole = face_plus_to_dodecahedron(faces, startf, startn);
const dds = [ pole ];
const queue = [ pole ];
const seen = {};
// colour first cell
const colours = colour_dodecahedron_from_face(pole, [ 1, 2, 3, 4, 5 ] );
let ncolours = {};
while( ncolours && queue.length > 0 ) {
const dd = queue.shift();
for( const face of dd ) {
let nextdd = follow_face_to_dodeca(faces, dd, face);
const fp = dd_fingerprint(nextdd);
if( ! (fp in seen) ) {
seen[fp] = true;
ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, pole, face, nextdd);
if( !ncolours ) {
nextdd = follow_face_to_dodeca(faces, pole, face, true);
ncolours = colour_next_dodeca_maybe(nodes, links, faces, colours, pole, face, nextdd);
if( !ncolours ) {
console.log("two mismatches");
}
}
for( const vertex in ncolours ) {
if( vertex in colours ) {
if( colours[vertex] !== ncolours[vertex] ) {
console.log(`label mismatch at ${vertex}: ${colours[vertex]}/${ncolours[vertex]}`);
}
} else {
colours[vertex] = ncolours[vertex];
}
}
dds.push(nextdd);
queue.push(nextdd);
}
}
}
const labels = { 1: [], 2:[], 3:[], 4:[], 5:[] };
for( const vstr in colours ) {
labels[colours[vstr]].push(Number(vstr));
}
return { dodecahedra: dds, labels: labels };
function collate_labels(labels) {
} }
@ -624,6 +744,28 @@ function make_120cell_cells(faces) {
} }
function dodeca_travers(nodes, links, n, fn) {
const queue = [];
const seen = {};
const nodes_id = {};
queue.push(n.id);
while( queue.length > 0 ) {
const v = queue.shift();
find_adjacent(links, v).map((aid) => {
if( !(aid in seen) ) {
seen[aid] = true;
queue.push(aid);
fn(nodes_id[aid]);
}
})
}
}
const cell120 = () => { const cell120 = () => {
const nodes = make_120cell_vertices(); const nodes = make_120cell_vertices();
const links = auto_detect_edges(nodes, 4); const links = auto_detect_edges(nodes, 4);
@ -656,3 +798,6 @@ const links = auto_detect_edges(nodes, 4);
const faces = auto_120cell_faces(links); const faces = auto_120cell_faces(links);
//const dodecas = make_120cell_cells(faces); //const dodecas = make_120cell_cells(faces);
const colours = all_meridians(nodes, links, faces, faces[0], 341);
console.log(JSON.stringify(colours));