Ejemplo n.º 1
0
        public CpSolverStatus Solve(CpModel model, SolutionCallback cb = null)
        {
            // Setup search.
            CreateSolveWrapper();
            if (string_parameters_ != null)
            {
                solve_wrapper_.SetStringParameters(string_parameters_);
            }
            if (log_callback_ != null)
            {
                solve_wrapper_.AddLogCallbackFromClass(log_callback_);
            }
            if (cb != null)
            {
                solve_wrapper_.AddSolutionCallback(cb);
            }

            response_ = solve_wrapper_.Solve(model.Model);

            // Cleanup search.
            if (cb != null)
            {
                solve_wrapper_.ClearSolutionCallback(cb);
            }
            ReleaseSolveWrapper();

            return(response_.Status);
        }
Ejemplo n.º 2
0
        private void solveButton_Click(object sender, EventArgs e)
        {
            if (nQueensInput.Text.Length > 0)
            {
                this.Cursor = Cursors.WaitCursor;

                solutionsList.Items.Clear();

                int nQueens = Int32.Parse(nQueensInput.Text.ToString());

                SolutionCallback solutionCallback = new SolutionCallback(this.OutputText);

                Solver solver = new Solver();

                string searchingMessage = string.Format(Strings.Searching, nQueens);
                this.OutputText(searchingMessage);
                this.OutputText("");

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                int numberOfSolutions = solver.Solve(nQueens, solutionCallback);

                stopwatch.Stop();

                string finalMessage = string.Format(Strings.FoundSolutions, numberOfSolutions, stopwatch.Elapsed.TotalSeconds);
                this.OutputText("");
                this.OutputText(finalMessage);

                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 3
0
        public CpSolverStatus SearchAllSolutions(CpModel model, SolutionCallback cb)
        {
            string old_parameters = string_parameters_;

            string_parameters_ += " enumerate_all_solutions:true";
            Solve(model, cb);
            string_parameters_ = old_parameters;
            return(response_.Status);
        }
Ejemplo n.º 4
0
 public CpSolverStatus SolveWithSolutionCallback(CpModel model, SolutionCallback cb)
 {
     if (string_parameters_ != null)
     {
         response_ = SatHelper.SolveWithStringParametersAndSolutionCallback(model.Model, string_parameters_, cb);
     }
     else
     {
         response_ = SatHelper.SolveWithStringParametersAndSolutionCallback(model.Model, "", cb);
     }
     return(response_.Status);
 }
Ejemplo n.º 5
0
 public CpSolverStatus SearchAllSolutions(CpModel model, SolutionCallback cb)
 {
     if (string_parameters_ != null)
     {
         string extra_parameters = " enumerate_all_solutions:true";
         response_ = SatHelper.SolveWithStringParametersAndSolutionCallback(
             model.Model, string_parameters_ + extra_parameters, cb);
     }
     else
     {
         string parameters = "enumerate_all_solutions:true";
         response_ = SatHelper.SolveWithStringParametersAndSolutionCallback(model.Model, parameters, cb);
     }
     return(response_.Status);
 }
Ejemplo n.º 6
0
 public static extern SolutionCallback SetOnSolutionHandler(IntPtr instance, SolutionCallback solutionCallback);
Ejemplo n.º 7
0
 public CpSolverStatus SolveWithSolutionCallback(CpModel model, SolutionCallback cb)
 {
     return(Solve(model, cb));
 }
Ejemplo n.º 8
0
        public ISolution Parse(string slnFilePath)
        {
            string slnFileText = File.ReadAllText(slnFilePath);

            ISolution solution = ISolutionFactory.create();

            //solution.setLogMessageCallback(log);
            solution.setErrorMessageCallback(log);

            SolutionCallback callback = new SolutionCallback();

            callback.LoadExternalAssemblyModuleCallback = new LoadExternalAssemblyModuleDelegate(loadExternalAssemblyModule2);
            callback.LoadTextFileCallback      = new LoadTextFileDelegate(loadTextFile);
            callback.PropertyEvaluatorCallback = new PropertyEvaluatorDelegate(propertyEvaluator);
            callback.BetterAssemblyCallback    = new BetterAssemblyDelegate(betterAssembly);

            modules = new Dictionary <string, IExternalAssemblyModule>();

            solution.loadSlnFile(
                slnFilePath,
                slnFileText.ToCharArray(),
                callback,
                project_namespace.pn_project_namespace
                );

            //apply configuration
            ISlnFileConfiguration[] configs = solution.getSlnFileConfigurations();
            string configuration            = configs[0].getConfiguration();
            string platform = configs[0].getPlatform();

            solution.applyConfiguration(
                configuration,
                platform,
                callback,
                true,
                AssemblyTypeMapping.atm_default
                );

            //parse
            //solution.setParseAccessibleTypesAndMembersOnly(true);
            solution.parse();


            //modules = new Dictionary<string, IExternalAssemblyModule>();

            //string slnFileText = File.ReadAllText(slnFilePath);

            //ISolution solution = ISolutionFactory.create();
            ////solution.setLogMessageCallback(log);

            //solution.loadSlnFile(
            //    slnFilePath,
            //    slnFileText.ToCharArray(),
            //    loadTextFile,
            //    loadExternalAssemblyModule2,
            //    project_namespace.pn_project_namespace
            //    );

            ////apply configuration
            //ISlnFileConfiguration[] configs = solution.getSlnFileConfigurations();
            //string configuration = configs[0].getConfiguration();
            //string platform = configs[0].getPlatform();
            //solution.applyConfiguration(
            //    configuration,
            //    platform,
            //    loadTextFile,
            //    loadExternalAssemblyModule2,
            //    propertyEvaluator,
            //    betterAssembly,
            //    true,
            //    AssemblyTypeMapping.atm_default
            //    );

            ////parse
            ////solution.setParseAccessibleTypesAndMembersOnly(true);
            ////solution.parse();

            return(solution);
        }