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); }
private static RosterEntry GetEntry(string variable, int variableIndex, int mode, int pathType, int votGroup, int minute) { RosterEntry entry = _rosterEntries[variableIndex][mode][pathType][votGroup][minute]; if (entry == null) { throw new RosterEntryNotFoundException(string.Format("There was not a roster entry that matched the combination of variable: {0}, mode: {1}, path type: {2}, vot group: {3}, and minute: {4}. Please adjust the roster accordingly.", variable, mode, pathType, votGroup, minute)); } return(entry); }
public static SkimValue GetValue(string variable, int mode, int pathType, double vot, int minute, int origin, int destination) { int votGroup = GetVotGroup(vot); RosterEntry entry = GetEntry(variable, mode, pathType, votGroup, minute); SkimValue skimValue = GetValue(origin, destination, entry, minute); //mb fix for 0 intrazonals if (origin == destination && skimValue.Variable < Constants.EPSILON) { if (variable == "distance") { skimValue.Variable = 0.25 * Global.Settings.DistanceUnitsPerMile; } else if (variable == "ivtime" || variable == "time" || variable == "ivtfree") { skimValue.Variable = (mode == Global.Settings.Modes.Walk) ? 5 : (mode == Global.Settings.Modes.Bike) ? 2 : (mode > Global.Settings.Modes.Bike && mode < Global.Settings.Modes.Transit) ? 1 : 0; } } if (string.IsNullOrEmpty(entry.BlendVariable)) { return(skimValue); } RosterEntry blendEntry = entry.BlendPathType == Global.Settings.PathTypes.None ? GetEntry(entry.BlendVariable, entry.Mode, entry.PathType, votGroup, minute) : GetEntry(entry.BlendVariable, entry.Mode, entry.BlendPathType, votGroup, minute); SkimValue blendSkimValue = GetValue(origin, destination, blendEntry, minute); skimValue.BlendVariable = blendSkimValue.Variable; //mb fix for 0 intrazonals. Assumes blend variable is distance if (origin == destination && skimValue.BlendVariable < Constants.EPSILON) { skimValue.BlendVariable = 0.25 * Global.Settings.DistanceUnitsPerMile; } return(skimValue); }
public static SkimValue GetValue(string variable, int mode, int pathType, double vot, int minute, IPoint origin, IPoint destination, double circuityDistance = Constants.DEFAULT_VALUE) { int votGroup = GetVotGroup(vot); RosterEntry entry = GetEntry(variable, mode, pathType, votGroup, minute); SkimValue skimValue = GetValue(origin.ZoneId, destination.ZoneId, entry, minute); //mb fix for 0 intrazonals if (Global.Configuration.DestinationScale == Global.Settings.DestinationScales.Zone && origin.ZoneId == destination.ZoneId && skimValue.Variable < Constants.EPSILON) { if (variable == "distance") { skimValue.Variable = 0.25 * Global.Settings.DistanceUnitsPerMile; } else if (variable == "ivtime" || variable == "time" || variable == "ivtfree") { skimValue.Variable = (mode == Global.Settings.Modes.Walk) ? 5 : (mode == Global.Settings.Modes.Bike) ? 2 : (mode > Global.Settings.Modes.Bike && mode < Global.Settings.Modes.Transit) ? 1 : 0; } } if (string.IsNullOrEmpty(entry.BlendVariable)) { return(skimValue); } RosterEntry blendEntry = entry.BlendPathType == Global.Settings.PathTypes.None ? GetEntry(entry.BlendVariable, entry.Mode, entry.PathType, votGroup, minute) : GetEntry(entry.BlendVariable, entry.Mode, entry.BlendPathType, votGroup, minute); SkimValue blendSkimValue = GetValue(origin.ZoneId, destination.ZoneId, blendEntry, minute); if (Global.Configuration.DestinationScale == Global.Settings.DestinationScales.Zone) { //skimValue.BlendVariable = blendSkimValue.BlendVariable; skimValue.BlendVariable = blendSkimValue.Variable; //JLB replaced above line 20130628 //mb fix for 0 intrazonals. Assumes blend variable is distance if (origin.ZoneId == destination.ZoneId && skimValue.BlendVariable < Constants.EPSILON) { skimValue.BlendVariable = 0.25 * Global.Settings.DistanceUnitsPerMile; } return(skimValue); } double networkDistance = blendSkimValue.Variable; double networkFraction = networkDistance / Global.Configuration.MaximumBlendingDistance; if (networkFraction > 1) { networkFraction = 1; } //intrazonals - use network fraction = 0, so blend distance is XY distance if (origin.ZoneId == destination.ZoneId) { networkFraction = 0; } double xyDistance; if (networkFraction >= 1) { // no blending xyDistance = networkDistance; } else if (circuityDistance > Constants.DEFAULT_VALUE + Constants.EPSILON) { // blending with circuity value //Global.PrintFile.WriteLine("Distances: Network {0} Circuity {1} Orthogonal {2}", networkDistance, circuityDistance, // (Math.Abs(origin.XCoordinate - destination.XCoordinate) + Math.Abs(origin.YCoordinate - destination.YCoordinate)) / 5280D); xyDistance = circuityDistance; } else { if (Global.Configuration.DataType == "Actum") { xyDistance = (Math.Abs(origin.XCoordinate - destination.XCoordinate) + Math.Abs(origin.YCoordinate - destination.YCoordinate)) / 5280D; } else { // default is orthogonal distance, with a miniumum of 300 feet for intra-microzone xyDistance = Math.Max(300D, (Math.Abs(origin.XCoordinate - destination.XCoordinate) + Math.Abs(origin.YCoordinate - destination.YCoordinate))) / 5280D; } } if (networkDistance >= Constants.EPSILON && xyDistance >= Constants.EPSILON) { skimValue.BlendVariable = networkFraction * networkDistance + (1 - networkFraction) * xyDistance; } else if (xyDistance >= Constants.EPSILON) { skimValue.BlendVariable = xyDistance; } else if (networkDistance >= Constants.EPSILON) { skimValue.BlendVariable = networkDistance; } else { skimValue.BlendVariable = 0; } if (!skimValue.BlendVariable.AlmostEquals(Constants.DEFAULT_VALUE)) { //new code for intrazonals allows overriding use of speed from skims if (Global.Configuration.DataType != "Actum" && (origin.ZoneId == destination.ZoneId)) { double minutesPerMile = (mode == Global.Settings.Modes.Walk && Global.Configuration.IntrazonalWalkMinutesPerMile_OverrideSkims > Constants.EPSILON) ? Global.Configuration.IntrazonalWalkMinutesPerMile_OverrideSkims : (mode == Global.Settings.Modes.Bike && Global.Configuration.IntrazonalBikeMinutesPerMile_OverrideSkims > Constants.EPSILON) ? Global.Configuration.IntrazonalBikeMinutesPerMile_OverrideSkims : (mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3 && Global.Configuration.IntrazonalAutoMinutesPerMile_OverrideSkims > Constants.EPSILON) ? Global.Configuration.IntrazonalAutoMinutesPerMile_OverrideSkims : networkDistance >= Constants.EPSILON ? skimValue.Variable / networkDistance : mode == Global.Settings.Modes.Walk ? 20.0 : mode == Global.Settings.Modes.Bike ? 6.0 : 3.0; skimValue.Variable = skimValue.BlendVariable * minutesPerMile; } else if (networkDistance >= Constants.EPSILON) { double minutesPerMile = skimValue.Variable / networkDistance; skimValue.Variable = skimValue.BlendVariable * minutesPerMile; } else // if networkDistance is 0 or tiny, cannot use pivot method, multiply blend distance by default speed depending on mode // TODO: Make these constants for minutesPerMile configurable. { double minutesPerMile = entry.Mode == Global.Settings.Modes.Walk ? 20.0 : entry.Mode == Global.Settings.Modes.Bike ? 6.0 : 3.0; skimValue.Variable = skimValue.BlendVariable * minutesPerMile; } } 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.RosterModes][][][]; // Initialize the mode array for (var mode = Global.Settings.Modes.Walk; mode < Global.Settings.Modes.RosterModes; 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 CountingReader(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); }