public OptimalCoalitionForm(List <string> Coalitions)
 {
     InitializeComponent();
     this.Coalitions = Coalitions;
     pp = new UI.ControlsAligner(PanelsPanel);
     FirstInterfaceSetup_Stability();
 }
        private void SecondInterfaceSetup_PayoffDivision()
        {
            //PanelsPanel.Hide();
            DivisionPanel.Show();

            UI.ControlsAligner cpanel = new UI.ControlsAligner(PanelsPanel.Controls[0]);
            for (int i = 0; i < PanelsPanel.Controls[0].Controls.Count - 1; i++)
            {
                cpanel.AddElement(PanelsPanel.Controls[0].Controls[i]);
            }
            cpanel.AddElement(PanelsPanel.Controls[0].Controls[PanelsPanel.Controls[0].Controls.Count - 1], false);
            cpanel.Align();

            UI.ControlsAligner spanel = new UI.ControlsAligner(PanelsPanel);
            spanel.AddElement(PanelsPanel.Controls[0]);
            spanel.Align(true);

            UI.ControlsAligner dpanel = new UI.ControlsAligner(DivisionPanel);
            dpanel.AddElement(PayoffDivisionLabel);
            for (int i = 0; i < Database.G.N; i++)
            {
                Label l = new Label();
                l.Text      = "µ(" + (i + 1) + ") = ";
                l.Font      = new System.Drawing.Font("Bookman Old Style", 14);
                l.ForeColor = Color.White;
                l.Size      = TextRenderer.MeasureText(l.Text, l.Font);

                TextBox tb = new TextBox();
                tb.Font      = new System.Drawing.Font("Bookman Old Style", 16);
                tb.TextAlign = HorizontalAlignment.Center;
                tb.Width     = 100;
                tb.Text      = "";

                if (i == 0)
                {
                    dpanel.AddElement(l, true);
                }
                else
                {
                    dpanel.AddElement(l, false);
                }
                dpanel.AddElement(tb, false, "HorBind");

                DivisionPanel.Controls.Add(l);
                DivisionPanel.Controls.Add(tb);
                TB.Add(tb);
            }
            dpanel.AddElement(RationalityCB, true, "Left");
            dpanel.Align();

            UI.ControlsAligner form = new UI.ControlsAligner(this);
            form.AddElement(PanelsPanel);
            form.AddElement(DivisionPanel, false);
            form.AddElement(FinishBTN, true, "Right");
            form.Align();
        }
        private void FirstInterfaceSetup_Stability()
        {
            GenerateCoalitionPanel(Coalitions[0], true);
            for (int i = 1; i < Coalitions.Count; i++)
            {
                GenerateCoalitionPanel(Coalitions[i], false);
            }
            pp.Align(true);

            UI.ControlsAligner form = new UI.ControlsAligner(this);
            form.AddElement(PanelsPanel);
            form.AddElement(FinishBTN, true, "Right");
            form.Align();
        }
 private void CreateNavigationPanel()
 {
     UI.ControlsAligner npanel = new UI.ControlsAligner(NavigationPanel);
     for (int i = 0; i < G.SingleGames.Count; i++)
     {
         CreateNavigationButton(i);
         if (i == 0)
         {
             npanel.AddElement(NavigationPanel.Controls[NavigationPanel.Controls.Count - 1], true, "Stretch");
         }
         else
         {
             npanel.AddElement(NavigationPanel.Controls[NavigationPanel.Controls.Count - 1], false, "Stretch");
         }
     }
     npanel.WidthFixed = true;
     npanel.Align(true);
 }
        //Test
        //public ViewCooperativeGameForm()
        //{
        //    InitializeComponent();
        //    Database.G = new CooperativeGame();
        //    Database.G.Generate(3);
        //    Database.G.GenerateCoalitions();
        //    Database.G.SolveCooperativeGame();
        //    G = Database.G.FindGame(Database.G.CoalitionsInText[0][0]);
        //    CGStudentProgress.SectionsCount = 2;

        //    FirstInterfaceSetup_CooperativeGameModelFormation();
        //    //SecondInterfaceSetup_Domination();
        //}

        private void FirstInterfaceSetup_CooperativeGameModelFormation()
        {
            StrategiesPanel.Show();
            B.Hide();

            UI.TWDNGrid Gs = new UI.TWDNGrid(S, 1, Database.G.N);
            Gs.InitializeHeaders("", "Количество стратегий", "Игрок", false, true);
            Gs.InitializeGrid(Database.G.S);

            UI.Grid Ga = new UI.Grid(A, Math.Min(10, G.SingleGames[0].A.Count), Math.Min(10, G.SingleGames[0].A[0].Count));
            A.Tag = Ga;
            Ga.InitializeHeaders("Стратегии", 100, 50);
            Ga.InitializeGrid();
            A.EditMode    = DataGridViewEditMode.EditProgrammatically;
            A.ReadOnly    = true;
            A.StandardTab = true;

            UI.ControlsAligner form = new UI.ControlsAligner(this);
            form.AddElement(NavigationPanel, true, "Stretch");
            form.AddElement(Task1Panel);
            form.AddElement(StrategiesPanel);
            form.AddElement(MatrixesPanel);
            form.AddElement(SkipBTN, true, "Left");
            form.AddElement(FinishBTN, false, "Right");

            UI.ControlsAligner spanel = new UI.ControlsAligner(StrategiesPanel);
            spanel.AddElement(S);
            spanel.Align(true);

            UI.ControlsAligner mpanel = new UI.ControlsAligner(MatrixesPanel);
            mpanel.AddElement(A);
            mpanel.Align(true);

            form.Align();
            CreateNavigationPanel();
            this.Text = "Заполните вектора стратегий";
        }
