Пример #1
0
        public Bus(List <RoadPoint> route, String name, Canvas parent, Brush color)
        {
            this.Route       = route;
            this.BusLineName = name;
            this.OnBoard     = new HashSet <Passenger>();
            this.Stops       = new List <string>();
            this.Parent      = parent;
            this.BusColor    = color;
            this.traces      = new List <Point[]>();
            this.netComm     = new BusNetComm();
            this.pasb        = new Storyboard();

            BusImage             = new Image();
            BusImage.Source      = new BitmapImage((new Uri(@"Img\bus.bmp", UriKind.Relative)));
            BusImage.Height      = 20;
            BusImage.Width       = 20;
            BusImage.ToolTip     = this.BusLineName;
            BusImage.MouseEnter += MouseOverEventHandler;
            BusImage.MouseLeave += MouseLeaveEventHandler;
            this.Parent.Children.Add(this.BusImage);

            int i = 0;

            this.points = new Point[Route.Count];
            foreach (RoadPoint rd in Route)
            {
                if (rd is RoadStop)
                {
                    RoadStop rs = (RoadStop)rd;
                    Stops.Add(rs.StopName);
                }
                points[i] = rd.Coordinate;
                i++;
            }
        }
Пример #2
0
        public Passenger(ulong id, RoadStop start, RoadStop dest, List <string> actions)
        {
            this.CellPhoneAddress = id;
            this.StartStop        = start;
            this.DestinationStop  = dest;
            this.ActionList       = new List <string>();
            this.Message          = "Message History:\n";

            foreach (string action in actions)
            {
                if (action[0].Equals('['))
                {
                    continue;
                }
                else if (action.Equals("cross"))
                {
                    ActionList.Add(action);
                }
                else
                {
                    ActionList.Add("Line" + action.Substring(8));
                }
            }

            if (NextAction().Equals("cross"))
            {
                start.Opposite.Passengers.Add(this);
                TakeBusOneStop();
            }
            else
            {
                start.Passengers.Add(this);
            }
        }
Пример #3
0
        //Draw a trace and return the trace
        public List <Line> OneStopTrace(string start)
        {
            List <Point> tempList = new List <Point>();
            int          index    = Route.Count + 1;

            for (int i = 0; i < Route.Count; i++)
            {
                if (i > index)
                {
                    tempList.Add(Route.ElementAt <RoadPoint>(i).Coordinate);
                }
                if (Route.ElementAt <RoadPoint>(i) is RoadStop)
                {
                    if (i > index)
                    {
                        break;
                    }
                    RoadStop rs = (RoadStop)Route.ElementAt <RoadPoint>(i);
                    if (rs.StopName.Equals(start))
                    {
                        index = i;
                        tempList.Add(rs.Coordinate);
                    }
                }
            }
            return(LineDrawing.DrawLine(tempList.ToArray(), this.Parent, this.BusColor));
        }
Пример #4
0
        public static void InitStopInfoControl(string stopconfig, Canvas Carrier)
        {
            TextReader tr     = new StreamReader(stopconfig);
            String     line   = tr.ReadLine();
            int        stopID = 1;

            while (line != null)
            {
                StopInfoControl control;
                int             x     = Convert.ToInt32(line.Substring(line.IndexOf("(") + 1, line.IndexOf(",") - line.IndexOf("(") - 1));
                int             y     = Convert.ToInt32(line.Substring(line.IndexOf(",") + 1, line.IndexOf(")") - line.IndexOf(",") - 1));
                int             angle = Convert.ToInt32(line.Substring(line.IndexOf("[") + 1, line.IndexOf("]") - line.IndexOf("[") - 1));
                String          name  = line.Substring(line.IndexOf("{") + 1, line.IndexOf("}") - line.IndexOf("{") - 1);
                if (stopID <= 4)
                {
                    control = new TerminalControl(new Point(x, y), angle, name, Carrier);
                }
                else
                {
                    control = new StopControl(new Point(x, y), angle, name, Carrier);
                }

                RoadStop rs = null;
                StopBase.StopTable.TryGetValue(name, out rs);
                control.AddRoadStop(rs);

                stopID++;
                line = tr.ReadLine();
            }
        }
Пример #5
0
 private void MenuItem_Click_2(object sender, RoutedEventArgs e)
 {
     BusLineBase.BusLineTable[(string)busLineList.SelectedItem].Route.RemoveAt(busRouteView.SelectedIndex);
     if (busRouteView.SelectedItem is RoadStop)
     {
         RoadStop temp = (RoadStop)busRouteView.SelectedItem;
         temp.RemoveBusLine((string)busLineList.SelectedItem);
     }
     busRouteView.Items.Refresh();
     isRouteModified[busLineList.SelectedIndex] = true;
 }
Пример #6
0
        private void ResetStopsAndPoints()
        {
            int i = 0;

            Stops.Clear();
            this.points = new Point[Route.Count];

            foreach (RoadPoint rd in Route)
            {
                if (rd is RoadStop)
                {
                    RoadStop rs = (RoadStop)rd;
                    Stops.Add(rs.StopName);
                }
                points[i] = rd.Coordinate;
                i++;
            }
        }
