/// <summary>
        /// Sets the solver to use for the optimization
        ///  - When an incorrect solver is specified an alternative will automatically be chosen instead
        /// </summary>
        /// <param name="slvrtype"></param>
        internal void setSolver(SolverType slvrtype)
        {
            var obj   = solverInfo.OptimizationObjective;
            var trace = solverInfo.Trace;

            // Implement rules for ensuring the correct solver is chosen
            if (modelInfo.Type == ModelType.MarkowitzMeanVariance && obj == Objective.MinimizeRisk)
            {
                // Solver type must be either QP or if unconstrained Analytic
                if (slvrtype == SolverType.QP || slvrtype == SolverType.Analytic)
                {
                    this.solverInfo = new SolverInfo(slvr: slvrtype, opt: obj, trace: trace);
                }
            }
            else if (modelInfo.Type == ModelType.MarkowitzMeanVariance && obj == Objective.MaximizeReturn)
            {
                // Do some stuff here
            }
            else
            {
                // no reason why it can't be changed to whatever the user wants
                this.solverInfo = new SolverInfo(slvr: slvrtype, opt: obj, trace: trace);
            }

            this.ChangedFlag = true;
        }
        internal PortfolioSpec()
        {
            modelInfo  = new ModelInfo();
            solverInfo = new SolverInfo();
            portfInfo  = new PortfolioInfo();

            // Ensure the solver's objective funtion is the same as that of the model
            solverInfo = new SolverInfo(opt: modelInfo.OptimizationObjective);

            this.ChangedFlag = true;
        }
        internal PortfolioSpec(ModelInfo mod, SolverInfo opt, PortfolioInfo frontier)
        {
            modelInfo  = mod;
            solverInfo = opt;
            portfInfo  = frontier;

            // Ensure the solver's objective funtion is the same as that of the model
            solverInfo = new SolverInfo(opt: modelInfo.OptimizationObjective);

            this.ChangedFlag = true;
        }
        internal void setModelObjective(Objective obj)
        {
            var estim = modelInfo.Estimator;
            var mtype = modelInfo.Type;

            // Overwrite current model
            this.modelInfo = new ModelInfo(type: mtype, opt: obj, est: estim);

            // Ensure integrity
            this.solverInfo  = new SolverInfo(opt: modelInfo.OptimizationObjective);
            this.ChangedFlag = true;
        }
Пример #5
0
        // create the non-graphical parts of the game
        private void InitializeTiles1()
        {
            gameNumber++;
            logicalLock = false;

            minesLeftSize = Math.Max(3, (int)Math.Log10(gameDescription.mines) + 1);

            MinesLeftHolder.Width = 24 * minesLeftSize + 8;
            for (int i = 0; i < digits.Length; i++)
            {
                if (i < minesLeftSize)
                {
                    digits[i].Visibility = Visibility.Visible;
                }
                else
                {
                    digits[i].Visibility = Visibility.Hidden;
                }
            }

            int seed = 0;

            if (useSeed.IsChecked == true)
            {
                try {
                    seed = int.Parse(SeedTextBox.Text);
                } catch (Exception) {
                }
            }

            //game = new MinesweeperGame(gameDescription, seed);
            game       = new MinesweeperGame(gameDescription, seed, (hardcore.IsChecked == true));
            solverInfo = new SolverInfo(gameDescription, verbose);

            RenderMinesLeft();

            long start = DateTime.Now.Ticks;

            tiles         = new ActionResult[gameDescription.width, gameDescription.height];
            solverActions = new SolverActionHeader();   // remove any hints from the previous game

            Utility.Write("Ticks to build screen " + (DateTime.Now.Ticks - start));
        }
Пример #6
0
        // this method runs on a different thread. gameNumber can be changed by clicking chosing a new game from the UI thread.
        private static GameStatus AutoPlayRunner(MinesweeperGame game)
        {
            //long start = DateTime.Now.Ticks;

            SolverActionHeader solverActions;

            GameResult result = game.ProcessActions(firstPlay);

            SolverInfo solverInfo = new SolverInfo(game.description);

            while (result.status == GameStatus.InPlay)
            {
                solverInfo.AddInformation(result);                  // let the solver know what has happened

                solverActions = SolverMain.FindActions(solverInfo); // pass the solver info into the solver and see what it comes up with

                if (solverActions.solverActions.Count == 0)
                {
                    Write("No actions returned by the solver!!");
                    break;
                }

                result = game.ProcessActions(solverActions.solverActions);

                //Write("Game controller returned " + result.actionResults.Count + " results from this action");

                //foreach (SolverAction action in solverActions) {
                //    Write("Playing " + action.AsText() + " probability " + action.safeProbability);
                //}
            }

            //long end = DateTime.Now.Ticks;

            //Write("game took " + (end - start) + " ticks");


            return(result.status);
        }