Ejemplo n.º 1
0
        public IActionResult SolveStart(string id, bool stopOnSolution, double duration = 1)
        {
            var ident = PuzzleIdent.Parse(id);
            var p     = compLib.GetPuzzleWithCaching(ident);

            var solver        = new MultiThreadedForwardReverseSolver(new SolverNodeFactoryPoolingConcurrentBag("byteseq"));
            var solverCommand = new SolverCommand()
            {
                Puzzle         = p.Puzzle,
                ExitConditions = new ExitConditions()
                {
                    Duration       = TimeSpan.FromMinutes(duration),
                    StopOnSolution = true
                }
            };
            var model = new SolverModel()
            {
                Token   = DateTime.Now.Ticks,
                Puzzle  = p,
                Command = solverCommand,
                State   = solver.Init(solverCommand)
            };

            staticState[model.Token] = model;

            model.Task = Task.Run(() =>
            {
                solver.Solve(model.State);
                model.IsFinished = true;
            });

            return(RedirectToAction("SolveMem", new { id, token = model.Token }));
        }
Ejemplo n.º 2
0
        public SolverViewModel(SolverModel solverModel, InputModel inputModel, DrawingModel drawingModel)
        {
            _solverModel  = solverModel;
            _inputModel   = inputModel;
            _drawingModel = drawingModel;

            InitializeCommand();
        }
Ejemplo n.º 3
0
        private static SolverNode GetNode(SolverModel state, int?nodeid)
        {
            var node = nodeid == null
                ? state.RootForward
                : nodeid > 0
                    ? (state.RootForward?.Recurse().FirstOrDefault(x => x.SolverNodeId == nodeid.Value)
                       ?? state.RootReverse?.Recurse().FirstOrDefault(x => x.SolverNodeId == nodeid.Value))
                    : state.RootReverse;

            return(node);
        }
Ejemplo n.º 4
0
        public IActionResult StartFromFile(string file)
        {
            var fileName = Path.GetFileName(file);
            var ident    = PuzzleIdent.Parse(fileName.Substring(0, fileName.IndexOf("-")));
            var p        = compLib.GetPuzzleWithCaching(ident);

            var solver        = new MultiThreadedForwardReverseSolver(new SolverNodeFactoryPoolingConcurrentBag("byteseq"));
            var solverCommand = new SolverCommand()
            {
                Puzzle         = p.Puzzle,
                ExitConditions = new ExitConditions()
                {
                    Duration       = TimeSpan.FromMinutes(0),
                    StopOnSolution = true
                }
            };
            var model = new SolverModel()
            {
                Token   = DateTime.Now.Ticks,
                Puzzle  = p,
                Command = solverCommand,
            };

            staticState[model.Token] = model;

            model.Task = Task.Run(() =>
            {
                var ser = new BinaryNodeSerializer();
                using (var f = System.IO.File.OpenRead(file))
                {
                    using (var br = new BinaryReader(f))
                    {
                        model.RootForward = ser.AssembleTree(br);
                    }
                }
                model.IsFinished = true;
            });

            return(RedirectToAction("SolveMem", new { id = ident.ToString(), token = model.Token }));
        }
Ejemplo n.º 5
0
 public void SetSolverModel(SolverModel pModel)
 {
     Newton.NewtonSetSolverModel(m_Handle, (int)pModel);
 }
Ejemplo n.º 6
0
 //NOTE:  Use Adaptive for games (exact is slow)
 public void SetSolverModel(SolverModel model)
 {
     Newton.NewtonSetSolverModel(_handle, (int)model);
 }
Ejemplo n.º 7
0
 public void SetSolverModel(SolverModel pModel)
 {
     Newton.NewtonSetSolverModel(m_Handle, (int)pModel);
 }
Ejemplo n.º 8
0
 public void SetSolverModel(SolverModel model)
 {
     NativeAPI.SetSolverModel(handle, (int)model);
 }