Skip to content

Instantly share code, notes, and snippets.

@barelyknown
Created December 9, 2015 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barelyknown/e3c1350a81a47b0402c6 to your computer and use it in GitHub Desktop.
Save barelyknown/e3c1350a81a47b0402c6 to your computer and use it in GitHub Desktop.
optimize-roster-2.js
function addSalaryCapConstraint(engine) {
// add a constraint for the overall salary cap
var salaryCapConstraint = engine.addConstraint(0, SALARY_CAP);
// for each player
for (var row = 1; row <= PLAYERS.getNumRows(); row++) {
var player = PLAYERS.getCell(
row,
PLAYERS_PLAYER_COLUMN
).getValue();
var playerSalary = PLAYERS.getCell(
row,
PLAYERS_SALARY_COLUMN
).getValue();
// add the player's salary to the constraint
salaryCapConstraint.setCoefficient(player, playerSalary);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment