Skip to content

Instantly share code, notes, and snippets.

@barelyknown
Created December 9, 2015 16:23
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/7fab862d4fb2e4f922fb to your computer and use it in GitHub Desktop.
Save barelyknown/7fab862d4fb2e4f922fb to your computer and use it in GitHub Desktop.
optimize-roster.js
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