Exemplo n.º 1
0
        public void Run()
        {
            var numberOfRegions = RegionNumbers.Count;
            var zones           = Root.ZoneSystem.ZoneArray.GetFlatData();
            var numberOfZones   = zones.Length;

            // Sum the employment and the Professional workers in each zone
            // that is not the airport per region aggregate at a regional level
            float[] employmentTotal   = new float[numberOfRegions];
            float[] professionalTotal = new float[numberOfRegions];
            float[] tripsToRegion     = new float[numberOfRegions];
            Flows = MirrorModeTree.CreateMirroredTree <float[][]>(Root.Modes);
            float[][] data = CreateData(numberOfZones);

            // Gather the information for each region
            float totalTrips = ComputeRegionInformation(numberOfRegions, zones, numberOfZones, employmentTotal, professionalTotal, tripsToRegion);

            // Now that we have the regional information we can use it to compute the primary airport
            ComputePrimaryAirport(zones, numberOfZones, employmentTotal, professionalTotal, tripsToRegion, data);
            // After computing the primary airport we can continue with the secondary airports
            ComputeSecondaryAirports(zones, numberOfZones, data, totalTrips);
            // now that we are done attach the data to our tree so that it can be read in for tallies
            AttachDataToTree(data);

            if (SaveMatrix)
            {
                SaveData(data);
            }
        }
Exemplo n.º 2
0
        public List <TreeData <float[][]> > ModeSplit(IEnumerable <SparseTwinIndex <float> > flowMatrix, int numberOfCategories)
        {
            this.Progress = 0;
            var ret   = MirrorModeTree.CreateMirroredTree <float[][]>(this.Root.Modes);
            var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
            int flows = 0;

            //double flowTotal = 0f;
            foreach (var flow in flowMatrix)
            {
                //flowTotal += SumFlow( flow );
                if (this.InteractiveUtilityTrees == null)
                {
                    TraditionalModeSplit(numberOfCategories, ret, zones, flows, flow);
                }
                else
                {
                    InteractiveModeSplit(numberOfCategories, ret, zones, flows, flow);
                    // reset ourselves out of interactive mode
                    this.EndInterativeModeSplit();
                }
                flows++;
            }
            //The ratios are too close to 1 to really justify the extra processing, and could lead to additional errors
            //Reconstitute( ret, flowTotal );
            return(ret);
        }
Exemplo n.º 3
0
        public void StartNewInteractiveModeSplit(int numberOfCategories)
        {
            var numberOfZones = this.Root.ZoneSystem.ZoneArray.GetFlatData().Length;

            this.NumberOfInteractiveCategories = numberOfCategories;
            if (this.InteractiveUtilityTrees == null)
            {
                this.InteractiveUtilityTrees = MirrorModeTree.CreateMirroredTree <float[]>(this.Root.Modes);
            }
            InitializeTree(this.InteractiveUtilityTrees, numberOfZones * numberOfZones);
        }
Exemplo n.º 4
0
 public void Run()
 {
     this.Progress = 0;
     this.Flows    = MirrorModeTree.CreateMirroredTree <float[][]>(this.Root.Modes);
     LoadFlows();
     this.Progress = 1;
     if (this.SaveModeChoiceOutput)
     {
         if (!Directory.Exists(this.PurposeName))
         {
             Directory.CreateDirectory(this.PurposeName);
         }
         for (int i = 0; i < this.Flows.Count; i++)
         {
             this.WriteModeSplit(this.Flows[i], this.Root.Modes[i], this.PurposeName);
         }
     }
 }
Exemplo n.º 5
0
 public void Run()
 {
     Progress = 0;
     Flows    = MirrorModeTree.CreateMirroredTree <float[][]>(Root.Modes);
     LoadFlows();
     Progress = 1;
     if (SaveModeChoiceOutput)
     {
         if (!Directory.Exists(PurposeName))
         {
             Directory.CreateDirectory(PurposeName);
         }
         for (int i = 0; i < Flows.Count; i++)
         {
             WriteModeSplit(Flows[i], Root.Modes[i], PurposeName);
         }
     }
 }
