1
0
Fork 0

Implement minimization of branches

pull/9/head
Nils Adermann 2011-08-20 23:03:52 -04:00
parent 0f6fb9b692
commit 6118c00086
1 changed files with 45 additions and 51 deletions

View File

@ -1336,8 +1336,8 @@ class Solver
while (!empty($this->branches)) { while (!empty($this->branches)) {
list($literals, $branchLevel) = $this->branches[count($this->branches) - 1]; list($literals, $branchLevel) = $this->branches[count($this->branches) - 1];
if ($branchLevel > -$level) { if ($branchLevel >= $level) {
continue; break;
} }
array_pop($this->branches); array_pop($this->branches);
@ -1416,16 +1416,14 @@ class Solver
// choose best package to install from decisionQueue // choose best package to install from decisionQueue
$literals = $this->policy->selectPreferedPackages($this, $this->pool, $this->installed, $decisionQueue); $literals = $this->policy->selectPreferedPackages($this, $this->pool, $this->installed, $decisionQueue);
$selectedLiteral = array_shift($literals);
// if there are multiple candidates, then branch // if there are multiple candidates, then branch
if (count($literals) > 1) { if (count($literals)) {
foreach ($literals as $i => $literal) { $this->branches[] = array($literals, -$level);
if (0 !== $i) {
$this->branches[] = array(array($literal), -$level);
}
}
} }
return $this->setPropagateLearn($level, $literals[0], $disableRules, $rule); return $this->setPropagateLearn($level, $selectedLiteral, $disableRules, $rule);
} }
protected function analyze($level, $rule) protected function analyze($level, $rule)
@ -2000,49 +1998,45 @@ class Solver
// $this->printDecisionMap(); // $this->printDecisionMap();
// $this->printDecisionQueue(); // $this->printDecisionQueue();
// minimization step
if (count($this->branches)) { if (count($this->branches)) {
die("minimization unimplemented");
// /* minimization step */ $lastLiteral = null;
// if (solv->branches.count) $lastLevel = null;
// { $lastBranchIndex = 0;
// int l = 0, lasti = -1, lastl = -1; $lastBranchOffset = 0;
// Id why;
// for ($i = count($this->branches) - 1; $i >= 0; $i--) {
// p = 0; list($literals, $level) = $this->branches[$i];
// for (i = solv->branches.count - 1; i >= 0; i--)
// { foreach ($literals as $offset => $literal) {
// p = solv->branches.elements[i]; if ($literal && $literal->isWanted() && $this->decisionMap[$literal->getPackageId()] > $level + 1) {
// if (p < 0) $lastLiteral = $literal;
// l = -p; $lastBranchIndex = $i;
// else if (p > 0 && solv->decisionmap[p] > l + 1) $lastBranchOffset = $offset;
// { $lastLevel = $level;
// lasti = i; }
// lastl = l; }
// } }
// }
// if (lasti >= 0) if ($lastLiteral) {
// { $this->branches[$lastBranchIndex][$lastBranchOffset] = null;
// /* kill old solvable so that we do not loop */ $minimizationSteps++;
// p = solv->branches.elements[lasti];
// solv->branches.elements[lasti] = 0; $level = $lastLevel;
// POOL_DEBUG(SAT_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, solvid2str(pool, p)); $this->revert($level);
// minimizationsteps++;
// $why = $this->decisionQueueWhy[count($this->decisionQueueWhy)];
// level = lastl;
// revert(solv, level); $oLevel = $level;
// why = -solv->decisionq_why.elements[solv->decisionq_why.count]; $level = $this->setPropagateLearn($level, $lastLiteral, $disableRules, $why);
// assert(why >= 0);
// olevel = level; if ($level == 0) {
// level = setpropagatelearn(solv, level, p, disablerules, why); return;
// if (level == 0) }
// {
// queue_free(&dq); continue;
// queue_free(&dqs); }
// return;
// }
// continue; /* back to main loop */
// }
// }
} }
break; break;