예제 #1
0
        //updates objective and variable
        public void populate_lblObj()
        {
            lblObj.Text = "";
            MyGlobals.model.Update();

            //objective function

            int int_sense = MyGlobals.model.Get(GRB.IntAttr.ModelSense);

            if (int_sense == -1)
            {
                lblObj.Text = "MAXIMIZE";
            }
            else if (int_sense == 1)
            {
                lblObj.Text = "MINIMIZE";
            }
            GRBLinExpr func = (GRBLinExpr)MyGlobals.model.GetObjective();

            for (int i = 0; i < func.Size; i++)
            {
                lblObj.Text = lblObj.Text + " " + func.GetCoeff(i) + func.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
            }

            //populate variables present in obj
            GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetObjective();

            Dictionary <string, GRBVar> D = new Dictionary <string, GRBVar>();
            GRBVar var;

            for (int i = 0; i < con_info.Size; i++)
            {
                var = con_info.GetVar(i);
                D.Add(con_info.GetVar(i).Get(GRB.StringAttr.VarName), var);
            }
            // Bind combobox(edit var) to dictionary
            cmbVarName2.DataSource    = new BindingSource(D, null);
            cmbVarName2.DisplayMember = "Key";
            cmbVarName2.ValueMember   = "Value";

            // Bind combobox(delet var) to dictionary
            cmbVarName3.DataSource    = new BindingSource(D, null);
            cmbVarName3.DisplayMember = "Key";
            cmbVarName3.ValueMember   = "Value";

            //populate all variables combobox addvar
            GRBVar[] allVar = MyGlobals.model.GetVars();
            Dictionary <string, GRBVar> D2 = new Dictionary <string, GRBVar>();

            for (int i = 0; i < allVar.Length; i++)
            {
                D2.Add(allVar[i].Get(GRB.StringAttr.VarName), allVar[i]);
            }
            // Bind combobox(add new var) to dictionary
            cmbAddVar.DataSource    = new BindingSource(D2, null);
            cmbAddVar.DisplayMember = "Key";
            cmbAddVar.ValueMember   = "Value";
        }
        private void btn_Update2_Click(object sender, EventArgs e)
        {
            try
            {
                double var_coco;
                double.TryParse(txtCoeff2.Text, out var_coco);
                MyGlobals.model.ChgCoeff(constraint, variable, var_coco);


                MyGlobals.model.Update();
                populate_cmbConstraint();
                BtnOK.Enabled     = true;
                BtnCancel.Enabled = false;

                lblUpdate2.Text = "";
                lblUpdate2.Text = constraint.Get(GRB.StringAttr.ConstrName) + ": ";

                GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetRow(constraint);

                for (int n = 0; n < con_info.Size; n++)
                {
                    lblUpdate2.Text += " " + con_info.GetCoeff(n) + con_info.GetVar(n).Get(GRB.StringAttr.VarName) + " +";
                }
                lblUpdate2.Text += " " + constraint.Get(GRB.CharAttr.Sense) + " " + constraint.Get(GRB.DoubleAttr.RHS) + "\n";
            }
            catch (GRBException exc)
            {
                MessageBox.Show("Error code: " + exc.ErrorCode + ". " + exc.Message, "Error occured", MessageBoxButtons.OK);
            }
            txtVarName.Clear();
            txtlb.Clear();
            txtub.Clear();
        }
예제 #3
0
        private void ObjItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            GRBLinExpr func = (GRBLinExpr)MyGlobals.model.GetObjective();

            if (func.Size != 0)
            {
                txtObj.Visible = true;
                lblObj.Visible = true;
                lblObj.Text    = "";

                //objective function
                int int_sense = MyGlobals.model.Get(GRB.IntAttr.ModelSense);
                if (int_sense == -1)
                {
                    lblObj.Text = "MAXIMIZE";
                }
                else if (int_sense == 1)
                {
                    lblObj.Text = "MINIMIZE";
                }

                for (int i = 0; i < func.Size; i++)
                {
                    lblObj.Text = lblObj.Text + " " + func.GetCoeff(i) + func.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
                }
            }
            else
            {
                MessageBox.Show("You have not added any objective function!");
            }
        }
        //DELETE Variable
        private void cmbCon5_SelectedIndexChanged(object sender, EventArgs e)
        {
            constraint = ((KeyValuePair <string, GRBConstr>)cmbCon5.SelectedItem).Value;
            GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetRow(constraint);

            Dictionary <string, GRBVar> D = new Dictionary <string, GRBVar>();
            GRBVar var;

            for (int i = 0; i < con_info.Size; i++)
            {
                var = con_info.GetVar(i);
                D.Add(con_info.GetVar(i).Get(GRB.StringAttr.VarName), var);
            }


            // Bind combobox(delete var) to dictionary
            cmbVarName3.DataSource    = new BindingSource(D, null);
            cmbVarName3.DisplayMember = "Key";
            cmbVarName3.ValueMember   = "Value";
        }
