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

            var 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));
            }

            var 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);
        }
        public virtual void ProcessEntries(IEnumerable <RosterEntry> entries)
        {
            VariableKeys = entries.Select(x => x.Variable.GetHashCode()).Distinct().OrderBy(x => x).ToArray();
            MatrixKeys   = entries.Select(x => x.MatrixKey).Distinct().OrderBy(x => x).ToArray();

            foreach (var entry in entries)
            {
                entry.VariableIndex = GetVariableIndex(entry.Variable);
                entry.MatrixIndex   = MatrixKeys.GetIndex(entry.MatrixKey);
            }

            RosterEntries = new RosterEntry[VariableKeys.Length][][][][];

            for (var variableIndex = 0; variableIndex < VariableKeys.Length; variableIndex++)
            {
                RosterEntries[variableIndex] = new RosterEntry[Global.Settings.Modes.TotalModes][][][];                 // Initialize the mode array

                for (var mode = Global.Settings.Modes.Walk; mode < Global.Settings.Modes.TotalModes; mode++)
                {
                    RosterEntries[variableIndex][mode] = new RosterEntry[Global.Settings.PathTypes.TotalPathTypes][][];                     // Initialize the path type array

                    for (var pathType = Global.Settings.PathTypes.FullNetwork; pathType < Global.Settings.PathTypes.TotalPathTypes; pathType++)
                    {
                        RosterEntries[variableIndex][mode][pathType] = new RosterEntry[Global.Settings.VotGroups.TotalVotGroups][];                         // Initialize the vot groups

                        for (var votGroup = Global.Settings.VotGroups.VeryLow; votGroup < Global.Settings.VotGroups.TotalVotGroups; votGroup++)
                        {
                            RosterEntries[variableIndex][mode][pathType][votGroup] = new RosterEntry[Global.Settings.Times.MinutesInADay + 1];                             // Initialize the minute array
                        }
                    }
                }
            }

            foreach (var entry in entries)
            {
                var startMinute = entry.StartMinute;
                var endMinute   = entry.EndMinute;

                // if roster entry for vot group is any or all or default, apply it to all vot groups
                var lowestVotGroup  = entry.VotGroup == Global.Settings.VotGroups.Default ? Global.Settings.VotGroups.VeryLow : entry.VotGroup;
                var highestVotGroup = entry.VotGroup == Global.Settings.VotGroups.Default ? Global.Settings.VotGroups.VeryHigh : entry.VotGroup;

                for (var votGroup = lowestVotGroup; votGroup <= highestVotGroup; votGroup++)
                {
                    if (startMinute > endMinute)
                    {
                        for (var minute = 1; minute <= endMinute; minute++)
                        {
                            RosterEntries[entry.VariableIndex][entry.Mode][entry.PathType][votGroup][minute] = entry;
                        }

                        for (var minute = startMinute; minute <= Global.Settings.Times.MinutesInADay; minute++)
                        {
                            RosterEntries[entry.VariableIndex][entry.Mode][entry.PathType][votGroup][minute] = entry;
                        }
                    }
                    else
                    {
                        for (var minute = startMinute; minute <= endMinute; minute++)
                        {
                            RosterEntries[entry.VariableIndex][entry.Mode][entry.PathType][votGroup][minute] = entry;
                        }
                    }
                }
            }

            VotRanges = ImpedanceRoster.GetVotRanges();
        }
        public virtual IEnumerable <RosterEntry> LoadRoster(string filename, bool checkCombination = true)
        {
            var file = filename.ToFile();

            Global.PrintFile.WriteFileInfo(file, true);

            _path = file.DirectoryName;

            var entries = new List <RosterEntry>();

            using (var reader = new StreamReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))) {
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    var tokens = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => t.Trim()).ToArray();

                    if (tokens.Length == 0)
                    {
                        continue;
                    }

                    var entry = new RosterEntry
                    {
                        Variable      = tokens[0].Clean(),
                        Mode          = tokens[1].ToMode(),
                        PathType      = tokens[2].ToPathType(),
                        VotGroup      = tokens[3].ToVotGroup(),
                        StartMinute   = int.Parse(tokens[4]).ToMinutesAfter3AM(),
                        EndMinute     = int.Parse(tokens[5]).ToMinutesAfter3AM(),
                        Length        = tokens[6].Clean(),
                        FileType      = tokens[7].Clean(),
                        Name          = tokens[8],
                        Field         = int.Parse(tokens[9]),
                        Transpose     = bool.Parse(tokens[10]),
                        BlendVariable = tokens[11].Clean(),
                        BlendPathType = tokens[12].ToPathType(),
                        Factor        = tokens[13].ToFactor(),
                        Scaling       = ParseScaling(tokens[14])
                    };

                    if (checkCombination)
                    {
                        if (!IsPossibleCombination(entry.Mode, entry.PathType))
                        {
                            throw new InvalidCombinationException(
                                      string.Format(
                                          "The combination of mode: {0} and path type: {1} is invalid. Please adjust the roster accordingly.", entry.Mode,
                                          entry.PathType));
                        }

                        ActualCombinations[entry.Mode][entry.PathType] = true;
                    }

                    entries.Add(entry);
                }
            }

            return(entries);
        }