Ejemplo n.º 1
0
        public PositionInformation_Form(Tree parent_input, GamePosition gp_input)
        {
            InitializeComponent();
            parent = parent_input;
            gp     = gp_input;

            if (gp.defined)
            {
                if (gp.LHStrategy.Count == 0)
                {
                    SolveGame(gp);
                }
                else
                {
                    show_result();
                }
            }
        }
Ejemplo n.º 2
0
 public void create_model_btn_Click(object sender, EventArgs e)
 {
     if ((gp.DataForm != null) && (gp.DataForm.Visible))
     {
         gp.DataForm.Focus();
     }
     else
     {
         BimatrixGamesForm form = new BimatrixGamesForm(gp);
         //D//
         DebugClass.BG = form;
         GamePosition before = gp;
         gp.DataForm        = form;
         form.StartPosition = FormStartPosition.CenterScreen;
         form.Text          = this.Text;
         form.Tag           = this;
         form.Show();
     }
 }
Ejemplo n.º 3
0
        public ParametersWeightsForm(GamePosition GP)
        {
            InitializeComponent();
            gp = GP;

            this.Text = "Parameters importance: '";
            if (GP.name != null)
            {
                this.Text += GP.name;
            }
            else
            {
                this.Text += GP.ID;
            }
            this.Text += "' position";

            Graphic_Interface.Grid G = new Graphic_Interface.Grid(dataGridView1, Information.AP_Names.Count, gp.N, "T", "T");
            G.initialize();
            dataGridView1.TopLeftHeaderCell.Value = "Parameters weights";
            for (int i = 0; i < Information.AP_Names.Count - 1; i++)
            {
                dataGridView1.Rows[i].HeaderCell.Value = Information.AP_Names[i + 1];
            }

            for (int i = 0; i < Information.AP_Names.Count; i++)
            {
                dataGridView1.Rows[i].HeaderCell.Value = Information.AP_Names[i] + " (" + Information.AP_KeyLetters[i] + ")";
            }

            for (int i = 0; i < gp.N; i++)
            {
                string Key = "";
                if ((Information.PlayersNames[i] == "") || (Information.PlayersNames[i] == null))
                {
                    Key = "Player " + (i + 1).ToString();
                }
                else
                {
                    Key = Information.PlayersNames[i];
                }

                dataGridView1.Columns[i].HeaderText = Key;
            }

            if (gp.Weights.Count < Information.AP_Names.Count)
            {
                int gpWC = gp.Weights.Count;
                for (int i = gpWC; i < Information.AP_Names.Count; i++)
                {
                    gp.Weights.Add(new List <string>());
                    for (int j = 0; j < gp.N; j++)
                    {
                        gp.Weights[i].Add("0");
                    }
                }
            }

            for (int i = 0; i < Information.AP_Names.Count; i++)
            {
                for (int j = 0; j < gp.N; j++)
                {
                    if (gp.Weights[i][j] == "")
                    {
                        gp.Weights[i][j] = "0";
                    }
                    dataGridView1[j, i].Value = gp.Weights[i][j];
                }
            }

            G.create_headers();

            this.Width  = dataGridView1.Right + dataGridView1.Left + 40;
            this.Height = dataGridView1.Top + dataGridView1.Bottom + 60;
        }
Ejemplo n.º 4
0
        public void SolveGame(GamePosition gp_input)
        {
            gp.N             = gp_input.N;
            gp.Strategies    = gp_input.Strategies;
            gp.payoffs       = gp_input.payoffs;
            gp.AdParamValues = gp_input.AdParamValues;

            for (int i = 0; i < gp.N; i++)
            {
                gp.V.Add(new List <double>());
                gp.LHStrategy.Add(new List <List <double> >());
                gp.OptimalStrategy_R.Add(new List <List <double> >());
                for (int j = 0; j < gp.N; j++)
                {
                    gp.V[i].Add(0);
                    gp.LHStrategy[i].Add(new List <double>());
                    gp.OptimalStrategy_R[i].Add(new List <double>());
                }
            }

            gp.Utility.Clear();
            for (int i = 0; i < gp.N; i++)
            {
                gp.Utility.Add(new List <List <List <double> > >());
                for (int j = 0; j < gp.N; j++)
                {
                    gp.Utility[i].Add(new List <List <double> >());
                }
            }

            for (int i = 0; i < gp.N; i++)
            {
                for (int j = 0; j < gp.N; j++)
                {
                    gp.Utility[i].Add(new List <List <double> >());
                    if (i < j)
                    {
                        GameTheory.LemkeHowson LH = new GameTheory.LemkeHowson(gp.Strategies[i], gp.Strategies[j]);
                        gp.CalculatePayoffsValues();

                        LH.A             = gp.CreateUtilityPayoffMatrix(i, j);
                        LH.B             = gp.CreateUtilityPayoffMatrix(j, i);
                        gp.Utility[i][j] = LH.A;
                        gp.Utility[j][i] = LH.B;
                        //DebugForm d = new DebugForm(LH.A, LH.B);
                        //d.ShowDialog();

                        LH.salvation();
                        gp.V[i][j] = LH.prize_1;
                        gp.V[j][i] = LH.prize_2;

                        if ((LH.prize_1 == 0) && (LH.prize_2 == 0))
                        {
                            System.Windows.Forms.MessageBox.Show
                                ("Lemke-Howson got into endless loop. /nAlgorithm is not optimal");
                            this.Close();
                        }
                        else
                        {
                            for (int k = 0; k < gp.Strategies[i]; k++)
                            {
                                gp.LHStrategy[i][j].Add(0);
                                gp.OptimalStrategy_R[i][j].Add(0);
                            }
                            for (int k = 0; k < gp.Strategies[j]; k++)
                            {
                                gp.LHStrategy[j][i].Add(0);
                                gp.OptimalStrategy_R[j][i].Add(0);
                            }

                            for (int k = 0; k < LH.strat1.Count; k++)
                            {
                                gp.LHStrategy[i][j][k]        = LH.strat1[k];
                                gp.OptimalStrategy_R[i][j][k] = LH.strat1[k];
                            }

                            for (int k = 0; k < LH.strat2.Count; k++)
                            {
                                gp.LHStrategy[j][i][k]        = LH.strat2[k];
                                gp.OptimalStrategy_R[j][i][k] = LH.strat2[k];
                            }
                        }
                    }
                }
            }

            gp.defined = true;

            show_result();
            menuStrip1.Show();
        }