예제 #5
0
        public override bool SetObj(object solver, int Column, double Value)
        {
            GRBModel grbSolver = solver as GRBModel;

            if (grbSolver == null)
            {
                return(false);
            }
            GRBLinExpr exp = grbSolver.GetObjective() as GRBLinExpr;

            exp.AddTerm(Value, exp.GetVar(Column));
            return(true);
        }
        //Add variable
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            {
                try
                {
                    //change GRBConst into GRBConst[]
                    GRBConstr[] CON = new GRBConstr[1];
                    CON[0] = constraint;

                    double var_coco;
                    double.TryParse(txtAddCon.Text, out var_coco);
                    //change double into double[]
                    Double[] COEFF = new Double[1];
                    COEFF[0] = var_coco;

                    //add variable to constraint
                    MyGlobals.model.ChgCoeff(constraint, variable, var_coco);


                    MyGlobals.model.Update();
                    populate_cmbConstraint();
                    BtnOK.Enabled     = true;
                    BtnCancel.Enabled = false;

                    lblUpdate.Text = "";
                    lblUpdate.Text = constraint.Get(GRB.StringAttr.ConstrName) + ": ";

                    GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetRow(constraint);

                    for (int n = 0; n < con_info.Size; n++)
                    {
                        lblUpdate.Text += " " + con_info.GetCoeff(n) + con_info.GetVar(n).Get(GRB.StringAttr.VarName) + " +";
                    }
                    lblUpdate.Text += " " + constraint.Get(GRB.CharAttr.Sense) + " " + constraint.Get(GRB.DoubleAttr.RHS) + "\n";
                }
                catch (GRBException exc)
                {
                    MessageBox.Show("Error code: " + exc.ErrorCode + ". " + exc.Message, "Error occured", MessageBoxButtons.OK);
                }
            }
        }
