Exemplo n.º 1
0
        public GridWorldForm2(GridWorldMap gw1, int blockSize, ISolver A, INode start, INode goal)
        {
            //set image
            InitializeComponent();

            GridWorldMap gwMap = DrawResults(gw1, blockSize, A.getPolicy(), start, goal);



            pictureBox1.Width  = gwMap.BitMap.Width;
            pictureBox1.Height = gwMap.BitMap.Height;
            pictureBox1.Image  = gwMap.BitMap;
            pictureBox1.Update();


            // print solver parameters to dataview
            DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

            col            = new DataGridViewTextBoxColumn();
            col.HeaderText = "Search parameters";
            ResultView.Columns.Add(col);
            ResultView.RowHeadersWidth = 50;

            col            = new DataGridViewTextBoxColumn();
            col.HeaderText = "Values";
            ResultView.Columns.Add(col);
            ResultView.RowHeadersWidth = 50;

            DataGridViewRow row;

            int i = 0;

            foreach (KeyValuePair <string, string> pair in A.GetSearchInfo().SearchResults.Union(A.GetSearchInfo().SearchParameters))
            {
                row = new DataGridViewRow();

                row.HeaderCell.Value = String.Format("{0}", i + 1);

                ResultView.Rows.Add(row);

                ResultView.Rows[i].Cells[0].Value = pair.Key;
                ResultView.Rows[i].Cells[1].Value = pair.Value;
                i += 1;
            }


            //add total reward
            row = new DataGridViewRow();
            row.HeaderCell.Value = String.Format("{0}", i + 1);
            ResultView.Rows.Add(row);
            ResultView.Rows[i].Cells[0].Value = "Cummulative reward";
            ResultView.Rows[i].Cells[1].Value = SumQ.ToString();

            ResultView.Width = col.Width + ResultView.RowHeadersWidth;
            ResultView.Update();
        }
Exemplo n.º 2
0
        public SolutionForm(ISolver A, IEnvironment env, INode start, INode goal)
        {
            InitializeComponent();

            DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

            col.HeaderText = "Operators";
            col.SortMode   = DataGridViewColumnSortMode.NotSortable;
            operatorsView.Columns.Add(col);
            operatorsView.RowHeadersWidth = 50;
            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;


            IState      currentState = start.State;
            IPolicy     policy       = A.getPolicy();
            ISearchInfo info         = A.GetSearchInfo();

            if (policy == null)
            {
                MessageBox.Show("No solution found");
            }


            //use policy to find solution

            int             i    = 0;
            int             maxi = 3000;
            double          SumQ = 0;
            DataGridViewRow row;

            while (policy != null && !currentState.Equals(goal.State) && i < maxi)
            {
                row = new DataGridViewRow();

                row.HeaderCell.Value = String.Format("{0}", i + 1);

                IOperator op = policy.action(currentState);

                operatorsView.Rows.Add(row);

                operatorsView.Rows[i].Cells[0].Value = op.Name;

                IOutcome outcome = env.act(currentState, policy.action(currentState));

                currentState = outcome.State;
                stateList.Add(outcome.State);

                SumQ += outcome.Reward;

                i += 1;
            }

            if (i >= maxi)
            {
                MessageBox.Show("No solution found");
                stateList.Clear();
            }
            operatorsView.Update();

            // print solver parameters + results
            col            = new DataGridViewTextBoxColumn();
            col.HeaderText = "Properties";
            ResultView.Columns.Add(col);
            ResultView.RowHeadersWidth = 50;

            col            = new DataGridViewTextBoxColumn();
            col.HeaderText = "Values";
            ResultView.Columns.Add(col);
            ResultView.RowHeadersWidth = 50;
            col.AutoSizeMode           = DataGridViewAutoSizeColumnMode.Fill;

            i = 0;
            foreach (KeyValuePair <string, string> pair in info.SearchResults.Union(info.SearchParameters))
            {
                row = new DataGridViewRow();

                row.HeaderCell.Value = String.Format("{0}", i + 1);

                ResultView.Rows.Add(row);

                ResultView.Rows[i].Cells[0].Value = pair.Key;
                ResultView.Rows[i].Cells[1].Value = pair.Value;
                i += 1;
            }


            //print total reward
            row = new DataGridViewRow();
            row.HeaderCell.Value = String.Format("{0}", i + 1);
            ResultView.Rows.Add(row);
            ResultView.Rows[i].Cells[0].Value = "Cummulative reward";
            ResultView.Rows[i].Cells[1].Value = SumQ.ToString();

            ResultView.Width = col.Width + ResultView.RowHeadersWidth + 20;
            ResultView.Update();

            ConfigureDGV(N);
            NPuzzleState npState = (NPuzzleState)start.State;

            FillDGV(npState.Tiles, N);
        }