Skip to content

Commit

Permalink
Ref #42
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Oct 21, 2024
1 parent 88a499e commit 7b39057
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ export class Balances {
const sent = this.sent[friend] || 0n;
const received = this.received[friend] || 0n;
if ((sent > 0) && (received > 0)) {
// console.log(`${name} has pos bilateral with ${friend}, min(${sent}, ${received}) = ${bigIntMin(sent, received)}`);
num++;
amount += bigIntMin(sent, received);
} else if ((sent < 0) && (received < 0)) {
// console.log(`${name} has neg bilateral with ${friend}, max(${sent}, ${received}) = ${bigIntMax(sent, received)}`);
num++;
amount += bigIntMax(sent, received);
}
Expand Down
4 changes: 2 additions & 2 deletions src/SingleThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class SingleThread {
stats.transfersReceived += workerStats.transfersReceived;
stats.transfersSent += workerStats.transfersSent;
stats.transferAmount += workerStats.transferAmount;
stats.bilateralNum += workerStats.bilateralNum;
stats.bilateralAmount += workerStats.bilateralAmount;
stats.bilateralNum += workerStats.bilateralNum / 2;
stats.bilateralAmount += workerStats.bilateralAmount / 2;
stats.multilateralNum += workerStats.multilateralNum;
stats.multilateralAmount += workerStats.multilateralAmount;
stats.numNodes += workerStats.numNodes;
Expand Down
2 changes: 1 addition & 1 deletion src/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class Worker {
stats.multilateralAmount += this.ourNodes[name].multilateralAmount;
stats.numNodes++;
});
console.log(`Worker ${this.workerNo} return stats`, stats);
// console.log(`Worker ${this.workerNo} return stats`, stats);
return stats;
}
getNode(name: string): Jerboa {
Expand Down
4 changes: 2 additions & 2 deletions src/jerboaChallenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ async function runSingleThread(numWorkers: number): Promise<void> {
}
console.log(`${stats.transfersSent} transfers between ${stats.numNodes} participants triggered an average of ${(stats.messagesSent / stats.transfersSent).toFixed(2)} messages each`);
console.log(`Transfer amount ${Math.round(stats.transferAmount)}`);
console.log(`${Math.round((stats.bilateralAmount / stats.transferAmount)*100)}% netted bilaterally`);
console.log(`${Math.round((stats.bilateralAmount / stats.transferAmount)*100)}% netted in total`);
console.log(`${Math.round((stats.multilateralAmount / stats.transferAmount)*100)}% netted multilaterally`);
console.log(`${Math.round((1 - (stats.bilateralAmount + stats.multilateralAmount) / stats.transferAmount)*100)}% not netted`);
console.log(`${Math.round((1 - (stats.bilateralAmount) / stats.transferAmount)*100)}% not netted`);
console.log(stats);
}

Expand Down

0 comments on commit 7b39057

Please sign in to comment.