Exemple #1
0
    public void GetPolynomCoefficients2()
    {
        double[] xx = { 1, 2, 3, 4 };
        double[] yy = { 6, 9, 2, 5, };

        double[] d = { 6, 3, -5, 10 / 3d };

        var p = new Polynom(d[0]);

        var p1  = new Polynom(-xx[0], 1);
        var pp1 = d[1] * p1;

        p += pp1;

        var p2 = new Polynom(-xx[1], 1);

        p += d[2] * p1 * p2;

        var p3 = new Polynom(-xx[2], 1);

        p += d[3] * p1 * p2 * p3;

        var expected_coefficients = p.Coefficients;

        var actual_coefficients = Newton.GetPolynomCoefficients(xx, yy);

        var actual_coefficients2 = Lagrange.GetPolynomCoefficients(xx, yy);

        const double accuracy = 7.106e-15;

        Assert.That.Collection(actual_coefficients).IsEqualTo(expected_coefficients, accuracy);
    }
Exemple #2
0
        public void PolynomFunction()
        {
            lagrangePolynomial = new Lagrange(nodes.ToArray(), values.ToArray());
            string result = MakeNormalForm(lagrangePolynomial.LagrangePolynomial());

            label1.Text = "Polynom: " + result;
        }
Exemple #3
0
        public void LagrangeShould()
        {
            string[] lines    = { "1,2,3", "4,5,6" };
            var      lagrange = new Lagrange();

            Assert.IsTrue(lagrange.PrepareData(lines));
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Parameter.p = int.Parse(textBox2.Text);
            Lagrange Lag = new Lagrange();

            Lag.findresult();
            //显示结果
            label2.Text = Lag.results;
            label4.Text = Lag.lowbound.ToString();
            //图象分析
            lagrangeChartForm.chartControl1.Series.Clear();
            if (checkBox1.Checked)
            {
                ChartSeries upboundSeries  = new ChartSeries("upbound");
                ChartSeries lowboundSeries = new ChartSeries("lowbound");
                upboundSeries.SeriesIndexedModelImpl  = new StringIndexedModel(upboundSeries, (double[])Lag.upbounds.ToArray(typeof(double)));
                lowboundSeries.SeriesIndexedModelImpl = new StringIndexedModel(lowboundSeries, (double[])Lag.lowbounds.ToArray(typeof(double)));
                lagrangeChartForm.chartControl1.Series.Add(upboundSeries);
                lagrangeChartForm.chartControl1.Series.Add(lowboundSeries);
            }
            if (checkBox2.Checked)
            {
                ChartSeries zukSeries = new ChartSeries("zuk");
                ChartSeries zlkSeries = new ChartSeries("zlk");
                zukSeries.SeriesIndexedModelImpl = new StringIndexedModel(zukSeries, (double[])Lag.zuks.ToArray(typeof(double)));
                zlkSeries.SeriesIndexedModelImpl = new StringIndexedModel(zlkSeries, (double[])Lag.zlks.ToArray(typeof(double)));
                lagrangeChartForm.chartControl1.Series.Add(zukSeries);
                lagrangeChartForm.chartControl1.Series.Add(zlkSeries);
            }
            for (int i = 0; i < lagrangeChartForm.chartControl1.Series.Count; i++)
            {
                lagrangeChartForm.chartControl1.Series[i].Type = ChartSeriesType.Line;
            }
        }
    private SolutionServer()
    {
        solutionSets = new Dictionary <string, ISolutionSet>();
        ISolutionSet s = new FigureEights();

        solutionSets.Add(s.GetName(), s);
        s = new Choreos();
        solutionSets.Add(s.GetName(), s);
        s = new Lagrange();
        solutionSets.Add(s.GetName(), s);
        s = new BrouckeA();
        solutionSets.Add(s.GetName(), s);
        s = new BrouckeR();
        solutionSets.Add(s.GetName(), s);
        s = new Henon();
        solutionSets.Add(s.GetName(), s);

        setNames = new string[solutionSets.Count];
        int count = 0;

        foreach (string key in solutionSets.Keys)
        {
            setNames[count] = key;
            count          += 1;
        }
    }
        public void saveSoln(string caseDir, Summery summery, Lagrange lag, int vitualRoutingValue)
        {
            //保存文件
            StreamWriter file_schedule = new StreamWriter(caseDir
                                                          + "交路内容与求解信息_" + lag.step_size + "_virRoutingVal_" + vitualRoutingValue + ".txt");
            StreamWriter file_iteration = new StreamWriter(caseDir
                                                           + "iterationBound" + lag.step_size + "_virRoutingVal_" + vitualRoutingValue + ".csv");

            file_schedule.WriteLine(summery.outputStr());
            file_schedule.Close();

            string LB_UB = "";

            file_iteration.WriteLine("CurLB_with,CurLB_without,CurUB_with");
            for (int i = 0; i < lag.CurLB.Count; i++)
            {
                LB_UB = "";
                LB_UB = i < lag.CurUB.Count ?
                        Convert.ToString(lag.CurLB[i]) + "," + Convert.ToString(lag.CurLB_without_penalty[i])
                        + "," + Convert.ToString(lag.CurUB[i])
                    : Convert.ToString(lag.CurLB[i]) + "," + Convert.ToString(lag.CurLB_without_penalty[i]);

                file_iteration.WriteLine(LB_UB);// + "," + lag.CurUB[i]);
            }
            file_iteration.Close();
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Parameter.p             = int.Parse(textBox2.Text);
            Parameter.coverdistance = double.Parse(textBox4.Text);
            Lagrange Lag = new Lagrange();

            Lag.findresult();
            //记录结果
            Parameter.opti = Lag.lowbound;
            Parameter.x    = Lag.xj1;
            Parameter.y    = Lag.yij1;
            Parameter.x_trans();
            //显示结果
            label2.Text = Lag.results;
            label4.Text = Lag.lowbound.ToString();
            //图象分析
            lagrangeChartForm.chartControl1.Series.Clear();
            if (checkBox1.Checked)
            {
                ChartSeries upboundSeries  = new ChartSeries("upbound");
                ChartSeries lowboundSeries = new ChartSeries("lowbound");
                upboundSeries.SeriesIndexedModelImpl  = new StringIndexedModel(upboundSeries, (double[])Lag.upbounds.ToArray(typeof(double)));
                lowboundSeries.SeriesIndexedModelImpl = new StringIndexedModel(lowboundSeries, (double[])Lag.lowbounds.ToArray(typeof(double)));
                lagrangeChartForm.chartControl1.Series.Add(upboundSeries);
                lagrangeChartForm.chartControl1.Series.Add(lowboundSeries);
            }
            if (checkBox2.Checked)
            {
                ChartSeries zukSeries = new ChartSeries("zuk");
                ChartSeries zlkSeries = new ChartSeries("zlk");
                zukSeries.SeriesIndexedModelImpl = new StringIndexedModel(zukSeries, (double[])Lag.zuks.ToArray(typeof(double)));
                zlkSeries.SeriesIndexedModelImpl = new StringIndexedModel(zlkSeries, (double[])Lag.zlks.ToArray(typeof(double)));
                lagrangeChartForm.chartControl1.Series.Add(zukSeries);
                lagrangeChartForm.chartControl1.Series.Add(zlkSeries);
            }
            for (int i = 0; i < lagrangeChartForm.chartControl1.Series.Count; i++)
            {
                lagrangeChartForm.chartControl1.Series[i].Type = ChartSeriesType.Line;
            }
            int flag = 0;

            for (int i = 0; i < Parameter.n; i++)
            {
                if (Lag.xj1[i] == 1)
                {
                    Parameter.x[flag] = i;
                    flag++;
                }
            }
            for (int i = 0; i < Parameter.n; i++)
            {
                label10.Text = label10.Text + Parameter.x[i].ToString() + " ";
            }
        }
