Example #1
0
        public void TestIsDecidedAndIsUndecided()
        {
            decisions.Decide(1, 1, defaultRule);
            decisions.Decide(-2, 1, defaultRule);

            Assert.IsTrue(decisions.IsDecided(1));
            Assert.IsTrue(decisions.IsDecided(2));
            Assert.IsTrue(decisions.IsUndecided(3));
        }
Example #2
0
        /// <summary>
        /// Resolve the requires of the requested.
        /// </summary>
        /// <param name="request">The request instance.</param>
        /// <param name="ignorePlantform">Whether is ignore plantform check.</param>
        /// <returns>An array of operation.</returns>
        public IOperation[] Solve(Request request, bool ignorePlantform = false)
        {
            jobs = request.GetJobs();

            SetupInstalledMap();
            rules = ruleSetGenerator.GetRulesFor(jobs, installedMap, ignorePlantform);
            CheckForRootRequiresProblems(ignorePlantform);

            decisions  = new Decisions(pool);
            watchGraph = new RuleWatchGraph();
            learnedWhy.Clear();
            learnedPool.Clear();
            branches.Clear();

            foreach (var rule in rules)
            {
                watchGraph.Add(rule);
            }

            SetupAssertionRuleDecisions();

            io.WriteError("Resolving requires through SAT", true, Verbosities.Debug);
            stopwatch.Restart();
            stopwatch.Start();

            RunSAT();

            io.WriteError(string.Empty, true, Verbosities.Debug);
            io.WriteError($"Dependency resolution completed in {stopwatch.Elapsed.TotalSeconds.ToString("0.00")} seconds", true, Verbosities.Debug);

            // If we don't make a decision about the packages we have
            // installed, then we think these packages will be uninstall.
            foreach (var item in installedMap)
            {
                var packageId = item.Key;
                if (decisions.IsUndecided(packageId))
                {
                    decisions.Decide(-packageId, 1, null);
                }
            }

            if (problems.Count > 0)
            {
                throw new SolverProblemsException(problems, installedMap);
            }

            var transaction = new Transaction(policy, pool, installedMap, decisions);

            return(transaction.GetOperations());
        }