예제 #7
0
        public void if_obj_loaded()
        {
            //IF OBJ IS ALREADY SET
            int        int_sense = MyGlobals.model.Get(GRB.IntAttr.ModelSense);
            GRBLinExpr func      = (GRBLinExpr)MyGlobals.model.GetObjective();

            if ((int_sense == -1) || (int_sense == 1))
            {
                if (func.Size != 0)
                {
                    lblObj.Text   = "";
                    lblSense.Text = "";

                    if (int_sense == -1)
                    {
                        lblSense.Text = "MAXIMIZE";
                        cmbSense.Text = "MAXIMIZE";
                    }
                    else if (int_sense == 1)
                    {
                        lblSense.Text = "MINIMIZE";
                        cmbSense.Text = "MINIMIZE";
                    }


                    for (int i = 0; i < func.Size; i++)
                    {
                        lblObj.Text = lblObj.Text + " " + func.GetCoeff(i) + func.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
                    }
                    cmbSense.Enabled   = false;
                    cmbVarName.Enabled = false;
                    txtCoeff.Enabled   = false;
                    btn_Undo.Enabled   = false;
                    button7.Enabled    = false;
                    btnClear.Enabled   = false;
                    btnAddTerm.Enabled = false;
                    btnOK.Enabled      = true;
                    btnNext.Enabled    = true;
                }
            }
        }
        private void btnUpdate_4_Click(object sender, EventArgs e)
        {
            double RHS;

            double.TryParse(txtRHS.Text, out RHS);
            constraint.Set(GRB.DoubleAttr.RHS, RHS);


            MyGlobals.model.Update();
            populate_cmbConstraint();
            BtnOK.Enabled     = true;
            BtnCancel.Enabled = false;

            lblUpdate4.Text = "";
            lblUpdate4.Text = constraint.Get(GRB.StringAttr.ConstrName) + ": ";

            GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetRow(constraint);

            for (int n = 0; n < con_info.Size; n++)
            {
                lblUpdate4.Text += " " + con_info.GetCoeff(n) + con_info.GetVar(n).Get(GRB.StringAttr.VarName) + " +";
            }
            lblUpdate4.Text += " " + constraint.Get(GRB.CharAttr.Sense) + " " + constraint.Get(GRB.DoubleAttr.RHS) + "\n";
        }
        private void btnUpdate_3_Click(object sender, EventArgs e)
        {
            string sense = this.cmbSense.GetItemText(this.cmbSense.SelectedItem);

            switch (sense)
            {
            case "EQUAL":
                constraint.Set(GRB.CharAttr.Sense, '=');
                break;

            case "LESS EQUAL":
                constraint.Set(GRB.CharAttr.Sense, '<');
                break;

            case "GREATER EQUAL":
                constraint.Set(GRB.CharAttr.Sense, '>');
                break;
            }

            //display constraint
            MyGlobals.model.Update();
            populate_cmbConstraint();
            BtnOK.Enabled     = true;
            BtnCancel.Enabled = false;

            lblUpdate3.Text = "";
            lblUpdate3.Text = constraint.Get(GRB.StringAttr.ConstrName) + ": ";

            GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetRow(constraint);

            for (int n = 0; n < con_info.Size; n++)
            {
                lblUpdate3.Text += " " + con_info.GetCoeff(n) + con_info.GetVar(n).Get(GRB.StringAttr.VarName) + " +";
            }
            lblUpdate3.Text += " " + constraint.Get(GRB.CharAttr.Sense) + " " + constraint.Get(GRB.DoubleAttr.RHS) + "\n";
        }
        //new variable is added to constraint
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string var_name = txtVarName.Text;
                string var_type = this.cmbVarType.GetItemText(this.cmbVarType.SelectedItem);

                double var_lb, var_ub;
                double var_obco, var_coco;
                double.TryParse(txtlb.Text, out var_lb);
                double.TryParse(txtub.Text, out var_ub);
                double.TryParse(txtObCo.Text, out var_obco);
                double.TryParse(txtCo_coeff.Text, out var_coco);

                //change GRBConst into GRBConst[]
                GRBConstr[] CON = new GRBConstr[1];
                CON[0] = constraint;


                //change double into double[]
                Double[] COEFF = new Double[1];
                COEFF[0] = var_coco;

                GRBVar x;
                switch (var_type)
                {
                case "BINARY":
                    if (use_infinite_ub == false)
                    {
                        x = MyGlobals.model.AddVar(var_lb, var_ub, var_obco, 'B', CON, COEFF, var_name);
                    }
                    else
                    {
                        x = MyGlobals.model.AddVar(var_lb, GRB.INFINITY, var_obco, 'B', CON, COEFF, var_name);
                    }
                    break;


                case "CONTINUOUS":
                    if (use_infinite_ub == false)
                    {
                        x = MyGlobals.model.AddVar(var_lb, var_ub, var_obco, 'C', CON, COEFF, var_name);
                    }
                    else
                    {
                        x = MyGlobals.model.AddVar(var_lb, GRB.INFINITY, var_obco, 'C', CON, COEFF, var_name);
                    }
                    break;

                case "INTERGER":
                    if (use_infinite_ub == false)
                    {
                        x = MyGlobals.model.AddVar(var_lb, var_ub, var_obco, 'I', CON, COEFF, var_name);
                    }
                    else
                    {
                        x = MyGlobals.model.AddVar(var_lb, GRB.INFINITY, var_obco, 'I', CON, COEFF, var_name);
                    }
                    break;

                case "SEMI-CONTINUOUS":
                    if (use_infinite_ub == false)
                    {
                        x = MyGlobals.model.AddVar(var_lb, var_ub, var_obco, 'S', CON, COEFF, var_name);
                    }
                    else
                    {
                        x = MyGlobals.model.AddVar(var_lb, GRB.INFINITY, var_obco, 'S', CON, COEFF, var_name);
                    }
                    break;

                case "SEMI-INTERGER":
                    if (use_infinite_ub == false)
                    {
                        x = MyGlobals.model.AddVar(var_lb, var_ub, var_obco, 'N', CON, COEFF, var_name);
                    }
                    else
                    {
                        x = MyGlobals.model.AddVar(var_lb, GRB.INFINITY, var_obco, 'N', CON, COEFF, var_name);
                    }
                    break;
                }
                MyGlobals.model.Update();
                populate_cmbConstraint();
                BtnOK.Enabled     = true;
                BtnCancel.Enabled = false;

                lblUpdate.Text = "";
                lblUpdate.Text = constraint.Get(GRB.StringAttr.ConstrName) + ": ";

                GRBLinExpr con_info = (GRBLinExpr)MyGlobals.model.GetRow(constraint);

                for (int n = 0; n < con_info.Size; n++)
                {
                    lblUpdate.Text += " " + con_info.GetCoeff(n) + con_info.GetVar(n).Get(GRB.StringAttr.VarName) + " +";
                }
                lblUpdate.Text += " " + constraint.Get(GRB.CharAttr.Sense) + " " + constraint.Get(GRB.DoubleAttr.RHS) + "\n";
            }
            catch (GRBException exc)
            {
                MessageBox.Show("Error code: " + exc.ErrorCode + ". " + exc.Message, "Error occured", MessageBoxButtons.OK);
            }
            txtVarName.Clear();
            txtlb.Clear();
            txtub.Clear();
        }
        private void refresh_display()
        {
            //model information
            lblObj.Text        = "";
            lblCon.Text        = "";
            lblOptimal.Text    = "";
            lblInfeasible.Text = "";


            MyGlobals.model.Update();
            //objective function
            int int_sense = MyGlobals.model.Get(GRB.IntAttr.ModelSense);

            if (int_sense == -1)
            {
                lblObj.Text = "MAXIMIZE";
            }
            else
            {
                lblObj.Text = "MINIMIZE";
            }

            GRBLinExpr func = (GRBLinExpr)MyGlobals.model.GetObjective();

            for (int i = 0; i < func.Size; i++)
            {
                lblObj.Text = lblObj.Text + " " + func.GetCoeff(i) + func.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
            }


            //constraints
            GRBConstr[] allCons = MyGlobals.model.GetConstrs();
            GRBLinExpr  con_info;
            string      co_name;
            char        co_sense;
            double      co_RHS;
            int         n;

            for (n = 0; n < allCons.Length; n++)
            {
                co_name      = allCons[n].Get(GRB.StringAttr.ConstrName);
                co_sense     = allCons[n].Get(GRB.CharAttr.Sense);
                co_RHS       = allCons[n].Get(GRB.DoubleAttr.RHS);
                con_info     = (GRBLinExpr)MyGlobals.model.GetRow(allCons[n]);
                lblCon.Text += co_name + ": ";
                for (int i = 0; i < con_info.Size; i++)
                {
                    lblCon.Text += " " + con_info.GetCoeff(i) + con_info.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
                }
                lblCon.Text += " " + co_sense + " " + co_RHS + "\n";
            }

            // Optimize model
            MyGlobals.model.Optimize();
            int optimstatus = MyGlobals.model.Get(GRB.IntAttr.Status);

            //If the model is infeasible or unbounded, turn off presolve and solve the model again
            if (optimstatus == GRB.Status.INF_OR_UNBD)
            {
                MyGlobals.model.GetEnv().Set(GRB.IntParam.Presolve, 0);
                MyGlobals.model.Optimize();
                optimstatus = MyGlobals.model.Get(GRB.IntAttr.Status);
            }

            //if the model is optimal, display solution in a worksheet
            if (optimstatus == GRB.Status.OPTIMAL)
            {
                load_optimal();
            }

            //if the model is infeasible, compute IIS
            else if (optimstatus == GRB.Status.INFEASIBLE)
            {
                lblInfeasible.Text = "INFEASIBLE";

                //compute IIS
                lblfollowing.Visible = true;
                lblRemove.Enabled    = true;
                lblRemove.Visible    = true;
                lblRemove.Text       = "";

                MyGlobals.model.ComputeIIS();
                foreach (GRBConstr c in MyGlobals.model.GetConstrs())
                {
                    if (c.Get(GRB.IntAttr.IISConstr) == 1)
                    {
                        lblRemove.Text += c.Get(GRB.StringAttr.ConstrName) + "  ";
                    }
                }
                btnRemove.Enabled = true;
                btnRemove.Visible = true;

                spreadsheetControl1.Visible = false;
                btn_Excel.Enabled           = false;
                btn_HTML.Enabled            = false;
                btn_PDF.Enabled             = false;
                btn_SaveSol.Enabled         = false;
            }

            //if the model is unbounded
            else if (optimstatus == GRB.Status.UNBOUNDED)
            {
                lblInfeasible.Text = "UNBOUNED\nModel cannot be solved.";

                spreadsheetControl1.Visible = false;
                btn_Excel.Enabled           = false;
                btn_HTML.Enabled            = false;
                btn_PDF.Enabled             = false;
                btn_SaveSol.Enabled         = false;
            }

            //NEITHER INFEASIBLE, NOR OPTIMAL, NOR UNBOUNDED
            else
            {
                lblInfeasible.Text = "Optimization stopped with \nstatus = " + optimstatus;
            }
        }
예제 #12
0
        private void FrmAnalyze_Load(object sender, EventArgs e)
        {
            MyGlobals.model.Update();

            //MODEL INFORMATION
            lblObj.Text = "";
            lblCon.Text = "";

            //OBJECTIVE FUNCTION
            int int_sense = MyGlobals.model.Get(GRB.IntAttr.ModelSense);

            if (int_sense == -1)
            {
                lblObj.Text = "MAXIMIZE";
            }
            else
            {
                lblObj.Text = "MINIMIZE";
            }

            GRBLinExpr func = (GRBLinExpr)MyGlobals.model.GetObjective();

            for (int i = 0; i < func.Size; i++)
            {
                lblObj.Text = lblObj.Text + " " + func.GetCoeff(i) + func.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
            }

            //CONSTRAINTS
            GRBConstr[] allCons = MyGlobals.model.GetConstrs();
            GRBLinExpr  con_info;
            string      co_name;
            char        co_sense;
            double      co_RHS;
            int         n;

            for (n = 0; n < allCons.Length; n++)
            {
                co_name      = allCons[n].Get(GRB.StringAttr.ConstrName);
                co_sense     = allCons[n].Get(GRB.CharAttr.Sense);
                co_RHS       = allCons[n].Get(GRB.DoubleAttr.RHS);
                con_info     = (GRBLinExpr)MyGlobals.model.GetRow(allCons[n]);
                lblCon.Text += co_name + ": ";
                for (int i = 0; i < con_info.Size; i++)
                {
                    lblCon.Text += " " + con_info.GetCoeff(i) + con_info.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
                }
                lblCon.Text += " " + co_sense + " " + co_RHS + "\n";
            }

            MyGlobals.model.Optimize();

            //VARIABLE TYPE PIE CHART

            //variables type count
            int varnum     = MyGlobals.model.Get(GRB.IntAttr.NumVars);
            int NXnum      = MyGlobals.model.Get(GRB.IntAttr.NumNZs);
            int INTnum     = MyGlobals.model.Get(GRB.IntAttr.NumIntVars);
            int BINnum     = MyGlobals.model.Get(GRB.IntAttr.NumBinVars);
            int CONnum     = 0;
            int SEMINTnum  = 0;
            int SEMICONnum = 0;


            GRBVar[] allVar = MyGlobals.model.GetVars();
            for (int i = 0; i < allVar.Length; i++)
            {
                if (allVar[i].Get(GRB.CharAttr.VType) == 'C')
                {
                    CONnum++;
                }
                if (allVar[i].Get(GRB.CharAttr.VType) == 'S')
                {
                    SEMICONnum++;
                }
                if (allVar[i].Get(GRB.CharAttr.VType) == 'N')
                {
                    SEMINTnum++;
                }
            }


            Dictionary <string, int> D = new Dictionary <string, int>();

            D.Add("Integer", INTnum);
            D.Add("Binary", BINnum);
            D.Add("Continous", CONnum);
            D.Add("Semi-Integer", SEMINTnum);
            D.Add("Semi-Continous", SEMICONnum);

            // Create a chart.
            ChartControl chartControl1 = new ChartControl();

            // Create an empty Bar series and add it to the chart.
            Series Series_VarType = new Series("Series1", ViewType.Pie);

            chartControl1.Series.Add(Series_VarType);

            // Bind chart to dictionary
            Series_VarType.DataSource = new BindingSource(D, null);

            // Specify data members to bind the series.
            Series_VarType.ArgumentScaleType  = ScaleType.Qualitative;
            Series_VarType.ArgumentDataMember = "Key";
            Series_VarType.ValueScaleType     = ScaleType.Numerical;
            Series_VarType.ValueDataMembers.AddRange(new string[] { "Value" });

            // Adjust the text pattern of the series label.
            PieSeriesLabel label = (PieSeriesLabel)Series_VarType.Label;

            label.TextPattern = "{A}: {V:F1} ({VP:P0})";

            chartControl1.PaletteName            = "Flow";
            chartControl1.PaletteBaseColorNumber = 0;

            // Dock the chart into its parent and add it to the current form.
            chartControl1.Dock = DockStyle.Bottom;
            groupBox1.Controls.Add(chartControl1);

            //OPTIMIZATION RESULTS
            lblRuntime.Text    = "";
            lblSolCount.Text   = "";
            lblOptimal.Text    = "";
            lblInfeasible.Text = "";
            lblRuntime.Text    = "";

            lblObjSol.Text = "";
            lblbound.Text  = "";
            lblGap.Text    = "";


            double Runtime = MyGlobals.model.Get(GRB.DoubleAttr.Runtime);


            if (MyGlobals.model.Get(GRB.IntAttr.Status) == GRB.Status.OPTIMAL)
            {
                double ObjSol   = MyGlobals.model.Get(GRB.DoubleAttr.ObjVal);
                double Bound    = MyGlobals.model.Get(GRB.DoubleAttr.ObjBound);
                double Gap      = MyGlobals.model.Get(GRB.DoubleAttr.MIPGap);
                int    SolCount = MyGlobals.model.Get(GRB.IntAttr.SolCount);

                lblOptimal.Text  = "OPTIMAL";
                lblSolCount.Text = SolCount.ToString();
                lblRuntime.Text  = Math.Round(Runtime, 3).ToString();

                lblObjSol.Text = ObjSol.ToString();
                lblbound.Text  = Bound.ToString();
                lblGap.Text    = Gap.ToString();
            }
            else
            {
                lblInfeasible.Text = "INFEASIBLE";
                lblRuntime.Text    = Runtime.ToString();
            }
            //ALGORITHM ITERATION CHART
            double simplex    = MyGlobals.model.Get(GRB.DoubleAttr.IterCount);
            int    bar        = MyGlobals.model.Get(GRB.IntAttr.BarIterCount);
            double barrier    = Convert.ToDouble(bar);
            double branchncut = MyGlobals.model.Get(GRB.DoubleAttr.NodeCount);


            Dictionary <string, double> DA = new Dictionary <string, double>();

            DA.Add("Simplex Iterations", simplex);
            DA.Add("Barrier Iterations", barrier);
            DA.Add("Branch-n-Cut Nodes", branchncut);

            // Create a chart.
            ChartControl chartControl2 = new ChartControl();

            // Create an empty Bar series and add it to the chart.
            Series Series_Iteration = new Series("Series2", ViewType.Bar);

            chartControl2.Series.Add(Series_Iteration);

            // Bind chart to dictionary
            Series_Iteration.DataSource = new BindingSource(DA, null);

            // Specify data members to bind the series.
            Series_Iteration.ArgumentScaleType  = ScaleType.Qualitative;
            Series_Iteration.ArgumentDataMember = "Key";
            Series_Iteration.ValueScaleType     = ScaleType.Numerical;
            Series_Iteration.ValueDataMembers.AddRange(new string[] { "Value" });

            // Adjust the text pattern of the series label.
            BarSeriesLabel lbl = (BarSeriesLabel)Series_Iteration.Label;

            lbl.TextPattern = "{V:F1}";

            Legend legend = chartControl2.Legend;

            // Display the chart control's legend.
            legend.Visible = false;


            chartControl2.PaletteName            = "Flow";
            chartControl2.PaletteBaseColorNumber = 0;

            // Dock the chart into its parent and add it to the current form.
            chartControl2.Dock = DockStyle.Fill;
            pnl_algo.Controls.Add(chartControl2);

            //COEFF STATS CHART
            double MAXCOEFF    = MyGlobals.model.Get(GRB.DoubleAttr.MaxCoeff);
            double MINCOEFF    = MyGlobals.model.Get(GRB.DoubleAttr.MinCoeff);
            double MAXBOUND    = MyGlobals.model.Get(GRB.DoubleAttr.MaxBound);
            double MINBOUND    = MyGlobals.model.Get(GRB.DoubleAttr.MinBound);
            double MAXOBJCOEFF = MyGlobals.model.Get(GRB.DoubleAttr.MaxObjCoeff);
            double MINOBJCOEFF = MyGlobals.model.Get(GRB.DoubleAttr.MinObjCoeff);


            // Create a chart.
            ChartControl chartControl3 = new ChartControl();

            // Create an empty Bar series and add it to the chart.
            Series Series_Coeff = new Series("Series3", ViewType.RangeBar);

            // Add points to them.
            Series_Coeff.Points.Add(new SeriesPoint("Matrix Coefficient", MAXCOEFF, MINCOEFF));
            Series_Coeff.Points.Add(new SeriesPoint("Variable Bound", MAXBOUND, MINBOUND));
            Series_Coeff.Points.Add(new SeriesPoint("Linear Obj Coefficient", MAXOBJCOEFF, MINOBJCOEFF));

            chartControl3.Series.Add(Series_Coeff);


            // Adjust the text pattern of the series label.
            RangeBarSeriesLabel lbl2 = (RangeBarSeriesLabel)Series_Coeff.Label;

            lbl2.TextPattern = "{V:F1}";

            // Hide the legend (if necessary).
            chartControl3.Legend.Visible = false;


            chartControl3.PaletteName            = "Flow";
            chartControl3.PaletteBaseColorNumber = 0;

            // Dock the chart into its parent and add it to the current form.
            chartControl3.Dock = DockStyle.Fill;
            pnl_coeff.Controls.Add(chartControl3);
        }
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Model Files (LP)|*.LP";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string ext = Path.GetExtension(openFileDialog1.FileName);
                //Dispose previous model
                MyGlobals.model.Dispose();
                MyGlobals.env.Dispose();

                lblFilename.Text  = "";
                lblObjective.Text = "";
                lblVar.Text       = "";
                lblCon.Text       = "";


                MyGlobals.env        = new GRBEnv();
                MyGlobals.model      = new GRBModel(MyGlobals.env, openFileDialog1.FileName);
                btn_Optimize.Enabled = true;

                if (ext == ".lp")
                {
                    lblFilename.Text = openFileDialog1.FileName;


                    //objective function
                    int int_sense = MyGlobals.model.Get(GRB.IntAttr.ModelSense);
                    if (int_sense == -1)
                    {
                        lblObjective.Text = "MAXIMIZE";
                    }
                    else
                    {
                        lblObjective.Text = "MINIMIZE";
                    }
                    GRBLinExpr func = (GRBLinExpr)MyGlobals.model.GetObjective();

                    for (int i = 0; i < func.Size; i++)
                    {
                        lblObjective.Text = lblObjective.Text + " " + func.GetCoeff(i) + func.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
                    }

                    //variables
                    GRBVar[] allVars = MyGlobals.model.GetVars();
                    int      n;
                    for (n = 0; n < allVars.Length; n++)
                    {
                        lblVar.Text += allVars[n].Get(GRB.StringAttr.VarName) + ", ";
                    }

                    //constraints
                    GRBLinExpr  con_info;
                    GRBConstr[] allCons = MyGlobals.model.GetConstrs();
                    string      co_name;
                    char        co_sense;
                    double      co_RHS;

                    for (n = 0; n < allCons.Length; n++)
                    {
                        co_name  = allCons[n].Get(GRB.StringAttr.ConstrName);
                        co_sense = allCons[n].Get(GRB.CharAttr.Sense);
                        co_RHS   = allCons[n].Get(GRB.DoubleAttr.RHS);


                        con_info = (GRBLinExpr)MyGlobals.model.GetRow(allCons[n]);

                        lblCon.Text += co_name + ": ";


                        for (int i = 0; i < con_info.Size; i++)
                        {
                            lblCon.Text += " " + con_info.GetCoeff(i) + con_info.GetVar(i).Get(GRB.StringAttr.VarName) + " +";
                        }

                        lblCon.Text += " " + co_sense + " " + co_RHS + "\n";
                    }
                }
                else
                {
                    MessageBox.Show("The File is not LP.");
                    MyGlobals.model.Dispose();
                    MyGlobals.env.Dispose();
                }
            }
        }