示例#1
0
 public int Distance(JamRange range)
 {
     if (range.StartIndex > EndIndex)
        return range.StartIndex - EndIndex-1;  //在後
        else
        return -(this.StartIndex - range.EndIndex-1);  //在前
 }
示例#2
0
 public int Distance(JamRange range)
 {
     if (range.StartIndex > EndIndex)
        return range.StartIndex - EndIndex - 1;  //在後
        else
        return -(this.StartIndex - range.EndIndex - 1);  //在前
        //if (range.StartIndex == StartIndex && range.EndIndex== EndIndex )
        //    return 0;
        //if (range.StartIndex > EndIndex)
        //    return range.StartIndex - EndIndex-1;  //在後
        //else
        //    return -(this.StartIndex - range.EndIndex-1);  //在前
 }
示例#3
0
        public JamRange[] Split()
        {
            //chek 22

               for (int i = 1; i < devlist.Count - 1; i++)
               {

               VDDeviceWrapper vd =devlist[i] as VDDeviceWrapper;
               int jamLevel, nextJamLevel;
               jamLevel = vd.jamLevel;
               nextJamLevel = ((VDDeviceWrapper)vd.NextDevice).jamLevel;
               if ((jamLevel == 2 && nextJamLevel == 2) || (jamLevel == -1 && nextJamLevel == 2) || (jamLevel == 2 && nextJamLevel == -1) || jamLevel < 2 && jamLevel >= 0) //2013-5-22
               {
                   JamRange[] splitrang = new JamRange[2];

                   splitrang[0] = new JamRange(devlist[0] as VDDeviceWrapper);
                   splitrang[1]=new JamRange(devlist[devlist.Count-1]  as VDDeviceWrapper);

                   for (int j = 1; j < i; j++)
                       splitrang[0].Merge(new JamRange(devlist[j]  as VDDeviceWrapper));

                  for (int j = (vd.jamLevel==2)?i + 2:i+1; j < devlist.Count-1; j++)
                       splitrang[1].Merge(new JamRange(devlist[j] as VDDeviceWrapper));

                   return splitrang;
               }

               }

               return null;
        }
示例#4
0
        public bool Merge( JamRange range)
        {
            //if (this.Equals(range)) //#
               //    return false;

               int distance = Distance(range);

               //相鄰超過兩座以上
               if (Math.Abs(distance) > 2) //2013-6-7  >= --> >
               return false;

               //相鄰一座
               if (distance == 1)
               {
               VDDeviceWrapper vd = (VDDeviceWrapper)range.devlist[0];
               if (((VDDeviceWrapper)vd.PreDevice).jamLevel < 2  && ((VDDeviceWrapper)vd.PreDevice).jamLevel>=0)  //2013-5-22
                   return false;

               }

               if (distance == -1)
               {

               VDDeviceWrapper vd = (VDDeviceWrapper)this.devlist[0];
               if (((VDDeviceWrapper)vd.PreDevice).jamLevel < 2 && ((VDDeviceWrapper)vd.PreDevice).jamLevel >=0) //2013-5-22
                   return false;
               }

               //2013-5-22 相鄰兩座
               if (distance == 2)  //range 在後
               {
               VDDeviceWrapper vd = (VDDeviceWrapper)range.devlist[0];
               VDDeviceWrapper pre_vd = (VDDeviceWrapper)vd.getPrevDev();
               VDDeviceWrapper prepre_vd = (VDDeviceWrapper)pre_vd.getPrevDev();
               if (!(pre_vd.jamLevel == -1 && prepre_vd.jamLevel == -1))
                   return false;
               }
               if (distance == -2)  //range 在前
               {
               VDDeviceWrapper vd = (VDDeviceWrapper)this.devlist[0];
               VDDeviceWrapper pre_vd = (VDDeviceWrapper)vd.getPrevDev();
               VDDeviceWrapper prepre_vd = (VDDeviceWrapper)pre_vd.getPrevDev();
               if (!(pre_vd.jamLevel == -1 && prepre_vd.jamLevel == -1))
                   return false;
               }

               foreach (VDDeviceWrapper dev in range.devlist)
               {
               if(!this.devlist.Contains(dev))
               this.devlist.Add(dev);
               }

               this.devlist.Sort();
               range.DelMark = true;
               return true;
             //  int distance=Distance(range);
             //  VDDeviceWrapper middledev=null;
             //  //相鄰超過兩座以上
             // if (Math.Abs(distance)>=2   )
             //    return false;

             // if (distance == 0)
             // {
             //     range.DelMark = true;
             //     return false;
             // }
             //  //相鄰一座

             //if (distance == 1)// range 在後
             //{
             //    VDDeviceWrapper vd = (VDDeviceWrapper)range.devlist[0];
             //    middledev = (VDDeviceWrapper)vd.PreDevice;
             //    if (middledev.jamLevel < 2)
             //        return false;

             //}

             //if (distance == -1)  //range 在前
             //{

             //    VDDeviceWrapper vd = (VDDeviceWrapper)this.devlist[0];
             //    middledev = (VDDeviceWrapper)vd.PreDevice;

             //    if (middledev.jamLevel < 2)
             //        return false;
             //}

             //foreach (VDDeviceWrapper dev in range.devlist.ToArray())
             //{
             //    if (!devlist.Contains(dev))  //#2013/4/20
             //            this.devlist.Add(dev);
             //}

             //if (middledev != null)
             //{
             //    if(!this.devlist.Contains(middledev)) //#2013/4/20
             //       this.devlist.Add(middledev);
             //}

             //  this.devlist.Sort();
             //  range.DelMark = true;
             //return true;
        }
