Esempio n. 1
0
        /// <summary>
        /// Complex and memory consuming resources may be prepared before the controller is started.
        /// </summary>
        public void PrepareForStart()
        {
            // Prepare the solver.
            if (mazeForm != null)
            {
                solver = SolverFactory.CreateSolver(mazeForm.StrategyName, this.Maze, mazePainter);
            }
            else
            {
                solver = SolverFactory.CreateSolver(null, this.Maze, mazePainter);
            }

            // Prepare the solution path.
            solutionPath = SolverFactory.SolutionPath(this.Maze);

            // If our Maze has embedded mazes, we need to supply them with embedded solvers.
            CreateEmbeddedSolvers();

            // Prepare embedded solvers.
            foreach (EmbeddedSolverController item in embeddedControllers)
            {
                item.PrepareForStart();
            }

            // After all controllers have been created, some resources need to be shared with the master controller.
            if (this.Maze.MazeId == MazeSquare.PrimaryMazeId)
            {
                CoordinateEmbeddedControllers(this);
            }
        }
Esempio n. 2
0
        public void SF_CreateSolverTest_01()
        {
            string testObject = "SWA.Ariadne.Logic.SolverFactory.CreateSolver";

            Maze        maze       = NewMaze();
            IMazeDrawer mazeDrawer = null;
            IMazeSolver actual     = SolverFactory.CreateSolver(null, maze, mazeDrawer);

            Assert.IsInstanceOfType(actual, typeof(IMazeSolver), testObject + " did not return an instanze of IMazeSolver");
        }
Esempio n. 3
0
        static int FromXMLFileInternal(string file, string name)
        {
            XmlDocument docu = new XmlDocument();

            docu.Load(file);

            XmlNode node = docu.SelectSingleNode("/SolverConfig/sparsesolver[@name='" + name + "']");

            var config = ilPSP.LinSolvers.SolverConfigurationParser.parseXMLConfigurationElements(node);
            var solver = SolverFactory.CreateSolver <ISparseSolver>(config);

            return(Infrastructure.RegisterObject(solver));
        }
Esempio n. 4
0
        // ReSharper disable UnusedMember.Global
        public static SimulationResults ExecuteModel(ModelInfo model, String solverName, double duration, int repeats, int samples)
        // ReSharper restore UnusedMember.Global
        {
            Console.WriteLine("Starting simulation...");

            ISolver solver = SolverFactory.CreateSolver(solverName, model, repeats, duration, samples);

            solver.Solve();
            var results = new SimulationResults(solver.GetTrajectoryLabels(), solver.GetTrajectoryData());

            Console.WriteLine("...finished simulation.");

            return(results);
        }
Esempio n. 5
0
        // ReSharper disable MemberCanBePrivate.Global
        public static void RunModel(ModelInfo model, String solverName, double duration, int repeats, int samples)
        // ReSharper restore MemberCanBePrivate.Global
        {
            Console.WriteLine("Starting simulation...");

            ISolver solver = SolverFactory.CreateSolver(solverName, model, repeats, duration, samples);

            Console.WriteLine("Using solver {0}", solver);
            solver.Solve();
            string outputPrefix = Configuration.CurrentConfiguration.GetParameterWithDefault("output.prefix", "trajectories");

            solver.OutputData(outputPrefix);

            Console.WriteLine("...finished simulation.");
        }
