Exemple #1
0
        //List<Task> tasks = new List<Task>();

        public void BatchRouting()
        {
            int _BatchSize = 1000;
            int _MaxCount  = context.TripData.Count();

            ThreadPool.GetMinThreads(out int _PoolSize, out int minPorts);
            ThreadPool.SetMaxThreads(_PoolSize, _PoolSize);
            int TaskCount = 0;

            int numberOfBatches = (int)((double)_MaxCount / (double)_BatchSize + 1.0f);

            Console.WriteLine("No. of Trips: {0}\t" +
                              "No. of Batchs: {1} of size {2}", _MaxCount, numberOfBatches, _BatchSize);

            Util.Progress progress = new Util.Progress(5000, _MaxCount);
            progress.Start();
            int BatchCount = 0;

            while (BatchCount < numberOfBatches)
            {
                ThreadPool.QueueUserWorkItem((obj) =>
                {
                    Batch((int)obj, _BatchSize, progress);
                }, BatchCount++);
                Thread.Sleep(500);
            }
        }
Exemple #2
0
        public void Batch(int batchIdx, int batchSize, Util.Progress progress)
        {
            int        i   = 0;
            SqlContext sql = new SqlContext();

            foreach (var trip in sql.TripData.Skip(batchIdx * batchSize).Take(batchSize))
            {
                //if (sql.TripRoute.Where(o => o.TripData.TripId == trip.TripId).Count() == 0)
                AddRouteDb(sql, router, trip, Itinero.Osm.Vehicles.Vehicle.Car.Shortest(), true);
                progress.inc();
            }
            sql.SaveChanges();
        }