Created
December 9, 2015 16:23
-
-
Save barelyknown/7fab862d4fb2e4f922fb to your computer and use it in GitHub Desktop.
optimize-roster.js
This file contains 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 optimizeRoster() { | |
// this sets engine to an instance of Google's LP/MIP solver | |
var engine = LinearOptimizationService.createEngine(); | |
// clear previous selections from the Players worksheet | |
clearPreviousSelections(); | |
// add the variables (players and their salaries) | |
// to the optimization problem | |
addVariables(engine); | |
// add the contraints that ensure that the correct number | |
// of players are on the roster for each position | |
addPositionConstraints(engine); | |
// add the constraint to ensure that the total | |
// of the salaries on the roster is under the salary cap | |
addSalaryCapConstraint(engine); | |
// solve the problem and set the solution | |
var solution = engine.setMaximization().solve(); | |
// export the solution to the Players worksheet | |
setSolution(solution); | |
// copy the optimal roster to a new worksheet | |
createRosterSheet(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment