Пример #1
0
        /// <summary>
        /// Create an object of type Merger from string infors
        /// </summary>
        /// <param name="MergerInfors"></param>
        /// <returns></returns>
        public static Merger createMergerFromStringArray(string[] MergerInfors)
        {
            Merger   mg            = null;
            int      id            = Convert.ToInt16(MergerInfors[1]);
            int      x             = Convert.ToInt32(MergerInfors[2]);
            int      y             = Convert.ToInt32(MergerInfors[3]);
            Point    Location      = new Point(x, y);
            double   CurrentFlow   = Convert.ToDouble(MergerInfors[4]);
            PipeLine inpipeline1   = new PipeLine(Convert.ToInt32(MergerInfors[5]), 0);
            PipeLine inpipeline2   = new PipeLine(Convert.ToInt32(MergerInfors[6]), 0);
            PipeLine outpipeline   = new PipeLine(Convert.ToInt32(MergerInfors[7]), 0);
            int      upperX        = Convert.ToInt32(MergerInfors[8]);
            int      upperY        = Convert.ToInt32(MergerInfors[9]);
            Point    UpperLocation = new Point(upperX, upperY);
            int      lowerX        = Convert.ToInt32(MergerInfors[10]);
            int      lowerY        = Convert.ToInt32(MergerInfors[11]);
            Point    LowerLocation = new Point(lowerX, lowerY);

            mg = new Merger(id, Location, CurrentFlow, inpipeline1, inpipeline2, outpipeline, UpperLocation, LowerLocation);
            return(mg);
        }
Пример #2
0
        /// <summary>
        /// Update the currentflow of all neighbors when pipeline is added
        /// </summary>
        public void UpdateCurrentFlowOfNetwork()
        {
            try
            {
                double mergerFlow = 0;
                foreach (PipeLine p in GetListOfPipeline())
                {
                    if (p.CompStart is Pump)
                    {
                        if (p.CompEnd is Merger)
                        {
                            mergerFlow += p.CompStart.GetFlow();
                            p.CompEnd.SetFlow(mergerFlow);
                            p.CurrentFlow = p.CompStart.GetFlow();
                        }
                        else
                        {
                            p.CompEnd.SetFlow(p.CompStart.GetFlow());
                            p.CurrentFlow = p.CompStart.GetFlow();
                        }
                    }
                }

                int countSplitters = 0;
                foreach (PipeLine p in GetListOfPipeline())
                {
                    if (p.CompStart is Spliter)
                    {
                        if (p.CompStart is AdjustableSpliter)
                        {
                            double            upperFlow = 0, lowerFlow = 0;
                            PipeLine          p1 = null, p2 = null;
                            AdjustableSpliter temp = (AdjustableSpliter)p.CompStart;
                            if (p.CompStart == temp && countSplitters == 0)
                            {
                                upperFlow      = temp.GetOutUpperFlow();
                                p1             = p;
                                p1.CurrentFlow = upperFlow;
                                countSplitters++;
                            }

                            if (p1 != p && p.CompStart == temp && countSplitters == 1)
                            {
                                lowerFlow      = temp.GetOutLowerFlow();
                                p2             = p;
                                p2.CurrentFlow = lowerFlow;
                            }
                            if (p1 != null)
                            {
                                p1.CompEnd.SetFlow(upperFlow);
                            }
                            if (p2 != null)
                            {
                                p2.CompEnd.SetFlow(lowerFlow);
                            }
                        }
                        else
                        {
                            p.CompEnd.SetFlow(p.CompStart.GetFlow() / 2);
                            p.CurrentFlow = p.CompStart.GetFlow() / 2;
                        }
                    }
                }

                foreach (PipeLine p in GetListOfPipeline())
                {
                    if (p.CompStart is Merger)
                    {
                        //double mergerCurrentFlow = 0;
                        Merger temp = (Merger)p.CompStart;

                        /*foreach (PipeLine pi in GetListOfPipeline())
                         * {
                         *  if (pi.CompEnd == temp)
                         *  {
                         *      mergerCurrentFlow = pi.CompEnd.GetFlow();
                         *  }
                         * }*/
                        p.CompEnd.SetFlow(p.CompStart.GetFlow());
                        p.CurrentFlow = p.CompStart.GetFlow();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Current flow update error.");
            }
        }
Пример #3
0
 /// <summary>
 /// Update Pipelines of Comps depending type of com
 /// </summary>
 /// <param name="c"></param>
 private void UpdatePipelinesOfComps(Component c)
 {
     if (c is Pump)
     {
         Pump p = (Pump)c;
         if (p.getOutPipeLine() != null)
         {
             PipeLine outPipeLine = GetPipeline(p.getOutPipeLine().getId());
             p.addOutPipeLine(outPipeLine);
         }
         else
         {
             p.addOutPipeLine(null);
         }
     }
     if (c is Spliter || c is AdjustableSpliter)
     {
         Spliter sp = null;
         sp = (Spliter)c;
         if (c is AdjustableSpliter)
         {
             sp = (AdjustableSpliter)c;
         }
         if (sp.getInPipeLine() != null)
         {
             PipeLine inPipeLine = GetPipeline(sp.getInPipeLine().getId());
             sp.addInPipeLine(inPipeLine);
         }
         else
         {
             sp.addInPipeLine(null);
         }
         if (sp.getOutPipeLine1() != null)
         {
             PipeLine outPipeLine1 = GetPipeline(sp.getOutPipeLine1().getId());
             sp.addOutPipeLine1(outPipeLine1);
         }
         else
         {
             sp.addOutPipeLine1(null);
         }
         if (sp.getOutPipeLine2() != null)
         {
             PipeLine outPipeLine2 = GetPipeline(sp.getOutPipeLine2().getId());
             sp.addOutPipeLine2(outPipeLine2);
         }
         else
         {
             sp.addOutPipeLine2(null);
         }
     }
     if (c is Merger)
     {
         Merger mg = (Merger)c;
         if (mg.getOutPipeLine() != null)
         {
             PipeLine outPipeline = GetPipeline(mg.getOutPipeLine().getId());
             mg.addOutPipeLine(outPipeline);
         }
         else
         {
             mg.addOutPipeLine(null);
         }
         if (mg.getInPipeLine1() != null)
         {
             PipeLine inPipeline1 = GetPipeline(mg.getInPipeLine1().getId());
             mg.addInPipeLine1(inPipeline1);
         }
         else
         {
             mg.addInPipeLine1(null);
         }
         if (mg.getInPipeLine2() != null)
         {
             PipeLine intPipeline2 = GetPipeline(mg.getInPipeLine2().getId());
             mg.addInPipeLine2(intPipeline2);
         }
         else
         {
             mg.addInPipeLine2(null);
         }
     }
     if (c is Sink)
     {
         Sink sk = (Sink)c;
         if (sk.getInPipeLine() != null)
         {
             PipeLine inPipeline = GetPipeline(sk.getInPipeLine().getId());
             sk.addInPipeLine(inPipeline);
         }
         else
         {
             sk.addInPipeLine(null);
         }
     }
 }