Exemple #8
0
        public void Lagrange_2()
        {
            xList = new List <double> {
                1, 2, 4
            };
            yList = new List <double> {
                1, 4, 16
            };

            string interpolacion = Lagrange.Interpolar(xList, yList, out string pasos).ToString();

            Assert.AreEqual("x^2", interpolacion);
        }
Exemple #9
0
        public void Lagrange_1()
        {
            xList = new List <double> {
                -5, -1, 3, 5
            };
            yList = new List <double> {
                333, -3, -83, -387
            };

            string interpolacion = Lagrange.Interpolar(xList, yList, out string pasos).ToString();

            Assert.AreEqual("-3x^3-x^2+3x-2", interpolacion);
        }
Exemple #10
0
        /// <summary>
        /// 根据已有数据预测后面时间的数据
        /// </summary>
        /// <param name="models">已有数据</param>
        /// <param name="time">要预测的时间长度</param>
        /// <param name="interval">时间间隔</param>
        /// <returns>返回预测数据加上已有数据</returns>
        public List <YuMiBaoZiModel> getPredictDataAfterTime(List <YuMiBaoZiModel> models, int time, int interval)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;
            List <YuMiBaoZiModel> allModels = getAllData(models);

            double[]      douX     = new double[allModels.Count];
            List <double> predictX = new List <double>();

            double[] douY = new double[allModels.Count];
            for (int i = 0; i < allModels.Count; i++)
            {
                douX[i] = Convert.ToDouble(allModels[i].xData);
                douY[i] = Convert.ToDouble(allModels[i].yData);
            }
            int    count = time / interval;
            int    flag  = time % interval;
            double xLast = douX[douX.Length - 1];

            for (int i = 0; i < count; i++)
            {
                xLast = xLast + interval;
                predictX.Add(xLast);
            }
            if (flag != 0)
            {
                xLast = xLast + flag;
                predictX.Add(xLast);
            }
            Lagrange      lan      = new Lagrange(douX, douY);
            List <double> predictY = lan.InsertDatas(predictX);

            for (int i = 0; i < predictY.Count; i++)
            {
                YuMiBaoZiModel model = new YuMiBaoZiModel();
                model.xData = predictX[i].ToString();
                model.yData = predictY[i].ToString();
                allModels.Add(model);
            }
            for (int i = 0; i < models.Count; i++)
            {
                allModels[i].high       = getMax(convert(allModels));
                allModels[i].low        = getMin(convert(allModels));
                allModels[i].media      = getMedia(convert(allModels));
                allModels[i].xLabel     = xLabel;
                allModels[i].canShuName = yLabel;
            }
            List <YuMiBaoZiModel> predictModels = getAllData(allModels);

            return(predictModels);
        }
Exemple #11
0
        public void LagrangeEqualValueOfXElements()
        {
            double[] xValue = new double[3] {
                1D, 1.001D, 2D
            };
            double[] yValue = new double[3] {
                3D, 2D, 3D,
            };

            Assert.DoesNotThrow(() =>
            {
                Lagrange lsm = new Lagrange(xValue, yValue);
            });
        }
Exemple #12
0
        public void LagrangeEqualValueOfXElementsException()
        {
            double[] xValue = new double[3] {
                1D, 1.0000000000001D, 2D
            };
            double[] yValue = new double[3] {
                3D, 2D, 3D,
            };

            Assert.Throws <ArgumentException>(() =>
            {
                Lagrange lsm = new Lagrange(xValue, yValue);
            });
        }
Exemple #13
0
        public void LagrangeEqualDimensionOfXandYException()
        {
            double[] xValue = new double[5] {
                -1D, 0D, 1D, 2D, 3D
            };
            double[] yValue = new double[4] {
                3D, 2D, 3D, 6D
            };

            Assert.Throws <ArgumentException>(() =>
            {
                Lagrange lsm = new Lagrange(xValue, yValue);
            });
        }
Exemple #14
0
    public void GetPolynomCoefficients()
    {
        var X = Interval.Range(0, 2, 0.1).ToArray();
        //var X = Interval.RangeN(0, 2, 5).ToArray();
        var Y = X.ToArray(Sinc);

        var polynom = Lagrange.GetPolynom(X, Y);

        var yy = X.ToArray(polynom.Value);

        var delta = Y.Zip(yy, (y0, y1) => y0 - y1);
        var error = delta.Sum(v => v.Pow2()) / (Y.Length + 1);

        Assert.That.Value(error).LessThan(2.00e-4, 6.36e-007);
    }
Exemple #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            Parameter.coverdistance = double.Parse(textBox4.Text);
            Lagrange Lag = new Lagrange();

            Lag.findresult();
            //显示结果
            int sum = 0;

            for (int i = 0; i < Parameter.n; i++)
            {
                sum += Lag.xj1[i];
            }
            label2.Text    = sum.ToString();
            label4.Text    = Lag.totalcost.ToString();
            Parameter.p    = sum;
            Parameter.opti = Lag.totalcost;
            Parameter.x_trans();
        }
Exemple #16
0
        public List <YuMiBaoZiModel> getLagPredictValue(List <YuMiBaoZiModel> models, int time)
        {
            string xLabel = models[0].xLabel;
            string yLabel = models[0].canShuName;
            List <YuMiBaoZiModel> allModels = getAllData(models);

            double[]      ownX = new double[time];
            double[]      ownY = new double[time];
            List <double> douX = new List <double>();
            List <double> douY;

            for (int i = 0; i < allModels.Count; i++)
            {
                if (i < time)
                {
                    ownX[i] = Convert.ToDouble(allModels[i].xData);
                    ownY[i] = Convert.ToDouble(allModels[i].yData);
                }
                douX.Add(Convert.ToDouble(allModels[i].xData));
            }

            Lagrange lan1 = new Lagrange(ownX, ownY);

            douY = lan1.InsertDatas(douX);
            List <YuMiBaoZiModel> predictAllModel = new List <YuMiBaoZiModel>();

            for (int i = 0; i < douY.Count; i++)
            {
                YuMiBaoZiModel model = new YuMiBaoZiModel();
                model.xData = douX[i].ToString();
                model.yData = douY[i].ToString();
                predictAllModel.Add(model);
            }
            for (int i = 0; i < predictAllModel.Count; i++)
            {
                predictAllModel[i].high            = getMax(convert(models));
                predictAllModel[i].low             = getMin(convert(models));
                predictAllModel[i].predictChaValue = Convert.ToDouble(allModels[i].yData) - Convert.ToDouble(predictAllModel[i].yData);
                predictAllModel[i].xLabel          = xLabel;
                predictAllModel[i].canShuName      = yLabel;
            }
            return(predictAllModel);
        }
Exemple #17
0
        public void TestMethod1()
        {
            var Lag = new Lagrange();

            const int size    = 5;
            var       xValues = new double[size];
            var       yValues = new double[size];

            xValues[0] = -5; yValues[0] = 25;
            xValues[1] = -3; yValues[1] = 9;
            xValues[2] = 0; yValues[2] = 0;
            xValues[3] = 3; yValues[3] = 9;
            xValues[4] = 5; yValues[4] = 25;

            double expected = 1;

            double result = Lagrange.InterpolateLagrangePolynomial(1, xValues, yValues, 5);

            Assert.AreEqual(expected, result);
        }
Exemple #18
0
        static void Main(string[] args)
        {
            var x = SymbolicExpression.Variable("x");

            Console.WriteLine(Taylor.GetTaylor(6,
                                               x,
                                               0,
                                               SymbolicExpression.E.Pow(x).Multiply(x.Sin())
                                               ));

            //---------
            // 2. Užrašykite liekamąjį narį.
            // Rn = M * (x-a)^(n+1) / (n+1)!
            // M = f(n+1)(x)

            // 3. Įvertinkite liekamąjį narį.
            Lagrange.GetError(-0.5, 0.5, 5);
            Lagrange.GetError(-0.1, 0.1, 5);
            Lagrange.GetError(-0.001, 0.001, 5);
        }
            internal void CalculateNewRow()
            {
                previousRow = newRow;
                int newRowWidth = GetPreviousRowSize() + 1;

                newRow = new List <Lagrange>();
                foreach (int iterator in Enumerable.Range(0, newRowWidth))
                {
                    long newValue = GetLeftOf(iterator) + GetRightOf(iterator);
                    //special case for initial (top) row
                    if (newValue == 0)
                    {
                        newValue = 1;
                    }
                    Lagrange newLagrange = new Lagrange {
                        combinations = newValue
                    };
                    newRow.Add(newLagrange);
                }
                allRows.Add(newRow);
            }
        public Summery(Lagrange lag, CreateNetWork_db net, double netConstructTime, double solveTime)
        {
            for (int i = 0; i < lag.YUB.Count; i++)
            {
                crew_schedule_content += "乘务交路" + (i + 1).ToString() + "为:" + lag.YUB[i] + "\n";
            }

            //opt_lb_with = lag.BestLB;
            //opt_ub_with = lag.BestUB;
            opt_lb_with    = lag.BestLB_with_penalty;
            opt_ub_with    = lag.BestUB_with_penalty;
            opt_lb_without = lag.BestLB_without_penalty;
            opt_ub_without = lag.BestUB_without_penalty;

            gap_with    = (opt_ub_with - opt_lb_with) / opt_ub_with;
            gap_without = (opt_ub_without - opt_lb_without) / opt_ub_without;

            iteration_num      = lag.k;
            state_node_num     = net.T_S_S_NodeList.Count;
            state_arc_num      = net.T_S_S_ArcList.Count;
            dvar_num           = state_arc_num * lag.CrewCount;
            net_construct_time = netConstructTime;
            solve_time         = solveTime;
        }
Exemple #21
0
        /// <summary>
        /// 得到后几天的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <param name="day">天数</param>
        /// <returns>得到的预测值</returns>
        public static List <DataValue> getPredictData(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = new List <double>();

            List <DateTime> dateTime   = new List <DateTime>();
            List <double>   grainTemp  = new List <double>();
            List <double>   WaterValue = new List <double>();

            a = SqlData.sqlGetData("dbo.小麦质量特性参数数据表", "CanNumberValue", str);

            dateTime = SqlData.sqlDataDate("dbo.小麦质量特性参数数据表", "Date", str);

            grainTemp = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "GrainTemp", str);

            WaterValue = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "Water", str);
            String canShuNumber = SqlData.getCanShuNumber("dbo.小麦参数实验总概括表", "CanShuNumber", str);
            String canShuName   = SqlData.getCanShuName("dbo.小麦参数名表", "CanShuName", canShuNumber);

            double[]   col0    = a.ToArray();
            DateTime[] date    = dateTime.ToArray();
            double[]   douTemp = grainTemp.ToArray();
            double[]   water   = WaterValue.ToArray();

            double low   = getLow(col0);
            double high  = getHigh(col0);
            double media = getMedia(col0);

            DataValue datapoint = null;

            for (int i = 0; i < col0.Length; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }
                datapoint = new DataValue();
                DateTime dYear = date[i];
                datapoint.date = dYear;

                if (i == 0)
                {
                    datapoint.SpeedData = 0;
                }
                else
                {
                    datapoint.SpeedData = getSpeedData(col0[i], col0[i - 1], 30);
                }
                datapoint.High         = high;
                datapoint.Low          = low;
                datapoint.Media        = media;
                datapoint.PredictData  = col0[i];
                datapoint.yLable       = canShuName;
                datapoint.CanShuNumber = canShuNumber;
                datapoint.index        = i + 1;
                datapoint.GrainTemp    = douTemp[i];
                datapoint.Water        = water[i];
                lists.Add(datapoint);
            }

            int      count  = day / 30;
            int      count1 = day % 30;
            int      index  = datapoint.index;
            DateTime d      = datapoint.date;
            double   d1     = datapoint.PredictData;

            List <double> dayDou = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }
            double[] dat;
            DateTime ti = date[date.Length - 1];

            if (count1 != 0)
            {
                dat = new double[count + 1];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(30);
                    dat[i] = ti.ToOADate();
                }
                dat[count] = ti.AddDays(count1).ToOADate();
            }
            else
            {
                dat = new double[count];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(7);
                    dat[i] = ti.ToOADate();
                }
            }
            Lagrange      lan    = new Lagrange(dayDou.ToArray(), col0);
            List <double> jieguo = lan.InsertDatas(dat.ToList <double>());

            double[] predictData = jieguo.ToArray();

            for (int i = 0; i < count; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.index       = index + 1;
                datapoint.PredictData = predictData[i];
                datapoint.date        = d.AddDays(30);

                datapoint.Water     = water[0];
                datapoint.yLable    = canShuName;
                datapoint.GrainTemp = douTemp[0];

                d     = datapoint.date;
                d1    = datapoint.PredictData;
                index = datapoint.index;
                lists.Add(datapoint);
            }
            if (count1 != 0)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.PredictData = predictData[count];
                datapoint.date        = d.AddDays(count1);

                datapoint.Water     = water[0];
                datapoint.yLable    = canShuName;
                datapoint.GrainTemp = douTemp[0];


                d  = datapoint.date;
                d1 = datapoint.PredictData;

                datapoint.index = index + 1;
                lists.Add(datapoint);
            }
            return(lists);
        }
 public void InitLR(CreateNetWork_db net, int stepSize)
 {
     LR = new Lagrange(net, stepSize);
 }
