Created
December 9, 2015 16:25
-
-
Save barelyknown/382c8ef2bab0206dfe29 to your computer and use it in GitHub Desktop.
optimize-roster-1.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addPositionConstraints(engine) { | |
// for each position | |
for (var row = 1; row <= POSITIONS.getNumRows(); row++) { | |
var position = POSITIONS.getCell( | |
row, | |
POSITIONS_POSITION_COLUMN | |
).getValue(); | |
var positionSpots = POSITIONS.getCell( | |
row, | |
POSITIONS_SPOTS_COLUMN | |
).getValue(); | |
// add a constraint that sets the number of spots | |
// required for the position | |
var constraint = engine.addConstraint( | |
positionSpots, | |
positionSpots | |
); | |
// for each player | |
for (var playerRow = 1; playerRow <= PLAYERS.getNumRows(); playerRow++) { | |
var player = PLAYERS.getCell( | |
playerRow, | |
PLAYERS_PLAYER_COLUMN | |
).getValue(); | |
var playerPosition = PLAYERS.getCell( | |
playerRow, | |
PLAYERS_POSITION_COLUMN | |
).getValue(); | |
// if the player plays the position | |
if (playerPosition == position) { | |
// add the player to the position contraint | |
constraint.setCoefficient(player, 1); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment