示例#1
0
        /// <summary>
        /// This is the main method of the CollectorWork's business logic.
        /// It should at least do something like:
        /// 1. Persist the event into either file or DB
        /// 2. Do some aggregation that might be helpful for the research
        /// </summary>
        /// <param name="evt"></param>
        public void Process(CellularTowerEvent evt)
        {
            string eventType     = Convert.ToString(evt.Event.EventType);
            long   eventTimeSpan = evt.CurrentTick;

            AddEvent(evt.IMSI, evt.LocationId, evt.CellularTowerId, eventType, eventTimeSpan);
        }
示例#2
0
        /// <summary>
        /// This is the main method of the CollectorWork's business logic.
        /// It should at least do something like:
        /// 1. Persist the event into either file or DB
        /// 2. Do some aggregation that might be helpful for the research
        /// </summary>
        /// <param name="evt"></param>
        public void Process(StreamWriter writer, CellularTowerEvent evt)
        {
            string eventType     = Convert.ToString(evt.Event.EventType);
            long   eventTimeSpan = evt.CurrentTick;

            AddEvent(writer, evt.IMSI, evt.CurLocationId, evt.CurCellularTowerId, evt.PreLocationId, evt.PreCellularTowerId, eventType, eventTimeSpan);
        }
 public void ProcessEvent(ConcurrentQueue<CellularTowerEvent> cellularTowerEvents)
 {
     CellularTowerEvent evt = null;
     if (cellularTowerEvents.TryDequeue(out evt))
     {
         process(evt);
     }
 }
        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();
                }
            }
        }
示例#5
0
 private void GenerateCellularStaticEvents()
 {
     while (!token.IsCancellationRequested)
     {
         foreach (Location lo in cellularNetwork.Locations)
         {
             foreach (CellTower cl in lo.Cells)
             {
                 //20% of the cells will have random non-vehicular events
                 //always assume each cell has 5000 cell phone users
                 for (int i = 0; i < 5000; i++)
                 {
                     //generate the events on cl level
                     Random rnd = new Random();
                     //get a random number
                     int cellRandN = rnd.Next(0, 10);
                     if (cellRandN <= 2)
                     {
                         //let's say 50% of them are power on events
                         Event evt = null;
                         if (rnd.Next(0, 10) <= 5)
                         {
                             evt = new Event(EventType.PowerOn);
                         }
                         else
                         {
                             evt = new Event(EventType.OnCall);
                         }
                         CellularTowerEvent cte = new CellularTowerEvent("-" + i.ToString(), lo.LocationId, cl.CellTowerId, lo.LocationId, cl.CellTowerId, evt, currentTick);
                         cellularTowerEvents.Add(cte);
                     }
                 }
             }
         }
     }
 }
        private void process(CellularTowerEvent evt)
        {


        }
示例#7
0
        /// <summary>
        /// This method attempts to create the OUTPUT QRACLE table.
        /// If will do nothing but print an error if the table already exists.
        /// </summary>
        //public void TryCreateTbale()
        //{

        //    using (SqlConnection con = new SqlConnection())
        //    {
        //        con.ConnectionString = ConfigurationManager.AppSettings["SqlConnectionString"];
        //        con.Open();
        //        try
        //        {
        //            using (SqlCommand command = new SqlCommand(
        //                "CREATE TBALE OUTPUT1(LocationId INT, CellularTowerId INT, EventType TEXT, EventTimeSpan TEXT)", con))
        //            {
        //                command.ExecuteNonQuery();
        //            }
        //        }
        //        catch
        //        {
        //            Console.WriteLine("Table already exists, or something wrong with the connection");
        //        }
        //    }
        //}

        public void Run()
        {
            vissim = new Vissim();
            ///Load Vissim net work
            vissim.LoadNet(VissimSimulatorFilePath, false);

            //initialize the cellular network
            cellularNetwork.LoadFromFile(CellLinkRelationFilePath, Delimiter);
            ///initialize the table
            //TryCreateTbale();
            //set up the collector threads. For now, only need one thread on this
            //for now, we only need 1 worker to collect the event

            using (StreamWriter writer = new StreamWriter(VissimEventsFilePath))
            {
                CollectorWorker worker        = new CollectorWorker(writer);
                Task            collectorTask = Task.Factory.StartNew(() =>
                {
                    foreach (CellularTowerEvent cEvent in cellularTowerEvents.GetConsumingEnumerable())
                    {
                        worker.Process(cEvent);
                    }
                });

                //simulation thread: including vissim simulation, events generation and detection
                Task simulator = Task.Factory.StartNew(() =>
                {
                    for (int currentTick = 0; currentTick < SimulationTicks; currentTick++)
                    {
                        foreach (IVehicle vehicle in vissim.Net.Vehicles)
                        {
                            //get the vehicle id+
                            int vehicleId = (int)vehicle.AttValue["No"];
                            //get the current vehicle link
                            ILane lane    = vehicle.Lane;
                            string linkId = lane.AttValue["Link"];
                            //Console.WriteLine(string.Format("vehicle {0} at link {1}", vehicleId, linkId));
                            //first check if this vehicle has event
                            if (vehicleEvents.ContainsKey(vehicleId.ToString()))
                            {
                                CellularTowerEvent cEvent = DetectEvent(vehicleId.ToString(), linkId, currentTick);
                                if (cEvent != null)
                                {
                                    cellularTowerEvents.Add(cEvent);
                                }
                            }
                            else //if no vehicle event, that means this is new vehicle entering the vissim network
                            {
                                GenerateEvent(vehicleId.ToString(), currentTick);
                            }
                        }
                        //make the Vissim simulation move forward one tick
                        vissim.Simulation.RunSingleStep();
                    }
                });
                try
                {
                    Task.WaitAll(simulator, collectorTask);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format("there are some exceptions happened: {0}", ex.Message));
                    throw ex;
                }
            }
        }