Remove debug output; Stop if the best estimated solution will never lead to a

solution (Infinity).
This commit is contained in:
Slava Kim
2014-04-08 19:26:18 -07:00
parent 07621e3c25
commit 9ccaa5c2e9
2 changed files with 11 additions and 15 deletions

View File

@@ -37,6 +37,10 @@ _.extend(PriorityQueue.prototype, {
empty: function () {
var self = this;
return self._heap.empty();
},
size: function () {
var self = this;
return self._heap.size();
}
});

View File

@@ -120,28 +120,21 @@ ConstraintSolver.Resolver.prototype.resolve =
pq.push(startState, [estimateCostFunction(startState, opts), 0]);
var someError = null;
var stateStrings = {};
while (! pq.empty()) {
var currentState = pq.pop();
var tentativeCost =
costFunction(currentState.choices, opts) +
estimateCostFunction(currentState, opts);
console.log(">> ", tentativeCost);
var tentativeCost =
costFunction(currentState.choices, opts) +
estimateCostFunction(currentState, opts);
if (tentativeCost === Infinity)
break;
if (_.isEmpty(currentState.dependencies))
return currentState.choices;
var currentCost = costFunction(currentState.choices, opts);
var neighborsObj = self._stateNeighbors(currentState);
if (! neighborsObj.success) {
console.log(":( ", currentState.choices.map(function (x) { return x.toString() }))
console.log("<< left: ", currentState.dependencies)
console.log("<< constr: ", _.map(_.filter(currentState.constraints, function (x) { return _.contains(currentState.dependencies, x.name) }), function (x) { return x.toString() }));
console.log(neighborsObj.failureMsg, '\n\n')
//console.log(neighborsObj.failureMsg, neighborsObj.triedUnitVersions.map(function (x) { return x.toString() }), '\n', neighborsObj.lastInvalidNeighbor.choices.map(function (x) { return x.toString() }), '\n', neighborsObj.lastInvalidNeighbor.constraints.map(function (x) { return x.toString() }), '\n\n')
someError = someError || neighborsObj.failureMsg;
} else {
_.each(neighborsObj.neighbors, function (state) {
@@ -149,8 +142,7 @@ ConstraintSolver.Resolver.prototype.resolve =
costFunction(state.choices, opts) +
estimateCostFunction(state, opts);
//if (_.isFinite(tentativeCost))
pq.push(state, [tentativeCost, -state.choices.length]);
pq.push(state, [tentativeCost, -state.choices.length]);
});
}
}