Exemplo n.º 6
0
 public override void Run()
 {
     // We only need to run in the first iteration
     if (Root.CurrentIteration == 0)
     {
         Flows = MirrorModeTree.CreateMirroredTree <float[][]>(Root.Modes);
         // Gather the data, process, then unload the data
         ExternalBaseYearDistribution.LoadData();
         ExternalBaseYearPopulation.LoadData();
         ExternalBaseYearEmployment.LoadData();
         var distribution = ExternalBaseYearDistribution.GiveData();
         var population   = ExternalBaseYearPopulation.GiveData();
         var employment   = ExternalBaseYearEmployment.GiveData();
         ProcessExternalModel(distribution, population, employment);
         ExternalBaseYearDistribution.UnloadData();
         ExternalBaseYearPopulation.UnloadData();
         ExternalBaseYearEmployment.UnloadData();
     }
 }
Exemplo n.º 7
0
        public List <TreeData <float[][]> > ModeSplit(IEnumerable <SparseTwinIndex <float> > flowMatrix, int numberOfCategories)
        {
            var ret          = MirrorModeTree.CreateMirroredTree <float[][]>(this.Root.Modes);
            int matrixNumber = 0;

            foreach (var matrix in flowMatrix)
            {
                var flatMatrix    = matrix.GetFlatData();
                var numberOfZones = flatMatrix.Length;
                try
                {
                    Parallel.For(0, numberOfZones, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = Environment.ProcessorCount
                    },
                                 delegate(int i)
                    {
                        var modes = this.Root.Modes;
                        for (int j = 0; j < numberOfZones; j++)
                        {
                            for (int m = ret.Count - 1; m >= 0; m--)
                            {
                                ProcessMode(ret[m], i, j, flatMatrix[i][j], modes[m], matrixNumber);
                            }
                        }
                    });
                }
                catch (AggregateException e)
                {
                    if (e.InnerException is XTMFRuntimeException)
                    {
                        throw new XTMFRuntimeException(e.InnerException.Message);
                    }
                    else
                    {
                        throw new XTMFRuntimeException(e.InnerException.Message + "\r\n" + e.InnerException.StackTrace);
                    }
                }
                matrixNumber++;
            }
            return(ret);
        }
Exemplo n.º 8
0
        private List <TreeData <float[][]> > LoadData()
        {
            var tree = MirrorModeTree.CreateMirroredTree <float[][]>(Root.Modes);

            try
            {
                BinaryHelpers.ExecuteReader(this, reader =>
                {
                    // ReSharper disable once UnusedVariable
                    foreach (var t in tree)
                    {
                        LoadData(reader);
                    }
                }, ResultCacheFile);
            }
            catch (IOException e)
            {
                throw new XTMFRuntimeException(this, e.Message);
            }
            return(tree);
        }
Exemplo n.º 9
0
 private void TraditionalModeSplit(int numberOfCategories, List <TreeData <float[][]> > ret, IZone[] zones, int flows, SparseTwinIndex <float> flow)
 {
     try
     {
         int soFar = 0;
         Parallel.For(0, zones.Length, new ParallelOptions()
         {
             MaxDegreeOfParallelism = Environment.ProcessorCount
         },
                      delegate()
         {
             return(MirrorModeTree.CreateMirroredTree <float>(this.Root.Modes));
         },
                      delegate(int o, ParallelLoopState _unused, List <TreeData <float> > utility)
         {
             var flatFlows = flow.GetFlatData();
             for (int d = 0; d < zones.Length; d++)
             {
                 var odFlow = flatFlows[o][d];
                 if (odFlow > 0)
                 {
                     GatherUtility(utility, o, d, zones);
                     ConvertToFlow(utility, zones, o, d, odFlow);
                     SaveResults(utility, ret, o, d, zones.Length);
                 }
             }
             this.Progress = ((Interlocked.Increment(ref soFar) / (float)zones.Length) / numberOfCategories) + (flows / (float)numberOfCategories);
             return(utility);
         },
                      delegate(List <TreeData <float> > _unused)
         {
             // do nothing
         });
     }
     catch (AggregateException e)
     {
         throw new XTMFRuntimeException(e.InnerException.Message + "\r\n" + e.InnerException.StackTrace);
     }
 }