From 3c01173fe0b24bfa858acb962e4ca1af21cd5717 Mon Sep 17 00:00:00 2001 From: Jason Ku Date: Thu, 3 Oct 2024 12:48:35 +0800 Subject: [PATCH] unify storage of BT, instead of transformation --- src/batch.js | 21 ++++++++++----------- src/compute.js | 18 ++++++++++-------- src/conversion.js | 21 +++++++++++---------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/batch.js b/src/batch.js index 8877db8..e2246ac 100644 --- a/src/batch.js +++ b/src/batch.js @@ -94,15 +94,14 @@ export const BATCH = { const [CF, FC] = X.EF_FV_SP_SE_CP_SC_2_CF_FC(EF, FV, SP, SE, CP, SC); const BF = X.EF_SP_SE_CP_CF_2_BF(EF, SP, SE, CP, CF); const BI = new Map(); - const num = {}; for (const [i, F] of BF.entries()) { BI.set(F, i); } - const [BT0, BT1, BT2] = X.BF_BI_EF_SE_CF_SC_2_BT0_BT1_BT2( - BF, BI, EF, SE, CF, SC); - num.BT0 = NOTE.count_subarrays(BT0)/6; - num.BT1 = NOTE.count_subarrays(BT1)/2; - num.BT2 = NOTE.count_subarrays(BT2)/2; - const CC = X.FC_BF_BI_BT1_2_CC(FC, BF, BI, BT1); - const BT = BF.map((F,i) => [BT0[i], BT1[i], BT2[i]]); + const BT = X.BF_BI_EF_SE_CF_SC_2_BT(BF, BI, EF, SE, CF, SC); + const BTn = [0, 0, 0]; + for (const bT of BT) { + for (let i = 0; i < 3; ++i) { BTn[i] += bT[i].length; } + } + for (const [i, d] of [[0, 6], [1, 2], [2, 2]]) { BTn[i] /= d; } + const CC = X.FC_BF_BI_BT_2_CC(FC, BF, BI, BT); const BA0 = SOLVER.EF_EA_Ff_BF_BI_2_BA0(EF, EA, Ff, BF, BI); const trans_count = {all: 0, reduced: 0}; const out = SOLVER.initial_assignment(BA0, BF, BT, BI, FC, CF, CC, trans_count); @@ -132,9 +131,9 @@ export const BATCH = { faces: FV.length, eps: eps, variables: BF.length, - "taco-taco": num.BT0, - "taco-tortilla": num.BT1, - "tortilla-tortilla": num.BT2, + "taco-taco": BTn[0], + "taco-tortilla": BTn[1], + "tortilla-tortilla": BTn[2], transitivity: trans_count.all/3, "reduced-trans": trans_count.reduced/3, components: GB.length, diff --git a/src/compute.js b/src/compute.js index d24493b..922575b 100644 --- a/src/compute.js +++ b/src/compute.js @@ -92,15 +92,17 @@ const actions = { const {EF} = G.FOLD; const {SP, SE, CP, SC, CF, FC} = G.CELL; NOTE.time("Computing non-transitivity constraints"); - const [BT0, BT1, BT2] = X.BF_BI_EF_SE_CF_SC_2_BT0_BT1_BT2( - G.BF, G.BI, EF, SE, CF, SC); - NOTE.count(BT0, "taco-taco", 6); - NOTE.count(BT1, "taco-tortilla", 2); - NOTE.count(BT2, "tortilla-tortilla", 2); + G.BT = X.BF_BI_EF_SE_CF_SC_2_BT(G.BF, G.BI, EF, SE, CF, SC); + const BTn = [0, 0, 0]; + for (const bT of G.BT) { + for (let i = 0; i < 3; ++i) { BTn[i] += bT[i].length; } + } + for (const [i, d] of [[0, 6], [1, 2], [2, 2]]) { BTn[i] /= d; } + NOTE.log(` - Found ${BTn[0]} taco-taco`); + NOTE.log(` - Found ${BTn[1]} taco-tortilla`); + NOTE.log(` - Found ${BTn[2]} tortilla-tortilla`); NOTE.lap(); - G.BT = G.BF.map((F,i) => [BT0[i], BT1[i], BT2[i]]); - G.CC = X.FC_BF_BI_BT1_2_CC(FC, G.BF, G.BI, BT1); - BT0.length = 0; BT1.length = 0; BT2.length = 0; + G.CC = X.FC_BF_BI_BT_2_CC(FC, G.BF, G.BI, G.BT); postMessage({type: "end", arg: []}); }, presolve: () => { diff --git a/src/conversion.js b/src/conversion.js index cec79c0..2937fa1 100644 --- a/src/conversion.js +++ b/src/conversion.js @@ -573,14 +573,15 @@ export const X = { // CONVERSION for (const p of pairs) { const i = BI.get(M.encode_order_pair(p)); if (i == undefined) { debugger; } - BT[type][i].push(M.encode(F)); + BT[i][type].push(M.encode(F)); } }, - BF_BI_EF_SE_CF_SC_2_BT0_BT1_BT2: (BF, BI, EF, SE, CF, SC) => { - const BT0 = BF.map(() => []); // taco-taco - const BT1 = BF.map(() => []); // taco-tortilla - const BT2 = BF.map(() => []); // tortilla-tortilla - const BT = [BT0, BT1, BT2]; + BF_BI_EF_SE_CF_SC_2_BT: (BF, BI, EF, SE, CF, SC) => { + const BT = BF.map(() => [ + [], // taco-taco + [], // taco-tortilla + [], // tortilla-tortilla + ]); NOTE.time("Computing from edge-edge intersections"); const ExE = EF.map(() => new Set()); for (const edges of SE) { @@ -671,12 +672,12 @@ export const X = { // CONVERSION ExF.length = 0; return BT; }, - FC_BF_BI_BT1_2_CC: (FC, BF, BI, BT1) => { + FC_BF_BI_BT_2_CC: (FC, BF, BI, BT) => { const FG = FC.map(() => new Map()); - NOTE.start_check("taco-tortilla", BT1); - for (const [i, T] of BT1.entries()) { // construct connectivity graphs + NOTE.start_check("taco-tortilla", BT); + for (const [i, T] of BT.entries()) { // construct connectivity graphs NOTE.check(i); - for (const k of T) { + for (const k of T[1]) { const [a, b, c] = M.decode(k); const G = FG[c]; if (!G.has(a)) { G.set(a, new Set()); }