Esempio n. 1
0
        public void Solutions_DivideOperator_Test()
        {
            //Try to represent the equation ((5+1) x 3) - 4
            IEquation node1     = new AddOperation(new Integer(5), new Integer(1));
            IEquation node2     = new MultiplyOperation(node1, new Integer(3));
            IEquation equation1 = new MinusOperation(node2, new Integer(4));

            //Try to represent the equation 1 + 2  +3
            IEquation node3     = new AddOperation(new Integer(1), new Integer(2));
            IEquation equation2 = new AddOperation(node3, new Integer(3));

            Solutions solutions = new Solutions();

            solutions.Add(equation1);
            solutions.Add(equation2);

            IEquation equation3 = new Integer(14);

            Solutions new_solutions = solutions / equation3;

            Assert.AreEqual(2, new_solutions.Count);
            Assert.AreEqual(1, new_solutions[0].Value);
            Assert.AreEqual((decimal)6 / (decimal)14, new_solutions[1].Value);

            new_solutions = solutions / new Integer(3);
            Assert.AreEqual(2, new_solutions.Count);
            Assert.AreEqual((decimal)14 / (decimal)3, new_solutions[0].Value);
            Assert.AreEqual(2, new_solutions[1].Value);
        }
Esempio n. 2
0
        public void Solutions_MinusOperator_Test()
        {
            //Try to represent the equation ((5+1) x 3) - 4
            IEquation node1 = new AddOperation(new Integer(5), new Integer(1));
            IEquation node2 = new MultiplyOperation(node1, new Integer(3));
            IEquation equation1 = new MinusOperation(node2, new Integer(4));

            //Try to represent the equation 1 + 2  +3
            IEquation node3 = new AddOperation(new Integer(1), new Integer(2));
            IEquation equation2 = new AddOperation(node3, new Integer(3));

            Solutions solutions = new Solutions();
            solutions.Add(equation1);
            solutions.Add(equation2);

            IEquation equation3 = new Integer(4);

            Solutions new_solutions = solutions - equation3;
            Assert.AreEqual(2, new_solutions.Count);
            Assert.AreEqual(10, new_solutions[0].Value);
            Assert.AreEqual(2, new_solutions[1].Value);

            new_solutions = equation3 - solutions;
            Assert.AreEqual(2, new_solutions.Count);
            Assert.AreEqual(-10, new_solutions[0].Value);
            Assert.AreEqual(-2, new_solutions[1].Value);
        }
        private void Dychotomy(Interval a, ref int k)
        {
            ++k;

            if (!F(a).Contains(0.0))
            {
                return;
            }

            var temp = new Interval(a.Middle, a.Middle);

            if (F(temp).Contains(0.0))
            {
                Solutions.Add(temp);
                Dychotomy(new Interval(a.Start, a.Middle - eps), ref k);
                Dychotomy(new Interval(a.Middle + eps, a.End), ref k);
            }
            else
            {
                if (a.Width <= eps)
                {
                    Solutions.Add(a);
                }
                else
                {
                    Dychotomy(new Interval(a.Start, a.Middle), ref k);
                    Dychotomy(new Interval(a.Middle, a.End), ref k);
                }
            }
        }
Esempio n. 4
0
        public void Calculate(double a, double b, double eps)
        {
            if (eps <= 0)
            {
                return;
            }

            if (a >= b)
            {
                return;
            }


            while (Math.Abs(b - a) > 2 * eps)
            {
                if (pf.F(a) * pf.ddF(a) < 0)
                {
                    a -= pf.F(a) * ((a - b) / pf.F(a) - pf.F(b));
                }
                else
                {
                    a -= pf.F(a) / pf.dF(a);
                }
                if (pf.F(b) * pf.ddF(b) < 0)
                {
                    b -= pf.F(b) * ((b - a) / pf.F(b) - pf.F(a));
                }
                else
                {
                    b -= pf.F(b) / pf.dF(b);
                }
                Log.Add(((a + b) / 2).ToString());
            }
            Solutions.Add((a + b) / 2);
        }