Exemple #23
0
        private void buttonok_Click(object sender, EventArgs e)
        {
            int maxdrivetime    = Convert.ToInt32(textBoxmaxdrive.Text);
            int mindrivetime    = Convert.ToInt32(textBoxmindrive.Text);
            int maxdaycrewtime  = Convert.ToInt32(textBoxmaxdaycrew.Text);
            int mindaycrewtime  = Convert.ToInt32(textBoxmindaycrew.Text);
            int maxconntime     = Convert.ToInt32(textBoxconn.Text);
            int mintranslation  = Convert.ToInt32(textBoxtran.Text);
            int minrelaxtime    = Convert.ToInt32(textBoxminrelax.Text);
            int maxrelaxtime    = Convert.ToInt32(textBoxmaxrelax.Text);
            int minoutrelaxtime = Convert.ToInt32(textBoxminoutrelax.Text);
            int maxoutrelaxtime = Convert.ToInt32(textBoxmaxoutrelax.Text);
            int days            = Convert.ToInt32(textBoxdays.Text);
            int step            = Convert.ToInt32(textBoxstep.Text);


            List <int[]> windows = new List <int[]>();

            //STLunch = 660; ETLunch = 780; STDinner = 1020; ETDinner = 1140; //2h
            //int STLunch = 630, ETLunch = 810, STDinner = 990, ETDinner = 1170; //3h
            windows.Add(new int[4] {
                660, 780, 1020, 1140
            });                                              //2h
            windows.Add(new int[4] {
                630, 810, 990, 1170
            });                                             //3h
            windows.Add(new int[4] {
                600, 840, 960, 1200
            });                                              //4h
            //windows.Add(new int[4] {480,   840,   900,   1260}); //不考虑 windows})
            windows.Add(new int[4] {
                4000, 8400, 9600, 14400
            });
            //windows.Add(new int[4] { 3000, 7200, 7210, 28800 });//INF

            string[] Cur_case = { "case21\\", "case22\\", "case33\\", "case34\\" };


            for (int j = 0; j < windows.Count - 3; j++)
            {
                #region MyRegion
                Stopwatch realTime = new Stopwatch();
                realTime.Restart();

                str = "";

                CGandLR LR_CG = new CGandLR();

                StartTime = DateTime.Now;
                int    sh        = StartTime.Hour;
                int    sm        = StartTime.Minute;
                int    ss        = StartTime.Second;
                int    sms       = StartTime.Millisecond;
                int    sa        = (sh * 60 + sm) * 60 + ss;
                double starttime = sa + 0.001 * sms;
                //Ds = net.ConnDataBase();
                //net.LoadData(Ds,days);
                net.LoadData_csv(days,
                                 "..\\DATA\\沪杭\\Timetable.csv",
                                 "..\\DATA\\沪杭\\CrewBase.csv",
                                 "..\\DATA\\沪杭\\Crew.csv",
                                 "..\\DATA\\沪杭\\Station.csv");
                net.CreateT_S_NetWork();

                net.SetMealWindows(windows[j][0], windows[j][1], windows[j][2], windows[j][3]);

                //net.CreateT_S_S_NetWork(mindrivetime,maxdrivetime,maxconntime,mintranslation,minrelaxtime, maxrelaxtime,minoutrelaxtime,maxoutrelaxtime, mindaycrewtime, maxdaycrewtime);//daycrewtime-120出退乘
                //net.CreateT_S_S_NetWork(180, 250, 40, 15, 3312, 3330, 3400, 3900, 180, 250);//京津城际实例
                net.CreateT_S_S_NetWork(240, 540, 90, 13, 3312, 3300, 3400, 3900, 240, 540);//沪宁杭
                //net.CreateT_S_S_NetWork(180, 720, 200, 6, 3312, 3330, 600, 2800, 180, 720);//bigscale
                //net.CreateT_S_S_NetWork(120, 780, 400, 6, 3312, 3330, 540, 2880, 120, 780);//bigscale2

                //lag = new Lagrange(net, 350);
                LR_CG.InitLR(net, 350);
                lag = LR_CG.LR;
                LR_CG.InitCG(net);

                string case_dir = System.Environment.CurrentDirectory +
                                  "\\12算例结果\\new_test\\沪杭\\" + Cur_case[j];

                StreamWriter file_1 = new StreamWriter(case_dir +
                                                       "交路内容与求解信息" + lag.step_size + "_M3_(1000)_in==0_nosppedLB.txt", false, Encoding.Default);
                StreamWriter file_2 = new StreamWriter(case_dir +
                                                       "iterationBound" + lag.step_size + "_M3_(1000)_in==0_nosppedLB.csv", false, Encoding.Default);
                StreamWriter file_3 = new StreamWriter(case_dir +
                                                       "convergeBound" + lag.step_size + "_M3_(1000)_in==0_nosppedLB.csv", false, Encoding.Default);

                Console.WriteLine("solve case: " + Cur_case[j]);
                Console.WriteLine("state arc number: " + net.T_S_S_ArcList.Count);
                Console.WriteLine("state node number: " + net.T_S_S_NodeList.Count);


                EndTime_Net = DateTime.Now;
                int    eh_Net      = EndTime_Net.Hour;
                int    em_Net      = EndTime_Net.Minute;
                int    es_Net      = EndTime_Net.Second;
                int    ems_Net     = EndTime_Net.Millisecond;
                int    ea_Net      = (eh_Net * 60 + em_Net) * 60 + es_Net;
                double endtime_Net = ea_Net + 0.001 * ems_Net;
                time_Net = endtime_Net - starttime;
                Console.WriteLine("create net spend time: {0} s", time_Net);

                bool isnotcontain = true;
                isnotcontain = net.AllLineContain();
                if (isnotcontain == false)//|| isnotcontain)
                {
                    //if (radioButtonk.Checked == true)
                    //{
                    //int K = 100;// Convert.ToInt32(textBoxend.Text);
                    //lag.k = 0;
                    //lag.IterationK(ref net, K);
                    //}
                    LR_CG.LR_and_CG(ref net, 10);

                    if (radioButtonGap.Checked == true)
                    {
                        double Gap = Convert.ToDouble(textBoxend.Text);

                        //lag.IterationGap(ref net, Gap);
                    }
                    if (radioButtonUB.Checked == true)
                    {
                        int N = Convert.ToInt32(textBoxend.Text);
                        //lag.IterationUBStay(ref net, N);
                    }

                    EndTime = DateTime.Now;
                    int    eh      = EndTime.Hour;
                    int    em      = EndTime.Minute;
                    int    es      = EndTime.Second;
                    int    ems     = EndTime.Millisecond;
                    int    ea      = (eh * 60 + em) * 60 + es;
                    double endtime = ea + 0.001 * ems;
                    time = endtime - starttime;

                    realTime.Stop();

                    Console.WriteLine("{0} spend time: {1} s", Cur_case[j], realTime.Elapsed.TotalSeconds);
                    Console.WriteLine("calculate time(except net construction time): {0} s"
                                      , realTime.Elapsed.TotalSeconds - time_Net);

                    if (checkCur.Checked == true && checkCurBest.Checked == false)
                    {
                        showgap_cur.Draw(lag.CurLB, lag.CurUB, time);
                        showgap_cur.Show();
                    }
                    else if (checkCur.Checked == false && checkCurBest.Checked == true)
                    {
                        showgap_curbest.Draw(lag.CurBestLB, lag.CurBestUB, time);
                        showgap_curbest.Show();
                    }
                    else if (checkCur.Checked == true && checkCurBest.Checked == true)
                    {
                        showgap_cur.Draw(lag.CurLB, lag.CurUB, time);
                        showgap_curbest.Draw(lag.CurBestLB, lag.CurBestUB, time);
                        showgap_curbest.Show();
                        showgap_cur.Show();
                    }

                    //保存文件
                    int i = 0;
                    for (i = 0; i < lag.YUB.Count; i++)
                    {
                        str += "乘务交路" + (i + 1).ToString() + "为:" + lag.YUB[i] + "\r\n";
                    }
                    double gap = (lag.BestUB - lag.BestLB) / lag.BestUB;
                    str += "BestLB为:" + lag.BestLB.ToString("f2") + "\r\n";
                    str += "BestUB为:" + lag.BestUB.ToString("f2") + "\r\n";
                    str += "迭代次数K为:" + lag.k.ToString() + "\r\n";
                    str += "Gap为:" + gap.ToString("f4") + "\r\n";
                    str += "建网时间为:" + time_Net.ToString("f2") + "s" + "\r\n";
                    str += "state arc number: " + net.T_S_S_ArcList.Count + "\r\n";
                    str += "state node number: " + net.T_S_S_NodeList.Count + "\r\n";
                    str += "求解时间为:" + time.ToString("f2") + "s" + "\r\n";
                    str += "real求解时间为:" + realTime.Elapsed.TotalSeconds.ToString("f2") + "s" + "\r\n";
                    str += "决策变量个数为:" + net.T_S_S_ArcList.Count * lag.CrewCount;

                    file_1.WriteLine(str);
                    file_1.Close();

                    string LB_UB = "";
                    file_2.WriteLine("CurLB,CurUB");
                    for (i = 0; i < lag.CurLB.Count; i++)
                    {
                        LB_UB = "";
                        LB_UB = i < lag.CurUB.Count ?
                                Convert.ToString(lag.CurLB[i]) + "," + Convert.ToString(lag.CurUB[i])
                            : Convert.ToString(lag.CurLB[i]);
                        file_2.WriteLine(LB_UB);// + "," + lag.CurUB[i]);
                    }
                    file_2.Close();

                    file_3.WriteLine("CurBestLB,CurBestUB");
                    for (i = 0; i < lag.CurBestLB.Count; i++)
                    {
                        LB_UB = "";
                        LB_UB = i < lag.CurBestUB.Count ?
                                Convert.ToString(lag.CurBestLB[i]) + "," + Convert.ToString(lag.CurBestUB[i])
                            : Convert.ToString(lag.CurBestLB[i]);
                        file_3.WriteLine(LB_UB);// + "," + lag.CurUB[i]);
                    }
                    file_3.Close();
                }

                Console.WriteLine("{0} 求解完成 ", Cur_case[j]);
                #endregion
            }

            MessageBox.Show("保存成功!", "please close",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Stop,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.ServiceNotification);
        }
