1
0
Fork 0

DecisionQueueFree is no longer needed

pull/779/head
Nils Adermann 2012-06-06 15:42:03 +02:00
parent 2fbc04b950
commit 5b1a48663e
2 changed files with 22 additions and 30 deletions

View File

@ -25,7 +25,6 @@ class Decisions implements \Iterator, \Countable
protected $pool;
protected $decisionMap;
protected $decisionQueue = array();
protected $decisionQueueFree = array();
public function __construct($pool)
{
@ -38,37 +37,13 @@ class Decisions implements \Iterator, \Countable
}
}
protected function addDecision($literal, $level)
{
$packageId = abs($literal);
$previousDecision = $this->decisionMap[$packageId];
if ($previousDecision != 0) {
$literalString = $this->pool->literalToString($literal);
$package = $this->pool->literalToPackage($literal);
throw new SolverBugException(
"Trying to decide $literalString on level $level, even though $package was previously decided as ".(int) $previousDecision."."
);
}
if ($literal > 0) {
$this->decisionMap[$packageId] = $level;
} else {
$this->decisionMap[$packageId] = -$level;
}
}
public function decide($literal, $level, $why, $addToFreeQueue = false)
public function decide($literal, $level, $why)
{
$this->addDecision($literal, $level);
$this->decisionQueue[] = array(
self::DECISION_LITERAL => $literal,
self::DECISION_REASON => $why,
);
if ($addToFreeQueue) {
$this->decisionQueueFree[count($this->decisionQueue) - 1] = true;
}
}
public function contain($literal)
@ -159,15 +134,12 @@ class Decisions implements \Iterator, \Countable
while ($decision = array_pop($this->decisionQueue)) {
$this->decisionMap[abs($decision[self::DECISION_LITERAL])] = 0;
}
$this->decisionQueueFree = array();
}
public function resetToOffset($offset)
{
while (count($this->decisionQueue) > $offset + 1) {
$decision = array_pop($this->decisionQueue);
unset($this->decisionQueueFree[count($this->decisionQueue)]);
$this->decisionMap[abs($decision[self::DECISION_LITERAL])] = 0;
}
}
@ -212,4 +184,24 @@ class Decisions implements \Iterator, \Countable
{
return count($this->decisionQueue) === 0;
}
protected function addDecision($literal, $level)
{
$packageId = abs($literal);
$previousDecision = $this->decisionMap[$packageId];
if ($previousDecision != 0) {
$literalString = $this->pool->literalToString($literal);
$package = $this->pool->literalToPackage($literal);
throw new SolverBugException(
"Trying to decide $literalString on level $level, even though $package was previously decided as ".(int) $previousDecision."."
);
}
if ($literal > 0) {
$this->decisionMap[$packageId] = $level;
} else {
$this->decisionMap[$packageId] = -$level;
}
}
}

View File

@ -275,7 +275,7 @@ class Solver
{
$level++;
$this->decisions->decide($literal, $level, $rule, true);
$this->decisions->decide($literal, $level, $rule);
while (true) {
$rule = $this->propagate($level);