Пример #1
0
        public List <ushort> GetAllAvailableOutEdgesOnVertex(string vertexIdentifier)
        {
            VertexModel vertex;

            return(_fallen8.TryGetVertex(out vertex, Convert.ToInt32(vertexIdentifier))
                       ? vertex.GetOutgoingEdgeIds()
                       : null);
        }
Пример #2
0
        /// <summary>
        /// Creates a scale free network
        /// </summary>
        /// <param name="nodeCound"></param>
        /// <param name="edgeCount"></param>
        /// <param name="fallen8"></param>
        public void CreateScaleFreeNetwork(int nodeCound, int edgeCount)
        {
            var creationDate = DateHelper.ConvertDateTime(DateTime.Now);
            var vertexIDs    = new List <Int32> ();
            var prng         = new Random();

            if (nodeCound < _numberOfToBeTestedVertices)
            {
                _numberOfToBeTestedVertices = nodeCound;
            }

            _toBeBenchenVertices = new List <VertexModel> (_numberOfToBeTestedVertices);

            for (var i = 0; i < nodeCound; i++)
            {
//                vertexIDs.Add(
//                    fallen8.CreateVertex(creationDate, new PropertyContainer[4]
//                                                           {
//                                                               new PropertyContainer { PropertyId = 23, Value = 4344 },
//                                                               new PropertyContainer { PropertyId = 24, Value = "Ein gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz langes Property" },
//                                                               new PropertyContainer { PropertyId = 25, Value = "Ein kurzes Property" },
//                                                               new PropertyContainer { PropertyId = 26, Value = "Ein gaaaaaaaanz langes Property" },
//                                                           }).Id);
                vertexIDs.Add(_f8.CreateVertex(creationDate).Id);
            }

            if (edgeCount != 0)
            {
                foreach (var aVertexId in vertexIDs)
                {
                    var targetVertices = new HashSet <Int32> ();

                    do
                    {
                        targetVertices.Add(vertexIDs [prng.Next(0, vertexIDs.Count)]);
                    } while (targetVertices.Count < edgeCount);

                    foreach (var aTargetVertex in targetVertices)
                    {
//                    fallen8.CreateEdge(aVertexId, 0, aTargetVertex, creationDate, new PropertyContainer[2]
//                                                           {
//                                                               new PropertyContainer { PropertyId = 29, Value = 23.4 },
//                                                               new PropertyContainer { PropertyId = 1, Value = 2 },
//                                                           });
//
                        _f8.CreateEdge(aVertexId, 0, aTargetVertex, creationDate);
                    }
                }

                _toBeBenchenVertices.AddRange(PickInterestingIDs(vertexIDs, prng)
                                              .Select(aId => {
                    VertexModel v = null;

                    _f8.TryGetVertex(out v, aId);

                    return(v);
                }));
            }
        }
Пример #3
0
        public void CreateGraph(int nodeCount, int edgeCount)
        {
            _f8.TabulaRasa();
            var creationDate = DateHelper.ConvertDateTime(DateTime.Now);
            var vertexIDs    = new List <Int32> ();
            var prng         = new Random();

            if (nodeCount < _numberOfToBeTestedVertices)
            {
                _numberOfToBeTestedVertices = nodeCount;
            }

            _toBeBenchenVertices = new List <VertexModel> (_numberOfToBeTestedVertices);

            for (var i = 0; i < nodeCount; i++)
            {
                vertexIDs.Add(_f8.CreateVertex(creationDate).Id);
            }

            if (edgeCount != 0)
            {
                foreach (var aVertexId in vertexIDs)
                {
                    var targetVertices = new HashSet <Int32> ();

                    do
                    {
                        targetVertices.Add(vertexIDs [prng.Next(0, vertexIDs.Count)]);
                    } while (targetVertices.Count < edgeCount);

                    foreach (var aTargetVertex in targetVertices)
                    {
                        _f8.CreateEdge(aVertexId, 0, aTargetVertex, creationDate);
                    }
                }

                _toBeBenchenVertices.AddRange(PickInterestingIDs(vertexIDs, prng)
                                              .Select(aId => {
                    VertexModel v = null;

                    _f8.TryGetVertex(out v, aId);

                    return(v);
                }));
            }
        }
Пример #4
0
        /// <summary>
        /// Checks if two F8 instances are equal
        /// </summary>
        /// <param name="a">The Fallen-8 a</param>
        /// <param name="b">The Fallen-8 b</param>
        /// <returns></returns>
        public static bool CheckIfFallen8IsEqual(Fallen8 a, Fallen8 b)
        {
            Assert.AreEqual(a.VertexCount, b.VertexCount);
            Assert.AreEqual(a.EdgeCount, b.EdgeCount);

            foreach (var aReference in a.GetVertices())
            {
                VertexModel pendant;
                Assert.IsTrue(b.TryGetVertex(out pendant, aReference.Id));
                CheckIfVerticesAreEqual(aReference, pendant);
            }

            foreach (var aReference in a.GetEdges())
            {
                EdgeModel pendant;
                Assert.IsTrue(b.TryGetEdge(out pendant, aReference.Id));
                CheckIfEdgesAreEqual(aReference, pendant);
            }

            return(true);
        }
        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
        }