| | | 1 | | using System; |
| | | 2 | | using System.Collections; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Linq; |
| | | 5 | | |
| | | 6 | | namespace Itinero.Network.Tiles.Standalone.Global; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// A global restriction. |
| | | 10 | | /// |
| | | 11 | | /// This contains: |
| | | 12 | | /// - The sequence of edges that incurs the cost. |
| | | 13 | | /// - A prohibitory flag: |
| | | 14 | | /// - true : only this specific turn with the prefix edges is forbidden, |
| | | 15 | | /// - false: only this turn is allowed, all other turns at the vertex are forbidden. |
| | | 16 | | /// |
| | | 17 | | /// Assumptions: |
| | | 18 | | /// - The restriction occurs at the vertex between the last two edges in the sequence. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <remarks> |
| | | 21 | | /// Why model restrictions like this: |
| | | 22 | | /// We do not know the full structure of the network at the time this is defined only the part within the tile. |
| | | 23 | | /// </remarks> |
| | | 24 | | public class GlobalRestriction : IReadOnlyList<GlobalEdgeId> |
| | | 25 | | { |
| | | 26 | | private readonly IReadOnlyList<GlobalEdgeId> _edges; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Creates a new network restriction. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="sequence">The sequence that is either prohibited or mandatory.</param> |
| | | 32 | | /// <param name="isProhibitory">Flag to set the restriction to prohibited or mandatory.</param> |
| | | 33 | | /// <param name="attributes">The attributes.</param> |
| | 4763 | 34 | | public GlobalRestriction(IEnumerable<GlobalEdgeId> sequence, bool isProhibitory, |
| | 4763 | 35 | | IEnumerable<(string key, string value)> attributes) |
| | 4763 | 36 | | { |
| | 4763 | 37 | | _edges = sequence.ToList(); |
| | 4763 | 38 | | if (_edges.Count < 2) throw new ArgumentException("A restriction has to have at least 2 edges"); |
| | | 39 | | |
| | 4763 | 40 | | this.IsProhibitory = isProhibitory; |
| | 4763 | 41 | | this.Attributes = attributes; |
| | 4763 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Returns true if the restriction is negative. |
| | | 46 | | /// </summary> |
| | 1034 | 47 | | public bool IsProhibitory { get; } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// The attributes associated with the restriction. |
| | | 51 | | /// </summary> |
| | 1032 | 52 | | public IEnumerable<(string key, string value)> Attributes { get; } |
| | | 53 | | |
| | | 54 | | public IEnumerator<GlobalEdgeId> GetEnumerator() |
| | 4752 | 55 | | { |
| | 4752 | 56 | | return _edges.GetEnumerator(); |
| | 4752 | 57 | | } |
| | | 58 | | |
| | | 59 | | IEnumerator IEnumerable.GetEnumerator() |
| | 0 | 60 | | { |
| | 0 | 61 | | return ((IEnumerable)_edges).GetEnumerator(); |
| | 0 | 62 | | } |
| | | 63 | | |
| | 3 | 64 | | public int Count => _edges.Count; |
| | | 65 | | |
| | 21 | 66 | | public GlobalEdgeId this[int index] => _edges[index]; |
| | | 67 | | } |