Skip to content

Instantly share code, notes, and snippets.

@barelyknown
Created December 9, 2015 16:25
Show Gist options
  • Save barelyknown/a5f8ac12ec29451afd1b to your computer and use it in GitHub Desktop.
Save barelyknown/a5f8ac12ec29451afd1b to your computer and use it in GitHub Desktop.
optimize-roster-0.js
function addVariables(engine) {
// for each player
for (var row = 1; row <= PLAYERS.getNumRows(); row++) {
var player = PLAYERS.getCell(
row,
PLAYERS_PLAYER_COLUMN
).getValue();
var projectedPoints = PLAYERS.getCell(
row, PLAYERS_PROJECTED_POINTS_COLUMN
).getValue();
// add a variable for the player that enables them
// to be selected (1) or not selected (0)
engine.addVariable(
player,
0,
1,
LinearOptimizationService.VariableType.INTEGER
);
// set the projected points as the coefficient for
// the player's variable
engine.setObjectiveCoefficient(player, projectedPoints);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment