コード例 #1
0
 public SolverPoolSlimLockWithLongTerm()
 {
     Statistics = new SolverStatistics()
     {
         Name = GetType().Name
     };
 }
コード例 #2
0
 public SolverPoolSimpleList()
 {
     Statistics = new SolverStatistics
     {
         Name = GetType().Name
     };
 }
コード例 #3
0
        public void WriteSummary(List <SolverResultSummary> results, SolverStatistics start)
        {
            var cc = 0;

            /* Example
             * GUYZEN running RT:3.1.3 OS:'WIN 6.2.9200.0' Threads:32 RELEASE x64 'AMD Ryzen Threadripper 2950X 16-Core Processor '
             * Git: '[DIRTY] c724b04 Progress notifications, rev:191' at 2020-04-08 09:14:51Z, v3.1.0
             */
            var line = DevHelper.FullDevelopmentContext();

            Report.WriteLine(line);
            if (WriteSummaryToConsole)
            {
                System.Console.WriteLine(line);
            }


            foreach (var result in results)
            {
                line = $"[{result.Puzzle.Ident}] {result.Text}";
                Report.WriteLine(line);
                if (WriteSummaryToConsole)
                {
                    System.Console.WriteLine(line);
                }
                cc++;
            }
        }
コード例 #4
0
 public SolverPoolLongTerm()
 {
     Statistics = new SolverStatistics()
     {
         Name = GetType().Name
     };
 }
コード例 #5
0
        protected override void UpdateInner(ISolver caller, SolverState state, SolverStatistics global, string txt)
        {
            var l = Render(caller, state, global, txt);

            a.WriteLine(l);
            UpdateConsoleInPlace(l);
        }
コード例 #6
0
ファイル: SolverQueue.cs プロジェクト: danisky94/SokoSolve
 public SolverQueue()
 {
     inner      = new Queue <SolverNode>();
     Statistics = new SolverStatistics
     {
         Name = GetType().Name
     };
 }
コード例 #7
0
 public SolverPoolBinarySearchTree(ISolverPoolBatching longTerm)
 {
     this.longTerm = longTerm;
     Statistics    = new SolverStatistics()
     {
         Name = GetType().Name
     };
 }
コード例 #8
0
 public SolverPoolSortedList(ISolverPoolBatching longTerm)
 {
     this.longTerm = longTerm;
     Statistics    = new SolverStatistics()
     {
         Name = GetType().Name
     };
 }
コード例 #9
0
 public SolverResultSummary(LibraryPuzzle puzzle, List <Path> solutions, ExitConditions.Conditions exited, string text, TimeSpan duration, SolverStatistics statistics)
 {
     Puzzle     = puzzle;
     Solutions  = solutions;
     Exited     = exited;
     Text       = text;
     Duration   = duration;
     Statistics = statistics;
 }
コード例 #10
0
        public void Update(ISolver caller, SolverState state, SolverStatistics global, string txt)
        {
            var dt = DateTime.Now - last;

            if (dt.TotalSeconds < sampleRateInSec)
            {
                return;
            }
            last = DateTime.Now;

            UpdateInner(caller, state, global, txt);
        }
コード例 #11
0
ファイル: TreeQueue.cs プロジェクト: danisky94/SokoSolve
 public TreeQueue(IEnumerable <SolverNode>?start, IDebugEventPublisher report)
 {
     Statistics  = new SolverStatistics();
     depthBands  = new List <Band>();
     this.report = report;
     count       = 0;
     if (start != null)
     {
         foreach (var ss in start)
         {
             Enqueue(ss);
         }
     }
 }
コード例 #12
0
 public SolverStatistics(SolverStatistics copy)
 {
     this.TotalNodes     = copy.TotalNodes;
     this.TotalDead      = copy.TotalDead;
     this.DepthCompleted = copy.DepthCompleted;
     this.DepthMax       = copy.DepthMax;
     this.DepthCurrent   = copy.DepthCurrent;
     this.Duplicates     = copy.Duplicates;
     this.Started        = copy.Started;
     this.Completed      = copy.Completed;
     this.Name           = copy.Name;
     this.Text           = copy.Text;
     this.Type           = copy.Type;
     this.MemUsed        = copy.MemUsed;
 }
コード例 #13
0
        protected override string Render(ISolver caller, SolverState state, SolverStatistics global, string txt)
        {
            if (global == null)
            {
                return(null);
            }

            var totalMemory = System.GC.GetTotalMemory(false);

            var delta = (prev != null) ? global.TotalNodes - prev.TotalNodes : global.TotalNodes;

            var sb = new FluentString()
                     .Append(txt)
                     .Sep()
                     .Append($"delta:{delta:#,##0}")
                     .Sep()
                     .Append($"mem({Humanise.SizeSuffix((ulong) totalMemory)} used")
                     .Block(b =>
            {
                if (DevHelper.TryGetTotalMemory(out var avail))
                {
                    b.Sep();
                    b.Append($"{Humanise.SizeSuffix(avail)} avail");
                }
            })
                     .Append(")");


            var telText = new FluentString(",")
                          .Append(global.DurationInSec.ToString()).Sep()
                          .Append(global.TotalNodes.ToString()).Sep()
                          .Append(global.NodesPerSec.ToString()).Sep()
                          .Append(delta.ToString()).Sep()
                          .Append(totalMemory.ToString()).Sep()
            ;

            tele.WriteLine(telText);

            prev = new SolverStatistics(global);



            return(sb);
        }
コード例 #14
0
 protected abstract string Render(ISolver caller, SolverState state, SolverStatistics global, string txt);
コード例 #15
0
 protected abstract void UpdateInner(ISolver caller, SolverState state, SolverStatistics global, string txt);
コード例 #16
0
 public SolverState()
 {
     Statistics = new SolverStatistics();
 }