Пример #7
0
        //Thread: Update Passenger and BusLine info
        private void AtBusStopActivity()
        {
            RoadStop currentStop = StopBase.StopTable[Stops[localid % Stops.Count]];

            lock (currentStop)
            {
                //Passengers alight---------------------------------
                //Bus Report
                BusReportMsg alightMessage = new BusReportMsg();
                alightMessage.busLine  = this.BusLineName;
                alightMessage.isBoard  = false;
                alightMessage.stopName = currentStop.StopName;
                alightMessage.time     = System.DateTime.Now;
                alightMessage.busId    = (uint)BusLineNo;
                HashSet <ulong> alightAddresses = new HashSet <ulong>();

                //Terminal Stop
                if (localid % Stops.Count == Stops.Count - 1)
                {
                    foreach (Passenger p in this.OnBoard)
                    {
                        currentStop.Passengers.Add(p);
                    }
                    foreach (Passenger p in this.OnBoard)
                    {
                        alightAddresses.Add(p.CellPhoneAddress);
                    }
                    this.OnBoard.Clear();
                }
                //Other Stops
                else
                {
                    List <Passenger> removeList = new List <Passenger>();
                    foreach (Passenger p in this.OnBoard)
                    {
                        if (!p.NextAction().Equals(this.BusLineName))
                        {
                            removeList.Add(p);
                            currentStop.Passengers.Add(p);
                        }
                    }
                    foreach (Passenger p in removeList)
                    {
                        alightAddresses.Add(p.CellPhoneAddress);
                        //Remove on board
                        this.OnBoard.Remove(p);
                    }
                }
                alightMessage.cellPhoneAddrSet = alightAddresses;
                if (alightMessage.cellPhoneAddrSet.Count != 0)
                {
                    netComm.SendMsg(alightMessage);
                }

                //Pick up passengers---------------------------------
                List <Passenger> removeList2  = new List <Passenger>();
                BusReportMsg     boardMessage = new BusReportMsg();
                boardMessage.busLine  = this.BusLineName;
                boardMessage.isBoard  = true;
                boardMessage.stopName = currentStop.StopName;
                boardMessage.time     = System.DateTime.Now;
                boardMessage.busId    = (uint)BusLineNo;
                HashSet <ulong> boardAddresses = new HashSet <ulong>();

                foreach (Passenger p in currentStop.Passengers)
                {
                    if (p.NextAction().Equals(this.BusLineName))
                    {
                        this.OnBoard.Add(p);
                        boardAddresses.Add(p.CellPhoneAddress);
                        removeList2.Add(p);
                    }
                }
                foreach (Passenger p in removeList2)
                {
                    currentStop.Passengers.Remove(p);
                }

                //Bus Report
                boardMessage.cellPhoneAddrSet = boardAddresses;
                if (boardMessage.cellPhoneAddrSet.Count != 0)
                {
                    netComm.SendMsg(boardMessage);
                }

                OnBoardDesc = GetOnBoardDesc();
            }

            //Spend some time at the bus stop
            Thread.Sleep(rn.Next(1000, 6000));

            mre.WaitOne();
            Parent.Dispatcher.Invoke(new UpdateBusInfo(UpdateBusInfoDelegate));
        }
Пример #8
0
 public void AddRoadStop(RoadStop rs)
 {
     this.StopPoint = rs;
 }
Пример #9
0
        public static void InitBus(string buslineconfig, Canvas Carrier)
        {
            StopBase.StopTable.Clear();
            BusLineBase.BusLineTable.Clear();
            TextReader tr   = new StreamReader(buslineconfig);
            String     line = tr.ReadLine();

            int lineNo = 0;

            while (line != null)
            {
                List <RoadPoint> route    = new List <RoadPoint>();
                string           linename = line.Substring(0, line.IndexOf(":"));
                line = line.Substring(line.IndexOf(":") + 1);
                string[] points = line.Split(';');
                for (int i = 0; i < points.Length; i++)
                {
                    string point = points[i];
                    if (!point[0].Equals('('))
                    {
                        string   stopname = point.Substring(0, point.IndexOf("("));
                        RoadStop rs       = null;
                        if (!StopBase.StopTable.TryGetValue(stopname, out rs))
                        {
                            int x = Convert.ToInt32(point.Substring(point.IndexOf("(") + 1, point.IndexOf(",") - point.IndexOf("(") - 1));
                            int y = Convert.ToInt32(point.Substring(point.IndexOf(",") + 1, point.IndexOf(")") - point.IndexOf(",") - 1));

                            rs = new RoadStop(x, y, stopname);
                            StopBase.StopTable.Add(stopname, rs);
                        }
                        if (i + 1 != points.Length)
                        {
                            rs.AddBusLine(linename);
                        }
                        route.Add(rs);
                    }
                    else
                    {
                        int       x  = Convert.ToInt32(point.Substring(point.IndexOf("(") + 1, point.IndexOf(",") - point.IndexOf("(") - 1));
                        int       y  = Convert.ToInt32(point.Substring(point.IndexOf(",") + 1, point.IndexOf(")") - point.IndexOf(",") - 1));
                        RoadPoint rp = new RoadPoint(x, y);
                        route.Add(rp);
                    }
                }
                BusLineBase.BusLineTable.Add(linename, new Bus(route, linename, Carrier, colors[lineNo / 2]));
                line = tr.ReadLine();
                lineNo++;

                //break;
            }

            //Calculate Stops that are opposite to each other
            for (int i = 0; i < StopBase.StopTable.Values.Count; i++)
            {
                RoadStop rs1 = StopBase.StopTable.Values.ElementAt <RoadStop>(i);
                for (int j = i + 1; j < StopBase.StopTable.Values.Count; j++)
                {
                    RoadStop rs2 = StopBase.StopTable.Values.ElementAt <RoadStop>(j);
                    if (isClose(rs1.Coordinate, rs2.Coordinate))
                    {
                        rs1.Opposite = rs2;
                        rs2.Opposite = rs1;
                        break;
                    }
                }
            }
        }