예제 #1
0
    void Populate()
    {
        string errorMessage = null;

        if (Session[_contextKey] != null)
        {
            DEAContext context = Session[_contextKey] as DEAContext;
            DataSet    ds      = context.ToDataSet(out errorMessage);
            if (ds != null)
            {
                GridViewProjects.Columns.Clear();
                BoundField bf = new BoundField();
                bf.HeaderText = context.ProjectIDFieldName;
                bf.DataField  = "NAME";
                GridViewProjects.Columns.Add(bf);

                foreach (DataRow r in ds.Tables["VARIABLES"].Rows)
                {
                    string varName = r["NAME"].ToString();
                    bf = new BoundField();
                    bf.HeaderStyle.CssClass      = "text-right";
                    bf.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                    bf.HeaderText       = varName;
                    bf.DataField        = varName;
                    bf.DataFormatString = "{0:f6}";
                    GridViewProjects.Columns.Add(bf);
                }

                bf = new BoundField();
                bf.HeaderStyle.CssClass      = "text-right";
                bf.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                bf.HeaderText       = "Relative Efficiency";
                bf.DataField        = "RELATIVE_Efficiency";
                bf.DataFormatString = "{0:f6}";
                GridViewProjects.Columns.Add(bf);

                if (ds.Tables["CONSTRAINTS"].Rows != null && ds.Tables["CONSTRAINTS"].Rows.Count > 0)
                {
                    bf = new BoundField();
                    bf.HeaderStyle.CssClass      = "text-right";
                    bf.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                    bf.HeaderText = "Selected";
                    bf.DataField  = "SELECTED";
                    bf.ReadOnly   = true;
                    GridViewProjects.Columns.Add(bf);
                }

                bf = new BoundField();
                bf.HeaderStyle.CssClass = "text-right";
                bf.HeaderText           = "Approximate";
                bf.DataField            = "APPROXIMATE";
                bf.DataFormatString     = "{0}";
                GridViewProjects.Columns.Add(bf);

                GridViewProjects.DataSource = ds.Tables["PROJECTS"];
                GridViewProjects.DataBind();
            }
        }
    }
예제 #2
0
        public void TestVADataUnconstrained()
        {
            string errorMessage   = null;
            string warningMessage = null;

            string csvFilePath  = @"C:\Projects\NCHRP 08-103\VA_TEST.csv";
            string xmlFilePath  = @"C:\Projects\NCHRP 08-103\VA_TEST.xml";
            string xmlFilePath2 = @"C:\Projects\NCHRP 08-103\VA_TEST-2.xml";

            bool       ok      = true;
            DEAContext context = new DEAContext("DEAContext", "Project");

            ok = context.AddVariable("Cost", "I", 1.0e-6, out errorMessage);
            if (ok)
            {
                ok = context.AddVariable("Congestion", "O", out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("Safety", "O", out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("Accessibility", "O", out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("Environmental Quality", "O", out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("Economic Development", "O", out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("Land Use", "O", out errorMessage);
            }
            if (ok)
            {
                ok = context.UploadCsvFile(csvFilePath, out warningMessage, out errorMessage);
            }

            if (ok)
            {
                ok = context.RunDEA(out errorMessage);
            }

            /*
             * if (ok)
             * {
             *  ok = context.AddCostConstraint("STOCK", 27.0, out errorMessage);
             *  if (ok)
             *      ok = context.AddCostConstraint("WAGES", 40, out errorMessage);
             * }
             *
             * if (ok)
             * {
             *  ok = context.ApplyCostConstraintsToProjectSelection(out errorMessage);
             * }
             */
            Assert.IsTrue(ok, errorMessage);

            if (ok)
            {
                DataSet ds = context.ToDataSet(out errorMessage);
                Assert.IsNotNull(ds, errorMessage);
                ok = ds != null;
            }

            if (ok)
            {
                ok = context.SaveToXmlFile(xmlFilePath, out errorMessage);
                Assert.IsTrue(ok, errorMessage);
            }

            if (ok)
            {
                DEAContext context2 = DEAContext.CreateFromXmlFile(xmlFilePath, out errorMessage);
                Assert.IsNotNull(context2, errorMessage);
                if (context2 != null)
                {
                    ok = context2.SaveToXmlFile(xmlFilePath2, out errorMessage);
                    Assert.IsTrue(ok, errorMessage);
                }
            }

            if (ok)
            {
                string json = context.ToJsonString(out errorMessage);
                Assert.IsNotNull(json, errorMessage);
            }
        }
예제 #3
0
        public void TestVACsvDataUnconstrained()
        {
            string errorMessage   = null;
            string warningMessage = null;

            string csvFilePath      = @"C:\Projects\NCHRP 08-103\VA_TEST_PROJECTS.csv";
            string csvConstFilePath = @"C:\Projects\NCHRP 08-103\VA_TEST_CONSTRAINTS.csv";
            string csvVarFilePath   = @"C:\Projects\NCHRP 08-103\VA_TEST_VARIABLES.csv";
            string xmlFilePath      = @"C:\Projects\NCHRP 08-103\VA_TEST-3.xml";
            string xmlFilePath2     = @"C:\Projects\NCHRP 08-103\VA_TEST-4.xml";

            bool       ok      = true;
            DEAContext context = new DEAContext("DEAContext", "Project");

            ok = context.LoadVariablesFromCsvFile(csvVarFilePath, out errorMessage);
            if (ok)
            {
                ok = context.UploadCsvFile(csvFilePath, out warningMessage, out errorMessage);
            }

            if (ok)
            {
                ok = context.LoadCsvConstraints(csvConstFilePath, out errorMessage);
            }
            if (ok)
            {
                ok = context.RunDEA(out errorMessage);
            }


            if (ok)
            {
                ok = context.ApplyCostConstraintsToProjectSelection(out errorMessage);
            }

            Assert.IsTrue(ok, errorMessage);

            if (ok)
            {
                DataSet ds = context.ToDataSet(out errorMessage);
                Assert.IsNotNull(ds, errorMessage);
                ok = ds != null;
            }

            if (ok)
            {
                ok = context.SaveToXmlFile(xmlFilePath, out errorMessage);
                Assert.IsTrue(ok, errorMessage);
            }

            if (ok)
            {
                DEAContext context2 = DEAContext.CreateFromXmlFile(xmlFilePath, out errorMessage);
                Assert.IsNotNull(context2, errorMessage);
                if (context2 != null)
                {
                    ok = context2.SaveToXmlFile(xmlFilePath2, out errorMessage);
                    Assert.IsTrue(ok, errorMessage);
                }
            }

            if (ok)
            {
                string json = context.ToJsonString(out errorMessage);
                Assert.IsNotNull(json, errorMessage);
            }
        }
예제 #4
0
        public void Test20DepotsConstrainedWeights()
        {
            string errorMessage   = null;
            string warningMessage = null;

            string csvFilePath  = @"C:\Projects\NCHRP 08-103\DEA-Example-20-depots.csv";
            string xmlFilePath  = @"C:\Projects\NCHRP 08-103\DEA-Example-20-depots.xml";
            string xmlFilePath2 = @"C:\Projects\NCHRP 08-103\DEA-Example-20-depots-2.xml";

            bool       ok      = true;
            DEAContext context = new DEAContext("DEAContext", "Depot");

            ok = context.AddVariable("STOCK", "I", out errorMessage);
            if (ok)
            {
                ok = context.AddVariable("WAGES", "I", out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("ISSUES", "O", 0.0, 1.0, out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("RECEIPTS", "O", 0.0, 1.0, out errorMessage);
            }
            if (ok)
            {
                ok = context.AddVariable("REQS", "O", 0.0, 1.0, out errorMessage);
            }

            if (ok)
            {
                ok = context.UploadCsvFile(csvFilePath, out warningMessage, out errorMessage);
            }

            if (ok)
            {
                ok = context.RunDEA(out errorMessage);
            }

            if (ok)
            {
                ok = context.AddCostConstraint("STOCK", 27.0, out errorMessage);
                if (ok)
                {
                    ok = context.AddCostConstraint("WAGES", 40, out errorMessage);
                }
            }

            if (ok)
            {
                ok = context.ApplyCostConstraintsToProjectSelection(out errorMessage);
            }
            Assert.IsTrue(ok, errorMessage);

            if (ok)
            {
                DataSet ds = context.ToDataSet(out errorMessage);
                Assert.IsNotNull(ds, errorMessage);
                ok = ds != null;
            }

            if (ok)
            {
                ok = context.SaveToXmlFile(xmlFilePath, out errorMessage);
                Assert.IsTrue(ok, errorMessage);
            }

            if (ok)
            {
                DEAContext context2 = DEAContext.CreateFromXmlFile(xmlFilePath, out errorMessage);
                Assert.IsNotNull(context2, errorMessage);
                if (context2 != null)
                {
                    ok = context2.SaveToXmlFile(xmlFilePath2, out errorMessage);
                    Assert.IsTrue(ok, errorMessage);
                }
            }

            if (ok)
            {
                string json = context.ToJsonString(out errorMessage);
                Assert.IsNotNull(json, errorMessage);
            }
        }
예제 #5
0
    public void Populate(string err = null)
    {
        string  errorMessage = null;
        DataSet ds           = null;

        try
        {
            if (Session[_contextKey] != null)
            {
                DEAContext context = Session[_contextKey] as DEAContext;
                ds = context.ToDataSet(out errorMessage);
                if (ds != null)
                {
                    GridViewParams.DataSource = ds.Tables["PARAMETERS"];
                    GridViewParams.DataBind();

                    GridViewVars.DataSource = ds.Tables["VARIABLES"];
                    GridViewVars.DataBind();

                    GridViewConst.DataSource = ds.Tables["CONSTRAINTS"];
                    GridViewConst.DataBind();

                    if (ds.Tables["CONSTRAINTS"].Rows == null || ds.Tables["CONSTRAINTS"].Rows.Count < 1)
                    {
                        LabelConst.Visible = false;
                    }

                    GridViewProjects.Columns.Clear();
                    BoundField bf = new BoundField();
                    bf.HeaderText = context.ProjectIDFieldName;
                    bf.DataField  = "NAME";
                    GridViewProjects.Columns.Add(bf);

                    foreach (DataRow r in ds.Tables["VARIABLES"].Rows)
                    {
                        string varName = r["NAME"].ToString();
                        bf = new BoundField();
                        bf.HeaderStyle.CssClass      = "text-right";
                        bf.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                        bf.HeaderText       = varName;
                        bf.DataField        = varName;
                        bf.DataFormatString = "{0:f6}";
                        GridViewProjects.Columns.Add(bf);
                    }
                    GridViewProjects.DataSource = ds.Tables["PROJECTS"];
                    GridViewProjects.DataBind();
                }
            }
        }
        catch (Exception ex)
        {
            errorMessage       = ex.Message;
            LabelError.Text    = errorMessage;
            LabelError.Visible = true;
            ButtonRun.Visible  = false;
        }

        if (string.IsNullOrEmpty(errorMessage))
        {
            ButtonRun.Visible = true;
            if (ds != null)
            {
                if (ds.Tables["CONSTRAINTS"].Rows != null && ds.Tables["CONSTRAINTS"].Rows.Count > 0)
                {
                    ButtonRun.ToolTip = "Click to rank projects by their relative efficiency and apply constraints to their selection.";
                }
                else
                {
                    ButtonRun.ToolTip = "Click to rank projects by their relative efficiency.";
                }
            }


            if (!string.IsNullOrEmpty(err))
            {
                LabelError.Text    = err;
                LabelError.Visible = true;
            }
        }
    }