Solver.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\DependencyResolver;
  12. use Composer\Repository\RepositoryInterface;
  13. use Composer\Package\PackageInterface;
  14. use Composer\DependencyResolver\Operation;
  15. /**
  16. * @author Nils Adermann <naderman@naderman.de>
  17. */
  18. class Solver
  19. {
  20. const RULE_INTERNAL_ALLOW_UPDATE = 1;
  21. const RULE_JOB_INSTALL = 2;
  22. const RULE_JOB_REMOVE = 3;
  23. const RULE_JOB_LOCK = 4;
  24. const RULE_NOT_INSTALLABLE = 5;
  25. const RULE_NOTHING_PROVIDES_DEP = 6;
  26. const RULE_PACKAGE_CONFLICT = 7;
  27. const RULE_PACKAGE_NOT_EXIST = 8;
  28. const RULE_PACKAGE_REQUIRES = 9;
  29. const RULE_PACKAGE_OBSOLETES = 10;
  30. const RULE_INSTALLED_PACKAGE_OBSOLETES = 11;
  31. const RULE_PACKAGE_SAME_NAME = 12;
  32. const RULE_PACKAGE_IMPLICIT_OBSOLETES = 13;
  33. const RULE_LEARNED = 14;
  34. protected $policy;
  35. protected $pool;
  36. protected $installed;
  37. protected $rules;
  38. protected $updateAll;
  39. protected $ruleToJob = array();
  40. protected $addedMap = array();
  41. protected $fixMap = array();
  42. protected $updateMap = array();
  43. protected $noObsoletes = array();
  44. protected $watches = array();
  45. protected $removeWatches = array();
  46. protected $decisionMap;
  47. protected $installedMap;
  48. protected $packageToUpdateRule = array();
  49. protected $packageToFeatureRule = array();
  50. public function __construct(PolicyInterface $policy, Pool $pool, RepositoryInterface $installed)
  51. {
  52. $this->policy = $policy;
  53. $this->pool = $pool;
  54. $this->installed = $installed;
  55. $this->rules = new RuleSet;
  56. }
  57. /**
  58. * Creates a new rule for the requirements of a package
  59. *
  60. * This rule is of the form (-A|B|C), where B and C are the providers of
  61. * one requirement of the package A.
  62. *
  63. * @param PackageInterface $package The package with a requirement
  64. * @param array $providers The providers of the requirement
  65. * @param int $reason A RULE_* constant describing the
  66. * reason for generating this rule
  67. * @param mixed $reasonData Any data, e.g. the requirement name,
  68. * that goes with the reason
  69. * @return Rule The generated rule or null if tautological
  70. */
  71. protected function createRequireRule(PackageInterface $package, array $providers, $reason, $reasonData = null)
  72. {
  73. $literals = array(new Literal($package, false));
  74. foreach ($providers as $provider) {
  75. // self fulfilling rule?
  76. if ($provider === $package) {
  77. return null;
  78. }
  79. $literals[] = new Literal($provider, true);
  80. }
  81. return new Rule($literals, $reason, $reasonData);
  82. }
  83. /**
  84. * Create a new rule for updating a package
  85. *
  86. * If package A1 can be updated to A2 or A3 the rule is (A1|A2|A3).
  87. *
  88. * @param PackageInterface $package The package to be updated
  89. * @param array $updates An array of update candidate packages
  90. * @param int $reason A RULE_* constant describing the
  91. * reason for generating this rule
  92. * @param mixed $reasonData Any data, e.g. the package name, that
  93. * goes with the reason
  94. * @return Rule The generated rule or null if tautology
  95. */
  96. protected function createUpdateRule(PackageInterface $package, array $updates, $reason, $reasonData = null)
  97. {
  98. $literals = array(new Literal($package, true));
  99. foreach ($updates as $update) {
  100. $literals[] = new Literal($update, true);
  101. }
  102. return new Rule($literals, $reason, $reasonData);
  103. }
  104. /**
  105. * Creates a new rule for installing a package
  106. *
  107. * The rule is simply (A) for a package A to be installed.
  108. *
  109. * @param PackageInterface $package The package to be installed
  110. * @param int $reason A RULE_* constant describing the
  111. * reason for generating this rule
  112. * @param mixed $reasonData Any data, e.g. the package name, that
  113. * goes with the reason
  114. * @return Rule The generated rule
  115. */
  116. protected function createInstallRule(PackageInterface $package, $reason, $reasonData = null)
  117. {
  118. return new Rule(new Literal($package, true));
  119. }
  120. /**
  121. * Creates a rule to install at least one of a set of packages
  122. *
  123. * The rule is (A|B|C) with A, B and C different packages. If the given
  124. * set of packages is empty an impossible rule is generated.
  125. *
  126. * @param array $packages The set of packages to choose from
  127. * @param int $reason A RULE_* constant describing the reason for
  128. * generating this rule
  129. * @param mixed $reasonData Any data, e.g. the package name, that goes with
  130. * the reason
  131. * @return Rule The generated rule
  132. */
  133. protected function createInstallOneOfRule(array $packages, $reason, $reasonData = null)
  134. {
  135. if (empty($packages)) {
  136. return $this->createImpossibleRule($reason, $reasonData);
  137. }
  138. $literals = array();
  139. foreach ($packages as $package) {
  140. $literals[] = new Literal($package, true);
  141. }
  142. return new Rule($literals, $reason, $reasonData);
  143. }
  144. /**
  145. * Creates a rule to remove a package
  146. *
  147. * The rule for a package A is (-A).
  148. *
  149. * @param PackageInterface $package The package to be removed
  150. * @param int $reason A RULE_* constant describing the
  151. * reason for generating this rule
  152. * @param mixed $reasonData Any data, e.g. the package name, that
  153. * goes with the reason
  154. * @return Rule The generated rule
  155. */
  156. protected function createRemoveRule(PackageInterface $package, $reason, $reasonData = null)
  157. {
  158. return new Rule(array(new Literal($package, false)), $reason, $reasonData);
  159. }
  160. /**
  161. * Creates a rule for two conflicting packages
  162. *
  163. * The rule for conflicting packages A and B is (-A|-B). A is called the issuer
  164. * and B the provider.
  165. *
  166. * @param PackageInterface $issuer The package declaring the conflict
  167. * @param Package $provider The package causing the conflict
  168. * @param int $reason A RULE_* constant describing the
  169. * reason for generating this rule
  170. * @param mixed $reasonData Any data, e.g. the package name, that
  171. * goes with the reason
  172. * @return Rule The generated rule
  173. */
  174. protected function createConflictRule(PackageInterface $issuer, PackageInterface $provider, $reason, $reasonData = null)
  175. {
  176. // ignore self conflict
  177. if ($issuer === $provider) {
  178. return null;
  179. }
  180. return new Rule(array(new Literal($issuer, false), new Literal($provider, false)), $reason, $reasonData);
  181. }
  182. /**
  183. * Intentionally creates a rule impossible to solve
  184. *
  185. * The rule is an empty one so it can never be satisfied.
  186. *
  187. * @param int $reason A RULE_* constant describing the reason for
  188. * generating this rule
  189. * @param mixed $reasonData Any data, e.g. the package name, that goes with
  190. * the reason
  191. * @return Rule An empty rule
  192. */
  193. protected function createImpossibleRule($reason, $reasonData = null)
  194. {
  195. return new Rule(array(), $reason, $reasonData);
  196. }
  197. /**
  198. * Adds a rule unless it duplicates an existing one of any type
  199. *
  200. * To be able to directly pass in the result of one of the rule creation
  201. * methods the rule may also be null to indicate that no rule should be
  202. * added.
  203. *
  204. * @param int $type A TYPE_* constant defining the rule type
  205. * @param Rule $newRule The rule about to be added
  206. */
  207. private function addRule($type, Rule $newRule = null) {
  208. if ($newRule) {
  209. if ($this->rules->containsEqual($newRule)) {
  210. return;
  211. }
  212. $this->rules->add($newRule, $type);
  213. }
  214. }
  215. protected function addRulesForPackage(PackageInterface $package)
  216. {
  217. $workQueue = new \SplQueue;
  218. $workQueue->enqueue($package);
  219. while (!$workQueue->isEmpty()) {
  220. $package = $workQueue->dequeue();
  221. if (isset($this->addedMap[$package->getId()])) {
  222. continue;
  223. }
  224. $this->addedMap[$package->getId()] = true;
  225. $dontFix = 0;
  226. if (isset($this->installedMap[$package->getId()]) && !isset($this->fixMap[$package->getId()])) {
  227. $dontFix = 1;
  228. }
  229. if (!$dontFix && !$this->policy->installable($this, $this->pool, $this->installedMap, $package)) {
  230. $this->addRule(RuleSet::TYPE_PACKAGE, $this->createRemoveRule($package, self::RULE_NOT_INSTALLABLE, (string) $package));
  231. continue;
  232. }
  233. foreach ($package->getRequires() as $link) {
  234. $possibleRequires = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  235. // the strategy here is to not insist on dependencies
  236. // that are already broken. so if we find one provider
  237. // that was already installed, we know that the
  238. // dependency was not broken before so we enforce it
  239. if ($dontFix) {
  240. $foundInstalled = false;
  241. foreach ($possibleRequires as $require) {
  242. if (isset($this->installedMap[$require->getId()])) {
  243. $foundInstalled = true;
  244. break;
  245. }
  246. }
  247. // no installed provider found: previously broken dependency => don't add rule
  248. if (!$foundInstalled) {
  249. continue;
  250. }
  251. }
  252. $this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createRequireRule($package, $possibleRequires, self::RULE_PACKAGE_REQUIRES, (string) $link));
  253. foreach ($possibleRequires as $require) {
  254. $workQueue->enqueue($require);
  255. }
  256. }
  257. foreach ($package->getConflicts() as $link) {
  258. $possibleConflicts = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  259. foreach ($possibleConflicts as $conflict) {
  260. if ($dontFix && isset($this->installedMap[$conflict->getId()])) {
  261. continue;
  262. }
  263. $this->addRule(RuleSet::TYPE_PACKAGE, $this->createConflictRule($package, $conflict, self::RULE_PACKAGE_CONFLICT, (string) $link));
  264. }
  265. }
  266. // check obsoletes and implicit obsoletes of a package
  267. // if ignoreinstalledsobsoletes is not set, we're also checking
  268. // obsoletes of installed packages (like newer rpm versions)
  269. //
  270. /** @TODO: if ($this->noInstalledObsoletes) */
  271. if (true) {
  272. $noObsoletes = isset($this->noObsoletes[$package->getId()]);
  273. $isInstalled = (isset($this->installedMap[$package->getId()]));
  274. foreach ($package->getReplaces() as $link) {
  275. $obsoleteProviders = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  276. foreach ($obsoleteProviders as $provider) {
  277. if ($provider === $package) {
  278. continue;
  279. }
  280. if ($isInstalled && $dontFix && isset($this->installedMap[$provider->getId()])) {
  281. continue; // don't repair installed/installed problems
  282. }
  283. $reason = ($isInstalled) ? self::RULE_INSTALLED_PACKAGE_OBSOLETES : self::RULE_PACKAGE_OBSOLETES;
  284. $this->addRule(RuleSet::TYPE_PACKAGE, $this->createConflictRule($package, $provider, $reason, (string) $link));
  285. }
  286. }
  287. // check implicit obsoletes
  288. // for installed packages we only need to check installed/installed problems (and
  289. // only when dontFix is not set), as the others are picked up when looking at the
  290. // uninstalled package.
  291. if (!$isInstalled || !$dontFix) {
  292. $obsoleteProviders = $this->pool->whatProvides($package->getName(), null);
  293. foreach ($obsoleteProviders as $provider) {
  294. if ($provider === $package) {
  295. continue;
  296. }
  297. if ($isInstalled && !isset($this->installedMap[$provider->getId()])) {
  298. continue;
  299. }
  300. // obsolete same packages even when noObsoletes
  301. if ($noObsoletes && (!$package->equals($provider))) {
  302. continue;
  303. }
  304. $reason = ($package->getName() == $provider->getName()) ? self::RULE_PACKAGE_SAME_NAME : self::RULE_PACKAGE_IMPLICIT_OBSOLETES;
  305. $this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createConflictRule($package, $provider, $reason, (string) $package));
  306. }
  307. }
  308. }
  309. foreach ($package->getRecommends() as $link) {
  310. foreach ($this->pool->whatProvides($link->getTarget(), $link->getConstraint()) as $recommend) {
  311. $workQueue->enqueue($recommend);
  312. }
  313. }
  314. foreach ($package->getSuggests() as $link) {
  315. foreach ($this->pool->whatProvides($link->getTarget(), $link->getConstraint()) as $suggest) {
  316. $workQueue->enqueue($suggest);
  317. }
  318. }
  319. }
  320. }
  321. /**
  322. * Adds all rules for all update packages of a given package
  323. *
  324. * @param PackageInterface $package Rules for this package's updates are to
  325. * be added
  326. * @param bool $allowAll Whether downgrades are allowed
  327. */
  328. private function addRulesForUpdatePackages(PackageInterface $package)
  329. {
  330. $updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package);
  331. $this->addRulesForPackage($package);
  332. foreach ($updates as $update) {
  333. $this->addRulesForPackage($update);
  334. }
  335. }
  336. /**
  337. * Alters watch chains for a rule.
  338. *
  339. * Next1/2 always points to the next rule that is watching the same package.
  340. * The watches array contains rules to start from for each package
  341. *
  342. */
  343. private function addWatchesToRule(Rule $rule)
  344. {
  345. // skip simple assertions of the form (A) or (-A)
  346. if ($rule->isAssertion()) {
  347. return;
  348. }
  349. if (!isset($this->watches[$rule->watch1])) {
  350. $this->watches[$rule->watch1] = null;
  351. }
  352. $rule->next1 = $this->watches[$rule->watch1];
  353. $this->watches[$rule->watch1] = $rule;
  354. if (!isset($this->watches[$rule->watch2])) {
  355. $this->watches[$rule->watch2] = null;
  356. }
  357. $rule->next2 = $this->watches[$rule->watch2];
  358. $this->watches[$rule->watch2] = $rule;
  359. }
  360. /**
  361. * Put watch2 on rule's literal with highest level
  362. */
  363. private function watch2OnHighest(Rule $rule)
  364. {
  365. $literals = $rule->getLiterals();
  366. // if there are only 2 elements, both are being watched anyway
  367. if ($literals < 3) {
  368. return;
  369. }
  370. $watchLevel = 0;
  371. foreach ($literals as $literal) {
  372. $level = abs($this->decisionMap[$literal->getPackageId()]);
  373. if ($level > $watchLevel) {
  374. $rule->watch2 = $literal->getId();
  375. $watchLevel = $level;
  376. }
  377. }
  378. }
  379. private function findDecisionRule(PackageInterface $package)
  380. {
  381. foreach ($this->decisionQueue as $i => $literal) {
  382. if ($package === $literal->getPackage()) {
  383. return $this->decisionQueueWhy[$i];
  384. }
  385. }
  386. return null;
  387. }
  388. // aka solver_makeruledecisions
  389. private function makeAssertionRuleDecisions()
  390. {
  391. // do we need to decide a SYSTEMSOLVABLE at level 1?
  392. $decisionStart = count($this->decisionQueue);
  393. for ($ruleIndex = 0; $ruleIndex < count($this->rules); $ruleIndex++) {
  394. $rule = $this->rules->ruleById($ruleIndex);
  395. if ($rule->isWeak() || !$rule->isAssertion() || $rule->isDisabled()) {
  396. continue;
  397. }
  398. $literals = $rule->getLiterals();
  399. $literal = $literals[0];
  400. if (!$this->decided($literal->getPackage())) {
  401. $this->decisionQueue[] = $literal;
  402. $this->decisionQueueWhy[] = $rule;
  403. $this->addDecision($literal, 1);
  404. continue;
  405. }
  406. if ($this->decisionsSatisfy($literal)) {
  407. continue;
  408. }
  409. // found a conflict
  410. if (RuleSet::TYPE_LEARNED === $rule->getType()) {
  411. $rule->disable();
  412. continue;
  413. }
  414. $conflict = $this->findDecisionRule($literal->getPackage());
  415. /** TODO: handle conflict with systemsolvable? */
  416. $this->learnedPool[] = array($rule, $conflict);
  417. if ($conflict && RuleSet::TYPE_PACKAGE === $conflict->getType()) {
  418. if ($rule->getType() == RuleSet::TYPE_JOB) {
  419. $why = $this->ruleToJob[$rule->getId()];
  420. } else {
  421. $why = $rule;
  422. }
  423. $this->problems[] = array($why);
  424. $this->disableProblem($why);
  425. continue;
  426. }
  427. // conflict with another job or update/feature rule
  428. $this->problems[] = array();
  429. // push all of our rules (can only be feature or job rules)
  430. // asserting this literal on the problem stack
  431. foreach ($this->rules->getIteratorFor(array(RuleSet::TYPE_JOB, RuleSet::TYPE_UPDATE, RuleSet::TYPE_FEATURE)) as $assertRule) {
  432. if ($assertRule->isDisabled() || !$assertRule->isAssertion() || $assertRule->isWeak()) {
  433. continue;
  434. }
  435. $assertRuleLiterals = $assertRule->getLiterals();
  436. $assertRuleLiteral = $assertRuleLiterals[0];
  437. if ($literal->getPackageId() !== $assertRuleLiteral->getPackageId()) {
  438. continue;
  439. }
  440. if ($assertRule->getType() === RuleSet::TYPE_JOB) {
  441. $why = $this->ruleToJob[$assertRule->getId()];
  442. } else {
  443. $why = $assertRule;
  444. }
  445. $this->problems[count($this->problems) - 1][] = $why;
  446. $this->disableProblem($why);
  447. }
  448. // start over
  449. while (count($this->decisionQueue) > $decisionStart) {
  450. $decisionLiteral = array_pop($this->decisionQueue);
  451. array_pop($this->decisionQueueWhy);
  452. unset($this->decisionQueueFree[count($this->decisionQueue)]);
  453. $this->decisionMap[$decisionLiteral->getPackageId()] = 0;
  454. }
  455. $ruleIndex = -1;
  456. }
  457. foreach ($this->rules as $rule) {
  458. if (!$rule->isWeak() || !$rule->isAssertion() || $rule->isDisabled()) {
  459. continue;
  460. }
  461. $literals = $rule->getLiterals();
  462. $literal = $literals[0];
  463. if ($this->decisionMap[$literal->getPackageId()] == 0) {
  464. $this->decisionQueue[] = $literal;
  465. $this->decisionQueueWhy[] = $rule;
  466. $this->addDecision($literal, 1);
  467. continue;
  468. }
  469. if ($this->decisionsSatisfy($literals[0])) {
  470. continue;
  471. }
  472. // conflict, but this is a weak rule => disable
  473. if ($rule->getType() == RuleSet::TYPE_JOB) {
  474. $why = $this->ruleToJob[$rule->getId()];
  475. } else {
  476. $why = $rule;
  477. }
  478. $this->disableProblem($why);
  479. /** TODO solver_reenablepolicyrules(solv, -(v + 1)); */
  480. }
  481. }
  482. protected function addChoiceRules()
  483. {
  484. // void
  485. // solver_addchoicerules(Solver *solv)
  486. // {
  487. // Pool *pool = solv->pool;
  488. // Map m, mneg;
  489. // Rule *r;
  490. // Queue q, qi;
  491. // int i, j, rid, havechoice;
  492. // Id p, d, *pp;
  493. // Id p2, pp2;
  494. // Solvable *s, *s2;
  495. //
  496. // solv->choicerules = solv->nrules;
  497. // if (!pool->installed)
  498. // {
  499. // solv->choicerules_end = solv->nrules;
  500. // return;
  501. // }
  502. // solv->choicerules_ref = sat_calloc(solv->rpmrules_end, sizeof(Id));
  503. // queue_init(&q);
  504. // queue_init(&qi);
  505. // map_init(&m, pool->nsolvables);
  506. // map_init(&mneg, pool->nsolvables);
  507. // /* set up negative assertion map from infarch and dup rules */
  508. // for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
  509. // if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
  510. // MAPSET(&mneg, -r->p);
  511. // for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
  512. // if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
  513. // MAPSET(&mneg, -r->p);
  514. // for (rid = 1; rid < solv->rpmrules_end ; rid++)
  515. // {
  516. // r = solv->rules + rid;
  517. // if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
  518. // continue; /* only look at requires rules */
  519. // // solver_printrule(solv, SAT_DEBUG_RESULT, r);
  520. // queue_empty(&q);
  521. // queue_empty(&qi);
  522. // havechoice = 0;
  523. // FOR_RULELITERALS(p, pp, r)
  524. // {
  525. // if (p < 0)
  526. // continue;
  527. // s = pool->solvables + p;
  528. // if (!s->repo)
  529. // continue;
  530. // if (s->repo == pool->installed)
  531. // {
  532. // queue_push(&q, p);
  533. // continue;
  534. // }
  535. // /* check if this package is "blocked" by a installed package */
  536. // s2 = 0;
  537. // FOR_PROVIDES(p2, pp2, s->name)
  538. // {
  539. // s2 = pool->solvables + p2;
  540. // if (s2->repo != pool->installed)
  541. // continue;
  542. // if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
  543. // continue;
  544. // if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
  545. // continue;
  546. // break;
  547. // }
  548. // if (p2)
  549. // {
  550. // /* found installed package p2 that we can update to p */
  551. // if (MAPTST(&mneg, p))
  552. // continue;
  553. // if (policy_is_illegal(solv, s2, s, 0))
  554. // continue;
  555. // queue_push(&qi, p2);
  556. // queue_push(&q, p);
  557. // continue;
  558. // }
  559. // if (s->obsoletes)
  560. // {
  561. // Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
  562. // s2 = 0;
  563. // while ((obs = *obsp++) != 0)
  564. // {
  565. // FOR_PROVIDES(p2, pp2, obs)
  566. // {
  567. // s2 = pool->solvables + p2;
  568. // if (s2->repo != pool->installed)
  569. // continue;
  570. // if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
  571. // continue;
  572. // if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
  573. // continue;
  574. // break;
  575. // }
  576. // if (p2)
  577. // break;
  578. // }
  579. // if (obs)
  580. // {
  581. // /* found installed package p2 that we can update to p */
  582. // if (MAPTST(&mneg, p))
  583. // continue;
  584. // if (policy_is_illegal(solv, s2, s, 0))
  585. // continue;
  586. // queue_push(&qi, p2);
  587. // queue_push(&q, p);
  588. // continue;
  589. // }
  590. // }
  591. // /* package p is independent of the installed ones */
  592. // havechoice = 1;
  593. // }
  594. // if (!havechoice || !q.count)
  595. // continue; /* no choice */
  596. //
  597. // /* now check the update rules of the installed package.
  598. // * if all packages of the update rules are contained in
  599. // * the dependency rules, there's no need to set up the choice rule */
  600. // map_empty(&m);
  601. // FOR_RULELITERALS(p, pp, r)
  602. // if (p > 0)
  603. // MAPSET(&m, p);
  604. // for (i = 0; i < qi.count; i++)
  605. // {
  606. // if (!qi.elements[i])
  607. // continue;
  608. // Rule *ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
  609. // if (!ur->p)
  610. // ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
  611. // if (!ur->p)
  612. // continue;
  613. // FOR_RULELITERALS(p, pp, ur)
  614. // if (!MAPTST(&m, p))
  615. // break;
  616. // if (p)
  617. // break;
  618. // for (j = i + 1; j < qi.count; j++)
  619. // if (qi.elements[i] == qi.elements[j])
  620. // qi.elements[j] = 0;
  621. // }
  622. // if (i == qi.count)
  623. // {
  624. // #if 0
  625. // printf("skipping choice ");
  626. // solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
  627. // #endif
  628. // continue;
  629. // }
  630. // d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
  631. // solver_addrule(solv, r->p, d);
  632. // queue_push(&solv->weakruleq, solv->nrules - 1);
  633. // solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
  634. // #if 0
  635. // printf("OLD ");
  636. // solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
  637. // printf("WEAK CHOICE ");
  638. // solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + solv->nrules - 1);
  639. // #endif
  640. // }
  641. // queue_free(&q);
  642. // queue_free(&qi);
  643. // map_free(&m);
  644. // map_free(&mneg);
  645. // solv->choicerules_end = solv->nrules;
  646. // }
  647. }
  648. /***********************************************************************
  649. ***
  650. *** Policy rule disabling/reenabling
  651. ***
  652. *** Disable all policy rules that conflict with our jobs. If a job
  653. *** gets disabled later on, reenable the involved policy rules again.
  654. ***
  655. *** /
  656. #define DISABLE_UPDATE 1
  657. #define DISABLE_INFARCH 2
  658. #define DISABLE_DUP 3
  659. */
  660. protected function jobToDisableQueue(array $job, array $disableQueue)
  661. {
  662. switch ($job['cmd']) {
  663. case 'install':
  664. foreach ($job['packages'] as $package) {
  665. if (isset($this->installedMap[$package->getId()])) {
  666. $disableQueue[] = array('type' => 'update', 'package' => $package);
  667. }
  668. /* all job packages obsolete * /
  669. qstart = q->count;
  670. pass = 0;
  671. memset(&omap, 0, sizeof(omap));
  672. FOR_JOB_SELECT(p, pp, select, what)
  673. {
  674. Id p2, pp2;
  675. if (pass == 1)
  676. map_grow(&omap, installed->end - installed->start);
  677. s = pool->solvables + p;
  678. if (s->obsoletes)
  679. {
  680. Id obs, *obsp;
  681. obsp = s->repo->idarraydata + s->obsoletes;
  682. while ((obs = *obsp++) != 0)
  683. FOR_PROVIDES(p2, pp2, obs)
  684. {
  685. Solvable *ps = pool->solvables + p2;
  686. if (ps->repo != installed)
  687. continue;
  688. if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
  689. continue;
  690. if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
  691. continue;
  692. if (pass)
  693. MAPSET(&omap, p2 - installed->start);
  694. else
  695. queue_push2(q, DISABLE_UPDATE, p2);
  696. }
  697. }
  698. FOR_PROVIDES(p2, pp2, s->name)
  699. {
  700. Solvable *ps = pool->solvables + p2;
  701. if (ps->repo != installed)
  702. continue;
  703. if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
  704. continue;
  705. if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
  706. continue;
  707. if (pass)
  708. MAPSET(&omap, p2 - installed->start);
  709. else
  710. queue_push2(q, DISABLE_UPDATE, p2);
  711. }
  712. if (pass)
  713. {
  714. for (i = j = qstart; i < q->count; i += 2)
  715. {
  716. if (MAPTST(&omap, q->elements[i + 1] - installed->start))
  717. {
  718. MAPCLR(&omap, q->elements[i + 1] - installed->start);
  719. q->elements[j + 1] = q->elements[i + 1];
  720. j += 2;
  721. }
  722. }
  723. queue_truncate(q, j);
  724. }
  725. if (q->count == qstart)
  726. break;
  727. pass++;
  728. }
  729. if (omap.size)
  730. map_free(&omap);
  731. if (qstart == q->count)
  732. return; /* nothing to prune * /
  733. if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
  734. return; /* all is set */
  735. /* now that we know which installed packages are obsoleted check each of them * /
  736. for (i = j = qstart; i < q->count; i += 2)
  737. {
  738. Solvable *is = pool->solvables + q->elements[i + 1];
  739. FOR_JOB_SELECT(p, pp, select, what)
  740. {
  741. int illegal = 0;
  742. s = pool->solvables + p;
  743. if ((set & SOLVER_SETEVR) != 0)
  744. illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore * /
  745. if ((set & SOLVER_SETARCH) != 0)
  746. illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore * /
  747. if ((set & SOLVER_SETVENDOR) != 0)
  748. illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore * /
  749. illegal = policy_is_illegal(solv, is, s, illegal);
  750. if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
  751. {
  752. /* it's ok if the EV is different * /
  753. if (evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
  754. illegal = 0;
  755. }
  756. if (illegal)
  757. break;
  758. }
  759. if (!p)
  760. {
  761. /* no package conflicts with the update rule * /
  762. /* thus keep the DISABLE_UPDATE * /
  763. q->elements[j + 1] = q->elements[i + 1];
  764. j += 2;
  765. }
  766. }
  767. queue_truncate(q, j);
  768. return;*/
  769. }
  770. break;
  771. case 'remove':
  772. foreach ($job['packages'] as $package) {
  773. if (isset($this->installedMap[$package->getId()])) {
  774. $disableQueue[] = array('type' => 'update', 'package' => $package);
  775. }
  776. }
  777. break;
  778. }
  779. return $disableQueue;
  780. }
  781. protected function disableUpdateRule($package)
  782. {
  783. // find update & feature rule and disable
  784. if (isset($this->packageToUpdateRule[$package->getId()])) {
  785. $this->packageToUpdateRule[$package->getId()]->disable();
  786. }
  787. if (isset($this->packageToFeatureRule[$package->getId()])) {
  788. $this->packageToFeatureRule[$package->getId()]->disable();
  789. }
  790. }
  791. /**
  792. * Disables all policy rules that conflict with jobs
  793. */
  794. protected function disablePolicyRules()
  795. {
  796. $lastJob = null;
  797. $allQueue = array();
  798. $iterator = $this->rules->getIteratorFor(RuleSet::TYPE_JOB);
  799. foreach ($iterator as $rule) {
  800. if ($rule->isDisabled()) {
  801. continue;
  802. }
  803. $job = $this->ruleToJob[$rule->getId()];
  804. if ($job === $lastJob) {
  805. continue;
  806. }
  807. $lastJob = $job;
  808. $allQueue = $this->jobToDisableQueue($job, $allQueue);
  809. }
  810. foreach ($allQueue as $disable) {
  811. switch ($disable['type']) {
  812. case 'update':
  813. $this->disableUpdateRule($disable['package']);
  814. break;
  815. default:
  816. throw new \RuntimeException("Unsupported disable type: " . $disable['type']);
  817. }
  818. }
  819. }
  820. public function solve(Request $request)
  821. {
  822. $this->jobs = $request->getJobs();
  823. $installedPackages = $this->installed->getPackages();
  824. $this->installedMap = array();
  825. foreach ($installedPackages as $package) {
  826. $this->installedMap[$package->getId()] = $package;
  827. }
  828. if (version_compare(PHP_VERSION, '5.3.3', '>')) {
  829. $this->decisionMap = new \SplFixedArray($this->pool->getMaxId() + 1);
  830. } else {
  831. $this->decisionMap = array_fill(0, $this->pool->getMaxId() + 1, 0);
  832. }
  833. foreach ($this->jobs as $job) {
  834. foreach ($job['packages'] as $package) {
  835. switch ($job['cmd']) {
  836. case 'fix':
  837. if (isset($this->installedMap[$package->getId()])) {
  838. $this->fixMap[$package->getId()] = true;
  839. }
  840. break;
  841. case 'update':
  842. if (isset($this->installedMap[$package->getId()])) {
  843. $this->updateMap[$package->getId()] = true;
  844. }
  845. break;
  846. }
  847. }
  848. }
  849. foreach ($installedPackages as $package) {
  850. $this->addRulesForPackage($package);
  851. }
  852. foreach ($installedPackages as $package) {
  853. $this->addRulesForUpdatePackages($package);
  854. }
  855. foreach ($this->jobs as $job) {
  856. foreach ($job['packages'] as $package) {
  857. switch ($job['cmd']) {
  858. case 'install':
  859. $this->installCandidateMap[$package->getId()] = true;
  860. $this->addRulesForPackage($package);
  861. break;
  862. }
  863. }
  864. }
  865. // solver_addrpmrulesforweak(solv, &addedmap);
  866. foreach ($installedPackages as $package) {
  867. $updates = $this->policy->findUpdatePackages($this, $this->pool, $this->installedMap, $package);
  868. $rule = $this->createUpdateRule($package, $updates, self::RULE_INTERNAL_ALLOW_UPDATE, (string) $package);
  869. if ($this->policy->allowUninstall()) {
  870. $rule->setWeak(true);
  871. $this->addRule(RuleSet::TYPE_FEATURE, $featureRule);
  872. $this->packageToFeatureRule[$package->getId()] = $rule;
  873. } else {
  874. $this->addRule(RuleSet::TYPE_UPDATE, $rule);
  875. $this->packageToUpdateRule[$package->getId()] = $rule;
  876. }
  877. }
  878. foreach ($this->jobs as $job) {
  879. switch ($job['cmd']) {
  880. case 'install':
  881. $rule = $this->createInstallOneOfRule($job['packages'], self::RULE_JOB_INSTALL, $job['packageName']);
  882. $this->addRule(RuleSet::TYPE_JOB, $rule);
  883. $this->ruleToJob[$rule->getId()] = $job;
  884. break;
  885. case 'remove':
  886. // remove all packages with this name including uninstalled
  887. // ones to make sure none of them are picked as replacements
  888. // todo: cleandeps
  889. foreach ($job['packages'] as $package) {
  890. $rule = $this->createRemoveRule($package, self::RULE_JOB_REMOVE);
  891. $this->addRule(RuleSet::TYPE_JOB, $rule);
  892. $this->ruleToJob[$rule->getId()] = $job;
  893. }
  894. break;
  895. case 'lock':
  896. foreach ($job['packages'] as $package) {
  897. if (isset($this->installedMap[$package->getId()])) {
  898. $rule = $this->createInstallRule($package, self::RULE_JOB_LOCK);
  899. } else {
  900. $rule = $this->createRemoveRule($package, self::RULE_JOB_LOCK);
  901. }
  902. $this->addRule(RuleSet::TYPE_JOB, $rule);
  903. $this->ruleToJob[$rule->getId()] = $job;
  904. }
  905. break;
  906. }
  907. }
  908. $this->addChoiceRules();
  909. foreach ($this->rules as $rule) {
  910. $this->addWatchesToRule($rule);
  911. }
  912. /* disable update rules that conflict with our job */
  913. $this->disablePolicyRules();
  914. /* make decisions based on job/update assertions */
  915. $this->makeAssertionRuleDecisions();
  916. $installRecommended = 0;
  917. $this->runSat(true, $installRecommended);
  918. //$this->printDecisionMap();
  919. //findrecommendedsuggested(solv);
  920. //solver_prepare_solutions(solv);
  921. return $this->createTransaction();
  922. }
  923. protected function createTransaction()
  924. {
  925. $transaction = array();
  926. $installMeansUpdateMap = array();
  927. foreach ($this->decisionQueue as $i => $literal) {
  928. $package = $literal->getPackage();
  929. // !wanted & installed
  930. if (!$literal->isWanted() && isset($this->installedMap[$package->getId()])) {
  931. $literals = array();
  932. if (isset($this->packageToUpdateRule[$package->getId()])) {
  933. $literals = array_merge($literals, $this->packageToUpdateRule[$package->getId()]->getLiterals());
  934. }
  935. if (isset($this->packageToFeatureRule[$package->getId()])) {
  936. $literals = array_merge($literals, $this->packageToFeatureRule[$package->getId()]->getLiterals());
  937. }
  938. foreach ($literals as $updateLiteral) {
  939. if (!$updateLiteral->equals($literal)) {
  940. $installMeansUpdateMap[$updateLiteral->getPackageId()] = $package;
  941. }
  942. }
  943. }
  944. }
  945. foreach ($this->decisionQueue as $i => $literal) {
  946. $package = $literal->getPackage();
  947. // wanted & installed || !wanted & !installed
  948. if ($literal->isWanted() == (isset($this->installedMap[$package->getId()]))) {
  949. continue;
  950. }
  951. if ($literal->isWanted()) {
  952. if (isset($installMeansUpdateMap[$literal->getPackageId()])) {
  953. $source = $installMeansUpdateMap[$literal->getPackageId()];
  954. $transaction[] = new Operation\UpdateOperation(
  955. $source, $package, $this->decisionQueueWhy[$i]
  956. );
  957. // avoid updates to one package from multiple origins
  958. unset($installMeansUpdateMap[$literal->getPackageId()]);
  959. $ignoreRemove[$source->getId()] = true;
  960. } else {
  961. $transaction[] = new Operation\InstallOperation(
  962. $package, $this->decisionQueueWhy[$i]
  963. );
  964. }
  965. } else if (!isset($ignoreRemove[$package->getId()])) {
  966. $transaction[] = new Operation\UninstallOperation(
  967. $package, $this->decisionQueueWhy[$i]
  968. );
  969. }
  970. }
  971. return array_reverse($transaction);
  972. }
  973. protected $decisionQueue = array();
  974. protected $decisionQueueWhy = array();
  975. protected $decisionQueueFree = array();
  976. protected $propagateIndex;
  977. protected $branches = array();
  978. protected $problems = array();
  979. protected $learnedPool = array();
  980. protected $recommendsIndex;
  981. protected function literalFromId($id)
  982. {
  983. $package = $this->pool->packageById(abs($id));
  984. return new Literal($package, $id > 0);
  985. }
  986. protected function addDecision(Literal $l, $level)
  987. {
  988. if ($l->isWanted()) {
  989. $this->decisionMap[$l->getPackageId()] = $level;
  990. } else {
  991. $this->decisionMap[$l->getPackageId()] = -$level;
  992. }
  993. }
  994. protected function addDecisionId($literalId, $level)
  995. {
  996. $packageId = abs($literalId);
  997. if ($literalId > 0) {
  998. $this->decisionMap[$packageId] = $level;
  999. } else {
  1000. $this->decisionMap[$packageId] = -$level;
  1001. }
  1002. }
  1003. protected function decisionsContain(Literal $l)
  1004. {
  1005. return (
  1006. $this->decisionMap[$l->getPackageId()] > 0 && $l->isWanted() ||
  1007. $this->decisionMap[$l->getPackageId()] < 0 && !$l->isWanted()
  1008. );
  1009. }
  1010. protected function decisionsContainId($literalId)
  1011. {
  1012. $packageId = abs($literalId);
  1013. return (
  1014. $this->decisionMap[$packageId] > 0 && $literalId > 0 ||
  1015. $this->decisionMap[$packageId] < 0 && $literalId < 0
  1016. );
  1017. }
  1018. protected function decisionsSatisfy(Literal $l)
  1019. {
  1020. return ($l->isWanted() && $this->decisionMap[$l->getPackageId()] > 0) ||
  1021. (!$l->isWanted() && $this->decisionMap[$l->getPackageId()] <= 0);
  1022. }
  1023. protected function decisionsConflict(Literal $l)
  1024. {
  1025. return (
  1026. $this->decisionMap[$l->getPackageId()] > 0 && !$l->isWanted() ||
  1027. $this->decisionMap[$l->getPackageId()] < 0 && $l->isWanted()
  1028. );
  1029. }
  1030. protected function decisionsConflictId($literalId)
  1031. {
  1032. $packageId = abs($literalId);
  1033. return (
  1034. $this->decisionMap[$packageId] > 0 && !($literalId < 0) ||
  1035. $this->decisionMap[$packageId] < 0 && $literalId > 0
  1036. );
  1037. }
  1038. protected function decided(PackageInterface $p)
  1039. {
  1040. return $this->decisionMap[$p->getId()] != 0;
  1041. }
  1042. protected function undecided(PackageInterface $p)
  1043. {
  1044. return $this->decisionMap[$p->getId()] == 0;
  1045. }
  1046. protected function decidedInstall(PackageInterface $p) {
  1047. return $this->decisionMap[$p->getId()] > 0;
  1048. }
  1049. protected function decidedRemove(PackageInterface $p) {
  1050. return $this->decisionMap[$p->getId()] < 0;
  1051. }
  1052. /**
  1053. * Makes a decision and propagates it to all rules.
  1054. *
  1055. * Evaluates each term affected by the decision (linked through watches)
  1056. * If we find unit rules we make new decisions based on them
  1057. *
  1058. * @return Rule|null A rule on conflict, otherwise null.
  1059. */
  1060. protected function propagate($level)
  1061. {
  1062. while ($this->propagateIndex < count($this->decisionQueue)) {
  1063. // we invert the decided literal here, example:
  1064. // A was decided => (-A|B) now requires B to be true, so we look for
  1065. // rules which are fulfilled by -A, rather than A.
  1066. $literal = $this->decisionQueue[$this->propagateIndex]->inverted();
  1067. $this->propagateIndex++;
  1068. // /* foreach rule where 'pkg' is now FALSE */
  1069. //for (rp = watches + pkg; *rp; rp = next_rp)
  1070. if (!isset($this->watches[$literal->getId()])) {
  1071. continue;
  1072. }
  1073. for ($rule = $this->watches[$literal->getId()]; $rule !== null; $rule = $nextRule) {
  1074. $nextRule = $rule->getNext($literal);
  1075. if ($rule->isDisabled()) {
  1076. continue;
  1077. }
  1078. $otherWatch = $rule->getOtherWatch($literal);
  1079. if ($this->decisionsContainId($otherWatch)) {
  1080. continue;
  1081. }
  1082. $ruleLiterals = $rule->getLiterals();
  1083. if (sizeof($ruleLiterals) > 2) {
  1084. foreach ($ruleLiterals as $ruleLiteral) {
  1085. if ($otherWatch !== $ruleLiteral->getId() &&
  1086. !$this->decisionsConflict($ruleLiteral)) {
  1087. if ($literal->getId() === $rule->watch1) {
  1088. $rule->watch1 = $ruleLiteral->getId();
  1089. $rule->next1 = (isset($this->watches[$ruleLiteral->getId()])) ? $this->watches[$ruleLiteral->getId()] : null ;
  1090. } else {
  1091. $rule->watch2 = $ruleLiteral->getId();
  1092. $rule->next2 = (isset($this->watches[$ruleLiteral->getId()])) ? $this->watches[$ruleLiteral->getId()] : null ;
  1093. }
  1094. $this->watches[$ruleLiteral->getId()] = $rule;
  1095. continue 2;
  1096. }
  1097. }
  1098. }
  1099. // yay, we found a unit clause! try setting it to true
  1100. if ($this->decisionsConflictId($otherWatch)) {
  1101. return $rule;
  1102. }
  1103. $this->addDecisionId($otherWatch, $level);
  1104. $this->decisionQueue[] = $this->literalFromId($otherWatch);
  1105. $this->decisionQueueWhy[] = $rule;
  1106. }
  1107. }
  1108. return null;
  1109. }
  1110. /**
  1111. * Reverts a decision at the given level.
  1112. */
  1113. private function revert($level)
  1114. {
  1115. while (!empty($this->decisionQueue)) {
  1116. $literal = $this->decisionQueue[count($this->decisionQueue) - 1];
  1117. if (!$this->decisionMap[$literal->getPackageId()]) {
  1118. break;
  1119. }
  1120. $decisionLevel = abs($this->decisionMap[$literal->getPackageId()]);
  1121. if ($decisionLevel <= $level) {
  1122. break;
  1123. }
  1124. /** TODO: implement recommendations
  1125. *if (v > 0 && solv->recommendations.count && v == solv->recommendations.elements[solv->recommendations.count - 1])
  1126. * solv->recommendations.count--;
  1127. */
  1128. $this->decisionMap[$literal->getPackageId()] = 0;
  1129. array_pop($this->decisionQueue);
  1130. array_pop($this->decisionQueueWhy);
  1131. $this->propagateIndex = count($this->decisionQueue);
  1132. }
  1133. while (!empty($this->branches)) {
  1134. list($literals, $branchLevel) = $this->branches[count($this->branches) - 1];
  1135. if ($branchLevel >= $level) {
  1136. break;
  1137. }
  1138. array_pop($this->branches);
  1139. }
  1140. $this->recommendsIndex = -1;
  1141. }
  1142. /**-------------------------------------------------------------------
  1143. *
  1144. * setpropagatelearn
  1145. *
  1146. * add free decision (solvable to install) to decisionq
  1147. * increase level and propagate decision
  1148. * return if no conflict.
  1149. *
  1150. * in conflict case, analyze conflict rule, add resulting
  1151. * rule to learnt rule set, make decision from learnt
  1152. * rule (always unit) and re-propagate.
  1153. *
  1154. * returns the new solver level or 0 if unsolvable
  1155. *
  1156. */
  1157. private function setPropagateLearn($level, Literal $literal, $disableRules, Rule $rule)
  1158. {
  1159. assert($rule != null);
  1160. assert($literal != null);
  1161. $level++;
  1162. $this->addDecision($literal, $level);
  1163. $this->decisionQueue[] = $literal;
  1164. $this->decisionQueueWhy[] = $rule;
  1165. $this->decisionQueueFree[count($this->decisionQueueWhy) - 1] = true;
  1166. while (true) {
  1167. $rule = $this->propagate($level);
  1168. if (!$rule) {
  1169. break;
  1170. }
  1171. if ($level == 1) {
  1172. return $this->analyzeUnsolvable($rule, $disableRules);
  1173. }
  1174. // conflict
  1175. list($newLevel, $newRule, $why) = $this->analyze($level, $rule);
  1176. assert($newLevel > 0);
  1177. assert($newLevel < $level);
  1178. $level = $newLevel;
  1179. $this->revert($level);
  1180. assert($newRule != null);
  1181. $this->addRule(RuleSet::TYPE_LEARNED, $newRule);
  1182. $this->learnedWhy[$newRule->getId()] = $why;
  1183. $this->watch2OnHighest($newRule);
  1184. $this->addWatchesToRule($newRule);
  1185. $literals = $newRule->getLiterals();
  1186. $this->addDecision($literals[0], $level);
  1187. $this->decisionQueue[] = $literals[0];
  1188. $this->decisionQueueWhy[] = $newRule;
  1189. }
  1190. return $level;
  1191. }
  1192. private function selectAndInstall($level, array $decisionQueue, $disableRules, Rule $rule)
  1193. {
  1194. // choose best package to install from decisionQueue
  1195. $literals = $this->policy->selectPreferedPackages($this->pool, $this->installedMap, $decisionQueue);
  1196. $selectedLiteral = array_shift($literals);
  1197. // if there are multiple candidates, then branch
  1198. if (count($literals)) {
  1199. $this->branches[] = array($literals, -$level);
  1200. }
  1201. return $this->setPropagateLearn($level, $selectedLiteral, $disableRules, $rule);
  1202. }
  1203. protected function analyze($level, $rule)
  1204. {
  1205. $ruleLevel = 1;
  1206. $num = 0;
  1207. $l1num = 0;
  1208. $seen = array();
  1209. $learnedLiterals = array(null);
  1210. $decisionId = count($this->decisionQueue);
  1211. $this->learnedPool[] = array();
  1212. while(true) {
  1213. $this->learnedPool[count($this->learnedPool) - 1][] = $rule;
  1214. foreach ($rule->getLiterals() as $literal) {
  1215. // skip the one true literal
  1216. if ($this->decisionsSatisfy($literal)) {
  1217. continue;
  1218. }
  1219. if (isset($seen[$literal->getPackageId()])) {
  1220. continue;
  1221. }
  1222. $seen[$literal->getPackageId()] = true;
  1223. $l = abs($this->decisionMap[$literal->getPackageId()]);
  1224. if (1 === $l) {
  1225. $l1num++;
  1226. } else if ($level === $l) {
  1227. $num++;
  1228. } else {
  1229. // not level1 or conflict level, add to new rule
  1230. $learnedLiterals[] = $literal;
  1231. if ($l > $ruleLevel) {
  1232. $ruleLevel = $l;
  1233. }
  1234. }
  1235. }
  1236. $l1retry = true;
  1237. while ($l1retry) {
  1238. $l1retry = false;
  1239. if (!$num && !--$l1num) {
  1240. // all level 1 literals done
  1241. break 2;
  1242. }
  1243. while (true) {
  1244. assert($decisionId > 0);
  1245. $decisionId--;
  1246. $literal = $this->decisionQueue[$decisionId];
  1247. if (isset($seen[$literal->getPackageId()])) {
  1248. break;
  1249. }
  1250. }
  1251. unset($seen[$literal->getPackageId()]);
  1252. if ($num && 0 === --$num) {
  1253. $learnedLiterals[0] = $this->literalFromId(-$literal->getPackageId());
  1254. if (!$l1num) {
  1255. break 2;
  1256. }
  1257. foreach ($learnedLiterals as $i => $learnedLiteral) {
  1258. if ($i !== 0) {
  1259. unset($seen[$literal->getPackageId()]);
  1260. }
  1261. }
  1262. // only level 1 marks left
  1263. $l1num++;
  1264. $l1retry = true;
  1265. }
  1266. $rule = $this->decisionQueueWhy[$decisionId];
  1267. }
  1268. }
  1269. $why = count($this->learnedPool) - 1;
  1270. $newRule = new Rule($learnedLiterals, self::RULE_LEARNED, $why);
  1271. return array($ruleLevel, $newRule, $why);
  1272. }
  1273. private function analyzeUnsolvableRule($conflictRule, &$lastWeakWhy)
  1274. {
  1275. $why = $conflictRule->getId();
  1276. if ($conflictRule->getType() == RuleSet::TYPE_LEARNED) {
  1277. $learnedWhy = $this->learnedWhy[$why];
  1278. $problem = $this->learnedPool[$learnedWhy];
  1279. foreach ($problem as $problemRule) {
  1280. $this->analyzeUnsolvableRule($problemRule, $lastWeakWhy);
  1281. }
  1282. return;
  1283. }
  1284. if ($conflictRule->getType() == RuleSet::TYPE_PACKAGE) {
  1285. // package rules cannot be part of a problem
  1286. return;
  1287. }
  1288. if ($conflictRule->isWeak()) {
  1289. /** TODO why > or < lastWeakWhy? */
  1290. if (!$lastWeakWhy || $why > $lastWeakWhy->getId()) {
  1291. $lastWeakWhy = $conflictRule;
  1292. }
  1293. }
  1294. if ($conflictRule->getType() == RuleSet::TYPE_JOB) {
  1295. $why = $this->ruleToJob[$conflictRule->getId()];
  1296. }
  1297. // if this problem was already found skip it
  1298. if (in_array($why, $this->problems[count($this->problems) - 1], true)) {
  1299. return;
  1300. }
  1301. $this->problems[count($this->problems) - 1][] = $why;
  1302. }
  1303. private function analyzeUnsolvable($conflictRule, $disableRules)
  1304. {
  1305. $lastWeakWhy = null;
  1306. $this->problems[] = array();
  1307. $this->learnedPool[] = array($conflictRule);
  1308. $this->analyzeUnsolvableRule($conflictRule, $lastWeakWhy);
  1309. $seen = array();
  1310. $literals = $conflictRule->getLiterals();
  1311. /* unnecessary because unlike rule.d, watch2 == 2nd literal, unless watch2 changed
  1312. if (sizeof($literals) == 2) {
  1313. $literals[1] = $this->literalFromId($conflictRule->watch2);
  1314. }
  1315. */
  1316. foreach ($literals as $literal) {
  1317. // skip the one true literal
  1318. if ($this->decisionsSatisfy($literal)) {
  1319. continue;
  1320. }
  1321. $seen[$literal->getPackageId()] = true;
  1322. }
  1323. $decisionId = count($this->decisionQueue);
  1324. while ($decisionId > 0) {
  1325. $decisionId--;
  1326. $literal = $this->decisionQueue[$decisionId];
  1327. // skip literals that are not in this rule
  1328. if (!isset($seen[$literal->getPackageId()])) {
  1329. continue;
  1330. }
  1331. $why = $this->decisionQueueWhy[$decisionId];
  1332. $this->learnedPool[count($this->learnedPool) - 1][] = $why;
  1333. $this->analyzeUnsolvableRule($why, $lastWeakWhy);
  1334. $literals = $why->getLiterals();
  1335. /* unnecessary because unlike rule.d, watch2 == 2nd literal, unless watch2 changed
  1336. if (sizeof($literals) == 2) {
  1337. $literals[1] = $this->literalFromId($why->watch2);
  1338. }
  1339. */
  1340. foreach ($literals as $literal) {
  1341. // skip the one true literal
  1342. if ($this->decisionsSatisfy($literal)) {
  1343. continue;
  1344. }
  1345. $seen[$literal->getPackageId()] = true;
  1346. }
  1347. }
  1348. if ($lastWeakWhy) {
  1349. array_pop($this->problems);
  1350. array_pop($this->learnedPool);
  1351. if ($lastWeakWhy->getType() === RuleSet::TYPE_JOB) {
  1352. $why = $this->ruleToJob[$lastWeakWhy];
  1353. } else {
  1354. $why = $lastWeakWhy;
  1355. }
  1356. if ($lastWeakWhy->getType() == RuleSet::TYPE_CHOICE) {
  1357. $this->disableChoiceRules($lastWeakWhy);
  1358. }
  1359. $this->disableProblem($why);
  1360. /**
  1361. @TODO what does v < 0 mean here? ($why == v)
  1362. if (v < 0)
  1363. solver_reenablepolicyrules(solv, -(v + 1));
  1364. */
  1365. $this->resetSolver();
  1366. return true;
  1367. }
  1368. if ($disableRules) {
  1369. foreach ($this->problems[count($this->problems) - 1] as $why) {
  1370. $this->disableProblem($why);
  1371. }
  1372. $this->resetSolver();
  1373. return true;
  1374. }
  1375. return false;
  1376. }
  1377. private function disableProblem($why)
  1378. {
  1379. if ($why instanceof Rule) {
  1380. $why->disable();
  1381. } else if (is_array($why)) {
  1382. // disable all rules of this job
  1383. foreach ($this->ruleToJob as $ruleId => $job) {
  1384. if ($why === $job) {
  1385. $this->rules->ruleById($ruleId)->disable();
  1386. }
  1387. }
  1388. }
  1389. }
  1390. private function resetSolver()
  1391. {
  1392. while ($literal = array_pop($this->decisionQueue)) {
  1393. $this->decisionMap[$literal->getPackageId()] = 0;
  1394. }
  1395. $this->decisionQueueWhy = array();
  1396. $this->decisionQueueFree = array();
  1397. $this->recommendsIndex = -1;
  1398. $this->propagateIndex = 0;
  1399. $this->recommendations = array();
  1400. $this->branches = array();
  1401. $this->enableDisableLearnedRules();
  1402. $this->makeAssertionRuleDecisions();
  1403. }
  1404. /*-------------------------------------------------------------------
  1405. * enable/disable learnt rules
  1406. *
  1407. * we have enabled or disabled some of our rules. We now reenable all
  1408. * of our learnt rules except the ones that were learnt from rules that
  1409. * are now disabled.
  1410. */
  1411. private function enableDisableLearnedRules()
  1412. {
  1413. foreach ($this->rules->getIteratorFor(RuleSet::TYPE_LEARNED) as $rule) {
  1414. $why = $this->learnedWhy[$rule->getId()];
  1415. $problem = $this->learnedPool[$why];
  1416. $foundDisabled = false;
  1417. foreach ($problem as $problemRule) {
  1418. if ($problemRule->disabled()) {
  1419. $foundDisabled = true;
  1420. break;
  1421. }
  1422. }
  1423. if ($foundDisabled && $rule->isEnabled()) {
  1424. $rule->disable();
  1425. } else if (!$foundDisabled && $rule->isDisabled()) {
  1426. $rule->enable();
  1427. }
  1428. }
  1429. }
  1430. private function runSat($disableRules = true, $installRecommended = false)
  1431. {
  1432. $this->propagateIndex = 0;
  1433. // /*
  1434. // * here's the main loop:
  1435. // * 1) propagate new decisions (only needed once)
  1436. // * 2) fulfill jobs
  1437. // * 3) try to keep installed packages
  1438. // * 4) fulfill all unresolved rules
  1439. // * 5) install recommended packages
  1440. // * 6) minimalize solution if we had choices
  1441. // * if we encounter a problem, we rewind to a safe level and restart
  1442. // * with step 1
  1443. // */
  1444. $decisionQueue = array();
  1445. $decisionSupplementQueue = array();
  1446. $disableRules = array();
  1447. $level = 1;
  1448. $systemLevel = $level + 1;
  1449. $minimizationSteps = 0;
  1450. $installedPos = 0;
  1451. $this->installedPackages = $this->installed->getPackages();
  1452. while (true) {
  1453. if (1 === $level) {
  1454. $conflictRule = $this->propagate($level);
  1455. if ($conflictRule !== null) {
  1456. if ($this->analyzeUnsolvable($conflictRule, $disableRules)) {
  1457. continue;
  1458. } else {
  1459. return;
  1460. }
  1461. }
  1462. }
  1463. // handle job rules
  1464. if ($level < $systemLevel) {
  1465. $iterator = $this->rules->getIteratorFor(RuleSet::TYPE_JOB);
  1466. foreach ($iterator as $rule) {
  1467. if ($rule->isEnabled()) {
  1468. $decisionQueue = array();
  1469. $noneSatisfied = true;
  1470. foreach ($rule->getLiterals() as $literal) {
  1471. if ($this->decisionsSatisfy($literal)) {
  1472. $noneSatisfied = false;
  1473. break;
  1474. }
  1475. $decisionQueue[] = $literal;
  1476. }
  1477. if ($noneSatisfied && count($decisionQueue)) {
  1478. // prune all update packages until installed version
  1479. // except for requested updates
  1480. if (count($this->installed) != count($this->updateMap)) {
  1481. $prunedQueue = array();
  1482. foreach ($decisionQueue as $literal) {
  1483. if (isset($this->installedMap[$literal->getPackageId()])) {
  1484. $prunedQueue[] = $literal;
  1485. if (isset($this->updateMap[$literal->getPackageId()])) {
  1486. $prunedQueue = $decisionQueue;
  1487. break;
  1488. }
  1489. }
  1490. }
  1491. $decisionQueue = $prunedQueue;
  1492. }
  1493. }
  1494. if ($noneSatisfied && count($decisionQueue)) {
  1495. $oLevel = $level;
  1496. $level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule);
  1497. if (0 === $level) {
  1498. return;
  1499. }
  1500. if ($level <= $oLevel) {
  1501. break;
  1502. }
  1503. }
  1504. }
  1505. }
  1506. $systemLevel = $level + 1;
  1507. // jobs left
  1508. $iterator->next();
  1509. if ($iterator->valid()) {
  1510. continue;
  1511. }
  1512. }
  1513. // handle installed packages
  1514. if ($level < $systemLevel) {
  1515. // use two passes if any packages are being updated
  1516. // -> better user experience
  1517. for ($pass = (count($this->updateMap)) ? 0 : 1; $pass < 2; $pass++) {
  1518. $passLevel = $level;
  1519. for ($i = $installedPos, $n = 0; $n < count($this->installedPackages); $i++, $n++) {
  1520. $repeat = false;
  1521. if ($i == count($this->installedPackages)) {
  1522. $i = 0;
  1523. }
  1524. $literal = new Literal($this->installedPackages[$i], true);
  1525. if ($this->decisionsContain($literal)) {
  1526. continue;
  1527. }
  1528. // only process updates in first pass
  1529. /** TODO: && or || ? **/
  1530. if (0 === $pass && !isset($this->updateMap[$literal->getPackageId()])) {
  1531. continue;
  1532. }
  1533. $rule = null;
  1534. if (isset($this->packageToUpdateRule[$literal->getPackageId()])) {
  1535. $rule = $this->packageToUpdateRule[$literal->getPackageId()];
  1536. }
  1537. if ((!$rule || $rule->isDisabled()) && isset($this->packageToFeatureRule[$literal->getPackageId()])) {
  1538. $rule = $this->packageToFeatureRule[$literal->getPackageId()];
  1539. }
  1540. if (!$rule || $rule->isDisabled()) {
  1541. continue;
  1542. }
  1543. $updateRuleLiterals = $rule->getLiterals();
  1544. $decisionQueue = array();
  1545. if (!isset($this->noUpdate[$literal->getPackageId()]) && (
  1546. $this->decidedRemove($literal->getPackage()) ||
  1547. isset($this->updateMap[$literal->getPackageId()]) ||
  1548. !$literal->equals($updateRuleLiterals[0])
  1549. )) {
  1550. foreach ($updateRuleLiterals as $ruleLiteral) {
  1551. if ($this->decidedInstall($ruleLiteral->getPackage())) {
  1552. // already fulfilled
  1553. $decisionQueue = array();
  1554. break;
  1555. }
  1556. if ($this->undecided($ruleLiteral->getPackage())) {
  1557. $decisionQueue[] = $ruleLiteral;
  1558. }
  1559. }
  1560. }
  1561. if (sizeof($decisionQueue)) {
  1562. $oLevel = $level;
  1563. $level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule);
  1564. if (0 === $level) {
  1565. return;
  1566. }
  1567. if ($level <= $oLevel) {
  1568. $repeat = true;
  1569. }
  1570. } else if (!$repeat && $this->undecided($literal->getPackage())) {
  1571. // still undecided? keep package.
  1572. $oLevel = $level;
  1573. if (isset($this->cleanDepsMap[$literal->getPackageId()])) {
  1574. // clean deps removes package
  1575. $level = $this->setPropagateLearn($level, $literal->invert(), $disableRules, null);
  1576. } else {
  1577. // ckeeping package
  1578. $level = $this->setPropagateLearn($level, $literal, $disableRules, $rule);
  1579. }
  1580. if (0 === $level) {
  1581. return;
  1582. }
  1583. if ($level <= $oLevel) {
  1584. $repeat = true;
  1585. }
  1586. }
  1587. if ($repeat) {
  1588. if (1 === $level || $level < $passLevel) {
  1589. // trouble
  1590. break;
  1591. }
  1592. if ($level < $oLevel) {
  1593. // redo all
  1594. $n = 0;
  1595. }
  1596. // repeat
  1597. $i--;
  1598. $n--;
  1599. continue;
  1600. }
  1601. }
  1602. if ($n < count($this->installedPackages)) {
  1603. $installedPos = $i; // retry this problem next time
  1604. break;
  1605. }
  1606. $installedPos = 0;
  1607. }
  1608. $systemLevel = $level + 1;
  1609. if ($pass < 2) {
  1610. // had trouble => retry
  1611. continue;
  1612. }
  1613. }
  1614. if ($level < $systemLevel) {
  1615. $systemLevel = $level;
  1616. }
  1617. for ($i = 0, $n = 0; $n < count($this->rules); $i++, $n++) {
  1618. if ($i == count($this->rules)) {
  1619. $i = 0;
  1620. }
  1621. $rule = $this->rules->ruleById($i);
  1622. $literals = $rule->getLiterals();
  1623. if ($rule->isDisabled()) {
  1624. continue;
  1625. }
  1626. $decisionQueue = array();
  1627. // make sure that
  1628. // * all negative literals are installed
  1629. // * no positive literal is installed
  1630. // i.e. the rule is not fulfilled and we
  1631. // just need to decide on the positive literals
  1632. //
  1633. foreach ($literals as $literal) {
  1634. if (!$literal->isWanted()) {
  1635. if (!$this->decidedInstall($literal->getPackage())) {
  1636. continue 2; // next rule
  1637. }
  1638. } else {
  1639. if ($this->decidedInstall($literal->getPackage())) {
  1640. continue 2; // next rule
  1641. }
  1642. if ($this->undecided($literal->getPackage())) {
  1643. $decisionQueue[] = $literal;
  1644. }
  1645. }
  1646. }
  1647. // need to have at least 2 item to pick from
  1648. if (count($decisionQueue) < 2) {
  1649. continue;
  1650. }
  1651. $oLevel = $level;
  1652. $level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule);
  1653. if (0 === $level) {
  1654. return;
  1655. }
  1656. // open suse sat-solver uses this, but why is $level == 1 trouble?
  1657. // SYSTEMSOLVABLE related? we don't have that, so should work
  1658. //if ($level < $systemLevel || $level == 1) {
  1659. if ($level < $systemLevel) {
  1660. break; // trouble
  1661. }
  1662. // something changed, so look at all rules again
  1663. $n = -1;
  1664. }
  1665. // minimization step
  1666. if (count($this->branches)) {
  1667. $lastLiteral = null;
  1668. $lastLevel = null;
  1669. $lastBranchIndex = 0;
  1670. $lastBranchOffset = 0;
  1671. for ($i = count($this->branches) - 1; $i >= 0; $i--) {
  1672. list($literals, $level) = $this->branches[$i];
  1673. foreach ($literals as $offset => $literal) {
  1674. if ($literal && $literal->isWanted() && $this->decisionMap[$literal->getPackageId()] > $level + 1) {
  1675. $lastLiteral = $literal;
  1676. $lastBranchIndex = $i;
  1677. $lastBranchOffset = $offset;
  1678. $lastLevel = $level;
  1679. }
  1680. }
  1681. }
  1682. if ($lastLiteral) {
  1683. $this->branches[$lastBranchIndex][$lastBranchOffset] = null;
  1684. $minimizationSteps++;
  1685. $level = $lastLevel;
  1686. $this->revert($level);
  1687. $why = $this->decisionQueueWhy[count($this->decisionQueueWhy)];
  1688. $oLevel = $level;
  1689. $level = $this->setPropagateLearn($level, $lastLiteral, $disableRules, $why);
  1690. if ($level == 0) {
  1691. return;
  1692. }
  1693. continue;
  1694. }
  1695. }
  1696. break;
  1697. }
  1698. }
  1699. private function printDecisionMap()
  1700. {
  1701. echo "\nDecisionMap: \n";
  1702. foreach ($this->decisionMap as $packageId => $level) {
  1703. if ($packageId === 0) {
  1704. continue;
  1705. }
  1706. if ($level > 0) {
  1707. echo ' +' . $this->pool->packageById($packageId)."\n";
  1708. } else {
  1709. echo ' -' . $this->pool->packageById($packageId)."\n";
  1710. }
  1711. }
  1712. echo "\n";
  1713. }
  1714. private function printDecisionQueue()
  1715. {
  1716. echo "DecisionQueue: \n";
  1717. foreach ($this->decisionQueue as $i => $literal) {
  1718. echo ' ' . $literal . ' ' . $this->decisionQueueWhy[$i]."\n";
  1719. }
  1720. echo "\n";
  1721. }
  1722. }