Exemple #1
0
 public result Simplex(int cols, int rows, OptimisationDirection direction, bound[] rowbounds, bound[] colbounds, int[] ia, int[] ja, double[] ar, double[] coeff)
 {
     LPProblem p = new LPProblem();
     p.ObjectiveDirection = direction;
     p.AddCols(cols);
     p.AddRows(rows);
     for (int i = 0; i < rowbounds.Length; i++)
     {
         p.SetRowBounds(i + 1, rowbounds[i].BoundType, rowbounds[i].lower, rowbounds[i].upper);
     }
     for (int i = 0; i < colbounds.Length; i++)
     {
         p.SetColBounds(i + 1, colbounds[i].BoundType, colbounds[i].lower, colbounds[i].upper);
     }
     p.LoadMatrix(ia, ja, ar);
     //p.SetMatRow(1, new int[] {0, 1, 2 }, new double[] {0, 1, 1 });
     for (int i = 0; i < coeff.Length; i++)
     {
         p.SetObjCoef(i+1, coeff[i]);
     }
     p.SolveSimplex();
     Console.WriteLine("result = {0}, x1 = {1}, x2 = {2}", p.GetObjectiveValue(), p.GetColPrimal(1), p.GetColPrimal(2));
     //Console.In.ReadLine();
     result r = new result();
     r.ObjResult = p.GetObjectiveValue();
     r.Columns = new double[cols];
     for (int i = 0; i < cols; i++)
     {
         r.Columns[i] = p.GetColPrimal(i + 1);
     }
     return r;
 }
