コード例 #1
0
ファイル: ModelInput.cs プロジェクト: govtmirror/hydrosense
        public void ReadHardcoded()
        {
            double[][]   Xs;
            double[][]   Ys;
            double[][]   Xd;
            double[][]   Yd;
            double[][][] Xt;
            double[][][] Yt;
            double[][][] Xtl;
            double[][][] Ytl;

            // marginal supply curves
            Xs          = new double[2][];
            Ys          = new double[2][];
            Xs[0]       = new double[] { 0.0, 2000.0, 4000.0, 5000.0, 7500.0, 10000.0, 20000.0, 30000.0, 50000.0, 65000.0 };
            Xs[1]       = new double[] { 0.0, 1000.0, 2500.0, 5000.0, 8000.0, 10000.0, 15000.0, 25000.0 };
            Ys[0]       = new double[] { 3.0, 3.061, 3.122, 3.154, 3.234, 3.316, 3.664, 4.050, 4.946, 5.747 };
            Ys[1]       = new double[] { 1.50, 1.546, 1.617, 1.743, 1.907, 2.025, 2.352, 3.176 };
            supplyNodes = new Nodes(Xs, Ys);

            // marginal demand curves
            Xd          = new double[3][];
            Yd          = new double[3][];
            Xd[0]       = new double[] { 0.0, 2000.0, 4000.0, 7500.0, 10000.0, 15000.0, 20000.0, 30000.0, 40000.0 };
            Xd[1]       = new double[] { 0.0, 3000.0, 7500.0, 12500.0, 20000.0, 30000.0 };
            Xd[2]       = new double[] { 0.0, 2500.0, 5000.0, 10000.0, 15000.0, 25000.0, 35000.0 };
            Yd[0]       = new double[] { 15.0, 12.782, 10.892, 8.232, 6.740, 4.518, 3.028, 1.361, 0.611 };
            Yd[1]       = new double[] { 10.0, 8.607, 6.873, 5.353, 3.679, 2.231 };
            Yd[2]       = new double[] { 25.0, 19.470, 15.163, 9.197, 5.578, 2.052, 0.755 };
            demandNodes = new Nodes(Xd, Yd);

            // transportation costs
            Xt        = new double[3][][];
            Xt[0]     = new double[2][];
            Xt[1]     = new double[2][];
            Xt[2]     = new double[2][];
            Xt[0][0]  = new double[] { 0.0, 40000.0 };
            Xt[0][1]  = new double[] { 0.0, 20000.0 };
            Xt[1][0]  = new double[] { 0.0, 43000.0 };
            Xt[1][1]  = new double[] { 0.0, 50000.0 };
            Xt[2][0]  = new double[] { 0.0, 50000.0 };
            Xt[2][1]  = new double[] { 0.0, 17500.0 };
            Yt        = new double[3][][];
            Yt[0]     = new double[2][];
            Yt[1]     = new double[2][];
            Yt[2]     = new double[2][];
            Yt[0][0]  = new double[] { 1.5, 1.5 };
            Yt[0][1]  = new double[] { 0.75, 0.75 };
            Yt[1][0]  = new double[] { 1.25, 1.25 };
            Yt[1][1]  = new double[] { 100.0, 100.0 };
            Yt[2][0]  = new double[] { 100.0, 100.0 };
            Yt[2][1]  = new double[] { 1.3, 1.3 };
            linkCosts = new LinkCosts(Xt, Yt);

            // transportation losses
            Xtl        = new double[3][][];
            Xtl[0]     = new double[2][];
            Xtl[1]     = new double[2][];
            Xtl[2]     = new double[2][];
            Xtl[0][0]  = new double[] { 0.0, 5000.0, 10000.0, 15000.0, 20000.0, 30000.0, 40000.0 };
            Xtl[0][1]  = new double[] { 0.0, 2500.0, 5000.0, 10000.0, 15000.0, 20000.0 };
            Xtl[1][0]  = new double[] { 0.0, 5000.0, 10000.0, 17500.0, 25000.0, 35000.0, 43000.0 };
            Xtl[1][1]  = new double[] { 0.0, 50000.0 };
            Xtl[2][0]  = new double[] { 0.0, 50000.0 };
            Xtl[2][1]  = new double[] { 0.0, 2500.0, 5000.0, 7500.0, 10000.0, 15000.0, 17500.0 };
            Ytl        = new double[3][][];
            Ytl[0]     = new double[2][];
            Ytl[1]     = new double[2][];
            Ytl[2]     = new double[2][];
            Ytl[0][0]  = new double[] { 0.0, 2661.0, 8147.0, 13753.0, 19134.0, 29426.0, 39487.0 };
            Ytl[0][1]  = new double[] { 0.0, 0.0, 1390.0, 6275.0, 11866.0, 17515.0 };
            Ytl[1][0]  = new double[] { 0.0, 1467.0, 5821.0, 13959.0, 22448.0, 33443.0, 41917.0 };
            Ytl[1][1]  = new double[] { 0.0, 0.0 };
            Ytl[2][0]  = new double[] { 0.0, 0.0 };
            Ytl[2][1]  = new double[] { 0.0, 303.0, 1717.0, 3707.0, 6071.0, 11403.0, 14209.0 };
            linkLosses = new LinkLosses(Xtl, Ytl);

            // initial guess
            Q    = new double[3][];
            Q[0] = new double[] { 10000, 10000 };
            Q[1] = new double[] { 10000, 0 };
            Q[2] = new double[] { 0, 10000 };
        }
コード例 #2
0
ファイル: ModelInput.cs プロジェクト: govtmirror/hydrosense
        public string ReadFromExcel(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return("Cannot find file: " + fileName);
            }

            IWorkbook wkbk;

            try
            {
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                wkbk = WorkbookFactory.Create(fs);
                fs.Close();
            }
            catch (Exception)
            {
                return("Unable to open input spreadsheet. Is file open?");
            }

            List <string> sheets = new List <string> {
                "Supply Curves", "Demand Curves", "Transportation Costs", "Transportation Losses", "Initial Guess"
            };

            string sheetsExist = CheckSheetsExist(wkbk, sheets);

            if (sheetsExist != string.Empty)
            {
                return(sheetsExist);
            }

            string error = string.Empty;

            Nodes sNodes = ReadNodesDataFromSheet(wkbk, "Supply Curves");

            error = CheckEqualNumberPoints(sNodes.x, sNodes.y);
            if (error != string.Empty)
            {
                return(error);
            }
            supplyNodes = new Nodes(sNodes.x, sNodes.y);

            Nodes dNodes = ReadNodesDataFromSheet(wkbk, "Demand Curves");

            error = CheckEqualNumberPoints(dNodes.x, dNodes.y);
            if (error != string.Empty)
            {
                return(error);
            }
            demandNodes = new Nodes(dNodes.x, dNodes.y);

            Links costs = ReadLinksDataFromSheet(wkbk, "Transportation Costs");

            error = CheckEqualNumberPoints(costs.x, costs.y);
            if (error != string.Empty)
            {
                return(error);
            }
            linkCosts = new LinkCosts(costs.x, costs.y);

            Links losses = ReadLinksDataFromSheet(wkbk, "Transportation Losses");

            error = CheckEqualNumberPoints(losses.x, losses.y);
            if (error != string.Empty)
            {
                return(error);
            }
            linkLosses = new LinkLosses(losses.x, losses.y);

            Q     = ReadQuantityDataFromSheet(wkbk, "Initial Guess");
            error = CheckEqualNumberPoints(Q);
            if (error != string.Empty)
            {
                return(error);
            }

            return(string.Empty);
        }