1
0
Fork 0

Rule literals are sorted, so first literal added is not first retrieved

Fixes #477
pull/521/head
Nils Adermann 2012-04-01 22:26:10 +02:00
parent 1fe24a3837
commit a16aa68c1d
2 changed files with 32 additions and 7 deletions

View File

@ -1352,7 +1352,7 @@ class Solver
} }
// conflict // conflict
list($newLevel, $newRule, $why) = $this->analyze($level, $rule); list($learnLiteral, $newLevel, $newRule, $why) = $this->analyze($level, $rule);
assert($newLevel > 0); assert($newLevel > 0);
assert($newLevel < $level); assert($newLevel < $level);
@ -1369,9 +1369,8 @@ class Solver
$this->watch2OnHighest($newRule); $this->watch2OnHighest($newRule);
$this->addWatchesToRule($newRule); $this->addWatchesToRule($newRule);
$literals = $newRule->getLiterals(); $this->addDecision($learnLiteral, $level);
$this->addDecision($literals[0], $level); $this->decisionQueue[] = $learnLiteral;
$this->decisionQueue[] = $literals[0];
$this->decisionQueueWhy[] = $newRule; $this->decisionQueueWhy[] = $newRule;
} }
@ -1437,7 +1436,6 @@ class Solver
$l1retry = true; $l1retry = true;
while ($l1retry) { while ($l1retry) {
$l1retry = false; $l1retry = false;
if (!$num && !--$l1num) { if (!$num && !--$l1num) {
@ -1483,7 +1481,7 @@ class Solver
assert($learnedLiterals[0] !== null); assert($learnedLiterals[0] !== null);
$newRule = new Rule($learnedLiterals, Rule::RULE_LEARNED, $why); $newRule = new Rule($learnedLiterals, Rule::RULE_LEARNED, $why);
return array($ruleLevel, $newRule, $why); return array($learnedLiterals[0], $ruleLevel, $newRule, $why);
} }
private function analyzeUnsolvableRule($problem, $conflictRule, &$lastWeakWhy) private function analyzeUnsolvableRule($problem, $conflictRule, &$lastWeakWhy)
@ -2029,7 +2027,7 @@ class Solver
{ {
echo "DecisionQueue: \n"; echo "DecisionQueue: \n";
foreach ($this->decisionQueue as $i => $literal) { foreach ($this->decisionQueue as $i => $literal) {
echo ' ' . $literal . ' ' . $this->decisionQueueWhy[$i]."\n"; echo ' ' . $literal . ' ' . $this->decisionQueueWhy[$i]." level ".$this->decisionMap[$literal->getPackageId()]."\n";
} }
echo "\n"; echo "\n";
} }

View File

@ -622,6 +622,33 @@ class SolverTest extends TestCase
} }
} }
public function testLearnLiteralsWithSortedRuleLiterals()
{
$this->repo->addPackage($packageTwig2 = $this->getPackage('twig/twig', '2.0'));
$this->repo->addPackage($packageTwig16 = $this->getPackage('twig/twig', '1.6'));
$this->repo->addPackage($packageTwig15 = $this->getPackage('twig/twig', '1.5'));
$this->repo->addPackage($packageSymfony = $this->getPackage('symfony/symfony', '2.0'));
$this->repo->addPackage($packageTwigBridge = $this->getPackage('symfony/twig-bridge', '2.0'));
$packageTwigBridge->setRequires(array(
new Link('symfony/twig-bridge', 'twig/twig', $this->getVersionConstraint('<', '2.0'), 'requires'),
));
$packageSymfony->setReplaces(array(
new Link('symfony/symfony', 'symfony/twig-bridge', $this->getVersionConstraint('==', '2.0'), 'replaces'),
));
$this->reposComplete();
$this->request->install('symfony/twig-bridge');
$this->request->install('twig/twig');
$this->checkSolverResult(array(
array('job' => 'install', 'package' => $packageTwig16),
array('job' => 'install', 'package' => $packageTwigBridge),
));
}
protected function reposComplete() protected function reposComplete()
{ {
$this->pool->addRepository($this->repoInstalled); $this->pool->addRepository($this->repoInstalled);