Fixed syntax error but the naive version of the tetrahedral
algorithm doesn't workfeature-120-cell-index
parent
a412b5d8aa
commit
85a171da22
174
polytopes.js
174
polytopes.js
|
@ -205,6 +205,96 @@ function label_nodes(nodes, ids, label) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function find_edges(links, nid) {
|
||||
return links.filter((l) => l.source === nid || l.target === nid );
|
||||
}
|
||||
|
||||
|
||||
function find_adjacent(links, nid) {
|
||||
return find_edges(links, nid).map((l) => {
|
||||
if( l.source === nid ) {
|
||||
return l.target;
|
||||
} else {
|
||||
return l.source;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function iterate_graph(nodes, links, n, fn) {
|
||||
const queue = [];
|
||||
const seen = {};
|
||||
const nodes_id = {};
|
||||
nodes.map((n) => nodes_id[n.id] = n);
|
||||
|
||||
queue.push(n.id);
|
||||
seen[n.id] = true;
|
||||
fn(n);
|
||||
|
||||
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]);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function dumb_label_120cell(nodes, links) {
|
||||
let l = 0;
|
||||
|
||||
iterate_graph(nodes, links, nodes[0], (n) => {
|
||||
n.label = l;
|
||||
console.log(`Labelled ${n.id} ${n.label}`);
|
||||
l++;
|
||||
if( l > 2 ) {
|
||||
l = 0;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// stupid tetrahedral labelling
|
||||
|
||||
|
||||
function naive_label_120cell(nodes, links, n) {
|
||||
const nodes_id = {};
|
||||
nodes.map((n) => nodes_id[n.id] = n);
|
||||
iterate_graph(nodes, links, nodes[0], (n) => {
|
||||
const cols = new Set();
|
||||
const nbors = find_adjacent(links, n.id);
|
||||
for( const nb of nbors ) {
|
||||
if( nodes_id[nb].label > 0 ) {
|
||||
cols.add(nodes_id[nb].label);
|
||||
}
|
||||
for( const nb2 of find_adjacent(links, nb) ) {
|
||||
if( nb2 !== n.id && nodes_id[nb].label > 0 ) {
|
||||
cols.add(nodes_id[nb2].label);
|
||||
}
|
||||
}
|
||||
}
|
||||
const pcols = [ 1, 2, 3, 4, 5 ].filter((c) => !cols.has(c));
|
||||
if( pcols.length < 1 ) {
|
||||
console.log(`Got stuck, no options at ${n.id}`);
|
||||
} else {
|
||||
n.label = pcols[0];
|
||||
console.log(`applied ${pcols[0]} to node ${n.id}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const cell120 = () => {
|
||||
const nodes = make_120cell_vertices();
|
||||
const links = auto_detect_edges(nodes, 4);
|
||||
|
@ -393,90 +483,6 @@ function audit_link_labels(nodes, links) {
|
|||
|
||||
|
||||
|
||||
function find_edges(links, nid) {
|
||||
return links.filter((l) => l.source === nid || l.target === nid );
|
||||
}
|
||||
|
||||
|
||||
function find_adjacent(links, nid) {
|
||||
return find_edges(links, nid).map((l) => {
|
||||
if( l.source === nid ) {
|
||||
return l.target;
|
||||
} else {
|
||||
return l.source;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function iterate_graph(nodes, links, n, fn) {
|
||||
const queue = [];
|
||||
const seen = {};
|
||||
const nodes_id = {};
|
||||
nodes.map((n) => nodes_id[n.id] = n);
|
||||
|
||||
queue.push(n.id);
|
||||
seen[n.id] = true;
|
||||
fn(n);
|
||||
|
||||
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]);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function dumb_label_120cell(nodes, links) {
|
||||
let l = 0;
|
||||
|
||||
iterate_graph(nodes, links, nodes[0], (n) => {
|
||||
n.label = l;
|
||||
console.log(`Labelled ${n.id} ${n.label}`);
|
||||
l++;
|
||||
if( l > 2 ) {
|
||||
l = 0;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// stupid tetrahedral labelling
|
||||
|
||||
|
||||
function naive_label_120cell(nodes, links, n) {
|
||||
const nodes_id = {};
|
||||
nodes.map((n) => nodes_id[n.id] = n);
|
||||
iterate_graph(nodes, links, nodes[0], (n) => {
|
||||
const cols = new Set();
|
||||
const nbors = find_adjacent(links, n.id);
|
||||
for( const nb of nbors ) {
|
||||
if( nodes_id[nb].label > 0 ) {
|
||||
cols.add(nodes_id[nb].label);
|
||||
}
|
||||
for( const nb2 of find_adjacent(links, nb) ) {
|
||||
if( nb2 !== n.id && nodes_id[nb].label > 0 ) {
|
||||
cols.add(nodes_id[nb2].label);
|
||||
}
|
||||
}
|
||||
}
|
||||
const pcols = [ 1, 2, 3, 4, 5 ].filter((c) => !cols.has(c));
|
||||
if( pcols.length < 1 ) {
|
||||
console.log(`Got stuck, no options at ${n.id}`);
|
||||
} else {
|
||||
n.label = pcols[0];
|
||||
console.log(`applied ${pcols[0]} to node ${n.id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const cell600 = () => {
|
||||
const nodes = make_600cell_vertices();
|
||||
const links = auto_detect_edges(nodes, 12);
|
||||
|
|
Loading…
Reference in New Issue