Exemple #24
0
        /// <summary>
        /// 得到后几天的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <param name="day">天数</param>
        /// <returns>得到的预测值</returns>
        public static List <DataValue> getPredictData(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = new List <double>();

            List <DateTime> dateTime  = new List <DateTime>();
            List <string>   inTemp    = new List <string>();
            List <double>   grainTemp = new List <double>();

            try
            {
                a = SqlData.sqlGetData("dbo.小麦害虫种群变化数据表", "CanShuValue", str);

                dateTime  = SqlData.sqlDataDate("dbo.小麦害虫种群变化数据表", "Date", str);
                inTemp    = SqlData.sqlDataInTemp("dbo.小麦害虫种群变化数据表", "InTemp", str);
                grainTemp = SqlData.sqlDataGrainTemp("dbo.小麦害虫种群变化数据表", "GrainTemp", str);
            }
            catch (Exception e)
            {
                throw e;
            }

            double[]   col0    = a.ToArray();
            DateTime[] date    = dateTime.ToArray();
            string[]   strTemp = inTemp.ToArray();
            double[]   douTemp = grainTemp.ToArray();

            double low   = getLow(col0);
            double high  = getHigh(col0);
            double media = getMedia(col0);



            DataValue datapoint = null;

            for (int i = 0; i < col0.Length; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }
                datapoint = new DataValue();
                DateTime dYear = date[i];
                datapoint.date = dYear;


                if (i == 0)
                {
                    datapoint.SpeedData = 0;
                }
                else
                {
                    datapoint.SpeedData = getSpeedData(col0[i], col0[i - 1], 7);
                }

                if (str == "000051")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];

                    datapoint.yLable    = "玉米象";
                    datapoint.index     = i + 1;
                    datapoint.GrainTemp = douTemp[i];
                    datapoint.InTemp    = strTemp[i];
                    lists.Add(datapoint);
                }
                else if (str == "000052")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];
                    datapoint.yLable      = "谷蠹";
                    datapoint.index       = i + 1;
                    datapoint.GrainTemp   = douTemp[i];
                    datapoint.InTemp      = strTemp[i];
                    lists.Add(datapoint);
                }
                else if (str == "000053")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];
                    datapoint.yLable      = "米象";
                    datapoint.index       = i + 1;
                    datapoint.GrainTemp   = douTemp[i];
                    datapoint.InTemp      = strTemp[i];
                    lists.Add(datapoint);
                }
                else if (str == "000054")
                {
                    datapoint.High        = high;
                    datapoint.Low         = low;
                    datapoint.Media       = media;
                    datapoint.PredictData = col0[i];
                    datapoint.yLable      = "米象";
                    datapoint.index       = i + 1;
                    datapoint.GrainTemp   = douTemp[i];
                    datapoint.InTemp      = strTemp[i];
                    lists.Add(datapoint);
                }
            }
            double firstdata;
            double speed;

            try
            {
                firstdata = SqlData.getInformationData("dbo.小麦参数实验总概括表", "StartCanShuValue", str);//起始数据
                speed     = SqlData.getInformationData("dbo.小麦参数实验总概括表", "CanShuChangeSpeed", str);
            }
            catch (Exception e)
            {
                throw e;
            }
            int count  = day / 7;
            int count1 = day % 7;
            int index  = datapoint.index;

            DateTime d  = datapoint.date;
            double   d1 = datapoint.PredictData;

            List <double> dayDou = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }
            double[] dat;
            DateTime ti = date[date.Length - 1];

            if (count1 != 0)
            {
                dat = new double[count + 1];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(7);
                    dat[i] = ti.ToOADate();
                }
                dat[count] = ti.AddDays(count1).ToOADate();
            }
            else
            {
                dat = new double[count];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(7);
                    dat[i] = ti.ToOADate();
                }
            }
            Lagrange      lan    = new Lagrange(dayDou.ToArray(), col0);
            List <double> jieguo = lan.InsertDatas(dat.ToList <double>());

            double[] predictData = jieguo.ToArray();

            for (int i = 0; i < count; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.index       = index + 1;
                datapoint.PredictData = predictData[i];
                datapoint.date        = d.AddDays(7);
                d     = datapoint.date;
                d1    = datapoint.PredictData;
                index = datapoint.index;
                lists.Add(datapoint);
            }
            if (count1 != 0)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.PredictData = predictData[count];
                datapoint.date        = d.AddDays(count1);
                d  = datapoint.date;
                d1 = datapoint.PredictData;
                datapoint.index = index + 1;
                lists.Add(datapoint);
            }
            return(lists);
        }
