Exemplo n.º 1
0
        /// <summary>
        /// Removes witnessed shortcuts.
        /// </summary>
        /// <param name="shortcuts"></param>
        /// <param name="witnesses"></param>
        /// <returns></returns>
        public static bool RemoveWitnessed <T>(this Shortcuts <T> shortcuts, WeightHandler <T> weightHandler, Dictionary <OriginalEdge, T> witnesses)
            where T : struct
        {
            bool witnessed = false;

            foreach (var witness in witnesses)
            {
                var edge = witness.Key;
                if (shortcuts.TryGetValue(edge, out Shortcut <T> shortcut))
                {
                    if (weightHandler.IsSmallerThan(witness.Value, shortcut.Forward))
                    {
                        shortcut.Forward = witness.Value;
                        shortcuts.AddOrUpdate(edge, shortcut, weightHandler);
                        witnessed = true;
                    }
                }
                // TODO: this should be 'else', in theory this extra check isn't needed.
                edge = edge.Reverse();
                if (shortcuts.TryGetValue(edge, out shortcut))
                {
                    if (weightHandler.IsSmallerThan(witness.Value, shortcut.Backward))
                    {
                        shortcut.Backward = witness.Value;
                        shortcuts.AddOrUpdate(edge, shortcut, weightHandler);
                        witnessed = true;
                    }
                }
            }
            return(witnessed);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Removes witnessed shortcuts.
 /// </summary>
 /// <param name="shortcuts"></param>
 /// <param name="witnesses"></param>
 /// <returns></returns>
 public static bool RemoveWitnessed <T>(this Shortcuts <T> shortcuts, WeightHandler <T> weightHandler, uint vertex, Dictionary <uint, Dictionary <OriginalEdge, T> > witnesses)
     where T : struct
 {
     if (witnesses.TryGetValue(vertex, out Dictionary <OriginalEdge, T> vertexWitnesses))
     {
         return(shortcuts.RemoveWitnessed(weightHandler, vertexWitnesses));
     }
     return(false);
 }
Exemplo n.º 3
0
 private VertexInfo(Shortcuts <T> shortcuts, int edgesCount, MetaEdge[] edges)
 {
     _shortcuts  = shortcuts;
     _edgesCount = edgesCount;
     _edges      = edges;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new vertex info object.
 /// </summary>
 public VertexInfo()
 {
     _shortcuts = new Shortcuts <T>();
     _edges     = new MetaEdge[64];
 }