コード例 #17
0
        public List <SolverResultSummary> Run(
            SolverRun run,
            SolverCommand baseCommand,
            ISolver solver,
            bool showSummary,
            BatchSolveComponent.BatchArgs?batchArgs = null)
        {
            if (run == null)
            {
                throw new ArgumentNullException(nameof(run));
            }
            if (baseCommand == null)
            {
                throw new ArgumentNullException(nameof(baseCommand));
            }
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver), "See: " + nameof(SingleThreadedForwardSolver));
            }

            Report.WriteLine("Puzzle Exit Conditions: {0}", run.PuzzleExit);
            Report.WriteLine("Batch Exit Conditions : {0}", run.BatchExit);
            Report.WriteLine("Environment           : {0}", DevHelper.RuntimeEnvReport());
            Report.WriteLine("Solver Environment    : v{0} -- {1}", SolverHelper.VersionUniversal, SolverHelper.VersionUniversalText);
            Report.WriteLine("Started               : {0}", DateTime.Now.ToString("u"));
            Report.WriteLine();

            var res   = new List <SolverResultSummary>();
            var start = new SolverStatistics
            {
                Started = DateTime.Now
            };
            SolverState?state            = null;
            var         pp               = 0;
            var         consecutiveFails = 0;

            foreach (var puzzle in run)
            {
                if (baseCommand.CheckAbort(baseCommand))
                {
                    Progress.WriteLine("EXITING...");
                    break;
                }

                try
                {
                    pp++;
                    Progress.WriteLine($"(Puzzle   {pp}/{run.Count}) Attempting: {puzzle.Ident} \"{puzzle.Name}\", R={StaticAnalysis.CalculateRating(puzzle.Puzzle)}. Stopping on [{baseCommand.ExitConditions}] ...");

                    Report.WriteLine("           Name: {0}", puzzle);
                    Report.WriteLine("          Ident: {0}", puzzle.Ident);
                    Report.WriteLine("         Rating: {0}", StaticAnalysis.CalculateRating(puzzle.Puzzle));
                    Report.WriteLine(puzzle.Puzzle.ToString());    // Adds 2x line feeds

                    IReadOnlyCollection <SolutionDTO> existingSolutions = null;
                    if (SkipPuzzlesWithSolutions && Repository != null)
                    {
                        existingSolutions = Repository.GetPuzzleSolutions(puzzle.Ident);
                        if (existingSolutions != null && existingSolutions.Any(
                                x => x.MachineName == Environment.MachineName && x.SolverType == solver.GetType().Name))
                        {
                            Progress.WriteLine("Skipping... (SkipPuzzlesWithSolutions)");
                            continue;
                        }
                    }



                    // #### Main Block Start --------------------------------------
                    var memStart     = GC.GetTotalMemory(false);
                    var attemptTimer = new Stopwatch();
                    attemptTimer.Start();
                    state = solver.Init(new SolverCommand(baseCommand)
                    {
                        Report = Report,
                        Puzzle = puzzle.Puzzle
                    });
                    var propsReport = GetPropReport(solver, state);
                    Tracking?.Begin(state);

                    try
                    {
                        solver.Solve(state);
                    }
                    catch (Exception e)
                    {
                        state.Exception = e;
                        state.Exit      = ExitConditions.Conditions.Error;
                        state.EarlyExit = true;
                    }
                    var memEnd = GC.GetTotalMemory(false);
                    state.Statistics.MemUsed = memEnd;
                    var memDelta     = memEnd - memStart;
                    var bytesPerNode = memDelta / state.Statistics.TotalNodes;
                    var maxNodes     = (ulong)0;
                    if (DevHelper.TryGetTotalMemory(out var totalMem))
                    {
                        maxNodes = totalMem / (ulong)bytesPerNode;
                    }
                    Report.WriteLine($"Memory Used: {Humanise.SizeSuffix(memEnd)}, delta: {Humanise.SizeSuffix(memDelta)} ~ {bytesPerNode:#,##0} bytes/node => max nodes:{maxNodes:#,##0}");
                    attemptTimer.Stop();
                    // #### Main Block End ------------------------------------------

                    state.Summary = new SolverResultSummary(
                        puzzle,
                        state.Solutions,
                        state.Exit,
                        SolverHelper.GenerateSummary(state),
                        attemptTimer.Elapsed,
                        state.Statistics
                        );

                    res.Add(state.Summary);

                    start.TotalNodes += state.Statistics.TotalNodes;
                    start.TotalDead  += state.Statistics.TotalDead;

                    Report.WriteLine("[DONE] {0}", state.Summary.Text);
                    Progress.WriteLine($" -> {state.Summary.Text}");

                    if (batchArgs != null && batchArgs.Save != null)
                    {
                        Console.WriteLine(" -> Saving...");
                        var binSer = new BinaryNodeSerializer();

                        var rootForward = state.GetRootForward();
                        if (rootForward != null)
                        {
                            var outState = System.IO.Path.Combine(batchArgs.Save, $"{puzzle.Ident}-forward.ssbn");
                            using (var f = File.Create(outState))
                            {
                                using (var bw = new BinaryWriter(f))
                                {
                                    binSer.WriteTree(bw, rootForward);
                                }
                            }
                            Report.WriteLine($"\tSaving State: {outState}");
                            Progress.WriteLine($"\tSaving State: {outState}");
                        }

                        var rootReverse = state.GetRootReverse();
                        if (rootReverse != null)
                        {
                            var outState = System.IO.Path.Combine(batchArgs.Save, $"{puzzle.Ident}-reverse.ssbn");
                            using (var f = File.Create(outState))
                            {
                                using (var bw = new BinaryWriter(f))
                                {
                                    binSer.WriteTree(bw, rootReverse);
                                }
                            }
                            Report.WriteLine($"\tSaving State: {outState}");
                            Progress.WriteLine($"\tSaving State: {outState}");
                        }
                    }

                    // Add Depth Reporting
                    Console.WriteLine(" -> Generating Reports...");
                    GenerateReports(state, solver);

                    if (Repository != null)
                    {
                        var id = StoreAttempt(solver, puzzle, state, propsReport.ToString());

                        if (id >= 0)
                        {
                            var solTxt = $"Checking against known solutions. SolutionId={id}";
                            Report.WriteLine(solTxt);
                            Console.WriteLine(solTxt);
                        }
                    }
                    else
                    {
                        Report.WriteLine($"Solution Repository not available: Skipping.");
                    }


                    if (state?.Summary?.Solutions != null && state.Summary.Solutions.Any()) // May have been removed above
                    {
                        consecutiveFails = 0;
                    }
                    else
                    {
                        consecutiveFails++;
                        if (StopOnConsecutiveFails != 0 && consecutiveFails > StopOnConsecutiveFails)
                        {
                            Progress.WriteLine("ABORTING... StopOnConsecutiveFails");
                            break;
                        }
                    }

                    Tracking?.End(state);

                    if (state.Exception != null)
                    {
                        Report.WriteLine("[EXCEPTION]");
                        WriteException(Report, state.Exception);
                    }
                    if (state.Exit == ExitConditions.Conditions.Aborted)
                    {
                        Progress.WriteLine("ABORTING...");
                        if (showSummary)
                        {
                            WriteSummary(res, start);
                        }
                        return(res);
                    }
                    if (start.DurationInSec > run.BatchExit.Duration.TotalSeconds)
                    {
                        Progress.WriteLine("BATCH TIMEOUT...");
                        if (showSummary)
                        {
                            WriteSummary(res, start);
                        }
                        return(res);
                    }

                    Progress.WriteLine();
                }
                catch (Exception ex)
                {
                    if (state != null)
                    {
                        state.Exception = ex;
                    }
                    Progress.WriteLine("ERROR: " + ex.Message);
                    WriteException(Report, ex);
                }
                finally
                {
                    state = null;

                    if (puzzle != run.Last())
                    {
                        GC.Collect();
                    }
                }
            }
            if (showSummary)
            {
                WriteSummary(res, start);
            }

            Report.WriteLine("Completed               : {0}", DateTime.Now.ToString("u"));
            return(res);
        }