Exemplo n.º 1
0
        private static SkimValue GetValue(int origin, int destination, RosterEntry entry, int minute)
        {
            if (entry.Name == null)
            {
                return(new SkimValue());
            }

            SkimMatrix skimMatrix = _skimMatrices[entry.MatrixIndex];

            if (skimMatrix.IsEmpty())
            {
                return(new SkimValue {
                    Variable = 0, BlendVariable = 0
                });
            }
            if (skimMatrix == null)
            {
                throw new SkimMatrixNotFoundException(string.Format("There is not a skim matrix defined for the combination of variable: {0}, mode: {1}, path type: {2}, and minute: {3}. Please adjust the roster accordingly.", entry.Variable, entry.Mode, entry.PathType, minute));
            }

            SkimValue skimValue = new SkimValue {
                Variable = entry.Transpose ? skimMatrix.GetValue(destination, origin) : skimMatrix.GetValue(origin, destination)
            };

            skimValue.Variable = skimValue.Variable / entry.Scaling;

            skimValue.Variable = skimValue.Variable * entry.Factor;

            return(skimValue);
        }
Exemplo n.º 2
0
        public virtual void LoadSkimMatrices(IEnumerable <RosterEntry> entries, Dictionary <int, int> zoneMapping, Dictionary <int, int> transitStopAreaMapping, Dictionary <int, int> microzoneMapping)
        {
            SkimMatrices = new SkimMatrix[MatrixKeys.Length];

            //            var cache = new Dictionary<string, List<float[]>>();
            Dictionary <string, List <double[]> > cache = new Dictionary <string, List <double[]> >(); // 20150703 JLB

            string currentFileName = "";

            foreach (var entry in entries.Where(x => x.FileType != null).Select(x => new { x.Name, x.Field, x.FileType, x.MatrixIndex, x.Scaling, x.Length }).Distinct().OrderBy(x => x.Name))
            {
                ISkimFileReader skimFileReader = null;

                //Issue #40 -- caching is to prevent same file from being read in multiple times. Can clear cache when we change files since group by name
                if (!entry.Name.Equals(currentFileName))
                {
                    cache.Clear();
                    currentFileName = entry.Name;
                }
                IFileReaderCreator creator = Global.ContainerDaySim.GetInstance <SkimFileReaderFactory>().GetFileReaderCreator(entry.FileType);

                /*switch (entry.FileType) {
                 *  case "text_ij":
                 *      skimFileReader = new TextIJSkimFileReader(cache, _path, mapping);
                 *      break;
                 *  case "bin":
                 *      skimFileReader = new BinarySkimFileReader(_path, mapping);
                 *      break;
                 * }*/

                if (creator == null)
                {
                    if (entry.FileType == "deferred")
                    {
                        continue;
                    }

                    throw new SkimFileTypeNotSupportedException(string.Format("The specified skim file type of \"{0}\" is not supported.", entry.FileType));
                }
                Dictionary <int, int> mapping = zoneMapping;

                bool useTransitStopAreaMapping = (entry.Length == "transitstop");
                if (useTransitStopAreaMapping)
                {
                    mapping = transitStopAreaMapping;
                }

                bool useMicrozoneMapping = (entry.Length == "microzone");
                if (useMicrozoneMapping)
                {
                    mapping = microzoneMapping;
                }

                skimFileReader = creator.CreateReader(cache, _path, mapping);

                float      scaleFactor = (float)entry.Scaling;
                SkimMatrix skimMatrix  = skimFileReader.Read(entry.Name, entry.Field, scaleFactor);

                SkimMatrices[entry.MatrixIndex] = skimMatrix;

                //new code - report a summary of the skim matrix data
                int    numZones    = mapping.Count;
                int    numPositive = 0;
                double avgPositive = 0;
                for (int row = 0; row < numZones; row++)
                {
                    for (int col = 0; col < numZones; col++)
                    {
                        ushort value = skimMatrix.GetValue(row, col);
                        if (value > Constants.EPSILON)
                        {
                            numPositive++;
                            avgPositive += value / scaleFactor;
                        }
                    }
                }
                double pctPositive = Math.Round(numPositive * 100.0 / (numZones * numZones));
                double avgValue    = avgPositive / Math.Max(numPositive, 1);
                Global.PrintFile.WriteLine("Skim File {0}, {1} percent of values are positive, with average value {2}.", entry.Name, pctPositive, avgValue);
            }

            foreach (
                var entry in
                entries.Where(x => x.FileType == null)
                .Select(x => new { x.Name, x.Field, x.FileType, x.MatrixIndex, x.Scaling, x.Length })
                .Distinct()
                .OrderBy(x => x.Name))
            {
                SkimMatrix skimMatrix = new SkimMatrix(null);
                SkimMatrices[entry.MatrixIndex] = skimMatrix;
            }
        }