Exemple #2
0
        public result Simplex(int cols, int rows, OptimisationDirection direction, bound[] rowbounds, bound[] colbounds, int[] ia, int[] ja, double[] ar, double[] coeff)
        {
            LPProblem p = new LPProblem();

            p.ObjectiveDirection = direction;
            p.AddCols(cols);
            p.AddRows(rows);
            for (int i = 0; i < rowbounds.Length; i++)
            {
                p.SetRowBounds(i + 1, rowbounds[i].BoundType, rowbounds[i].lower, rowbounds[i].upper);
            }
            for (int i = 0; i < colbounds.Length; i++)
            {
                p.SetColBounds(i + 1, colbounds[i].BoundType, colbounds[i].lower, colbounds[i].upper);
            }
            p.LoadMatrix(ia, ja, ar);
            //p.SetMatRow(1, new int[] {0, 1, 2 }, new double[] {0, 1, 1 });
            for (int i = 0; i < coeff.Length; i++)
            {
                p.SetObjCoef(i + 1, coeff[i]);
            }
            p.SolveSimplex();
            Console.WriteLine("result = {0}, x1 = {1}, x2 = {2}", p.GetObjectiveValue(), p.GetColPrimal(1), p.GetColPrimal(2));
            //Console.In.ReadLine();
            result r = new result();

            r.ObjResult = p.GetObjectiveValue();
            r.Columns   = new double[cols];
            for (int i = 0; i < cols; i++)
            {
                r.Columns[i] = p.GetColPrimal(i + 1);
            }
            return(r);
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (reactionObjetiveComboBox.Text.Length > 0 && comboreactionexchange.Text.Length > 0)
            {
                if (Sbml.There(reactionObjetiveComboBox, reactionObjetiveComboBox.Text) && Sbml.There(comboreactionexchange, comboreactionexchange.Text))
                {
                    if ((aNumericUpDown.Value != bNumericUpDown.Value) && (aNumericUpDown.Value < bNumericUpDown.Value))
                    {
                        makefba = new MakeFba();

                        int i = 0;

                        bool find = false;

                        foreach (Reaction item in sbml.ListReaction)
                        {
                            if (item.Id == reactionObjetiveComboBox.Text)
                            {
                                reactionoptimize = reactionObjetiveComboBox.Text;

                                find = true;

                                break;
                            }
                            i++;
                        }
                        if (find)
                        {
                            if (radiomax.Checked)
                            {
                                pd = OptimisationDirection.MAXIMISE;
                            }
                            else
                            {
                                pd = OptimisationDirection.MINIMISE;
                            }

                            pointresult = makefba.Rna(sbml, i, pd, (int)aNumericUpDown.Value, (int)bNumericUpDown.Value, comboreactionexchange.Text);



                            resultlist.Items.Clear();

                            string[] str;

                            ListViewItem list;


                            for (int k = 0; k < pointresult.Length; k++)
                            {
                                int kaux = k + 1;
                                str = new string[3] {
                                    kaux.ToString(), pointresult[k].X.ToString(), pointresult[k].Y.ToString()
                                };

                                list = new ListViewItem(str);
                                resultlist.Items.Add(list);
                            }
                            results         = true;
                            button3.Enabled = true;
                        }
                        else
                        {
                            results         = false;
                            button3.Enabled = false;
                            MessageBox.Show("This reaction not exist in the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The values of A and B must be different, and A less than B", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Select the objective functions to optimize and to be varied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Select the objective functions to optimize and to be varied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (reactionObjetiveComboBox.Text.Length > 0)
            {
                makefba = new MakeFba();

                int i = 0;

                bool find = false;

                foreach (Reaction item in sbml.ListReaction)
                {
                    if (item.Id == reactionObjetiveComboBox.Text)
                    {
                        reactionoptimize = reactionObjetiveComboBox.Text;

                        find = true;

                        break;
                    }
                    i++;
                }
                if (find)
                {
                    if (radiomax.Checked)
                    {
                        pd = OptimisationDirection.MAXIMISE;
                    }
                    else
                    {
                        pd = OptimisationDirection.MINIMISE;
                    }
                    Funcion_obj = i;
                    makefba.Fba(sbml, i, pd);

                    double z = makefba.Lp.GetObjectiveValue();

                    resultlist.Items.Clear();

                    string[] str = new string[2] {
                        "Z = " + reactionObjetiveComboBox.Text, z.ToString()
                    };

                    ListViewItem list = new ListViewItem(str);
                    resultlist.Items.Add(list);

                    for (int k = 0; k < sbml.ListReaction.Length; k++)
                    {
                        str = new string[2] {
                            sbml.ListReaction[k].Id, makefba.Lp.GetColPrimal(k + 1).ToString()
                        };

                        list = new ListViewItem(str);
                        resultlist.Items.Add(list);
                    }
                    results         = true;
                    button5.Enabled = true;
                    button3.Enabled = true;
                }
                else
                {
                    results         = false;
                    button3.Enabled = false;
                    MessageBox.Show("This reaction not exist in the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Select the function to optimize", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (reactionObjetiveComboBox.Text.Length > 0 && reactionObjetiveComboBox2.Text.Length > 0)
            {
                if (Sbml.There(reactionObjetiveComboBox, reactionObjetiveComboBox.Text) && Sbml.There(reactionObjetiveComboBox2, reactionObjetiveComboBox2.Text))
                {
                    makefba = new MakeFba();

                    int i = 0;
                    int j = 0;

                    int ii = 0;
                    int jj = 0;

                    int find = 0;

                    foreach (Reaction item in sbml.ListReaction)
                    {
                        if (item.Id == reactionObjetiveComboBox.Text)
                        {
                            reactionoptimize1 = reactionObjetiveComboBox.Text;

                            find++;

                            ii = i;
                        }
                        if (item.Id == reactionObjetiveComboBox2.Text)
                        {
                            reactionoptimize2 = reactionObjetiveComboBox2.Text;

                            find++;

                            jj = j;
                        }
                        if (find == 2)
                        {
                            break;
                        }

                        j++;
                        i++;
                    }
                    if (find == 2)
                    {
                        if (radiomax.Checked)
                        {
                            pd = OptimisationDirection.MAXIMISE;
                        }
                        else
                        {
                            pd = OptimisationDirection.MINIMISE;
                        }

                        fva = makefba.Fva(sbml, ii, jj, pd);

                        double z1 = fva.Lp1.GetObjectiveValue();
                        double z2 = fva.Lp2.GetObjectiveValue();


                        resultlist.Items.Clear();

                        string[] str = new string[3] {
                            "Z1,Z2", "Z1 = " + z1.ToString(), "Z2 = " + z2.ToString()
                        };


                        ListViewItem list = new ListViewItem(str, 0, Color.Black, Color.YellowGreen, new Font("Arial", 12));


                        resultlist.Items.Add(list);


                        for (int k = 0; k < sbml.ListReaction.Length; k++)
                        {
                            str = new string[3] {
                                sbml.ListReaction[k].Id, fva.Lp1.GetColPrimal(k + 1).ToString(), fva.Lp2.GetColPrimal(k + 1).ToString()
                            };

                            if (fva.Lp1.GetColPrimal(k + 1) == fva.Lp2.GetColPrimal(k + 1))
                            {
                                list = new ListViewItem(str);
                                resultlist.Items.Add(list);
                            }
                            else
                            {
                                list = new ListViewItem(str, 0, Color.Black, Color.YellowGreen, new Font("Arial", 12));
                                resultlist.Items.Add(list);
                            }
                        }
                        results         = true;
                        button3.Enabled = true;
                    }
                    else
                    {
                        results         = false;
                        button3.Enabled = false;

                        MessageBox.Show("This reaction not exist in the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("One of the functions not exist in the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Select the functions to optimize", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }