/// <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(); } } }