Esempio n. 5
0
 private void MoveQueen(int Level)
 {
     if (Level > 7)
     {
         for (int j = 0; j <= 7; j++)
         {
             for (int i = 0; i <= 7; i++)
             {
                 if ((Queens[j].Row == j) & (Queens[j].Column == i))
                 {
                     mCells[i, j] = true;
                 }
                 else
                 {
                     mCells[i, j] = false;
                 }
             }
         }
         Solutions.Add(mCells.Clone());
         return;
     }
     for (int j = 0; j <= 7; j++)
     {
         if (Level < 8)
         {
             Queens[Level].Row    = Level;
             Queens[Level].Column = j;
             if (CheckAll(Level))
             {
                 MoveQueen(Level + 1);
             }
         }
     }
 }
Esempio n. 6
0
 public void AddSolution(string solutionFile)
 {
     if (!Solutions.ContainsKey(solutionFile))
     {
         Solutions.Add(solutionFile, new SDSolution(solutionFile));
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method loads a solution into the view model.</summary>
        ///
        /// <param name="solutionURL">The solution file path.</param>
        ///--------------------------------------------------------------------------------
        public SolutionViewModel LoadSolution(string solutionURL = null)
        {
            SolutionViewModel solutionView = null;

            try
            {
                // create a solution under solution
                if (solutionURL != null)
                {
                    if (File.Exists(solutionURL))
                    {
                        // load solution from xml
                        Solution solution = new Solution();
                        if (solutionURL != null)
                        {
                            solution.Load(solutionURL);
                        }
                        solution.ResetModified(false);
                        solutionView            = new SolutionViewModel(solution, solutionURL, true);
                        solutionView.Updated   += new EventHandler(Children_Updated);
                        solutionView.Loaded    += new EventHandler(solutionView_Loaded);
                        solutionView.IsSelected = true;

                        // compile and load into view
                        solutionView.BuildSolution(true);

                        // add to recent solutions
                        AddSolutionToRecentSolutions(solution, solutionURL);
                    }
                    else
                    {
                        // display bad path issue
                        ShowIssue(String.Format(DisplayValues.Issue_SolutionFileNotFound, solutionURL));
                    }
                }
                else
                {
                    // create new solution
                    Solution solution = new Solution();
                    solution.SolutionID     = Guid.NewGuid();
                    solution.Name           = Resources.DisplayValues.NodeName_SolutionDefault;
                    solutionView            = new SolutionViewModel(solution, solutionURL);
                    solutionView.Updated   += new EventHandler(Children_Updated);
                    solutionView.Loaded    += new EventHandler(solutionView_Loaded);
                    solutionView.IsSelected = true;
                    Solutions.Add(solutionView);
                    Items.Add(solutionView);
                    Refresh(false);
                }
            }
            catch (ApplicationException ex)
            {
                ShowException(ex);
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
            return(solutionView);
        }
Esempio n. 8
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method updates the view model data and sends update command back
        /// to the solution builder.</summary>
        ///--------------------------------------------------------------------------------
        protected override void OnUpdate()
        {
            // send update for any updated children
            foreach (SolutionViewModel item in Solutions)
            {
                if (item.IsEdited == true)
                {
                    item.Update();
                }
            }
            // send update for any new children
            foreach (SolutionViewModel item in ItemsToAdd.OfType <SolutionViewModel>())
            {
                item.Update();
                Solutions.Add(item);
            }
            ItemsToAdd.Clear();

            // send delete for any deleted children
            foreach (SolutionViewModel item in ItemsToDelete.OfType <SolutionViewModel>())
            {
                item.Delete();
                Solutions.Remove(item);
            }
            ItemsToDelete.Clear();

            // reset modified for children
            foreach (SolutionViewModel item in Solutions)
            {
                item.ResetModified(false);
            }
        }
Esempio n. 9
0
        public SimplexAnswer(SimplexTable finalTable, AnswerStatus status = AnswerStatus.NoSolutions)
        {
            Status = status;
            Solution solution = new Solution();

            solution.BasisIndexes = (int[])finalTable.BasisVariablesIndexes.Clone();
            solution.OptimalValue = finalTable.GoalFunctionValue;
            double[]   optimalCoefficients = new double[finalTable.CountOfVariables];
            List <int> freeIndexes         = new List <int>();

            // все небазисные (свободные) переменные равны 0
            for (int i = 0; i < finalTable.CountOfVariables; i++)
            {
                if (finalTable.BasisVariablesIndexes.Contains(i))
                {
                    optimalCoefficients[i] = finalTable.FreeMemebers[i];
                }
                else
                {
                    freeIndexes.Add(i);
                    optimalCoefficients[i] = 0;
                }
            }
            solution.FreeIndexes         = freeIndexes.ToArray();
            solution.OptimalCoefficients = optimalCoefficients;
            solution.StartIndexes        = finalTable.StartVariablesIndexes;
            Solutions.Add(solution);
        }
Esempio n. 10
0
        public ISolution1D CreateExactTimeDependentSolution(IGrid1D grid, object physicalData, double dt)
        {
            var solution = new DbGroup1D((DbGrid1D)grid, physicalData, dt);

            Solutions.Add(solution);
            return(solution);
        }
Esempio n. 11
0
        private void UpdateSolutions(sbyte[] solution)
        {
            // For SolutionMode.Single:
            if (SolutionMode == SolutionMode.Single)
            {
                Solutions.Add(solution);
                return;
            }

            var symmetricalSolutions = Utility.GetSymmetricalSolutions(solution);

            // For SolutionMode.All, add this solution and all its symmetrical counterparts to Solutions.
            if (SolutionMode == SolutionMode.All)
            {
                Solutions.Add(solution);
                symmetricalSolutions.ForEach(s => Solutions.Add(s));
                return;
            }

            // For SolutionMode.Unique: Add this solution to Solutions only if no overlaps between Solutions and symmetricalSolutions are found.
            if (!Solutions.Overlaps(symmetricalSolutions))
            {
                Solutions.Add(solution);
            }
        }
        private void Moore(Interval a, ref int k)
        {
            ++k;

            if (a.Width <= eps)
            {
                Solutions.Add(a);
                return;
            }

            if (dFdx(a).Contains(0.0))
            {
                Interval A1 = new Interval(a.Start, a.Middle - eps);
                Interval A2 = new Interval(a.Middle + eps, a.End);

                if (dFdx(A1).Contains(0.0))
                {
                    Moore(A1, ref k);
                }
                else
                {
                    var      c  = A1.Middle;
                    Interval U1 = A1.Middle - F(A1.Middle) / dFdx(A1);
                    Interval X1 = Interval.Intersection(U1, A1);
                    if (X1.Width > eps)
                    {
                        Moore(X1, ref k);
                    }
                }

                if (dFdx(A2).Contains(0.0))
                {
                    Moore(A2, ref k);
                }
                else
                {
                    var      c  = A1.Middle;
                    Interval U1 = A2.Middle - F(A2.Middle) / dFdx(A2);
                    Interval X1 = Interval.Intersection(U1, A2);
                    if (X1.Width > eps)
                    {
                        Moore(X1, ref k);
                    }
                }
            }
            else
            {
                double   c = a.Middle;
                Interval U = c - F(c) / dFdx(a);
                Interval X = Interval.Intersection(U, a);
                if (X.Width > eps)
                {
                    Moore(X, ref k);
                }
                else
                {
                    Solutions.Add(X);
                }
            }
        }
Esempio n. 13
0
        public ISolution1D CreateExactSolution(IGrid1D grid, object physicalData)
        {
            var solution = new DbGroup1D((DbGrid1D)grid, physicalData);

            Solutions.Add(solution);
            return(solution);
        }
Esempio n. 14
0
        /// <summary>
        /// Solve the given downcount game
        /// </summary>
        /// <param name="game"></param>
        /// <param name="allSolutions"></param>
        /// <returns></returns>
        public static Solutions Solve(DownCountGame game, bool allSolutions = true)
        {
            Solutions solutions = new Solutions();

            if (game.Numbers.Contains(game.TargetNumber))
            {
                solutions.Add(new Integer(game.TargetNumber));
            }

            if (!allSolutions && solutions.Count > 0)
            {
                return(solutions);
            }

            if (game.Numbers.Count == 1)
            {
                return(solutions);
            }

            for (int i = 0; i < game.Numbers.Count; ++i)
            {
                solutions.AddRange(SolveSubset(game, i, allSolutions));

                if (!allSolutions && solutions.Count > 0)
                {
                    return(solutions);
                }
            }

            return(solutions);
        }
Esempio n. 15
0
        public ISolution1D CreateNumericTimeDependentSolution(IGrid1D grid, object physicalData, double dt, Type solverType)
        {
            var solution = new DbGroup1D((DbGrid1D)grid, physicalData, dt, solverType);

            Solutions.Add(solution);
            return(solution);
        }
Esempio n. 16
0
        public void Calculate(double a, double b, double eps)
        {
            if (eps <= 0)
            {
                return;
            }

            if (a >= b)
            {
                return;
            }



            while (Math.Abs(b - a) >= eps)
            {
                double x = (a + b) / 2;
                if (pf.F(a) * pf.F(x) < 0)
                {
                    b = x;
                }
                else
                {
                    a = x;
                }
                Log.Add(x.ToString());
            }
            Log.Add(((a + b) / 2).ToString());
            Solutions.Add((a + b) / 2);
        }
 /// <summary>
 /// Получено решение для миграции
 /// </summary>
 /// <param name="message"></param>
 private void OnMigrateSolutions(MigrateSolutionsMessage message)
 {
     foreach (var solution in message.Solutions)
     {
         Solutions.Add(solution);
     }
 }
Esempio n. 18
0
        private double[] LoadControlledNR(double[] forceVector)
        {
            double[] incrementDf    = VectorOperations.VectorScalarProductNew(forceVector, lambda);
            double[] solutionVector = localSolutionVector;
            double[] incrementalExternalForcesVector = new double[forceVector.Length];
            double[] tempSolutionVector = new double[solutionVector.Length];
            double[] deltaU             = new double[solutionVector.Length];
            double[] internalForcesTotalVector;
            double[] dU;
            double[] residual;
            double   residualNorm;

            for (int i = 0; i < numberOfLoadSteps; i++)
            {
                incrementalExternalForcesVector = VectorOperations.VectorVectorAddition(incrementalExternalForcesVector, incrementDf);
                discretization.UpdateDisplacements(solutionVector);
                internalForcesTotalVector = discretization.CreateTotalInternalForcesVector();
                double[,] stiffnessMatrix = discretization.CreateTotalStiffnessMatrix();
                //OnConvergenceResult("Newton-Raphson: Solution not converged at load step" + i);
                dU             = linearSolver.Solve(stiffnessMatrix, incrementDf);
                solutionVector = VectorOperations.VectorVectorAddition(solutionVector, dU);
                residual       = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector);
                residualNorm   = VectorOperations.VectorNorm2(residual);
                int iteration = 0;
                Array.Clear(deltaU, 0, deltaU.Length);
                while (residualNorm > Tolerance && iteration < MaxIterations)
                {
                    stiffnessMatrix    = discretization.CreateTotalStiffnessMatrix();
                    deltaU             = VectorOperations.VectorVectorSubtraction(deltaU, linearSolver.Solve(stiffnessMatrix, residual));
                    tempSolutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU);
                    discretization.UpdateDisplacements(tempSolutionVector);
                    internalForcesTotalVector = discretization.CreateTotalInternalForcesVector();
                    residual     = VectorOperations.VectorVectorSubtraction(internalForcesTotalVector, incrementalExternalForcesVector);
                    residualNorm = VectorOperations.VectorNorm2(residual);
                    if (residualNorm <= Tolerance)
                    {
                        OnConvergenceResult("Newton-Raphson: Load Step " + i + " - Solution converged at iteration " + iteration + " - Residual Norm = " + residualNorm);
                    }
                    else
                    {
                        OnConvergenceResult("Newton-Raphson: Load Step " + i + " - Solution not converged at iteration " + iteration + " - Residual Norm = " + residualNorm);
                    }
                    iteration = iteration + 1;
                    //(Application.Current.Windows[0] as MainWindow).LogTool.Text = "ok";
                    //OnConvergenceResult("Newton-Raphson: Solution not converged at load step" + iteration);
                }
                InternalForces.Add(i + 1, internalForcesTotalVector);
                solutionVector = VectorOperations.VectorVectorAddition(solutionVector, deltaU);
                Solutions.Add(i + 1, solutionVector);
                if (iteration >= MaxIterations)
                {
                    OnConvergenceResult("Newton-Raphson did not converge at Load Step " + i + ". Exiting solution.");
                    LoadStepConvergence.Add("Solution not converged.");
                    break;
                }
                LoadStepConvergence.Add("Solution converged.");
            }
            return(solutionVector);
        }
Esempio n. 19
0
            public Solution CreateSolution()
            {
                Solution solution = new Solution();

                SolutionCurrent = solution;
                Solutions.Add(solution);
                return(solution);
            }
Esempio n. 20
0
        public StubSolution()
        {
            rnd = new Random();
            Solution s1 = new Solution(Solution1);
            Solution s2 = new Solution(Solution2);

            Solutions.Add(s1);
            Solutions.Add(s2);
        }
Esempio n. 21
0
        protected async Task LoadSolutions()
        {
            var solutions = await DataManager.GetSolutionsAsync();

            foreach (var solution in solutions)
            {
                Solutions.Add(solution);
            }
        }
Esempio n. 22
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies solution updates.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessEditSolutionPerformed(SolutionEventArgs data)
        {
            try
            {
                bool isItemMatch = false;
                if (data != null && data.Solution != null)
                {
                    foreach (SolutionViewModel item in Solutions)
                    {
                        if (item.Solution.SolutionID == data.Solution.SolutionID)
                        {
                            isItemMatch = true;
                            item.Solution.TransformDataFromObject(data.Solution, null, false);

                            #region protected
                            if (!String.IsNullOrEmpty(item.Solution.TemplatePath))
                            {
                                if (item.CodeTemplatesFolder.Items.Count == 0 || String.IsNullOrEmpty(item.OriginalTemplatePath) || System.IO.Directory.GetParent(item.OriginalTemplatePath).FullName != System.IO.Directory.GetParent(item.Solution.TemplateAbsolutePath).FullName)
                                {
                                    item.CodeTemplatesFolder.LoadTemplateDirectories();
                                    item.OriginalTemplatePath = item.Solution.TemplatePath;
                                }
                            }
                            #endregion protected

                            item.OnUpdated(item, null);
                            item.ShowInTreeView();
                            break;
                        }
                    }
                    if (isItemMatch == false)
                    {
                        // add new Solution
                        SolutionViewModel newItem = new SolutionViewModel(data.Solution);
                        newItem.Updated += new EventHandler(Children_Updated);
                        Solutions.Add(newItem);

                        #region protected
                        if (String.IsNullOrEmpty(newItem.OriginalTemplatePath) || System.IO.Directory.GetParent(newItem.OriginalTemplatePath).FullName != System.IO.Directory.GetParent(newItem.Solution.TemplateAbsolutePath).FullName)
                        {
                            newItem.CodeTemplatesFolder.LoadTemplateDirectories();
                            newItem.OriginalTemplatePath = newItem.Solution.TemplatePath;
                        }
                        #endregion protected

                        Items.Add(newItem);
                        OnUpdated(this, null);
                        newItem.ShowInTreeView();
                    }
                }
            }
            catch (Exception ex)
            {
                ShowIssue(ex.Message + ex.StackTrace);
            }
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method manages the update of this view when the solution is loaded.</summary>
 ///
 /// <param name="sender">The sender of the loaded event.</param>
 /// <param name="e">The event arguments.</param>
 ///--------------------------------------------------------------------------------
 private void solutionView_Loaded(object sender, EventArgs e)
 {
     if (sender is SolutionViewModel)
     {
         Solutions.Add(sender as SolutionViewModel);
         Items.Add(sender as SolutionViewModel);
         Refresh(true);
         IsExpanded = true;
     }
 }
Esempio n. 24
0
        /* EXPRESSIONS */

        private void SolveExpression(Expression ex)
        {
            if (ex.OnlyArithmeticTokens())
            {
                ex.Simplify();
                if (!ex.IsSimplified)
                {
                    throw new Exception("Expected the expression was arithmetic tokens only, but failed to simplify.");
                }
                Solutions.Add(ex.ToString());
                PrintStatus();
            }
        }
Esempio n. 25
0
        private void EquationAdded(object?sender, string solutionEquation)
        {
            if (Solutions.Count > _config.MaxEquationPerSpot)
            {
                return;
            }

            Solutions.Add(solutionEquation);
            if (CurrentSolution == -1)
            {
                CurrentSolution = 0;
            }
        }
Esempio n. 26
0
        public TProblem()
        {
            var solMethods = this.GetType().GetMethods().Where(m => m.GetCustomAttributes(typeof(SolutionMethodAttribute), true).Length > 0);

            foreach (var method in solMethods)
            {
                var s = method.CreateDelegate(typeof(Solution), this);
                Solutions.Add(s as Solution);
            }
            LoadSamples();
            AddManualSamples();
            TargetedSamples();
        }
Esempio n. 27
0
        /// <summary>
        /// 载入处理
        /// </summary>
        public void OnSolutionLoad()
        {
            if (!Solutions.Contains(Solution))
            {
                Solutions.Add(Solution);
            }
            TryAdd(Entities, Solution.Entities);
            TryAdd(Projects, Solution.Projects);
            TryAdd(Enums, Solution.Enums);
            TryAdd(ApiItems, Solution.ApiItems);

            Solution.EntityList.CollectionChanged  += (s, e) => CollectionChanged(Entities, e);
            Solution.ProjectList.CollectionChanged += (s, e) => CollectionChanged(Projects, e);
            Solution.EnumList.CollectionChanged    += (s, e) => CollectionChanged(Projects, e);
            Solution.ApiList.CollectionChanged     += (s, e) => CollectionChanged(Projects, e);
        }
Esempio n. 28
0
        private void Hansen(Interval a, ref int k)
        {
            ++k;

            if (a.Width <= eps)
            {
                Solutions.Add(a);
                return;
            }

            if (dFdx(a).Contains(0.0))
            {
                Interval[] D = Interval.Division(F(a.Middle), a);

                Interval A1 = D[0];
                Interval A2 = D[1];

                Interval U1 = A1.Middle - F(A1.Middle) / dFdx(A1);
                Interval X1 = Interval.Intersection(U1, A1);
                if (X1.Width > 2 * eps)
                {
                    Hansen(X1, ref k);
                }

                Interval U2 = A2.Middle - F(A2.Middle) / dFdx(A2);
                Interval X2 = Interval.Intersection(U2, A2);
                if (X2.Width > 2 * eps)
                {
                    Hansen(X2, ref k);
                }
            }
            else
            {
                Interval U = a.Middle - F(a.Middle) / dFdx(a);
                Interval X = Interval.Intersection(U, a);
                if (X.Width > 2 * eps)
                {
                    Hansen(X, ref k);
                }
                else
                {
                    Solutions.Add(X);
                }
            }
        }
Esempio n. 29
0
        private void SolveEquation(Equation eq)
        {
            if (eq.OnlyArithmeticTokens())
            {
                Solutions.Add(IsArithmeticEquasionTrue(eq).ToString());
                return;
            }

            if (LeftHasVariables && RightHasVariables)
            {
                SolveForVariablesOnBothSide(eq);
                Solutions.Add(eq.ToString());
                return;
            }

            eq.EnsureVariableOnLeft();

            if (LeftHasVariables)
            {
                if (Left.Variables.Count() > 1)
                {
                    SolveForMultipleVariables(eq);
                }
                else if (!Left.IsVariableIsolated)
                {
                    IsolateSingleVariable(eq);
                }

                if (!Left.IsVariableIsolated)
                {
                    throw new Exception($"Failed to isolate LeftHandSide. Equation: '{eq.ToString()}'");
                }

                if (!Right.IsSimplified)
                {
                    throw new Exception($"Failed to simplify RightHandSide. Equation: '{eq.ToString()}'");
                }

                Solutions.Add(eq.ToString());
                AddSolvedVariable(Left.Variables.Single(), Right.Numbers.Single());
                return;
            }

            throw new Exception("Not sure what to do here. Equations should have been solved.");
        }
Esempio n. 30
0
        /// <summary>
        /// Attempts to add the given solution to the set.
        /// </summary>
        /// <param name="solution">Solution to add.</param>
        /// <returns>True if the solution was added. False otherwise.</returns>
        public bool SafeAdd(FuriganaSolution solution)
        {
            if (!solution.Check())
            {
                // The specified solution is not valid.
                return(false);
            }

            if (Solutions.Any(s => s.Equals(solution)))
            {
                // We already have an equivalent solution.
                return(false);
            }

            // All is good.
            Solutions.Add(solution);
            return(true);
        }
        /// <summary>
        /// 载入处理
        /// </summary>
        public void OnSolutionLoad()
        {
            if (!Solutions.Contains(Solution))
            {
                Solutions.Add(Solution);
            }
            Entities.AddRange(Solution.Entities);
            Projects.AddRange(Solution.Projects);
            Enums.AddRange(Solution.Enums);
            TypedefItems.AddRange(Solution.TypedefItems);
            NotifyItems.AddRange(Solution.NotifyItems);
            ApiItems.AddRange(Solution.ApiItems);

            Solution.Entities.CollectionChanged     += (s, e) => CollectionChanged(Entities, e);
            Solution.Projects.CollectionChanged     += (s, e) => CollectionChanged(Projects, e);
            Solution.Enums.CollectionChanged        += (s, e) => CollectionChanged(Projects, e);
            Solution.TypedefItems.CollectionChanged += (s, e) => CollectionChanged(TypedefItems, e);
            Solution.ApiItems.CollectionChanged     += (s, e) => CollectionChanged(Projects, e);
            Solution.NotifyItems.CollectionChanged  += (s, e) => CollectionChanged(Projects, e);
        }
Esempio n. 32
0
        /// <summary>
        /// Solve the given downcount game
        /// </summary>
        /// <param name="game"></param>
        /// <param name="allSolutions"></param>
        /// <returns></returns>
        public static Solutions Solve(DownCountGame game, bool allSolutions = true)
        {
            Solutions solutions = new Solutions();

            if (game.Numbers.Contains(game.TargetNumber))
                solutions.Add(new Integer(game.TargetNumber));

            if (!allSolutions && solutions.Count > 0)
                return solutions;

            if (game.Numbers.Count == 1)
                return solutions;

            for (int i = 0; i < game.Numbers.Count; ++i)
            {
                solutions.AddRange(SolveSubset(game, i, allSolutions));

                if (!allSolutions && solutions.Count > 0)
                    return solutions;
            }

            return solutions;
        }