Skip to content

Commit

Permalink
deduplicate paths that are each other's reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Sep 19, 2024
1 parent 3604fb5 commit 08d2826
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 11 additions & 1 deletion __tests__/fixtures/testnet-sarafu.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@
6 4 0.5
4 6 100.0
4 6 200.0
3 6 100.0
3 6 100.0
4 3 2.0
4 6 2.0
3 6 23.0
5 7 400.0
7 3 12.0
4 7 10.0
7 6 10.0
4 6 20.0
0 8 621.6898006764151
0 9 714.3782984916287
18 changes: 15 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { BatchedNetworkSimulator, Badger as Node } from './main.js';

const TESTNET_CSV = '__tests__/fixtures/testnet-sarafu.csv';
const NUM_ROUNDS_PER_LINE = 50;
function reversePath(path: string): string {
const hops = path.split('.');
const innerHops = hops.slice(1, hops.length - 1);
const reverseInnerHops = innerHops.reverse();
return [].concat(hops[0], reverseInnerHops, hops[0]).join('.');
}

async function run(): Promise<void> {
console.log("This simulation will take about 60 seconds to complete.");
Expand Down Expand Up @@ -94,12 +100,18 @@ async function run(): Promise<void> {
paths[path].push(loopId);
}
});
console.log(`Found ${Object.keys(paths).length} paths:`);
Object.keys(paths).sort().forEach((path) => {
const reverses = [];
const deduplicated = Object.keys(paths).sort().filter(path => {
reverses.push(reversePath(path));
return (reverses.indexOf(path) === -1);
});
console.log(`Found ${deduplicated.length} paths:`);
deduplicated.forEach((path) => {
// console.log(path, paths[path]);
console.log(path);
});
console.log(networkSimulator.getPlantUml('possible'));
// console.log(reverses);
// console.log(networkSimulator.getPlantUml('possible'));
}


Expand Down

0 comments on commit 08d2826

Please sign in to comment.