示例#5
0
 public bool IsContain(JamRange r)
 {
     return StartIndex <= r.StartIndex && EndIndex >= r.EndIndex;
 }
示例#6
0
        public JamRange[] Split()
        {
            //chek 22

               for (int i = 1; i < devlist.Count - 1; i++)
               {

               VDDeviceWrapper vd =devlist[i] as VDDeviceWrapper;
               if ((vd.jamLevel == 2 && ((VDDeviceWrapper)vd.NextDevice).jamLevel == 2) || vd.jamLevel < 2)
               {
                   JamRange[] splitrang = new JamRange[2];

                   splitrang[0] = new JamRange(devlist[0] as VDDeviceWrapper);
                   splitrang[1]=new JamRange(devlist[devlist.Count-1]  as VDDeviceWrapper);

                   for (int j = 1; j < i; j++)
                       splitrang[0].Merge(new JamRange(devlist[j]  as VDDeviceWrapper));

                  for (int j = (vd.jamLevel==2)?i + 2:i+1; j < devlist.Count-1; j++)
                       splitrang[1].Merge(new JamRange(devlist[j] as VDDeviceWrapper));

                   return splitrang;
               }

               }

               return null;
        }
示例#7
0
        public bool Merge( JamRange range)
        {
            int distance=Distance(range);

               //相鄰超過兩座以上
              if (Math.Abs(distance)>=2)
             return false;
               //相鄰一座

             if (distance == 1)
             {
             VDDeviceWrapper vd = (VDDeviceWrapper)range.devlist[0];
             if (((VDDeviceWrapper)vd.PreDevice).jamLevel < 2)
                 return false;

             }

             if (distance == -1)
             {

             VDDeviceWrapper vd = (VDDeviceWrapper)this.devlist[0];
             if (((VDDeviceWrapper)vd.PreDevice).jamLevel < 2)
                 return false;
             }

             foreach (VDDeviceWrapper dev in range.devlist)

             this.devlist.Add(dev);

               this.devlist.Sort();
               range.DelMark = true;
             return true;
        }
示例#8
0
 public JamEvent(long eventid,JamRange jamrange,EventMode mode)
     : base(eventid,mode)
 {
     this.jamRange = jamrange;
 }