Esempio n. 6
0
        public static void RunCompetition()
        {
            System.Console.BackgroundColor = ConsoleColor.Blue;
            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.Clear();

            System.Console.WriteLine("*** Competition ***");
            for (int n = 0; n < 3; ++n)
            {
                System.Console.WriteLine("Round {0} - Standard Numbers Game with {1} big numbers", (n + 1), n);
                for (int t = 0; t < 10; ++t)
                {
                    System.Console.WriteLine("Test {0}", t + 1);


                    int[] initialNumbers;
                    int   target;
                    if (GameGenerator.GenerateCountdownGame(n, out initialNumbers, out target))
                    {
                        System.Console.Write("Numbers: [");
                        for (int i = 0; i < initialNumbers.Length; ++i)
                        {
                            System.Console.Write("{0}", initialNumbers[i]);
                            if (i < initialNumbers.Length - 1)
                            {
                                System.Console.Write(", ");
                            }
                        }
                        System.Console.WriteLine("]");
                        System.Console.WriteLine("\r\nTarget: {0}", target);
                    }
                    // Now try our solutions
                    int numSolvers = SolverFactory.RegisteredSolvers;
                    for (int s = 0; s < numSolvers; ++s)
                    {
                        var       solver = SolverFactory.CreateSolver(s);
                        ISolution solution;
                        if (solver.GetSolution(initialNumbers, target, out solution))
                        {
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public static void PlayGame()
        {
            System.Console.WriteLine("Enter your numbers, one at a time, or together separated by commas.");
            System.Console.WriteLine("You can also specify the target after '=', or enter it separately.");

            while (true)
            {
                int[] numbers;
                int   target;
                if (GetNumbersFromConsole(out numbers, out target))
                {
                    System.Console.Write("The numbers are: [ ");
                    for (int idx = 0; idx < numbers.Length; ++idx)
                    {
                        System.Console.Write("{0}", numbers[idx]);
                        if (idx < numbers.Length - 1)
                        {
                            System.Console.Write(", ");
                        }
                    }
                    System.Console.WriteLine(" ]");
                    System.Console.WriteLine("Target: {0}", target);

                    var solver = SolverFactory.CreateSolver(_defaultSolver);

                    ISolution solution;
                    if (solver.GetSolution(numbers, target, out solution))
                    {
                        System.Console.WriteLine("Solved in {0}s, as follows:\r\n{1}",
                                                 solution.ExecutionTime.TotalSeconds,
                                                 solution.GetMultilineDisplayString());
                    }
                    else
                    {
                        System.Console.WriteLine("Not solvable, exhausted possibilities in {0}s",
                                                 solution.ExecutionTime.TotalSeconds);
                    }
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 8
0
        public void SolverFactoryTest()
        {
            var     model  = EmodlLoader.LoadEMODLModel(_sirModel);
            ISolver solver = SolverFactory.CreateSolver("SSA", model, 1, 2.0, 3);

            Assert.IsTrue(solver is Gillespie);
            solver = SolverFactory.CreateSolver("FIRST", model, 1, 2.0, 3);
            Assert.IsTrue(solver is GillespieFirstReaction);
            solver = SolverFactory.CreateSolver("NEXT", model, 1, 2.0, 3);
            Assert.IsTrue(solver is GibsonBruck);
            solver = SolverFactory.CreateSolver("HYBRID", model, 1, 2.0, 3);
            Assert.IsTrue(solver is HybridSSA);
            solver = SolverFactory.CreateSolver("TAU", model, 1, 2.0, 3);
            Assert.IsTrue(solver is TauLeaping);
            solver = SolverFactory.CreateSolver("MID", model, 1, 2.0, 3);
            Assert.IsTrue(solver is MidPoint);
            solver = SolverFactory.CreateSolver("R", model, 1, 2.0, 3);
            Assert.IsTrue(solver is RLeaping);
            solver = SolverFactory.CreateSolver("RFAST", model, 1, 2.0, 3);
            Assert.IsTrue(solver is RLeapingFast);
            solver = SolverFactory.CreateSolver("BLEAP", model, 1, 2.0, 3);
            Assert.IsTrue(solver is BLeaping);
            solver = SolverFactory.CreateSolver("TSSA", model, 1, 2.0, 3);
            Assert.IsTrue(solver is TransportSSA);
            solver = SolverFactory.CreateSolver("DFSP", model, 1, 2.0, 3);
            Assert.IsTrue(solver is DFSP);
            solver = SolverFactory.CreateSolver("OTSSA", model, 1, 2.0, 3);
            Assert.IsTrue(solver is OptimalTransportSSA);

/* Fractional diffusion solver doesn't handle single node models gracefully.
 *          solver = SolverFactory.CreateSolver("LEVY", model, 1, 2.0, 3);
 *          Assert.IsTrue(solver is FractionalDiffusion);
 */
/* Exit times solver doesn't handle missing target condition gracefully.
 *          solver = SolverFactory.CreateSolver("EXITTIMES", model, 1, 2.0, 3);
 *          Assert.IsTrue(solver is ExitTimes);
 */
/* dwSSA solver automatically starts solving
 *          Configuration.CurrentConfiguration = Configuration.ConfigurationFromString("{\"dwSSA\":{\"re_name\":\"I\",\"re_val\":500}}");
 *          solver = SolverFactory.CreateSolver("DWSSA", model, 1, 2.0, 3);
 *          Assert.IsTrue(solver is dwSSA);
 */
        }
Esempio n. 9
0
        static void FromXMLInternal(out int ref_, string xmlString)
        {
            xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \n" +
                        "<document>\n" +
                        xmlString +
                        "</document>";
            //Console.WriteLine(xmlString);
            XmlDocument docu = new XmlDocument();

            docu.LoadXml(xmlString);

            XmlNode node = docu.SelectSingleNode("/document/sparsesolver");

            var config = ilPSP.LinSolvers.SolverConfigurationParser.parseXMLConfigurationElements(node);

            var solver = SolverFactory.CreateSolver <ISparseSolver>(config);

            ref_ = Infrastructure.RegisterObject(solver);
        }
Esempio n. 10
0
        private bool ExecuteSirModel(string prng)
        {
            SetCurrentPrng(prng);
            var       modelInfo = EmodlLoader.LoadEMODLFile("resources\\sir.emodl");
            const int repeats   = 128;
            const int samples   = 100;
            var       solver    = SolverFactory.CreateSolver("SSA", modelInfo, repeats, 548.0, samples);

            solver.Solve();
            var tempFilename   = Path.GetTempFileName();
            var trajectoryData = solver.GetTrajectoryData();
            var means          = new double[3][];
            var speciesMin     = new[] { double.MaxValue, double.MaxValue, double.MaxValue };
            var speciesMax     = new double[3];

            for (int species = 0; species < 3; species++)
            {
                means[species] = new double[samples];
                for (int trajectory = 0; trajectory < repeats; trajectory++)
                {
                    for (int sample = 0; sample < samples; sample++)
                    {
                        means[species][sample] += trajectoryData[species * repeats + trajectory][sample];
                    }
                }

                for (int sample = 0; sample < samples; sample++)
                {
                    var mean = means[species][sample] / repeats;
                    speciesMin[species]    = Math.Min(speciesMin[species], mean);
                    speciesMax[species]    = Math.Max(speciesMax[species], mean);
                    means[species][sample] = mean;
                }
            }

            const double minSmin = 19.0;
            const double maxSmin = 27.0;
            const double maxS    = 990.0;
            const double minI    = 10.0;
            const double minImax = 551.0;
            const double maxImax = 571.0;
            const double minR    = 0.0;
            const double minRmax = 859.0;
            const double maxRmax = 879.0;

            Console.WriteLine("Susceptible: min = {0}, max = {1} (limits- {2} <= min <= {3}, max == {4})",
                              speciesMin[0], speciesMax[0], minSmin, maxSmin, maxS);
            Console.WriteLine("Infectious:  min = {0}, max = {1} (limits- min == {2}, {3} <= max <= {4})",
                              speciesMin[1], speciesMax[1], minI, minImax, maxImax);
            Console.WriteLine("Recovered:   min = {0}, max = {1} (limits- min == {2}, {3} <= max <= {4})",
                              speciesMin[2], speciesMax[2], minR, minRmax, maxRmax);

            // ReSharper disable CompareOfFloatsByEqualityOperator
            var susceptibleOkay = (minSmin <= speciesMin[0]) && (speciesMin[0] <= maxSmin) && (speciesMax[0] == maxS);
            var infectiousOkay  = (speciesMin[1] == minI) && (minImax <= speciesMax[1]) && (speciesMax[1] <= maxImax);
            var recoveredOkay   = (speciesMin[2] == minR) && (minRmax <= speciesMax[2]) && (speciesMax[2] <= maxRmax);

            // ReSharper restore CompareOfFloatsByEqualityOperator

            if (!(susceptibleOkay && infectiousOkay && recoveredOkay))
            {
                solver.OutputData(tempFilename);
                Console.WriteLine("Wrote SIR simulation data (with {0} PRNG) to {1}", prng, tempFilename);
            }
            else
            {
                File.Delete(tempFilename);
            }

            var passed = susceptibleOkay && infectiousOkay && recoveredOkay;

            return(passed);
        }