Esempio n. 1
0
        public SolverEngine(ReaderEngine engine, SolvingMethod method, int length)
        {
            _isInitialized = true;
            _readerEngine = engine;
            _solverMethod = method;
            _caseLength = length;

            if (_readerEngine == ReaderEngine.Python)
            {
                _scriptReader = new PythonScriptReader();
            }
            else if (_readerEngine == ReaderEngine.CSharp)
            {
                _scriptReader = new BuiltInFunctions();
            }
            else if (_readerEngine == ReaderEngine.FSharp)
            {
            }
            else if (_readerEngine == ReaderEngine.Ruby)
            {
            }
            else if (_readerEngine == ReaderEngine.BuiltIn)
            {
            }
        }
Esempio n. 2
0
        internal static void Solve(PuzzleSource source, SolvingMethod method, DirectoryInfo directory, int id, int threads, int timeout, bool verbose)
        {
            try
            {
                GameState gameState = GetPuzzle(source, directory, id, verbose);

                Solver solver;
                double timeElapsed;

                switch (method)
                {
                case SolvingMethod.Sequential:
                    solver = new SequentialSolver(gameState, timeout);
                    Logging.Message($"Attempting to solve using {method} solver...", verbose);
                    break;

                case SolvingMethod.Parallel:
                    solver = new ThreadPoolSolver(gameState, timeout, threads);
                    Logging.Message($"Attempting to solve puzzle #{id} using {method} solver ({threads} threads)...");
                    break;

                default:
                    throw new NotImplementedException();
                }

                timeElapsed = TimeSolverAverage(solver, 1);

                Logging.Message($"{solver.Solutions.Count( x => true )} solution(s) found in {timeElapsed:0.00E+00} seconds:");

                foreach (GameState solution in solver.Solutions)
                {
                    Console.WriteLine();
                    solution.Print();
                }

                Console.WriteLine();
            }
            catch (NonogramException exception)
            {
                Logging.Error(exception.Message);
            }
            catch (TimeoutException exception)
            {
                Logging.Error(exception.Message);
            }
            catch (NotImplementedException)
            {
                Logging.Error("Feature not implemented.");
            }
            catch (System.Exception exception)
            {
                #if DEBUG
                Logging.Error("Unexpected exception");
                Console.WriteLine(exception);
                #else
                Logging.Error("Unknown");
                #endif
            }
        }
Esempio n. 3
0
 internal BenchmarkData(int puzzleID, int width, int height, SolvingMethod method, int threadCount, double times)
 {
     this.puzzleID    = puzzleID;
     this.width       = width;
     this.height      = height;
     this.method      = method;
     this.threadCount = threadCount;
     this.times       = times;
 }
 public Matrix GetMatrix(Expert expert, SolvingMethod solvingMethod)
 {
     if (expertMatrixDictionary.ContainsKey(expert))
     {
         return(expertMatrixDictionary[expert][(int)solvingMethod]);
     }
     else
     {
         AddExpert(expert);
         return(GetMatrix(expert, solvingMethod));
     }
 }
Esempio n. 5
0
 public override void Read(PackFileDeserializer des, BinaryReaderEx br)
 {
     base.Read(des, br);
     m_solvingMethod  = (SolvingMethod)br.ReadByte();
     m_bodiesToNotify = br.ReadByte();
     m_velocityStabilizationFactor = new hkUFloat8();
     m_velocityStabilizationFactor.Read(des, br);
     m_enableLinearImpulseLimit = br.ReadBoolean();
     br.ReadUInt16();
     m_breachImpulse = br.ReadSingle();
     m_inertiaStabilizationFactor = br.ReadSingle();
 }
Esempio n. 6
0
        public SolvingMethod InputSolvingMethod()
        {
            bool          valid = false;
            string        inputStr;
            SolvingMethod solvingMethod = SolvingMethod.None;

            Console.Clear();
            TowerUtilities.DisplayTowers(GetTowers());

            WriteLine("\n\nOptions: ");
            WriteLine("- M - Solve the puzzle manually");
            WriteLine("- A - Auto-solve");
            WriteLine("- S - Auto-solve Step by Step");

            do
            {
                inputStr = string.Empty;
                Write($"\nChoose an approach: ");
                inputStr = ReadKey().KeyChar.ToString().Trim().ToUpper();
                valid    = inputStr == "M" || inputStr == "A" || inputStr == "S" ? true : false;
                if (!valid)
                {
                    WriteLine("\nInvalid Input: Press \"M\" or \"A\" or \"S\" to choose an approach.");
                    valid = false;
                }
            } while (!valid);

            switch (inputStr)
            {
            case "M":
                solvingMethod = SolvingMethod.Manual;
                break;

            case "A":
                solvingMethod = SolvingMethod.Auto;
                break;

            case "S":
                solvingMethod = SolvingMethod.AutoSolveStepByStep;
                break;
            }

            return(solvingMethod);
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            bool    continueYN = true;
            TowerUI ui         = null;

            do
            {
                Console.Clear();
                ui = new TowerUI();

                int discs = ui.InputNumberOfDiscs();
                if (ui.CreateTowers())
                {
                    SolvingMethod solvingMethod = ui.InputSolvingMethod();

                    if (solvingMethod == SolvingMethod.Manual)
                    {
                        ui.InputMoveAction();
                    }
                    else if (solvingMethod == SolvingMethod.Auto)
                    {
                        ui.AutoSolve();
                    }
                    else if (solvingMethod == SolvingMethod.AutoSolveStepByStep)
                    {
                        ui.AutoSolveStepByStep();
                    }

                    // List Moves
                    //ui.ViewMoveRecords();
                    ui.PostGameReview();
                }

                // Ask to continue
                Write("\n\nWant to try again (press 'Y' to continue): ");
                string inputStr = ReadKey().KeyChar.ToString().ToUpper();
                continueYN = inputStr == "Y" ? true : false;
            } while (continueYN);

            ui = null;
            WriteLine("\n\nBye. See you again! Press any key to finish up.");
            ReadKey();
            return;
        }
Esempio n. 8
0
        public SolverEngine(ReaderEngine engine, SolvingMethod method, int length)
        {
            _randomGenerator = new Random(DateTime.Now.Millisecond);
            _solvedData = new List<ICustomer>();
            _carhopses = new List<Carhops>();
            _globalList = new FutureEventList();

            _isInitialized = true;
            _readerEngine = engine;
            _solverMethod = method;
            _caseLength = length;

            if (_readerEngine == ReaderEngine.Python)
            {
                _scriptReader = new PythonScriptReader();
            }
            else if (_readerEngine == ReaderEngine.BuiltIn)
            {
                _scriptReader = new BuiltInFunctions();
            }
        }
Esempio n. 9
0
        private string ConvertMethodToString(SolvingMethod solvingMethod)
        {
            switch (solvingMethod)
            {
            case SolvingMethod.PairComparison:
                return("Метод парных сравнений");

            case SolvingMethod.WeightedJudgement:
                return("Метод взвешенных экспертных оценок");

            case SolvingMethod.Prefer:
                return("Метод предпочтения");

            case SolvingMethod.Rang:
                return("Метод ранга");

            case SolvingMethod.FullPairMatching:
                return("Метод полного попарного сопоставления");

            default:
                return("");
            }
        }