Skip to content

Commit

Permalink
fair: Fix bug in increase algo to match decrease algo
Browse files Browse the repository at this point in the history
  • Loading branch information
timgott committed Jun 30, 2024
1 parent 6bd1447 commit 0be117d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions socialchoice/src/algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,18 @@ export function findSwappableTowards(
let connectedAgents = new Set<Agent>();
let connectedItems = new Set<Item>();
let predecessor = new Map<Agent, [Item, Agent]>();
bfsSimple(root, (agent: Agent) => {
bfsFold(root, () => null, (agent: Agent, parent: [Item, Agent] | null) => {
connectedAgents.add(agent);

if (parent) {
predecessor.set(agent, parent);
}
// find alternating continuation (mbb, then allocation)
const mbb = mbbSets.get(agent)!;
const children: Agent[] = [];
const children: [Agent, [Item, Agent]][] = [];
for (const item of mbb) {
connectedItems.add(item);
const owner = getOwner(item);
if (!connectedAgents.has(owner)) {
children.push(owner);
predecessor.set(owner, [item, agent]);
}
children.push([owner, [item, agent]]);
}

return children;
Expand Down
4 changes: 2 additions & 2 deletions socialchoice/src/main.allocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
computeMBBSet,
findBudgetViolatorsUpTo1,
findLeastSpenders,
findSwappableComponent,
findSwappableTowards,
improveAllocationStep,
} from "./algo";
import {
Expand Down Expand Up @@ -253,7 +253,7 @@ class AllocationGraph {
let mbbSets = mapFromFunction<Agent,Set<Item>>(
model.agents, a => computeMBBSet(a, model.market.prices)
);
let swapComponent = findSwappableComponent(leastSpenders, model.market, mbbSets);
let swapComponent = findSwappableTowards(leastSpenders, model.market, mbbSets);
for (let [agent, agentNode] of this.agentMap) {
// connect MBB set
let mbbSet = ensured(mbbSets.get(agent));
Expand Down

0 comments on commit 0be117d

Please sign in to comment.