Esempio n. 1
0
        private IEnumerable <CellularTowerEvent> DetectEvent(string vehicleId, string linkId, long currentTick)
        {
            VehicleEvent vEvent = vehicleEvents[vehicleId];

            //if the linkId is null, it means the vehicle event is pre-defined (non-vehicular event)
            if (string.IsNullOrEmpty(linkId))
            {
                linkId = vEvent.CurLinkId;
            }
            else
            {
                vEvent.PreLinkId = vEvent.CurLinkId;
                vEvent.CurLinkId = linkId;
            }

            //find out the active event on this vehicle
            foreach (Event evt in vEvent.GetActiveEvent(currentTick))
            {
                //check if the event is happenning
                if (evt != null)
                {
                    ///current time.
                    Location  curLocation = null;
                    CellTower curCell     = null;
                    Location  preLocation = null;
                    CellTower preCell     = null;
                    curLocation = cellularNetwork.FindLocationByLinkId(vEvent.CurLinkId);
                    curCell     = cellularNetwork.FindCellTowerByLinkId(vEvent.CurLinkId);

                    preLocation = cellularNetwork.FindLocationByLinkId(vEvent.PreLinkId);
                    preCell     = cellularNetwork.FindCellTowerByLinkId(vEvent.PreLinkId);

                    switch (evt.EventType)
                    {
                    case EventType.OnCall:
                        //for any oncall events, just return the location
                        if (curCell != null && preCell != null && !curCell.Equals(preCell))
                        {
                            yield return(new CellularTowerEvent(vehicleId, curLocation.LocationId, curCell.CellTowerId, preLocation?.LocationId, preCell?.CellTowerId, evt, currentTick));
                        }
                        break;

                    case EventType.PowerOn:
                        if (curLocation != null && curCell != null &&
                            preLocation != null && preCell != null &&
                            !curCell.Equals(preCell))
                        {
                            //for now just use vechileId to represnet IMSI
                            yield return(new CellularTowerEvent(vehicleId, curLocation.LocationId, curCell.CellTowerId, preLocation.LocationId, preCell.CellTowerId, evt, currentTick));
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            yield return(null);
        }
        /// <summary>
        /// Read the csv files to initialize the cellular network
        /// The format of the CellLinkRelation file is as follows:
        /// LINK_ID,CELLID,LAC
        /// </summary>
        /// <param name="networkFilePath">csv file of the cellular network definition</param>
        /// <param name="delimiter">delimiter</param>
        public void LoadFromFile(string networkFilePath, char delimiter)
        {
            //read the cell-location relation file
            using (StreamReader cellLinkReader = new StreamReader(File.OpenRead(networkFilePath)))
            {
                //skip the header line
                string line = cellLinkReader.ReadLine();

                //read the rest of the file
                while ((line = cellLinkReader.ReadLine()) != null)
                {
                    string[] values = line.Split(delimiter);

                    string   locationId = values[2];
                    string   cellId     = values[1];
                    string   linkId     = values[0];
                    Location location;

                    if (!this.ContainsLocation(locationId))
                    {
                        location = new Location(locationId);
                        //if the Location is new location, then the cell must be new cell
                        CellTower cell = new CellTower();
                        cell.CellTowerId = cellId;
                        //if the cell is a new cell, then the link must be a new link
                        cell.Links.Add(linkId);

                        location.AddCellTower(cell);
                        //add the location to the cellular network
                        this.AddLocation(location);
                    }
                    else
                    {
                        //if this location pre exists
                        location = this.GetLocation(locationId);
                        //check if the cell also exists
                        if (location.ContainsCell(cellId))
                        {
                            //if cell exists
                            CellTower cell = location.GetCell(cellId);

                            //check if link exists, most likely it doesn't exist otherwise the file is corrupted
                            if (cell.Links.Contains(linkId))
                            {
                                throw new Exception("the link is already exists");
                            }

                            cell.AddLink(linkId);
                        }
                        else //if cell doesn't pre exist
                        {
                            CellTower cell = new CellTower(cellId);
                            cell.AddLink(linkId);
                        }
                    }
                }
            }
        }
        public void Run()
        {
            Vissim vissim = new Vissim();
            ///Load Vissim net work
            VissimSimulator.LoadNet(@"C:\Users\Public\Documents\PTV Vision\PTV Vissim 6\Examples Demo\Urban Intersection Beijing.CN\Intersection Beijing.inpx");
            ///Read table contains Cellular tower information and correspoing link information
            var cellTowerInformation = new StreamReader(File.OpenRead(@"C:\test.csv"));
            CellularTowerEvent cte = new CellularTowerEvent();
            while (!cellTowerInformation.EndOfStream)
            {
                var line = cellTowerInformation.ReadLine();
                var values = line.Split(';');

                cte.CellularTowerId = CellTower.AddLink(Int32.Parse(values[0]));
                cte.LocationId = Location.AddCellTower(Int32.Parse(values[1]));
            }
            ///Generate the random event, when vehicle passing a fixed location and the Timespan is satisfied.
            foreach (IVehicle vehicle in vissim.Net.Vehicles)
            {
                ///Select Random Vehicle
                int vehiclePossible = rnd.Next(0, 10);
                //Only Selected Vehicle can generate the Event.
                if (vehiclePossible == 0)
                {
                    Event evet = new Event();
                    ///Create random event type.
                    int i = rnd.Next(0, 1);
                    evet.TimeSpan = EventFactory.CreateTimeSpan();
                    evet.EventType = EventFactory.CreateEventType;
                    cte.Event = evet;
                }
                ///record the event information 
                CollectorWorker collect = new CollectorWorker();
                if (vehicle.Location == cte.CellTowerId & cte.Event.TimeSpan == simulationTime)
                {
                    collect.ProcessEvent(cte);
                }
            ///Make the program check the all vehicle in Vissim network every 1 sec.
            for (int i = 0; i < simulationTime; i++)
            {
                vissim.Simulation.RunSingleStep();
                foreach (CollectorWorker worker in CollectorWorkers)
                {
                    Task workerTask = Task.Run(() =>
                    {
                        worker.ProcessEvent(CellularTowerEvents);
                    });

                    workerTask.Wait();
                }
            }
        }
Esempio n. 4
0
        private CellularTowerEvent DetectEvent(string vehicleId, string linkId, long currentTick)
        {
            VehicleEvent vEvent = vehicleEvents[vehicleId];

            //find out the active event on this vehicle
            Event evt = vEvent.GetActiveEvent(currentTick);

            //check if the event is happenning
            if (evt != null)
            {
                ///current time.
                Location  curlocation = null;
                CellTower curCell     = null;
                switch (evt.EventType)
                {
                case EventType.PowerOn:     //this is a LU event
                    curlocation = cellularNetwork.FindLocationByLinkId(linkId);
                    curCell     = cellularNetwork.FindCellTowerByLinkId(linkId);
                    if (curlocation != null && curCell != null)
                    {
                        //for now just use vechileId to represnet IMSI
                        return(new CellularTowerEvent(vehicleId, curlocation.LocationId, curCell.CellTowerId, evt, currentTick));
                    }
                    break;

                case EventType.OnCall:     //this is a hand-off event
                    curlocation = cellularNetwork.FindLocationByLinkId(linkId);
                    curCell     = cellularNetwork.FindCellTowerByLinkId(linkId);
                    if (curlocation != null && curCell != null)
                    {
                        //for now just use vechileId to represnet IMSI
                        return(new CellularTowerEvent(vehicleId, curlocation.LocationId, curCell.CellTowerId, evt, currentTick));
                    }
                    break;

                default:
                    break;
                }
            }
            return(null);
        }
Esempio n. 5
0
 /// <summary>
 /// Add a cell tower to the location
 /// </summary>
 /// <param name="tower">CellTower</param>
 public void AddCellTower(CellTower tower)
 {
     cellTowers.Add(tower.CellTowerId, tower);
 }
Esempio n. 6
0
        public override bool Equals(object obj)
        {
            CellTower cell = obj as CellTower;

            return(this.CellTowerId.Equals(cell.CellTowerId));
        }
Esempio n. 7
0
 /// <summary>
 /// Add a cell tower to the location
 /// </summary>
 /// <param name="tower">CellTower</param>
 public void AddCellTower(CellTower cell)
 {
     cellTowers.Add(cell.CellTowerId, cell);
 }