示例#9
0
        void CheckLineJam(string key)
        {
            ArrayList tmp=new ArrayList();
            ArrayList  vdlist= (ArrayList) lines[key];
            ArrayList rangelist = (ArrayList)lineJamRanges[key];
            ArrayList rmlst = new ArrayList();

            // 壅塞範圍改變檢查

            //try
            //{
            //    if (System.IO.File.Exists(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "jam.log")))
            //        System.IO.File.Delete(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "jam.log"));
            //}
            //catch (Exception ex)
            //{
            //    ConsoleServer.WriteLine(ex.Message);
            //}
            foreach (JamRange r in rangelist)
            {

                try
                {
                    if (r.Shrink())
                        r.invokeRangeChange();
                    else if (r.DelMark)
                        rmlst.Add(r);
                }
                catch (Exception ex)
                {
                    ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
                }

                //event here

            }

            CheckState = 5;

            foreach (JamRange r in rmlst)
            {
                try
                {
                    rangelist.Remove(r);
                }
                catch (Exception ex)
                {
                    Util.SysLog("sys.log", "In Jam Check" + ex.Message + "," + ex.StackTrace);
                    ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
                }
                try
                {
                    r.invokeStop();
                }
                catch(Exception ex)
                {
                    Util.SysLog("sys.log", "In Jam Check" + ex.Message + "," + ex.StackTrace);
                   ConsoleServer.WriteLine(ex.Message+","+ex.StackTrace) ;
                }
            }

            rmlst.Clear();
            //  檢查所有壅塞程度為 3 的車輛偵測器
            CheckState = 6;
            for (int i = 0; i < vdlist.Count; i++)
            {
                VDDeviceWrapper vd = (VDDeviceWrapper)vdlist[i];
                if (vd.jamLevel == 3)
                {

                    Util.SysLog("jam.log", vd.deviceName+" try to join\r\n");

                    bool hasContain=false;
                    for (int j = 0; j < rangelist.Count; j++)
                    {
                        try
                        {
                            JamRange range = (JamRange)rangelist[j];

                            if (!range.DelMark && range.IsInRange(i))
                            {
                                hasContain = true;

                                Util.SysLog("jam.log", vd.deviceName + " contain in " + range.ToString() + "\r\n");

                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Util.SysLog("jam.log", ex.Message + "," + ex.StackTrace);
                            ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
                        }
                    }

                    if (!hasContain)
                    {

                        Util.Log("jam.log", vd.deviceName + " new to range \r\n");

                        tmp.Add(new JamRange(vd));

                    }

                }
            }

            CheckState = 7;
               // check 合併  tmp range
            rmlst.Clear();
            Util.SysLog("jam.log", "tmp count:"+tmp.Count+ "\r\n");
            for (int i = 0; i < tmp.Count - 1; i++)
            {
                JamRange rangei = tmp[i] as JamRange;
                if (rangei.DelMark)
                    continue;
                for (int j = i + 1; j < tmp.Count  ; j++)
                {
                    try
                    {
                        JamRange rangej = tmp[j] as JamRange;
                        if (rangej.DelMark)
                            continue;
                        if (rangei.Merge(rangej))
                        {
                            rmlst.Add(rangej);
                        }
                    }
                    catch (Exception ex)
                    {
                        Util.SysLog("jam.log", ex.Message + "," + ex.StackTrace);
                    }

                }
            }
               foreach(JamRange r in rmlst)
               {
            tmp.Remove(r);
               }
               rmlst.Clear();

               CheckState = 71;

            foreach (JamRange tmprange in tmp.ToArray())  // 20130425 to array
            {
              //  bool isMerge = false;
                foreach(JamRange range in  rangelist.ToArray())  //20130425 to array
                {
                    try
                    {
                        if (range.Merge(tmprange)) //2013-3-22 加上 delmark 條件
                        {

                            Util.SysLog("jam.log", range.ToString() + "Merge" + tmprange.ToString() + "\r\n");

                            rmlst.Add(tmprange);
                            range.invokeRangeChange();

                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Util.SysLog("jam.log", ex.Message + "," + ex.StackTrace);
                        ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
                    }
                }
            }

            CheckState = 8;
            foreach (JamRange r in rmlst)
            {
                tmp.Remove(r);
                //r.invokeAbort();
            }

            rmlst.Clear();
            CheckState = 9;
               // 現有的壅塞範圍合併
            for (int i = 0; i < rangelist.Count-1; i++)
            {
                JamRange rangei = rangelist[i] as JamRange;
                if (rangei.DelMark)
                    continue;
                for (int j = i + 1; j < rangelist.Count; j++)
                {
                    JamRange rangej = rangelist[j] as JamRange;
                    if (rangej.DelMark)
                        continue;
                    try
                    {
                        if (rangei.Merge(rangej))
                        {
                            //Event here
                            //   rangei.invokeRangeChange();

                            rangei.DelMark = true;
                            JamRange newrange = new JamRange(rangei.getDevList()[0] as VDDeviceWrapper);
                            newrange.setDevList(rangei.getDevList());
                            rangelist.Add(newrange);

                            Program.matrix.event_mgr.AddEvent(newrange);

                        }
                    }
                    catch (Exception ex)
                    {
                        Util.SysLog("jam.log", ex.Message + "," + ex.StackTrace);
                        ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
                    }

                }
            }
            CheckState = 10;
             foreach (JamRange r in rangelist )
                if (r.DelMark)
                {
                    rmlst.Add(r);

                }

             CheckState = 11;
            foreach (JamRange r in rmlst)
            {
                //Event here
                try
                {
                    r.invokeAbort();

                    rangelist.Remove(r);
                }
                catch (Exception ex)
                {
                    Util.SysLog("jam.log", ex.Message + "," + ex.StackTrace);
                }

            }
               //加入新的壅塞範圍
            foreach (JamRange r in tmp)
            {
                rangelist.Add(r);

                //add event mgr  here
              //  Util.SysLog("sys.log",DateTime.Now+":"+ r.ToString());
                Program.matrix.event_mgr.AddEvent(r);
               // Util.SysLog("sys.log", DateTime.Now + ":" + r.ToString()+ "add completed!" );
            }

            CheckState = 12;
               //壅塞範圍分割

            foreach (JamRange r in rangelist.ToArray())
            {
                 JamRange[] rs;
                 if ((rs = r.Split()) != null)
                {
                    try
                    {
                        CheckState = 121;
                        r.invokeAbort();
                        CheckState = 122;
                        rangelist.Remove(r);
                        CheckState = 123;
                        rangelist.Add(rs[0]);
                        CheckState = 124;
                        rangelist.Add(rs[1]);
                        CheckState = 125;

                        Program.matrix.event_mgr.AddEvent(rs[0]);
                        CheckState = 126;
                        Program.matrix.event_mgr.AddEvent(rs[1]);
                        CheckState = 127;
                    }
                    catch (Exception ex)
                    {
                        Util.SysLog("jam.log", ex.Message + "," + ex.StackTrace);
                        ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace );
                    }
                     //add event mgr  here

                }

            }
            CheckState = 13;
        }