예제 #1
0
        // These set of functions helps to generate new tableaus
        private tableau1 fuzzy1(tableau1 tab, int type, int cons, int vars, float[,,] tabb)
        {
            int   pc = tab.getPC();
            int   pr = tab.getPR(pc);
            float pe = tab.getPE(pc, pr);

            tab.setSide();
            //creating a new tableau instance
            tableau1 _tb = new tableau1(tabb, type, cons, vars, side1);

            //then the instance is used to generate a new table, i.e tableau 2
            _tb.getNewTableau(tabb, pc, pr, pe);
            _tb.rank();
            return(_tb);
        }
예제 #2
0
        // These set of functions handles the event click of the "Go" buttons
        private void eq22go_Click(object sender, RoutedEventArgs e)
        {
            cons = 2; vars = 2;

            string[,,] text = new string[3, 3, 4] {
                { //first row
                    { eq22000.Text, eq22001.Text, eq22002.Text, eq22003.Text },
                    { eq22010.Text, eq22011.Text, eq22012.Text, eq22013.Text },
                    { eq22020.Text, eq22021.Text, eq22022.Text, eq22023.Text }
                },
                { //second row
                    { eq22100.Text, eq22101.Text, eq22102.Text, eq22103.Text },
                    { eq22110.Text, eq22111.Text, eq22112.Text, eq22113.Text },
                    { eq22120.Text, eq22121.Text, eq22122.Text, eq22123.Text }
                },
                { //z-row
                    { eq22z00.Text, eq22z01.Text, eq22z02.Text, eq22z03.Text },
                    { eq22z10.Text, eq22z11.Text, eq22z12.Text, eq22z13.Text },
                    { "0", "0", "0", "0" }
                }
            };

            // Validation
            string[] tiers = new string[9];
            string[] tier = new string[9];
            int      n = 0; bool ans; bool status = false;

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    for (int z = 0; z < 4; z++)
                    {
                        eqn22[x, y, z] = isValid(text[x, y, z]) ? float.Parse(text[x, y, z]) : 0;
                    }
                    tiers[n] = eqn22[x, y, 0] + "-" + eqn22[x, y, 1] + "-" + eqn22[x, y, 2] + "-" + eqn22[x, y, 3];
                    List <float> temp = new List <float> {
                        eqn22[x, y, 0], eqn22[x, y, 1], eqn22[x, y, 2], eqn22[x, y, 3]
                    };
                    temp.Sort();
                    tier[n] = temp[0] + "-" + temp[1] + "-" + temp[2] + "-" + temp[3];
                    n       = n + 1;
                }
            }

            for (int i = 0; i < 9; i++)
            {
                ans = isArranged(tiers[i], tier[i]);
                if (ans == true)
                {
                    status          = true;
                    err1.Visibility = Visibility.Visible;
                    err1.Foreground = Brushes.Green;
                    err1.Content    = "Inputs are Ok.";
                }
                else if (ans == false)
                {
                    status          = false;
                    err1.Visibility = Visibility.Visible;
                    err1.Foreground = Brushes.Red;
                    err1.Content    = "Inputs are not Ok.";
                    break;
                }
            }

            if (status == true)
            {
                // Assigning the
                float[,,] eqn_22 =
                {
                    //row 1
                    { { eqn22[0, 0, 0], eqn22[0, 0, 1], eqn22[0, 0, 2], eqn22[0, 0, 3], 0 },
                        { eqn22[0, 1, 0], eqn22[0, 1, 1], eqn22[0, 1, 2], eqn22[0, 1, 3], 0 },
                        { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 },
                        { eqn22[0, 2, 0], eqn22[0, 2, 1], eqn22[0, 2, 2], eqn22[0, 2, 3], 0 } },
                    //row 2
                    { { eqn22[1, 0, 0], eqn22[1, 0, 1], eqn22[1, 0, 2], eqn22[1, 0, 3], 0 },
                        { eqn22[1, 1, 0], eqn22[1, 1, 1], eqn22[1, 1, 2], eqn22[1, 1, 3], 0 },
                        { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 },
                        { eqn22[1, 2, 0], eqn22[1, 2, 1], eqn22[1, 2, 2], eqn22[1, 2, 3], 0 } },
                    //z-row
                    { { eqn22[2, 0, 0], eqn22[2, 0, 1], eqn22[2, 0, 2], eqn22[2, 0, 3], 0 },
                        { eqn22[2, 1, 0], eqn22[2, 1, 1], eqn22[2, 1, 2], eqn22[2, 1, 3], 0 },
                        { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } }
                };

                //Major
                //initialize the draw segment
                int       offset = 20;
                tableGrid page   = new tableGrid(stacky, offset);
                page.clear();
                tableau1 tb22 = new tableau1(eqn_22, type, cons, vars, side1);
                tb22.toCompForm();
                tb22.rank();
                //gives optimal the value of the isOptimal method of the current tableau
                optimal = tb22.isOptimal();
                //int itr = 1;
                for (int i = 0; optimal == false; i++)
                {
                    if (tb22.isOptimal())
                    {
                        //stop
                        tab1            = tb22.tab;
                        pref.Visibility = Visibility.Collapsed;
                        comm.Visibility = Visibility.Collapsed;
                        page.draw1(tab1, "Tableau " + (i + 1), "Tableau is Optimal", 0, side1);
                        optimal = true;
                        page.statement("Z* = " + tab1[2, 4, 0] + " , " + tab1[2, 4, 1] + " , " + tab1[2, 4, 2] + " , " + tab1[2, 4, 3] + " | " + tab1[2, 4, 4] + "\n" +
                                       side1[0] + "* = " + tab1[0, 4, 0] + " , " + tab1[0, 4, 1] + " , " + tab1[0, 4, 2] + " , " + tab1[0, 4, 3] + " | " + tab1[0, 4, 4] + " , " +
                                       side1[1] + "* = " + tab1[1, 4, 0] + " , " + tab1[1, 4, 1] + " , " + tab1[1, 4, 2] + " , " + tab1[1, 4, 3] + " | " + tab1[1, 4, 4]);
                        break;
                    }
                    else
                    {
                        tab1 = tb22.tab;
                        pc   = tb22.getPC();
                        pr   = tb22.getPR(pc);
                        float pe  = tb22.getPE(pc, pr);
                        int   pos = getPeNum1(pr, pc);
                        pref.Visibility = Visibility.Collapsed;
                        comm.Visibility = Visibility.Collapsed;
                        side1           = tb22.side;
                        page.draw1(tab1, "Tableau " + (i + 1), "Tableau is not Optimal", pos, side1);
                        tb22    = fuzzy1(tb22, type, cons, vars, tab1);
                        optimal = false;
                        offset  = page.off;
                    }
                }
            }
        }