Exemple #25
0
        /// <summary>
        /// 得到后几天的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <param name="day">天数</param>
        /// <returns>得到的预测值</returns>
        public static List <DataValue> getPredictData(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = new List <double>();

            List <DateTime> dateTime  = new List <DateTime>();
            List <string>   grainTemp = new List <string>();
            List <double>   PeatsMiDu = new List <double>();

            a = SqlData.sqlGetData("dbo.害虫对小麦参数的影响数据表", "CanShuValue", str);

            dateTime = SqlData.sqlDataDate("dbo.害虫对小麦参数的影响数据表", "CheckDate", str);

            grainTemp = SqlData.sqlDataStringValue("dbo.害虫对小麦参数的影响数据表", "GrainTemp", str);
            PeatsMiDu = SqlData.sqlDataDoubleValue("dbo.害虫对小麦参数的影响数据表", "PeatsMiDu", str);

            DateTime endTime      = SqlData.getInformationDate("dbo.小麦参数实验总概括表", "EndTime", str);
            DateTime startTime    = SqlData.getInformationDate("dbo.小麦参数实验总概括表", "StartTime", str);
            String   canShuNumber = SqlData.getCanShuNumber("dbo.小麦参数实验总概括表", "CanShuNumber", str);
            String   canShuName   = SqlData.getCanShuName("dbo.小麦参数名表", "CanShuName", canShuNumber);

            double[]   col0      = a.ToArray();
            DateTime[] date      = dateTime.ToArray();
            string[]   douTemp   = grainTemp.ToArray();
            double[]   peatsMiDu = PeatsMiDu.ToArray();

            double low   = getLow(col0);
            double high  = getHigh(col0);
            double media = getMedia(col0);

            DataValue datapoint = null;

            for (int i = 0; i < col0.Length; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }
                datapoint = new DataValue();
                DateTime dYear = date[i];
                datapoint.date = dYear;

                if (i == 0)
                {
                    datapoint.SpeedData = 0;
                }
                else
                {
                    datapoint.SpeedData = getSpeedData(col0[i], col0[i - 1], DateTime.Compare(dateTime[1], dateTime[0]));
                }
                datapoint.High         = high;
                datapoint.Low          = low;
                datapoint.Media        = media;
                datapoint.PredictData  = col0[i];
                datapoint.yLable       = canShuName;
                datapoint.CanShuNumber = canShuNumber;
                datapoint.index        = i + 1;
                datapoint.InTemp       = douTemp[i];
                datapoint.PeatsMiDu    = peatsMiDu[i];
                lists.Add(datapoint);
            }

            int      count  = day / DateTime.Compare(dateTime[1], dateTime[0]);
            int      count1 = day % DateTime.Compare(dateTime[1], dateTime[0]);
            int      index  = datapoint.index;
            DateTime d      = datapoint.date;
            double   d1     = datapoint.PredictData;

            List <double> dayDou = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }
            double[] dat;
            DateTime ti = date[date.Length - 1];

            if (count1 != 0)
            {
                dat = new double[count + 1];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(DateTime.Compare(dateTime[1], dateTime[0]));
                    dat[i] = ti.ToOADate();
                }
                dat[count] = ti.AddDays(count1).ToOADate();
            }
            else
            {
                dat = new double[count];
                for (int i = 0; i < count; i++)
                {
                    ti     = ti.AddDays(DateTime.Compare(dateTime[1], dateTime[0]));
                    dat[i] = ti.ToOADate();
                }
            }
            Lagrange      lan    = new Lagrange(dayDou.ToArray(), col0);
            List <double> jieguo = lan.InsertDatas(dat.ToList <double>());

            double[] predictData = jieguo.ToArray();

            for (int i = 0; i < count; i++)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint              = new DataValue();
                datapoint.index        = index + 1;
                datapoint.PredictData  = predictData[i];
                datapoint.PeatsMiDu    = peatsMiDu[0];
                datapoint.yLable       = canShuName;
                datapoint.InTemp       = douTemp[0];
                datapoint.CanShuNumber = canShuNumber;
                datapoint.date         = d.AddDays(DateTime.Compare(dateTime[1], dateTime[0]));
                d     = datapoint.date;
                d1    = datapoint.PredictData;
                index = datapoint.index;
                lists.Add(datapoint);
            }
            if (count1 != 0)
            {
                if (datapoint != null)
                {
                    datapoint = null;
                }

                datapoint             = new DataValue();
                datapoint.PredictData = predictData[count];
                datapoint.date        = d.AddDays(count1);
                d  = datapoint.date;
                d1 = datapoint.PredictData;
                datapoint.index = index + 1;
                lists.Add(datapoint);
            }
            return(lists);
        }
Exemple #26
0
        /// <summary>
        /// Lagrange得到的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <returns></returns>
        public static List <DataValue> getLagPredictValue(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <double>    a     = SqlData.sqlGetData("dbo.小麦质量特性参数数据表", "CanNumberValue", str);

            List <DateTime> dateTime = SqlData.sqlDataDate("dbo.小麦质量特性参数数据表", "Date", str);

            List <double> grainTemp    = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "GrainTemp", str);
            List <double> WaterValue   = SqlData.sqlDataDoubleValue("dbo.小麦质量特性参数数据表", "Water", str);
            String        canShuNumber = SqlData.getCanShuNumber("dbo.小麦参数实验总概括表", "CanShuNumber", str);
            String        canShuName   = SqlData.getCanShuName("dbo.小麦参数名表", "CanShuName", canShuNumber);


            double[]      douTemp = grainTemp.ToArray();
            double[]      col0    = a.ToArray();
            DateTime[]    date    = dateTime.ToArray();
            double[]      water   = WaterValue.ToArray();
            List <double> dayDou  = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }

            List <double> doubleDay = new List <double>();

            for (double j = dayDou[0]; j <= dayDou[dayDou.Count - 1]; j++)
            {
                doubleDay.Add(j);
            }
            double[] ceshi = spline.setSplineData(dayDou.ToArray(), col0, doubleDay.ToArray());//实际值

            List <double> time1 = new List <double>();
            List <double> col1  = new List <double>();

            for (int i = 0; i < day; i++)
            {
                time1.Add(doubleDay[i]);
            }
            for (int i = 0; i < day; i++)
            {
                col1.Add(ceshi[i]);
            }

            Lagrange lan1 = new Lagrange(time1.ToArray(), col1.ToArray());

            List <double> jieguo1 = lan1.InsertDatas(doubleDay);//预测值


            DateTime dDay  = date[0];
            int      index = -1;

            for (int i = 0; i < doubleDay.Count; i++)
            {
                DataValue datapoint = new DataValue();
                datapoint.PredictData = jieguo1[i];
                if (i % 30 == 0)
                {
                    index++;
                }

                datapoint.GrainTemp    = douTemp[index];
                datapoint.Water        = water[index];
                datapoint.CanShuNumber = canShuNumber;
                datapoint.yLable       = canShuName;

                datapoint.date     = dDay.AddDays(1);
                dDay               = datapoint.date;
                datapoint.ChaValue = ceshi[i] - jieguo1[i];

                datapoint.Y = ceshi[i];


                lists.Add(datapoint);
            }
            return(lists);
        }
Exemple #27
0
        private void OnCalculateButtonClicked()
        {
            string failedMessage = "";
            bool   isFailed      = false;

            if (_yValues != null)
            {
                try
                {
                    double[] xValues = new double[_yValues.Length];
                    for (int i = 0; i < _yValues.Length; i++)
                    {
                        xValues[i] = i + 1;
                    }
                    LSM lsm = new LSM(xValues, _yValues);
                    lsm.Polynomial(3);
                    StringBuilder polinom = new StringBuilder();
                    for (int i = 0; i < lsm.Coeff.Length; i++)
                    {
                        polinom.Append("x " + i + "*" + lsm.Coeff[i].ToString("0.00") + " + ");
                    }
                    GraphicView.DrawLSM(CreateSetOfPointsFromPolinom(lsm.Coeff));
                }
                catch
                {
                    failedMessage += "МНК модели";
                    isFailed       = true;
                }

                try
                {
                    double[] xs = new double[_yValues.Length];
                    for (int i = 0; i < _yValues.Length; i++)
                    {
                        xs[i] = i + 1;
                    }
                    Lagrange lagrange = new Lagrange(xs, _yValues);

                    Vector2[] setOfPoints = new Vector2[Constants.PointsNumber];
                    for (int i = 0; i < setOfPoints.Length; i++)
                    {
                        double x      = (i + 10) / 10.0f;
                        double height = lagrange.GetValue(x);

                        setOfPoints[i] = new Vector3((float)x, (float)height, 0);
                    }
                    GraphicView.DrawLagrange(setOfPoints);
                }
                catch
                {
                    if (failedMessage.Length > 0)
                    {
                        failedMessage += ", ";
                    }
                    failedMessage += "Лагранж модели";
                    isFailed       = true;
                }
                if (isFailed)
                {
                    Text.text = "Ошибка при расчете " + failedMessage;
                }
            }
        }
Exemple #28
0
        /// <summary>
        /// Lagrange得到的预测值
        /// </summary>
        /// <param name="str">实验号</param>
        /// <returns></returns>
        public static List <DataValue> getLagPredictValue(String str, int day)
        {
            List <DataValue> lists = new List <DataValue>();
            List <DateTime>  dateTime;
            List <double>    a;
            List <string>    inTemp;
            List <double>    grainTemp;

            try
            {
                dateTime  = SqlData.sqlDataDate("dbo.小麦害虫种群变化数据表", "Date", str);
                a         = SqlData.sqlGetData("dbo.小麦害虫种群变化数据表", "CanShuValue", str);
                inTemp    = SqlData.sqlDataInTemp("dbo.小麦害虫种群变化数据表", "InTemp", str);
                grainTemp = SqlData.sqlDataGrainTemp("dbo.小麦害虫种群变化数据表", "GrainTemp", str);
            }
            catch (Exception e)
            {
                throw e;
            }

            string[]      strTemp = inTemp.ToArray();
            double[]      douTemp = grainTemp.ToArray();
            double[]      col0    = a.ToArray();
            DateTime[]    date    = dateTime.ToArray();
            List <double> dayDou  = new List <double>();//将有数据的日期转换为double类型

            for (int i = 0; i < date.Length; i++)
            {
                dayDou.Add(date[i].ToOADate());
            }

            List <double> doubleDay = new List <double>();

            for (double j = dayDou[0]; j <= dayDou[dayDou.Count - 1]; j++)
            {
                doubleDay.Add(j);
            }
            double[] ceshi = spline.setSplineData(dayDou.ToArray(), col0, doubleDay.ToArray());//实际值

            List <double> time1 = new List <double>();
            List <double> col1  = new List <double>();

            for (int i = 0; i < day; i++)
            {
                time1.Add(doubleDay[i]);
            }
            for (int i = 0; i < day; i++)
            {
                col1.Add(ceshi[i]);
            }

            Lagrange lan1 = new Lagrange(time1.ToArray(), col1.ToArray());

            List <double> jieguo1 = lan1.InsertDatas(doubleDay);//预测值


            DateTime dDay  = date[0];
            int      index = -1;

            for (int i = 0; i < doubleDay.Count; i++)
            {
                DataValue datapoint = new DataValue();
                datapoint.PredictData = jieguo1[i];
                if (i % 7 == 0)
                {
                    index++;
                }
                datapoint.InTemp    = strTemp[index];
                datapoint.GrainTemp = douTemp[index];

                datapoint.date     = dDay.AddDays(1);
                dDay               = datapoint.date;
                datapoint.ChaValue = ceshi[i] - jieguo1[i];
                if (str == "000051")
                {
                    datapoint.Y = ceshi[i];
                }
                else if (str == "000052")
                {
                    datapoint.Y = ceshi[i];
                }
                else if (str == "000053")
                {
                    datapoint.Y = ceshi[i];
                }
                else if (str == "000054")
                {
                    datapoint.Y = ceshi[i];
                }
                lists.Add(datapoint);
            }
            return(lists);
        }
Exemple #29
0
        public void LagrangeShouldNot(string[] lines)
        {
            var lagrange = new Lagrange();

            Assert.IsFalse(lagrange.PrepareData(lines));
        }
        public void RunTest()
        {
            for (int caseIndex = 1; caseIndex < 2 /*TestInstances.Length*/; caseIndex++)
            {
                string caseName = TestInstances[caseIndex];

                //caseName = "SmallCaseSet\\small01";

                string input_dir = @".\DATA\" + caseName + "\\";

                for (int windowIndex = 0; windowIndex < 1 /*FixedMealWindowsDict.Count*/; windowIndex++)
                {
                    KeyValuePair <string, FixedMealWindow> windowNameToParam =
                        FixedMealWindowsDict.ElementAt(windowIndex);
                    string          meal_window   = windowNameToParam.Key;
                    FixedMealWindow curMealWindow = windowNameToParam.Value;
                    string          output_dir    = @".\12算例结果\" + caseName + "\\" + meal_window + "\\";

                    Console.WriteLine("**********START TEST CASE [{0}] CONSIDERING MEAL TIME WINDOW [{1}]**********",
                                      caseName, meal_window);

                    Stopwatch solveTimer = new Stopwatch();
                    solveTimer.Start();
                    Stopwatch netTimer = new Stopwatch();
                    netTimer.Start();

                    //CreateNetWork net = new CreateNetWork();
                    CreateNetWork_db net = new CreateNetWork_db();

                    net.LoadData_csv(1,
                                     input_dir + "Timetable.csv",
                                     input_dir + "CrewBase.csv",
                                     input_dir + "Crew.csv",
                                     input_dir + "Station.csv");

                    net.SetBasicTimeRules(crewRules[caseIndex][0], crewRules[caseIndex][1],
                                          crewRules[caseIndex][2], crewRules[caseIndex][3],
                                          crewRules[caseIndex][4], crewRules[caseIndex][5]);
                    net.ShowBasicTimeRules();
                    //net.CreateT_S_NetWork();
                    net.CreateT_S_NetWork_db();

                    net.SetMealWindows(curMealWindow.lunch_start, curMealWindow.lunch_end,
                                       curMealWindow.supper_start, curMealWindow.supper_end);

                    //net.SetMealTime(30, 40);
                    net.SetMealTime(InstanceMealSpan[caseName][0], 40);
                    if (meal_window == "INF_h")   //不考虑时间窗,则用餐时间设为0
                    {
                        net.minMealTime = 0;
                    }
                    net.SetVirRoutingCost(1000);//(InstanceVirRoutingCostMap[caseName]);

                    //net.CreateT_S_S_NetWork(net_params[caseIndex][0], net_params[caseIndex][1],
                    //    net_params[caseIndex][2], net_params[caseIndex][3],
                    //    net_params[caseIndex][4], net_params[caseIndex][5],
                    //    net_params[caseIndex][6], net_params[caseIndex][7],
                    //    net_params[caseIndex][8], net_params[caseIndex][9]);

                    //net.SetBasicTimeRules(20, 450, 15, 400, 20, 450); //smallcase01

                    //net.SetArcPenaltyMealViolate(crewRules[caseIndex][5]);
                    net.SetArcPenaltyMealViolate(1400);

                    net.CreateT_S_S_Network_db();

                    netTimer.Stop();

                    //StreamWriter logFile = new StreamWriter(output_dir + "stateNodeSet_db.csv");
                    //logFile.WriteLine("ID,NodeType,OStation,LineID,TrainCode,Station,TimeCode,SuperPointID,SuperPointType,PrevNodeID," +
                    //    "DriveTime,DayCrewTime,Lunch,Dinner," +
                    //    "PassLines,PassStateNodes");
                    //foreach (var node in net.T_S_S_NodeList) {
                    //    logFile.Write(Logger.stateNodeInfoToStr(node, OutputMode.file));
                    //    logFile.Write(",");
                    //    logFile.WriteLine(Logger.stateNodePartialPathToStr(node, OutputMode.file));
                    //    //Console.WriteLine(Logger.stateNodePartialPathToStr(node, OutputMode.console));
                    //}
                    //logFile.Close();

                    Console.WriteLine("state arc num: {0}", net.T_S_S_ArcList.Count);
                    Console.WriteLine("state node num: {0}", net.T_S_S_NodeList.Count);


                    bool isnotcontain = true;
                    isnotcontain = net.AllLineContain();
                    if (isnotcontain == false)
                    {
                        CGandLR LR_CG = new CGandLR();
                        LR_CG.InitLR(net, InstanceStepSize[caseName]);
                        //LR_CG.InitLR(net, 100);
                        Lagrange lag = LR_CG.LR;

                        LR_CG.InitCG(net);

                        LR_CG.LR_and_CG(ref net, InstanceLRIteration[caseName]);

                        solveTimer.Stop();

                        Summery summery = new Summery(lag, net, netTimer.Elapsed.TotalSeconds, solveTimer.Elapsed.TotalSeconds);
                        saveSoln(output_dir, summery, lag, 1000 /*InstanceVirRoutingCostMap[caseName]*/);

                        Logger.GetScheduleForVisualize(LR_CG.GetOptPairingSet(), output_dir, caseName, meal_window);
                    }
                    else
                    {
                        throw new Exception("*************current network is not covered all lines, there might be some errors!!!*************\n");
                    }

                    Console.WriteLine("total time spended in solve this case is {0} s", solveTimer.Elapsed.TotalSeconds);
                    Console.WriteLine("**********END TEST CASE [{0}] CONSIDERING MEAL TIME WINDOW [{1}]", caseName, windowIndex);
                }
            }
        }