Exemple #1
0
        //进行计算时间上可行的第一个空间位置
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "")
                {
                    MessageBox.Show("请输入应急资源仓库数据", "输入应急资源仓库数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox2.Text == "")
                {
                    MessageBox.Show("请输入道路网络数据", "输入道路网络数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox3.Text == "")
                {
                    MessageBox.Show("请输入污染物扩散模拟过程数据", "输入污染物扩散模拟过程数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (textBox1.Text == "")
                {
                    MessageBox.Show("请输入应急处置工程建设时间(单位:分钟):", "输入应急处置工程建设时间(单位:分钟):", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox4.Text == "")
                {
                    MessageBox.Show("请输出可供选择首个应急处置空间位置", "输出可供选择首个应急处置空间位置", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    int    row = 0, column = 0;
                    double X = 0.0, Y = 0.0;
                    double pixelvalue = 0.0;

                    IRasterLayer  pRasterLayer       = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text);
                    IFeatureLayer pFeatureLayerDepot = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text);
                    IFeatureLayer pFeatureLayerroad  = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text);
                    //获取污染物模拟河流的外包络线
                    IRaster      pRaster      = pRasterLayer.Raster;
                    IRasterProps pRasterprops = pRaster as IRasterProps;
                    IEnvelope    pEnvelope    = pRasterprops.Extent;
                    IPoint       p1           = new PointClass();
                    IPoint       p2           = new PointClass();
                    IPoint       p3           = new PointClass();
                    IPoint       p4           = new PointClass();
                    p1 = pEnvelope.UpperLeft;
                    p2 = pEnvelope.LowerLeft;
                    p3 = pEnvelope.LowerRight;
                    p4 = pEnvelope.UpperRight;
                    IPointCollection pointCollection = new PolygonClass();
                    object           missing         = Type.Missing;
                    pointCollection.AddPoint(p1, ref missing, ref missing);
                    pointCollection.AddPoint(p2, ref missing, ref missing);
                    pointCollection.AddPoint(p3, ref missing, ref missing);
                    pointCollection.AddPoint(p4, ref missing, ref missing);
                    pointCollection.AddPoint(p1, ref missing, ref missing);
                    IPolygon  polygon   = (IPolygon)pointCollection;
                    IGeometry pGeometry = new PolygonClass();
                    pGeometry = polygon as IGeometry;
                    //获取应急资源仓库到达各个节点的最短路径
                    List <IFeature> listFeature = new List <IFeature>();
                    listFeature = GetPolygonFeatureList(pFeatureLayerroad, pGeometry);
                    RoutePlanResult startNoderesult = null, EndNoderesult = null, minStartNodeResult = null, minEndNodeResult = null;
                    DijkstraDepotToAllNodeMethod path = new DijkstraDepotToAllNodeMethod();
                    path.InitializationRoadNetwork(pFeatureLayerDepot);
                    List <PlanCourse> resultplancourse = path.DepotToAllNode();

                    RasterManagement.GetRasterCount(pRasterLayer, ref row, ref column);
                    double[] desttime = new double[2];
                    int      sign     = 0;
                    //IFeature pFeature = null;
                    string    strStartID = null, strEndID = null;
                    double    time = 0.0;
                    double    returnX = 0.0, returnY = 0.0;
                    double    pFrompointToOutpointLength = 0.0, pOutpointToEndpointLength = 0.0;
                    IPolyline polyline = new PolylineClass();
                    //对污染物模拟栅格从[0,0]进行循环,选取从时间上作为应急处置空间位置的可行性的点
                    for (int i = 0; i < row; i++)
                    {
                        for (int j = 0; j < column; j++)
                        {
                            pixelvalue = Convert.ToDouble(RasterManagement.GetPixelValue(pRasterLayer, 0, j, i));
                            if (pixelvalue != 0)
                            {
                                IFeature pFeature = null;
                                RasterManagement.NumbercovertXY(pRasterLayer, ref X, ref Y, j, i);
                                IPoint point = new PointClass();
                                point.PutCoords(X, Y);

                                IPoint ppoint = new PointClass();
                                GetMindistanceandpoint(point, listFeature, ref returnX, ref returnY, ref pFeature, ref pFrompointToOutpointLength);
                                ppoint.PutCoords(returnX, returnY);
                                strStartID = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField("StartNodeI")));
                                strEndID   = Convert.ToString(pFeature.get_Value(pFeature.Fields.FindField("EndNodeID")));
                                time       = Convert.ToDouble(pFeature.get_Value(pFeature.Fields.FindField("Minutes")));
                                polyline   = pFeature.Shape as IPolyline;
                                pOutpointToEndpointLength = polyline.Length - pFrompointToOutpointLength;
                                //获取应急仓库到达应急处置点最短时间的点
                                minStartNodeResult = startNoderesult = RoutePlanner.GetResult(resultplancourse[0], strStartID);
                                minEndNodeResult   = EndNoderesult = RoutePlanner.GetResult(resultplancourse[0], strEndID);
                                for (int m = 1; m < resultplancourse.Count; m++)
                                {
                                    startNoderesult = RoutePlanner.GetResult(resultplancourse[m], strStartID);
                                    EndNoderesult   = RoutePlanner.GetResult(resultplancourse[m], strEndID);
                                    if (minStartNodeResult.WeightValues > startNoderesult.WeightValues)
                                    {
                                        minStartNodeResult = startNoderesult;
                                    }
                                    if (minEndNodeResult.WeightValues > EndNoderesult.WeightValues)
                                    {
                                        minEndNodeResult = EndNoderesult;
                                    }
                                }
                                desttime[0] = time * (pFrompointToOutpointLength / (pFrompointToOutpointLength + pOutpointToEndpointLength));
                                desttime[1] = time - desttime[0];
                                //判断污染物到达该应急处置空间位置的时间是否大于应急资源调度时间与工程措施建设时间之和
                                if (minStartNodeResult.WeightValues + desttime[0] > minEndNodeResult.WeightValues + desttime[1])
                                {
                                    if ((minEndNodeResult.WeightValues + desttime[1] + Convert.ToDouble(textBox1.Text)) < pixelvalue)
                                    {
                                        List <IPoint> pointlist = new List <IPoint>();
                                        pointlist.Add(point);
                                        SaveVector.pointtoFeatureLayer(comboBox4.Text, pointlist, pFeatureLayerDepot);
                                        sign = 1;
                                        break;
                                    }
                                }
                                else
                                {
                                    if ((minStartNodeResult.WeightValues + desttime[0] + Convert.ToDouble(textBox1.Text)) < pixelvalue)
                                    {
                                        List <IPoint> pointlist = new List <IPoint>();
                                        pointlist.Add(point);
                                        SaveVector.pointtoFeatureLayer(comboBox4.Text, pointlist, pFeatureLayerDepot);
                                        sign = 1;
                                        break;
                                    }
                                }
                            }
                        }
                        if (sign == 1)
                        {
                            break;
                        }
                    }
                    MessageBox.Show("处理完毕!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
            }
        }
        //保存应急处置空间位置的信息
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "")
                {
                    MessageBox.Show("请输入可供选择的应急处置空间位置的数据", "输入可供选择的应急处置空间位置的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox2.Text == "")
                {
                    MessageBox.Show("请输入河流流速的数据", "输入河流流速的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox3.Text == "")
                {
                    MessageBox.Show("请输入河流流量的数据", "输入河流流量的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox4.Text == "")
                {
                    MessageBox.Show("请输入河流宽度的数据", "输入河流宽度的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox5.Text == "")
                {
                    MessageBox.Show("请输入河流污染物浓度的数据", "输入河流污染物浓度的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox6.Text == "")
                {
                    MessageBox.Show("请输入河流总量的数据", "输入河流污染物总量的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    IRasterLayer   pVRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox2.Text);
                    IRasterLayer   pQRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text);
                    IRasterLayer   pLRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox4.Text);
                    IRasterLayer   pCRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox5.Text);
                    IRasterLayer   pSRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox6.Text);
                    IFeatureLayer  pFeatureLayerSave  = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text);
                    IFeatureClass  pFeatureClassSave  = pFeatureLayerSave.FeatureClass;
                    IFeatureCursor pFeatureCursorSave = pFeatureClassSave.Update(null, false);
                    IFeature       pFeatureSave       = pFeatureCursorSave.NextFeature();
                    IPoint         point = new PointClass();
                    double         X = 0.0, Y = 0.0;
                    int            column = 0, row = 0;
                    while (pFeatureSave != null)
                    {
                        point = pFeatureSave.Shape as IPoint;
                        X     = point.X;
                        Y     = point.Y;
                        RasterManagement.XYconvertNumber(pVRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("V"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pVRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pQRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("Q"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pQRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pLRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("L"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pLRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pCRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("C"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pCRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pSRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("S"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pSRasterLayer, 0, column, row)), 4));

                        pFeatureCursorSave.UpdateFeature(pFeatureSave);
                        pFeatureSave = pFeatureCursorSave.NextFeature();
                    }

                    MessageBox.Show("程序运行完成!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
            }
        }
Exemple #3
0
        //进行应急资源调度模型的计算
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "")
                {
                    MessageBox.Show("请输入应急资源仓库数据", "输入应急资源仓库数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox2.Text == "")
                {
                    MessageBox.Show("请输入应急处置空间位置数据", "输入应急处置空间位置数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox3.Text == "")
                {
                    MessageBox.Show("请输入污染物扩散模拟过程数据", "输入污染物扩散模拟过程数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    //初始化应急处置空间位置应急资源调度到达时间
                    IFeatureLayer             pFeatureLayerDepot = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text);//获取应急仓库图层
                    IFeatureClass             pFeatureClassDepot = pFeatureLayerDepot.FeatureClass;
                    int                       DepotCount         = pFeatureClassDepot.FeatureCount(null);
                    int                       DepotFieldCount    = pFeatureClassDepot.Fields.FieldCount;
                    IFeatureLayer             pFeatureLayerDest  = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text); //获取应急处置空间位置图层
                    IFeatureClass             pFeatureClassDest  = pFeatureLayerDest.FeatureClass;
                    int                       DestCount          = pFeatureClassDest.FeatureCount(null);
                    int                       DestFieldCount     = pFeatureClassDest.Fields.FieldCount;
                    DijkstraDepotToDestMethod path       = new DijkstraDepotToDestMethod();
                    List <Result>             resultlist = new List <Result>();
                    resultlist = path.DepotToDest(pFeatureLayerDepot, pFeatureLayerDest);
                    //获取应急资源仓库到达应急处置空间位置的时间
                    double[,] materialArrivetime = new double[DepotCount, DestCount];
                    int count = 0;
                    for (int m = 0; m < DepotCount; m++)
                    {
                        for (int n = 0; n < DestCount; n++)
                        {
                            materialArrivetime[m, n] = resultlist[count].WeightTime;
                            count++;
                        }
                    }

                    double[,] materialdemand = new double[DestCount, DestFieldCount - 4];
                    List <DestProperty> pMaterialdemand = new List <DestProperty>();
                    string[]            pFieldName      = new string[DestFieldCount - 4];
                    //获取应急资源名称
                    int namecount = 0;
                    for (int i = 0; i < DestFieldCount; i++)
                    {
                        IField pField = new FieldClass();
                        pField = pFeatureLayerDest.FeatureClass.Fields.get_Field(i);
                        if (pField.Name.ToUpper() == "FID" || pField.Name.ToUpper() == "SHAPE" || pField.Name.ToUpper() == "NAME" || pField.Name.ToUpper() == "PROJECT")
                        {
                            continue;
                        }
                        else
                        {
                            pFieldName[namecount] = pField.Name;
                            namecount++;
                        }
                    }
                    double[,] materialstore = new double[DepotCount, pFieldName.Length];
                    List <DepotProperty> pERDepot            = new List <DepotProperty>();
                    IFeatureCursor       pFeatureCursorDepot = pFeatureClassDepot.Search(null, false);
                    IFeature             pFeatureDepot       = pFeatureCursorDepot.NextFeature();
                    int pdepotcount = 0;
                    while (pFeatureDepot != null)
                    {
                        for (int i = 0; i < pFieldName.Length; i++)
                        {
                            materialstore[pdepotcount, i] = Convert.ToDouble(pFeatureDepot.get_Value(pFeatureDepot.Fields.FindField(pFieldName[i])));
                            DepotProperty erdepot = new DepotProperty();
                            erdepot.Resourcename = pFieldName[i];
                            erdepot.Depotname    = Convert.ToString(pFeatureDepot.get_Value(pFeatureDepot.Fields.FindField("Name")));
                            erdepot.Row          = pdepotcount;
                            erdepot.Column       = i;
                            erdepot.Number       = Convert.ToDouble(pFeatureDepot.get_Value(pFeatureDepot.Fields.FindField(pFieldName[i])));
                            pERDepot.Add(erdepot);
                        }
                        pdepotcount++;
                        pFeatureDepot = pFeatureCursorDepot.NextFeature();
                    }
                    //污染物扩散过程到达应急处置空间位置的时间
                    IRasterLayer   pRasterLayer       = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text);
                    IFeatureCursor pFeatureCursorDest = pFeatureClassDest.Search(null, false);
                    IFeature       pFeatureDest       = pFeatureCursorDest.NextFeature();
                    IPoint         pointDest          = new PointClass();
                    List <PollutionArriveDestProperty> PollutionArriveTime = new List <PollutionArriveDestProperty>();
                    List <PollutionArriveDestProperty> ProjectTime         = new List <PollutionArriveDestProperty>();
                    int pdestcount = 0;
                    while (pFeatureDest != null)
                    {
                        //获取污染物到达应急处置空间位置的时间,即为应急处置的最高时间
                        string destname = Convert.ToString(pFeatureDest.get_Value(pFeatureDest.Fields.FindField("Name")));
                        double X = 0.0, Y = 0.0;
                        int    column = 0, row = 0;
                        pointDest = pFeatureDest.Shape as IPoint;
                        X         = pointDest.X;
                        Y         = pointDest.Y;
                        RasterManagement.XYconvertNumber(pRasterLayer, X, Y, ref column, ref row);
                        PollutionArriveDestProperty pullutionarrivetime = new PollutionArriveDestProperty();
                        pullutionarrivetime.Arrivetime = Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pRasterLayer, 0, column, row)), 2);
                        pullutionarrivetime.Destname   = destname;
                        pullutionarrivetime.Sequence   = pdestcount + 1;
                        PollutionArriveTime.Add(pullutionarrivetime);
                        //获取应急处置空间位置应急物资需求
                        for (int i = 0; i < pFieldName.Length; i++)
                        {
                            materialdemand[pdestcount, i] = Convert.ToDouble(pFeatureDest.get_Value(pFeatureDest.Fields.FindField(pFieldName[i])));
                            DestProperty erdest = new DestProperty();
                            erdest.Resourcename = pFieldName[i];
                            erdest.Destname     = destname;
                            erdest.Row          = pdestcount;
                            erdest.Column       = i;
                            erdest.Number       = Convert.ToDouble(pFeatureDest.get_Value(pFeatureDest.Fields.FindField(pFieldName[i])));
                            pMaterialdemand.Add(erdest);
                        }
                        PollutionArriveDestProperty projecttime = new PollutionArriveDestProperty();
                        projecttime.Arrivetime = Convert.ToDouble(pFeatureDest.get_Value(pFeatureDest.Fields.FindField("Project")));
                        projecttime.Destname   = destname;
                        ProjectTime.Add(projecttime);
                        pdestcount++;
                        pFeatureDest = pFeatureCursorDest.NextFeature();
                    }
                    BubbleSort(PollutionArriveTime);
                    List <EmergencyScheduleArriveProperty> ERSTime = new List <EmergencyScheduleArriveProperty>();
                    //根据污染物到达应急处置空间位置先后顺序进行应急资源调度
                    for (int j = 0; j < PollutionArriveTime.Count; j++)
                    {
                        listBox1.Items.Add(PollutionArriveTime[j].Destname + "应急资源的调度情况:");
                        listBox1.Items.Add("");
                        ERSTime.Clear();
                        int destsequence = (PollutionArriveTime[j].Sequence - 1) * pFieldName.Length;

                        //对应急物资资源库到达应急处置空间位置的时间进行排序,以便从最短的应急资源仓库进行调度
                        int pdestsequence = PollutionArriveTime[j].Sequence - 1;
                        for (int n = 0; n < DepotCount; n++)
                        {
                            EmergencyScheduleArriveProperty pertime = new EmergencyScheduleArriveProperty();
                            pertime.TotalTime = resultlist[pdestsequence].WeightTime + ProjectTime[PollutionArriveTime[j].Sequence - 1].Arrivetime;
                            pertime.Sequence  = n + 1;
                            ERSTime.Add(pertime);
                            pdestsequence += DestCount;
                        }
                        BubbleSort(ERSTime);
                        //根据应急处置点需求的应急资源进行处置
                        for (int m = 0; m < pFieldName.Length; m++)
                        {
                            listBox1.Items.Add(pFieldName[m] + "需求量为:" + pMaterialdemand[destsequence].Number.ToString());

                            //根据应急资源需求的紧迫度,进行应急资源的调度
                            if (pMaterialdemand[destsequence].Number > 0)
                            {
                                for (int k = 0; k < ERSTime.Count; k++)
                                {
                                    if (ERSTime[k].TotalTime > PollutionArriveTime[j].Arrivetime)
                                    {
                                        listBox1.Items.Add("剩余的应急资源物资无法在指定时间范围内到该应急处置空间位置!");
                                        break;
                                    }
                                    else if (pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number > pMaterialdemand[destsequence].Number && ERSTime[k].TotalTime <= PollutionArriveTime[j].Arrivetime)
                                    {
                                        string strNumber = (pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number - pMaterialdemand[destsequence].Number).ToString("N2");
                                        pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number = Convert.ToDouble(strNumber);
                                        listBox1.Items.Add(pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Depotname + "→" + pMaterialdemand[destsequence].Destname + ":" + pMaterialdemand[destsequence].Number.ToString());
                                        Result pResult = new Result();
                                        pResult.DepotName = pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Depotname;
                                        pResult.DestName  = pMaterialdemand[destsequence].Destname;
                                        for (int x = 0; x < resultlist.Count; x++)
                                        {
                                            if (resultlist[x].DepotName == pResult.DepotName && resultlist[x].DestName == pResult.DestName)
                                            {
                                                if (resultlist[x].dynamicschedule == false)
                                                {
                                                    resultlist[x].dynamicschedule = true;
                                                }
                                            }
                                        }
                                        pMaterialdemand[destsequence].Number = 0.0;
                                        break;
                                    }
                                    else if (pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number > 0 && pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number < pMaterialdemand[destsequence].Number && ERSTime[k].TotalTime <= PollutionArriveTime[j].Arrivetime)
                                    {
                                        string strNumber = (pMaterialdemand[destsequence].Number - pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number).ToString("N2");
                                        pMaterialdemand[destsequence].Number = Convert.ToDouble(strNumber);
                                        listBox1.Items.Add(pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Depotname + "→" + pMaterialdemand[destsequence].Destname + ":" + pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number.ToString());
                                        Result pResult = new Result();
                                        pResult.DepotName = pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Depotname;
                                        pResult.DestName  = pMaterialdemand[destsequence].Destname;
                                        for (int x = 0; x < resultlist.Count; x++)
                                        {
                                            if (resultlist[x].DepotName == pResult.DepotName && resultlist[x].DestName == pResult.DestName)
                                            {
                                                if (resultlist[x].dynamicschedule == false)
                                                {
                                                    resultlist[x].dynamicschedule = true;
                                                }
                                            }
                                        }
                                        pERDepot[(ERSTime[k].Sequence - 1) * pFieldName.Length + m].Number = 0.0;
                                        if (k == ERSTime.Count - 1 && pMaterialdemand[destsequence].Number != 0)
                                        {
                                            listBox1.Items.Add("应急资源仓库的存储应急资源物资不足!");
                                        }
                                    }
                                }
                            }
                            destsequence++;
                            listBox1.Items.Add("");
                        }
                        listBox1.Items.Add("应急资源调度路线:");
                    }


                    Collection <RouteNode> routeNodes = new Collection <RouteNode>();       //存储某起点和终点最短路径网络所经过的结点

                    List <IPolyline> routeroad = new List <IPolyline>();

                    string r;
                    for (int y = 0; y < resultlist.Count; y++)
                    {
                        r = null;
                        if (resultlist[y].dynamicschedule == true)
                        {
                            foreach (string str in resultlist[y].StrResultNode)
                            {
                                r += str + "→";
                                DijkstraDepotToDestMethod.addRouteNodes(routeNodes, str);
                            }
                            r += resultlist[y].EndNodeID;
                            DijkstraDepotToDestMethod.addRouteNodes(routeNodes, resultlist[y].EndNodeID);
                            listBox1.Items.Add(r);
                            path.GetIElement(routeNodes);
                            routeroad.Add(Variable.PElement.Geometry as IPolyline);
                            routeNodes.Clear();
                        }
                        else
                        {
                            continue;
                        }
                    }
                    //获取
                    DijkstraDepotToDestMethod.GetIElement(routeroad);
                    DijkstraDepotToDestMethod.displayElement();
                    //IFeatureLayer comboBoxFeature=CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text);
                    //SaveVector.polylinetoFeatureLayer(comboBox4.Text, routeroad, comboBoxFeature);
                    MessageBox.Show("处理完毕!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
            }
        }
Exemple #4
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox2.Text == "")
                {
                    MessageBox.Show("请输入应急资源仓库数据", "输入应急资源仓库数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox3.Text == "")
                {
                    MessageBox.Show("请输入污染物扩散模拟数据", "输入污染物扩散模拟数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    //获取各个应急资源仓库到达应急处置空间位置的时间
                    pFeatureLayerDepot = CDataImport.ImportFeatureLayerFromControltext(comboBox2.Text);
                    String pFeatureFID = "FID=" + Convert.ToString(Convert.ToInt32(comboBox4.Text) - 1);
                    EmergencySpaceSelectionDijkstra pEmergencySpaceSelection = new EmergencySpaceSelectionDijkstra();
                    List <Result> resultlist = new List <Result>();
                    resultlist = pEmergencySpaceSelection.DepotToDest(pFeatureLayerDepot, pFeatureLayerDept, pFeatureFID);

                    //判断应急资源需求的种类
                    int EmergencyNumber = 0;
                    if (checkBox1.Checked == true)
                    {
                        EmergencyNumber++;
                    }
                    for (int i = 0; i < pCheckBox.Length; i++)
                    {
                        if (pCheckBox[i].Checked == true)
                        {
                            EmergencyNumber++;
                        }
                    }

                    //获取应急资需求的名称
                    string[] EmergencyVarietyName      = new string[EmergencyNumber];
                    int      EmergencyVarietyNameIndex = 0;
                    if (checkBox1.Checked == true)
                    {
                        int EmergencyVarietyIndex = label8.Text.LastIndexOf(":");
                        EmergencyVarietyName[EmergencyVarietyNameIndex] = label8.Text.Substring(0, EmergencyVarietyIndex);
                        EmergencyVarietyNameIndex++;
                    }
                    for (int j = 0; j < pLabel.Length; j++)
                    {
                        if (pCheckBox[j].Checked == true)
                        {
                            int EmergencyVarietyIndex = pLabel[j].Text.LastIndexOf(":");
                            EmergencyVarietyName[EmergencyVarietyNameIndex] = pLabel[j].Text.Substring(0, EmergencyVarietyIndex);
                            EmergencyVarietyNameIndex++;
                        }
                    }

                    //获取应急处置空间位置应急资源需求
                    pEmergencyDeptResource = new List <EmergencyDeptResource>();
                    int EmergencyDemandResourceNumber = 0;
                    if (checkBox1.Checked == true)
                    {
                        EmergencyDeptResource emergencydeptresource = new EmergencyDeptResource();
                        int EmergencyDemandResourceIndex            = label8.Text.LastIndexOf(":");
                        emergencydeptresource.EmergencyDemandResourceName   = EmergencyVarietyName[EmergencyDemandResourceNumber];
                        emergencydeptresource.EmergencyDemandResourceNumber = Convert.ToDouble(label8.Text.Substring(EmergencyDemandResourceIndex + 1));
                        pEmergencyDeptResource.Add(emergencydeptresource);
                        EmergencyDemandResourceNumber++;
                    }
                    for (int k = 0; k < pLabel.Length; k++)
                    {
                        if (pCheckBox[k].Checked == true)
                        {
                            EmergencyDeptResource emergencydeptresource = new EmergencyDeptResource();
                            int EmergencyDemandResourceIndex            = pLabel[k].Text.LastIndexOf(":");
                            emergencydeptresource.EmergencyDemandResourceName   = EmergencyVarietyName[EmergencyDemandResourceNumber];
                            emergencydeptresource.EmergencyDemandResourceNumber = Convert.ToDouble(pLabel[k].Text.Substring(EmergencyDemandResourceIndex + 1));
                            pEmergencyDeptResource.Add(emergencydeptresource);
                            EmergencyDemandResourceNumber++;
                        }
                    }


                    //获取应急资源仓库存储的的应急资源
                    IFeatureClass  pFeatureClassDepot    = pFeatureLayerDepot.FeatureClass;
                    int            DepotNumber           = pFeatureClassDepot.FeatureCount(null);
                    IFeatureCursor pFeatureCursorDepot   = pFeatureClassDepot.Search(null, false);
                    IFeature       pFeatureDepot         = pFeatureCursorDepot.NextFeature();
                    int            DepotNumberArriveDept = 0;
                    pEmergencyDepotResource = new List <EmergencyDepotResource>();
                    while (pFeatureDepot != null)
                    {
                        EmergencyDepotResource emergencydepotresource = new EmergencyDepotResource();
                        emergencydepotresource.DepotName           = Convert.ToString(pFeatureDepot.get_Value(pFeatureDepot.Fields.FindField("Name")));
                        emergencydepotresource.DepotArriveDeptTime = Math.Round(Convert.ToDouble(resultlist[DepotNumberArriveDept].WeightTime), 4);
                        DepotNumberArriveDept++;
                        emergencydepotresource.EmergencyVarietyNameNumber = new double[EmergencyNumber];
                        emergencydepotresource.EmergencyVarietyName       = new string[EmergencyNumber];
                        for (int k = 0; k < EmergencyNumber; k++)
                        {
                            emergencydepotresource.EmergencyVarietyName[k]       = EmergencyVarietyName[k];
                            emergencydepotresource.EmergencyVarietyNameNumber[k] = Convert.ToDouble(pFeatureDepot.get_Value(pFeatureDepot.Fields.FindField(EmergencyVarietyName[k])));
                        }
                        pEmergencyDepotResource.Add(emergencydepotresource);
                        pFeatureDepot = pFeatureCursorDepot.NextFeature();
                    }



                    //获取污染物扩散到达应急处置空间位置的时间
                    double        pollutionArriveTime = 0.0;
                    IFeatureClass pFeatureClassDept   = pFeatureLayerDept.FeatureClass;
                    IQueryFilter  pQueryFilterDept    = new QueryFilterClass();
                    pQueryFilterDept.WhereClause = "FID=" + Convert.ToString(Convert.ToInt32(comboBox4.Text) - 1);
                    IFeatureCursor pFeatureCursorDept = pFeatureClassDept.Search(pQueryFilterDept, false);
                    IFeature       pFeatureDept       = pFeatureCursorDept.NextFeature();
                    IPoint         point = new PointClass();
                    while (pFeatureDept != null)
                    {
                        point        = pFeatureDept.Shape as IPoint;
                        pFeatureDept = pFeatureCursorDept.NextFeature();
                    }
                    double X = 0.0, Y = 0.0;
                    X = Math.Round(point.X, 4);
                    Y = Math.Round(point.Y, 4);
                    int          column = 0, row = 0;
                    IRasterLayer pRasterLayer = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text);
                    RasterManagement.XYconvertNumber(pRasterLayer, X, Y, ref column, ref row);
                    pollutionArriveTime = Convert.ToDouble(RasterManagement.GetPixelValue(pRasterLayer, 0, column, row));

                    //读取构架应急工程措施的时间
                    double SetProjectTime = Math.Round(Convert.ToDouble(textBox1.Text), 4);

                    //对各个应急资源仓库到达应急处置空间位置的时间进行排序
                    BubbleSort(pEmergencyDepotResource);

                    //进行应急资源调度
                    List <EmergencyResourceResult> pEergencyResourceResult = new List <EmergencyResourceResult>();
                    for (int k = 0; k < DepotNumber; k++)                                                          //按照到达应急处置空间位置的应急仓库进行排序
                    {
                        if (pEmergencyDepotResource[k].DepotArriveDeptTime + SetProjectTime < pollutionArriveTime) //判断到达应急处置空间位置与构建工程时间之和小于污染物扩散到达时间
                        {
                            //创建应急资源调度的结果
                            EmergencyResourceResult emergencyresourceresult = new EmergencyResourceResult();
                            emergencyresourceresult.EmergencyResourceName   = new string[pEmergencyDepotResource[k].EmergencyVarietyName.Length];
                            emergencyresourceresult.EmergencyResourceNumber = new double[pEmergencyDepotResource[k].EmergencyVarietyNameNumber.Length];
                            for (int l = 0; l < pEmergencyDeptResource.Count; l++)                               //应急处置空间位置需要的应急资源种类
                            {
                                for (int h = 0; h < pEmergencyDepotResource[k].EmergencyVarietyName.Length; h++) //对应急资源仓库的应急资源名称进行查找和应急处置空间位置名称相同
                                {
                                    if (pEmergencyDepotResource[k].EmergencyVarietyName[h] == pEmergencyDeptResource[l].EmergencyDemandResourceName && pEmergencyDepotResource[k].EmergencyVarietyNameNumber[h] > 0)
                                    {
                                        emergencyresourceresult.DepotName = pEmergencyDepotResource[k].DepotName;
                                        emergencyresourceresult.EmergencyResourceArriveTime = pEmergencyDepotResource[k].DepotArriveDeptTime;
                                        if (pEmergencyDeptResource[l].EmergencyDemandResourceNumber <= pEmergencyDepotResource[k].EmergencyVarietyNameNumber[h])
                                        {
                                            emergencyresourceresult.EmergencyResourceName[l]          = pEmergencyDeptResource[l].EmergencyDemandResourceName;
                                            emergencyresourceresult.EmergencyResourceNumber[l]        = pEmergencyDeptResource[l].EmergencyDemandResourceNumber;
                                            pEmergencyDepotResource[k].EmergencyVarietyNameNumber[h] -= pEmergencyDeptResource[l].EmergencyDemandResourceNumber;
                                            pEmergencyDepotResource[k].EmergencyDepotBool             = true;
                                            pEmergencyDeptResource[l].EmergencyDemandResourceNumber  -= pEmergencyDeptResource[l].EmergencyDemandResourceNumber;
                                        }
                                        else
                                        {
                                            emergencyresourceresult.EmergencyResourceName[l]         = pEmergencyDeptResource[l].EmergencyDemandResourceName;
                                            emergencyresourceresult.EmergencyResourceNumber[l]       = pEmergencyDepotResource[k].EmergencyVarietyNameNumber[h];
                                            pEmergencyDeptResource[l].EmergencyDemandResourceNumber -= pEmergencyDepotResource[k].EmergencyVarietyNameNumber[l];
                                            pEmergencyDepotResource[k].EmergencyVarietyNameNumber[l] = 0.0;
                                            pEmergencyDepotResource[k].EmergencyDepotBool            = true;
                                        }
                                    }
                                }
                            }


                            //将有应急资源仓库调度资源的显示在ListBox中
                            for (int f = 0; f < emergencyresourceresult.EmergencyResourceNumber.Length; f++)
                            {
                                if (emergencyresourceresult.EmergencyResourceNumber[f] > 0)
                                {
                                    listBox1.Items.Add(pEmergencyDepotResource[k].DepotName);
                                    break;
                                }
                            }


                            //将应急资源调度的结果显示在ListBox
                            for (int a = 0; a < emergencyresourceresult.EmergencyResourceNumber.Length; a++)
                            {
                                if (emergencyresourceresult.EmergencyResourceNumber[a] > 0)
                                {
                                    listBox1.Items.Add(emergencyresourceresult.EmergencyResourceName[a] + ":" + Convert.ToString(emergencyresourceresult.EmergencyResourceNumber[a]));
                                }
                            }
                        }
                        else
                        {
                            //listBox1.Items.Add("其他的应急资源仓库的应急资源无法到达应急处置空间位置!");
                            break;
                        }

                        //如果应急处置空间位置的应急资源满足,则跳出应急资源调度过程
                        int DeptVarietyNumber = 0;
                        for (int b = 0; b < pEmergencyDeptResource.Count; b++)
                        {
                            if (pEmergencyDeptResource[b].EmergencyDemandResourceNumber == 0)
                            {
                                DeptVarietyNumber++;
                                continue;
                            }
                        }
                        if (DeptVarietyNumber == pEmergencyDeptResource.Count)
                        {
                            break;
                        }
                    }

                    //刷新应急处置点信息情况
                    for (int c = 0; c < pEmergencyDeptResource.Count; c++)
                    {
                        for (int d = 0; d < pLabel.Length; d++)
                        {
                            string VarietyName = pLabel[d].Text.Substring(0, pLabel[d].Text.LastIndexOf(":"));
                            if (VarietyName == pEmergencyDeptResource[c].EmergencyDemandResourceName)
                            {
                                pLabel[d].Text = pEmergencyDeptResource[c].EmergencyDemandResourceName + ":" + pEmergencyDeptResource[c].EmergencyDemandResourceNumber.ToString();
                                break;
                            }
                        }
                    }
                    groupBox4.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
            }
        }