Ejemplo n.º 5
0
        private void WritePath()
        {
            Path.Add(EndPositions[OptIndex]);

            GamePosition Pendulum = Path.Last();

            if (Pendulum.name != "")
            {
                PathLB.Text = Pendulum.name;
            }
            else
            {
                PathLB.Text = Pendulum.ID;
            }
            while (Pendulum.parent != null)
            {
                Pendulum = Pendulum.parent;
                Path.Insert(0, Pendulum);
            }

            for (int i = 0; i < Path.Count - 1; i++)
            {
                for (int j = 0; j < Path[i].children.Count; j++)
                {
                    if (Path[i + 1] == Path[i].children[j])
                    {
                        Direction.Add(j);
                    }
                }
            }


            PathLB.Text = "";
            for (int i = 0; i < Path.Count; i++)
            {
                if ((Path[i].name != null) && (Path[i].name != ""))
                {
                    PathLB.Text += Path[i].name;
                }
                else
                {
                    PathLB.Text += Path[i].ID;
                }
                if (i != Path.Count - 1)
                {
                    PathLB.Text += "-->";
                }
            }

            panel1.Width = PathLB.Right + 10;

            for (int i = 0; i < Information.players_number; i++)
            {
                Strategies.Add(new List <string>());
            }

            for (int i = 0; i < Path.Count - 1; i++)
            {
                List <string> Combination = Path[i].Combinations[Direction[i]];
                for (int j = 0; j < Combination.Count; j++)
                {
                    Strategies[j].Add(Combination[j]);
                }
            }

            for (int i = 0; i < Information.players_number; i++)
            {
                CreatePlayerPanel(i);
            }
        }
Ejemplo n.º 6
0
 public FunctionEditor(Object Father, List <double> ValuesInput, ref TextBox Current, GamePosition gp)
 {
     InitializeComponent();
     if (Father is ExtensiveFormGame)
     {
         EF = (Father as ExtensiveFormGame);
     }
     else
     {
         BG = (Father as BimatrixGamesForm);
     }
     T      = Current;
     Values = ValuesInput;
     if (T.Text != "")
     {
         Function_TB.Text = T.Text;
     }
 }
        public ParametersValuesForm(GamePosition GP)
        {
            InitializeComponent();
            gp = GP;

            this.Text = "Parameters values: '";
            if (GP.name != null)
            {
                this.Text += GP.name;
            }
            else
            {
                this.Text += GP.ID;
            }
            this.Text += "' position";

            Graphic_Interface.Grid G = new Graphic_Interface.Grid(dataGridView1, Information.AP_Names.Count, gp.N, "T", "T");
            G.initialize();
            for (int i = 0; i < Information.AP_Names.Count - 1; i++)
            {
                dataGridView1.Rows[i].HeaderCell.Value = Information.AP_Names[i + 1];
            }
            dataGridView1.TopLeftHeaderCell.Value = "Parameters values";
            dataGridView1.Rows[0].ReadOnly        = true;
            for (int i = 0; i < Information.AP_Names.Count; i++)
            {
                dataGridView1.Rows[i].HeaderCell.Value = Information.AP_Names[i] + " (" + Information.AP_KeyLetters[i] + ")";
            }

            for (int i = 0; i < gp.N; i++)
            {
                string Key = "";
                if ((Information.PlayersNames[i] == "") || (Information.PlayersNames[i] == null))
                {
                    Key = "Player " + (i + 1).ToString();
                }
                else
                {
                    Key = Information.PlayersNames[i];
                }

                dataGridView1.Columns[i].HeaderText = Key;
            }
            for (int i = 0; i < gp.N; i++)
            {
                if (gp.cash.Count > i)
                {
                    dataGridView1[i, 0].Value = gp.cash[i];
                }
            }

            for (int i = 0; i < gp.AdParamValues.Count; i++)
            {
                for (int j = 0; j < gp.AdParamValues[i].Count; j++)
                {
                    dataGridView1[j, i + 1].Value = gp.AdParamValues[i][j];
                }
            }

            G.create_headers();

            this.Width  = dataGridView1.Right + dataGridView1.Left + 40;
            this.Height = dataGridView1.Top + dataGridView1.Bottom + 60;
        }