Beispiel #1
0
        public void CalculateShortestPathIntegrationTest()
        {
            Assert.Inconclusive("TODO.");

            IRead       target              = CreateIRead();            // TODO: Initialize to an appropriate value
            List <Path> result              = null;                     // TODO: Initialize to an appropriate value
            List <Path> resultExpected      = null;                     // TODO: Initialize to an appropriate value
            string      algorithmname       = string.Empty;             // TODO: Initialize to an appropriate value
            int         sourceVertexId      = 0;                        // TODO: Initialize to an appropriate value
            int         destinationVertexId = 0;                        // TODO: Initialize to an appropriate value
            int         maxDepth            = 0;                        // TODO: Initialize to an appropriate value
            double      maxPathWeight       = 0F;                       // TODO: Initialize to an appropriate value
            int         maxResults          = 0;                        // TODO: Initialize to an appropriate value

            PathDelegates.EdgePropertyFilter edgePropertyFilter = null; // TODO: Initialize to an appropriate value
            PathDelegates.VertexFilter       vertexFilter       = null; // TODO: Initialize to an appropriate value
            PathDelegates.EdgeFilter         edgeFilter         = null; // TODO: Initialize to an appropriate value
            PathDelegates.EdgeCost           edgeCost           = null; // TODO: Initialize to an appropriate value
            PathDelegates.VertexCost         vertexCost         = null; // TODO: Initialize to an appropriate value
            bool expected = false;                                      // TODO: Initialize to an appropriate value
            bool actual;

            actual = target.CalculateShortestPath(out result, algorithmname, sourceVertexId, destinationVertexId, maxDepth, maxPathWeight, maxResults, edgePropertyFilter, vertexFilter, edgeFilter, edgeCost, vertexCost);
            Assert.AreEqual(resultExpected, result);
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void CalculateWeightUnitTest()
        {
            Assert.Inconclusive("TODO");

            PathElement pathElement = null;                  // TODO: Initialize to an appropriate value
            var         target      = new Path(pathElement); // TODO: Initialize to an appropriate value

            PathDelegates.VertexCost vertexCost = null;      // TODO: Initialize to an appropriate value
            PathDelegates.EdgeCost   edgeCost   = null;      // TODO: Initialize to an appropriate value
            target.CalculateWeight(vertexCost, edgeCost);
        }
Beispiel #3
0
        /// <summary>
        ///   Calculates the weight of this path element
        /// </summary>
        /// <param name="vertexCost"> The vertex cost delegate. </param>
        /// <param name="edgeCost"> The edge cost delegate </param>
        public virtual void CalculateWeight(PathDelegates.VertexCost vertexCost, PathDelegates.EdgeCost edgeCost)
        {
            Weight = 0;

            if (vertexCost != null)
            {
                Weight = vertexCost(TargetVertex);
            }

            if (edgeCost != null)
            {
                Weight += edgeCost(Edge);
            }
        }
        public void CalculateWeightUnitTest()
        {
            Assert.Inconclusive("TODO");

            EdgeModel edge           = null;                                                     // TODO: Initialize to an appropriate value
            ushort    edgePropertyId = 0;                                                        // TODO: Initialize to an appropriate value
            var       direction      = new Direction();                                          // TODO: Initialize to an appropriate value
            double    weight         = 0F;                                                       // TODO: Initialize to an appropriate value
            var       target         = new PathElement(edge, edgePropertyId, direction, weight); // TODO: Initialize to an appropriate value

            PathDelegates.VertexCost vertexCost = null;                                          // TODO: Initialize to an appropriate value
            PathDelegates.EdgeCost   edgeCost   = null;                                          // TODO: Initialize to an appropriate value
            target.CalculateWeight(vertexCost, edgeCost);
        }
Beispiel #5
0
        public bool CalculateShortestPath(
            out List <Path> result,
            string algorithmname,
            Int32 sourceVertexId,
            Int32 destinationVertexId,
            Int32 maxDepth       = 1,
            Double maxPathWeight = Double.MaxValue,
            Int32 maxResults     = 1,
            PathDelegates.EdgePropertyFilter edgePropertyFilter = null,
            PathDelegates.VertexFilter vertexFilter             = null,
            PathDelegates.EdgeFilter edgeFilter = null,
            PathDelegates.EdgeCost edgeCost     = null,
            PathDelegates.VertexCost vertexCost = null)
        {
            IShortestPathAlgorithm algo;

            if (PluginFactory.TryFindPlugin(out algo, algorithmname))
            {
                algo.Initialize(this, null);

                if (ReadResource())
                {
                    try
                    {
                        result = algo.Calculate(sourceVertexId, destinationVertexId, maxDepth, maxPathWeight, maxResults,
                                                edgePropertyFilter,
                                                vertexFilter, edgeFilter, edgeCost, vertexCost);

                        return(result != null && result.Count > 0);
                    }
                    finally
                    {
                        FinishReadResource();
                    }
                }

                throw new CollisionException(this);
            }

            result = null;
            return(false);
        }
Beispiel #6
0
        public void CalculateUnitTest()
        {
            Assert.Inconclusive("TODO");

            var    target              = new BidirectionalLevelSynchronousSSSP(); // TODO: Initialize to an appropriate value
            int    sourceVertexId      = 0;                                       // TODO: Initialize to an appropriate value
            int    destinationVertexId = 0;                                       // TODO: Initialize to an appropriate value
            int    maxDepth            = 0;                                       // TODO: Initialize to an appropriate value
            double maxPathWeight       = 0F;                                      // TODO: Initialize to an appropriate value
            int    maxResults          = 0;                                       // TODO: Initialize to an appropriate value

            PathDelegates.EdgePropertyFilter edgePropertyFilter = null;           // TODO: Initialize to an appropriate value
            PathDelegates.VertexFilter       vertexFilter       = null;           // TODO: Initialize to an appropriate value
            PathDelegates.EdgeFilter         edgeFilter         = null;           // TODO: Initialize to an appropriate value
            PathDelegates.EdgeCost           edgeCost           = null;           // TODO: Initialize to an appropriate value
            PathDelegates.VertexCost         vertexCost         = null;           // TODO: Initialize to an appropriate value
            List <Path> expected = null;                                          // TODO: Initialize to an appropriate value
            List <Path> actual;

            actual = target.Calculate(sourceVertexId, destinationVertexId, maxDepth, maxPathWeight, maxResults, edgePropertyFilter, vertexFilter, edgeFilter, edgeCost, vertexCost);
            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
 /// <summary>
 /// Calculates the weight.
 /// </summary>
 /// <param name='vertexCost'>
 /// Vertex cost.
 /// </param>
 /// <param name='edgeCost'>
 /// Edge cost.
 /// </param>
 public void CalculateWeight(PathDelegates.VertexCost vertexCost, PathDelegates.EdgeCost edgeCost)
 {
     _pathElements.ForEach(_ => _.CalculateWeight(vertexCost, edgeCost));
     Weight = _pathElements.Sum(_ => _.Weight);
 }
        public List <Path> Calculate(
            int sourceVertexId,
            int destinationVertexId,
            Int32 maxDepth       = 1,
            Double maxPathWeight = Double.MaxValue,
            Int32 maxResults     = 1,
            PathDelegates.EdgePropertyFilter edgePropertyFilter = null,
            PathDelegates.VertexFilter vertexFilter             = null,
            PathDelegates.EdgeFilter edgeFilter = null,
            PathDelegates.EdgeCost edgeCost     = null,
            PathDelegates.VertexCost vertexCost = null)
        {
            #region initial checks

            VertexModel sourceVertex;
            VertexModel targetVertex;
            if (!(_fallen8.TryGetVertex(out sourceVertex, sourceVertexId) &&
                  _fallen8.TryGetVertex(out targetVertex, destinationVertexId)))
            {
                return(null);
            }

            if (maxDepth == 0 || maxResults == 0 || maxResults <= 0)
            {
                return(null);
            }

            if (ReferenceEquals(sourceVertex, targetVertex))
            {
                return(null);
            }

            #endregion

            #region data

            var sourceVisitedVertices = new BigBitArray();
            sourceVisitedVertices.SetValue(sourceVertex.Id, true);

            var targetVisitedVertices = new BigBitArray();
            targetVisitedVertices.SetValue(targetVertex.Id, true);

            #endregion

            #region maxdepth = 1

            if (maxDepth == 1)
            {
                var depthOneFrontier = GetGlobalFrontier(new List <VertexModel> {
                    sourceVertex
                }, sourceVisitedVertices, edgePropertyFilter, edgeFilter, vertexFilter);
            }

            #endregion

            #region maxdepth > 1

            //find the middle element  s-->m-->t
            Int32 sourceLevel = 0;
            Int32 targetLevel = 0;

            var sourceFrontiers = new List <Dictionary <VertexModel, VertexPredecessor> >();
            var targetFrontiers = new List <Dictionary <VertexModel, VertexPredecessor> >();
            Dictionary <VertexModel, VertexPredecessor> currentSourceFrontier = null;
            Dictionary <VertexModel, VertexPredecessor> currentTargetFrontier = null;
            IEnumerable <VertexModel> currentSourceVertices = new List <VertexModel> {
                sourceVertex
            };
            IEnumerable <VertexModel> currentTargetVertices = new List <VertexModel> {
                targetVertex
            };

            List <VertexModel> middleVertices = null;

            do
            {
                #region calculate frontier

                #region source --> target

                currentSourceFrontier = GetGlobalFrontier(currentSourceVertices, sourceVisitedVertices, edgePropertyFilter, edgeFilter, vertexFilter);
                sourceFrontiers.Add(currentSourceFrontier);
                currentSourceVertices = sourceFrontiers[sourceLevel].Keys;
                sourceLevel++;

                if (currentSourceFrontier.ContainsKey(targetVertex))
                {
                    if (middleVertices == null)
                    {
                        middleVertices = new List <VertexModel> {
                            targetVertex
                        };
                    }
                    else
                    {
                        middleVertices.Add(targetVertex);
                    }
                    break;
                }
                if (FindMiddleVertices(out middleVertices, currentSourceFrontier, currentTargetFrontier))
                {
                    break;
                }
                if ((sourceLevel + targetLevel) == maxDepth)
                {
                    break;
                }

                #endregion

                #region target --> source

                currentTargetFrontier = GetGlobalFrontier(currentTargetVertices, targetVisitedVertices, edgePropertyFilter, edgeFilter, vertexFilter);
                targetFrontiers.Add(currentTargetFrontier);
                currentTargetVertices = targetFrontiers[targetLevel].Keys;
                targetLevel++;


                if (currentTargetFrontier.ContainsKey(sourceVertex))
                {
                    if (middleVertices == null)
                    {
                        middleVertices = new List <VertexModel> {
                            sourceVertex
                        };
                    }
                    else
                    {
                        middleVertices.Add(sourceVertex);
                    }
                    break;
                }
                if (FindMiddleVertices(out middleVertices, currentSourceFrontier, currentTargetFrontier))
                {
                    break;
                }
                if ((sourceLevel + targetLevel) == maxDepth)
                {
                    break;
                }

                #endregion

                #endregion
            } while (true);

            return(middleVertices != null
                ? CreatePaths(middleVertices, sourceFrontiers, targetFrontiers, maxResults, sourceLevel, targetLevel)
                : null);

            #endregion
        }