Example #6
0
        public TestSelectionForm()
        {
            InitializeComponent();

            GenerateResultPanels();

            UI.ControlsAligner p = new UI.ControlsAligner(panel1);
            p.AddElement(coopGamesButton);
            if (CGStudentProgress.Finished)
            {
                p.AddElement(CGResult, false, "HorBind");
            }

            p.AddElement(CKernelButton, true, "Stretch");
            if (CKResult.Visible)
            {
                p.AddElement(CKResult, false, "HorBind");
            }

            p.AddElement(shapleyButton, true, "Stretch");
            if (ShapleyResult.Visible)
            {
                p.AddElement(ShapleyResult, false, "HorBind");
            }

            p.Left             *= 2;
            p.Right            *= 2;
            p.Top              *= 2;
            p.Bottom           *= 2;
            p.VerticalInterval *= 2;
            p.Align();


            UI.ControlsAligner form = new UI.ControlsAligner(this);
            form.AddElement(panel1);
            form.Align();
        }
        private void SecondInterfaceSetup_Domination()
        {
            Task1Panel.Hide();
            Task2Panel.Show();
            NavigationPanel.Hide();
            StrategiesPanel.Hide();
            B.Show();
            CreateArrays(0, 1);

            UI.ControlsAligner gpanel = new UI.ControlsAligner(MatrixesPanel);
            gpanel.AddElement(A);
            gpanel.AddElement(B, false);
            gpanel.Align();

            UI.ControlsAligner form = new UI.ControlsAligner(this);
            form.AddElement(Task2Panel);
            form.AddElement(MatrixesPanel);
            form.AddElement(SkipBTN, true, "Left");
            form.AddElement(FinishBTN, false, "Right");
            form.Align();

            this.Location = new Point((Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, 50);
            this.Text     = "Сократите матрицы используя отношение доминирования";
        }
        private void FourthInterfaceSetup_PayoffDistributionAndSufficiency()
        {
            Random R = new Random((int)DateTime.Now.Ticks);

            //CGStudentProgress.DistributionType = R.Next(0, 2); //0 = contribution in a coalition price; 1 = incooperative payoff
            CGStudentProgress.DistributionType = 1;
            if (CGStudentProgress.DistributionType == 0)
            {
                PayoffDivisionLabel.Text += " с учетом индивидуальных вкладов\nигроков в выигрыш коалиции.";
            }
            else
            {
                PayoffDivisionLabel.Text += " с учетом индивидуальных выигрышей\nигроков в некооперативной игре.";
            }

            PayoffDivisionLabel.TextAlign = ContentAlignment.MiddleCenter;

            CoalitionAPayoffLabel.Text += G.SingleGames[0].FirstPlayer + " = " + G.SingleGames[0].Ha.ToString("0.00");
            CoalitionBPayoffLabel.Text += G.SingleGames[0].SecondPlayer + " = " + G.SingleGames[0].Hb.ToString("0.00");;
            GameFunctionLabel.Text     += (G.SingleGames[0].Ha + G.SingleGames[0].Hb).ToString("0.00");
            for (int i = 0; i < G.SingleGames[0].x.Count; i++)
            {
                x.Text += G.SingleGames[0].x[i].ToString("0.00") + " ";
            }
            x.Text += ")";

            for (int i = 0; i < G.SingleGames[0].y.Count; i++)
            {
                y.Text += G.SingleGames[0].y[i].ToString("0.00") + " ";
            }
            y.Text += ")";

            UI.ControlsAligner quizpanel = new UI.ControlsAligner(PayoffDivisionPanel);
            quizpanel.AddElement(GameFunctionLabel);
            quizpanel.AddElement(CoalitionAPayoffLabel);
            quizpanel.AddElement(CoalitionBPayoffLabel, false);
            quizpanel.AddElement(x);
            quizpanel.AddElement(y);
            quizpanel.AddElement(SufficiencyLabel);
            quizpanel.AddElement(YesRB_CG);
            quizpanel.AddElement(NoRB_CG, false);

            quizpanel.AddElement(FirstLine);

            quizpanel.AddElement(PayoffDivisionLabel);
            for (int i = 0; i < Database.G.N; i++)
            {
                Label l = new Label();
                l.Text      = "µ(" + (i + 1) + ") = ";
                l.Font      = new System.Drawing.Font("Bookman Old Style", 14);
                l.ForeColor = Color.White;
                l.Size      = TextRenderer.MeasureText(l.Text, l.Font);

                TextBox tb = new TextBox();
                tb.Font      = new System.Drawing.Font("Bookman Old Style", 16);
                tb.TextAlign = HorizontalAlignment.Center;
                tb.Width     = 100;
                tb.Text      = "";

                if (i == 0)
                {
                    quizpanel.AddElement(l, true);
                }
                else
                {
                    quizpanel.AddElement(l, false);
                }
                quizpanel.AddElement(tb, false, "HorBind");

                PayoffDivisionPanel.Controls.Add(l);
                PayoffDivisionPanel.Controls.Add(tb);
                PayoffDistributionTB.Add(tb);
            }

            quizpanel.AddElement(SecondLine);

            quizpanel.AddElement(DistributionRationalityLabel);
            quizpanel.AddElement(RationalityPanel, true, "Stretch");
            quizpanel.Align();
            RationalityPanel.Top -= 10;

            Graphical2x2SolutionPanel.Hide();
            PayoffDivisionPanel.Show();
            MatrixesPanel.Hide();

            UI.ControlsAligner form = new UI.ControlsAligner(this);
            form.AddElement(PayoffDivisionPanel);
            form.AddElement(SkipBTN, true, "Left");
            form.AddElement(FinishBTN, false, "Right");
            form.Align();

            UI.ControlsAligner rpanel = new UI.ControlsAligner(RationalityPanel);
            rpanel.AddElement(YesRB_RD);
            rpanel.AddElement(NoRB_RD, false);
            rpanel.Align(true);
        }
        private void ThirdInterfaceSetup_GraphicalSolution(bool skipped)
        {
            Task2Panel.Hide();

            if (skipped)
            {
                List <int>    Drows    = new List <int>();
                List <int>    Dcolumns = new List <int>();
                List <string> Cheaders = new List <string>();
                List <string> Rheaders = new List <string>();
                SingleGame    D        = G.SingleGames[0].Dominate(Drows, Dcolumns);

                for (int i = 0; i < Drows.Count; i++)
                {
                    Rheaders.Add(A.Rows[Drows[i]].HeaderCell.Value.ToString());
                }
                for (int i = 0; i < Dcolumns.Count; i++)
                {
                    Cheaders.Add(A.Columns[Dcolumns[i]].HeaderCell.Value.ToString());
                }
                Ga             = new UI.StrategiesGrid(A, D.A.Count, D.A[0].Count);
                Gb             = new UI.StrategiesGrid(B, D.A.Count, D.A[0].Count);
                Ga.LimitedSize = true;
                Gb.LimitedSize = true;
                Ga.InitializeHeaders("", G.SingleGames[0].FirstPlayer, G.SingleGames[0].SecondPlayer, Database.G.S);
                Gb.InitializeHeaders("", G.SingleGames[0].FirstPlayer, G.SingleGames[0].SecondPlayer, Database.G.S);
                Ga.InitializeGrid(D.A);
                Gb.InitializeGrid(D.B);
                for (int i = 0; i < A.Rows.Count; i++)
                {
                    A.Rows[i].HeaderCell.Value = Rheaders[i];
                    B.Rows[i].HeaderCell.Value = Rheaders[i];
                }
                for (int j = 0; j < A.ColumnCount; j++)
                {
                    A.Columns[j].HeaderCell.Value = Cheaders[j];
                    B.Columns[j].HeaderCell.Value = Cheaders[j];
                }
            }

            if ((A.Rows.Count == 2) && (A.Columns.Count == 2))
            {
                Graphical2x2SolutionPanel.Show();

                UI.ControlsAligner gpanel = new UI.ControlsAligner(MatrixesPanel);
                gpanel.AddElement(A);
                gpanel.AddElement(B, false);
                gpanel.Align();

                UI.ControlsAligner form = new UI.ControlsAligner(this);
                form.AddElement(MatrixesPanel);
                form.AddElement(Graphical2x2SolutionPanel);
                form.AddElement(SkipBTN, true, "Left");
                form.AddElement(FinishBTN, false, "Right");
                form.Align();
            }
            else
            {
                CGStudentProgress.NewSection();
                FourthInterfaceSetup_PayoffDistributionAndSufficiency();
            }
        }
        public ViewCooperativeGameForm(TestForm parent, string Coalition)
        {
            InitializeComponent();
            G              = Database.G.FindGame(Coalition);
            this.parent    = parent;
            this.Coalition = Coalition;
            if (CGStudentProgress.CurrentSection == 6)
            {
                CreateArrays(0, 1);
                UI.ControlsAligner mpanel = new UI.ControlsAligner(MatrixesPanel);
                mpanel.AddElement(A);
                mpanel.AddElement(B, false);
                mpanel.Align();

                RP_v1.Text         += G.SingleGames[0].FirstPlayer + " = " + G.SingleGames[0].Ha.ToString("0.00");
                RP_v2.Text         += G.SingleGames[0].SecondPlayer + " = " + G.SingleGames[0].Hb.ToString("0.00");;
                RP_PriceLabel.Text += (G.SingleGames[0].Ha + G.SingleGames[0].Hb).ToString("0.00");
                for (int i = 0; i < G.SingleGames[0].x.Count; i++)
                {
                    RP_x.Text += G.SingleGames[0].x[i].ToString("0.00") + " ";
                }
                RP_x.Text += ")";

                for (int i = 0; i < G.SingleGames[0].y.Count; i++)
                {
                    RP_y.Text += G.SingleGames[0].y[i].ToString("0.00") + " ";
                }
                RP_y.Text += ")";


                UI.ControlsAligner rpanel = new UI.ControlsAligner(GameResultPanel);
                rpanel.AddElement(RP_PriceLabel);
                rpanel.AddElement(RP_v1);
                rpanel.AddElement(RP_v2, false);
                rpanel.AddElement(RP_x);
                rpanel.AddElement(RP_y);
                rpanel.Align();
                SkipBTN.Text    = "Несущественная";
                SkipBTN.Width   = 200;
                FinishBTN.Text  = "Существенная";
                FinishBTN.Width = SkipBTN.Width;
                GameResultPanel.Show();

                UI.ControlsAligner form = new UI.ControlsAligner(this);
                Task1Panel.Hide();
                form.AddElement(NavigationPanel);
                form.AddElement(MatrixesPanel);
                form.AddElement(GameResultPanel);
                form.AddElement(SkipBTN, true, "Left");
                form.AddElement(FinishBTN, false, "Right");
                form.Align();
                CreateNavigationPanel();
            }
            else
            {
                this.ControlBox = false;
                SecondInterfaceSetup_Domination();
                CGStudentProgress.NewSection();
                A.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ColumnHeadersMouseClick);
                A.RowHeaderMouseClick    += new DataGridViewCellMouseEventHandler(RowHeaderMouseClick);
                B.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ColumnHeadersMouseClick);
                B.RowHeaderMouseClick    += new DataGridViewCellMouseEventHandler(RowHeaderMouseClick);
            }
        }
        private void GenerateCoalitionPanel(string Coalition, bool first)
        {
            BimatrixGame G = Database.G.FindGame(Coalition);

            Panel p = new Panel();

            PanelsPanel.Controls.Add(p);
            p.BackColor = Color.Silver;

            Label name = new Label();

            name.Text      = Coalition;
            name.Font      = new System.Drawing.Font("Bookman Old Style", 16);
            name.Width     = TextRenderer.MeasureText(name.Text, name.Font).Width;
            name.Height   += 5;
            name.BackColor = Color.Maroon;
            name.ForeColor = Color.White;

            Label outcome = new Label();

            outcome.Text = "V = " + G.outcome.ToString("0.00");
            outcome.Font = new Font(name.Font.Name, name.Font.Size - 2);
            outcome.Size = TextRenderer.MeasureText(outcome.Text, outcome.Font);

            Label v1 = new Label();

            v1.Text = "V" + G.SingleGames[0].FirstPlayer + " = " + G.SingleGames[0].Ha.ToString("0.00");
            v1.Font = new Font(name.Font.Name, name.Font.Size - 4);
            v1.Size = TextRenderer.MeasureText(v1.Text, v1.Font);

            Label v2 = new Label();

            v2.Text = "V" + G.SingleGames[0].SecondPlayer + " = " + G.SingleGames[0].Hb.ToString("0.00");
            v2.Font = new Font(name.Font.Name, name.Font.Size - 4);
            v2.Size = TextRenderer.MeasureText(v2.Text, v2.Font);

            CheckBox c = new CheckBox();

            c.Text    = "Экономически устойчивая";
            c.Font    = new System.Drawing.Font("Bookman Old Style", 12);
            c.Size    = TextRenderer.MeasureText(c.Text, c.Font);
            c.Tag     = G;
            c.Width  += 20;
            c.Height += 10;
            CB.Add(c);


            p.Controls.Add(name);
            p.Controls.Add(outcome);
            p.Controls.Add(v1);
            p.Controls.Add(v2);
            p.Controls.Add(c);

            UI.ControlsAligner panel = new UI.ControlsAligner(p);
            panel.AddElement(name);
            panel.AddElement(outcome);
            panel.AddElement(v1);
            panel.AddElement(v2, false);
            panel.AddElement(c);
            panel.Align();
            pp.AddElement(p, first);
        }
        private void ThirdInterfaceSetup_CGNecessity()
        {
            if (RationalityCB.Checked)
            {
                for (int i = 0; i < TB.Count; i++)
                {
                    TB[i].Enabled = false;
                }
                RationalityCB.Enabled = false;

                NecessityPanel.Show();

                //delete
                string             Coalition = PanelsPanel.Controls[0].Controls[0].Text;
                List <List <int> > C         = new List <List <int> >();
                for (int i = 0; i < Coalition.Length; i++)
                {
                    if (Coalition[i] == '{')
                    {
                        C.Add(new List <int>());
                    }
                    if ((Coalition[i] >= '0') && (Coalition[i] <= '9'))
                    {
                        C.Last().Add(Convert.ToInt32(Coalition[i] - '0'));
                    }
                }


                for (int i = 0; i < TB.Count; i++)
                {
                    double ActualValue;
                    double IncooperativePrize      = Database.G.payoffs[i],
                           CoalitionPrize          = 0,
                           CoalitionPlayersPayoffs = 0;
                    int CoalitionIndex             = -1;
                    for (int p = 0; p < C.Count; p++)
                    {
                        for (int q = 0; q < C[p].Count; q++)
                        {
                            if (C[p][q] - 1 == i)
                            {
                                CoalitionIndex = p;
                            }
                        }
                    }
                    CoalitionPrize = G.payoffs[CoalitionIndex];
                    for (int j = 0; j < C[CoalitionIndex].Count; j++)
                    {
                        CoalitionPlayersPayoffs += Database.G.payoffs[C[CoalitionIndex][j] - 1];
                    }
                    ActualValue = IncooperativePrize * CoalitionPrize / CoalitionPlayersPayoffs;
                    TB[i].Text  = ActualValue.ToString("0.00");
                }

                UI.ControlsAligner npanel = new UI.ControlsAligner(NecessityPanel);
                npanel.AddElement(NecessityLabel);
                for (int i = 0; i < Database.G.N; i++)
                {
                    Label l = new Label();
                    l.Text      = "ΔV(" + (i + 1) + ") = ";
                    l.Font      = new System.Drawing.Font("Bookman Old Style", 14);
                    l.ForeColor = Color.White;
                    l.Size      = TextRenderer.MeasureText(l.Text, l.Font);

                    TextBox tb = new TextBox();
                    tb.Font      = new System.Drawing.Font("Bookman Old Style", 16);
                    tb.TextAlign = HorizontalAlignment.Center;
                    tb.Width     = 100;
                    tb.Text      = "";

                    if (i == 0)
                    {
                        npanel.AddElement(l, true);
                    }
                    else
                    {
                        npanel.AddElement(l, false);
                    }
                    npanel.AddElement(tb, false, "HorBind");

                    NecessityPanel.Controls.Add(l);
                    NecessityPanel.Controls.Add(tb);
                    NTB.Add(tb);
                }
                npanel.Align();

                UI.ControlsAligner form = new UI.ControlsAligner(this);
                form.AddElement(PanelsPanel);
                form.AddElement(DivisionPanel, false);
                form.AddElement(NecessityPanel);
                form.AddElement(FinishBTN, true, "Right");
                form.Align();
            }
            else
            {
                //Different division method
            }
        }