Call "nudge" from constraint solver

This commit is contained in:
David Greenspan
2015-03-09 23:50:48 -07:00
parent 979554ab55
commit 76cf2f28ad
2 changed files with 11 additions and 4 deletions

View File

@@ -63,7 +63,11 @@ CS.PackagesResolver.prototype.resolve = function (dependencies, constraints,
// - allAnswers (for testing, calculate all possible answers and put an extra
// property named "allAnswers" on the result)
CS.PackagesResolver._resolveWithInput = function (input, options) {
var solver = new CS.Solver(input);
options = options || {};
var solver = new CS.Solver(input, {
nudge: options.nudge
});
// Disable runtime type checks (they slow things down by a factor of 3)
return Logic._disablingTypeChecks(function () {

View File

@@ -18,7 +18,7 @@ CS.Solver = function (input, options) {
return p + "@" + vConstraint.raw;
});
self.options = options;
self.options = options || {};
self.steps = [];
self.stepsByName = {};
@@ -180,8 +180,11 @@ CS.Solver.prototype.minimize = function (step, options) {
self.solution = logic.minimize(
self.solution, costTerms, costWeights, {
progress: function (status, cost) {
if (status === 'improving') {
if (DEBUG) {
if (self.options.nudge) {
self.options.nudge();
}
if (DEBUG) {
if (status === 'improving') {
console.log(cost + " ... trying to improve ...");
}
}