예제 #1
0
        /// <summary>
        /// Adds an edge between the coordinates orig and dest
        /// to this graph.
        /// </summary>
        /// <param name="orig">the edge origin location</param>
        /// <param name="dest">the edge destination location</param>
        /// <returns>the created edge</returns>
        public virtual HalfEdge AddEdge(Coordinate orig, Coordinate dest)
        {
            int cmp = dest.CompareTo(orig);
            // ignore zero-length edges
            if (cmp == 0)
                return null;

            // Attempt to find the edge already in the graph.
            // Return it if found.
            // Otherwise, use a found edge with same origin (if any) to construct new edge. 
            HalfEdge eAdj;
            bool eAdjFound = vertexMap.TryGetValue(orig, out eAdj);
            HalfEdge eSame = null;
            if (eAdjFound)
                eSame = eAdj.Find(dest);
            if (eSame != null)
                return eSame;

            HalfEdge e = Insert(orig, dest, eAdj);
            return e;
        }
예제 #2
0
 /// <summary>
 /// Test if an the coordinates for an edge form a valid edge (with non-zero length)
 /// </summary>
 /// <param name="orig">The start coordinate</param>
 /// <param name="dest">The end coordinate</param>
 /// <returns><value>true</value> of the edge formed is valid</returns>
 public static bool IsValidEdge(Coordinate orig, Coordinate dest)
 {
     var cmp = dest.CompareTo(orig);
     return cmp != 0;
 }
        /// <summary>
        /// Adds a new entry to cache, and marks it as unsynced so that next push operation
        /// will send it to the redis server.
        /// </summary>
        /// <param name="a">First coordinate</param>
        /// <param name="b">Second coordinate</param>
        /// <param name="dt">Distance-Time pair</param>
        public void AddCachedDistanceTimeEntry(Coordinate a, Coordinate b, Pair<Int32, Int32> dt)
        {
            // sort coordinates
            if (a.CompareTo(b) > 0)
            {
                Coordinate tmp = a;
                a = b;
                b = tmp;
            }

            // create pair
            Pair<Coordinate, Coordinate> key = new Pair<Coordinate, Coordinate>(a, b);

            AddCachedDistanceTimeEntry(key, dt);
        }
        /// <summary>
        /// Checks if the specified key exists within the cache
        /// </summary>
        /// <param name="a">Coordinate A</param>
        /// <param name="b">Coordinate B</param>
        /// <returns>Boolean indicating whether the key is found</returns>
        public Boolean IsIstanceTimeEntryCached(Coordinate a, Coordinate b)
        {
            // sort coordinates
            if (a.CompareTo(b) > 0)
            {
                Coordinate tmp = a;
                a = b;
                b = tmp;
            }

            // create pair
            Pair<Coordinate, Coordinate> key = new Pair<Coordinate, Coordinate>(a, b);

            return distanceTimeCache.ContainsKey(key);
        }
        /// <summary>
        /// Gets a cached distance-time entry from cache.
        /// </summary>
        /// <param name="a">Coordinate A</param>
        /// <param name="b">Coordinate B</param>
        /// <returns>Distance-Time pair; null if operation fails</returns>
        public Pair<Int32, Int32> GetCachedDistanceTime(Coordinate a, Coordinate b)
        {
            // sort coordinates
            if (a.CompareTo(b) > 0)
            {
                Coordinate tmp = a;
                a = b;
                b = tmp;
            }

            // create pair
            Pair<Coordinate, Coordinate> key = new Pair<Coordinate, Coordinate>(a, b);

            // look for entry
            if (distanceTimeCache.ContainsKey(key))
                return distanceTimeCache[key];
            else
                return null;
        }
예제 #6
0
        public void TestCompareTo()
        {
            Coordinate lowest = new Coordinate(10.0, 100.0, 50.0);
            Coordinate highest = new Coordinate(20.0, 100.0, 50.0);
            Coordinate equalToHighest = new Coordinate(20.0, 100.0, 50.0);
            Coordinate higherStill = new Coordinate(20.0, 200.0, 50.0);

            Assert.AreEqual(-1, lowest.CompareTo(highest));
            Assert.AreEqual(1, highest.CompareTo(lowest));
            Assert.AreEqual(-1, highest.CompareTo(higherStill));
            Assert.AreEqual(0, highest.CompareTo(equalToHighest));
        }