How the Maximize Trades Algorithm Works
This page describes, in pseudocode, the "maximize trades" algorithm used by the "no-risk trade resolution tool".
The algorithm for maximizing trades is basically:
for i = (1..100) {
results = runScoringAlgorithms();
if(results.trades > maxTrades){
bestResult = results;
maxTrades = results.trades;
}
}
for i = (1..100) {
results = runGrowAlgorithm();
if(results.trades > maxTrades){
bestResult = results;
maxTrades = results.trades;
}
}
So, how do the individual algorithms work? Well, there's two basic kinds: "scoring" and "growing". Most of the trial algorithms are "scoring" algorithms, but often the longest list comes from the "growing" algorithm.
"Scoring" algorithms look like this:
removePeopleWhoWantNothing();
removePeopleWhoAreUnwanted();
tryToResolve();
function tryToResolve {
scoreRemainingPeople();
foreach person (sort-by-score(people)){
foreach pick (person.picks){
if(stillAvailable(pick)){
tentativelyAssignGame(pick, person);
last;
}
}
if(no-game-assigned-to(person)){
remove(person);
tryToResolve();
}
}
}
The difference among the scoring algorithms is in what "scoreRemainingPeople()" looks like. Some of them base scoring on how popular their game is, some score based on what they want, etc.
The "growing" algorithm is very different:
c = grow(); // Grow the first chain
while(c != failed){
grow(); // Grow any available chains from remaining people
}
function grow(chain){
if(lastIn(chain) wants firstIn(chain)){
return chain;
}
p2 = chooseRandomAvailableWant(lastIn(chain));
if(p2 == nothing) { return failed; }
markTaken(p2);
addToEndOfChain(chain, p2);
grow(chain);
}
So, there you have it.