Пример #1
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="EdgeModel" /> class.
 /// </summary>
 /// <param name='id'> Identifier. </param>
 /// <param name='creationDate'> Creation date. </param>
 /// <param name='targetVertex'> Target vertex. </param>
 /// <param name='sourceVertex'> Source vertex. </param>
 /// <param name='properties'> Properties. </param>
 public EdgeModel(Int32 id, UInt32 creationDate, VertexModel targetVertex, VertexModel sourceVertex,
     PropertyContainer[] properties)
     : base(id, creationDate, properties)
 {
     TargetVertex = targetVertex;
     SourceVertex = sourceVertex;
 }
Пример #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="EdgeModel" /> class.
 /// </summary>
 /// <param name='id'> Identifier. </param>
 /// <param name='creationDate'> Creation date. </param>
 /// <param name='targetVertex'> Target vertex. </param>
 /// <param name='sourceVertex'> Source vertex. </param>
 /// <param name='properties'> Properties. </param>
 public EdgeModel(Int32 id, UInt32 creationDate, VertexModel targetVertex, VertexModel sourceVertex,
                  PropertyContainer[] properties)
     : base(id, creationDate, properties)
 {
     TargetVertex = targetVertex;
     SourceVertex = sourceVertex;
 }
Пример #3
0
 /// <summary>
 ///   Initializes a new instance of the EdgeModel class.
 /// </summary>
 /// <param name='id'> Identifier. </param>
 /// <param name='creationDate'> Creation date. </param>
 /// <param name='modificationDate'> Modification date. </param>
 /// <param name='targetVertex'> Target vertex. </param>
 /// <param name='sourceVertex'> Source vertex. </param>
 /// <param name='properties'> Properties. </param>
 internal EdgeModel(Int32 id, UInt32 creationDate, UInt32 modificationDate, VertexModel targetVertex,
                    VertexModel sourceVertex, PropertyContainer[] properties)
     : base(id, creationDate, properties)
 {
     TargetVertex     = targetVertex;
     SourceVertex     = sourceVertex;
     ModificationDate = modificationDate;
 }
Пример #4
0
 /// <summary>
 ///   Initializes a new instance of the EdgeModel class.
 /// </summary>
 /// <param name='id'> Identifier. </param>
 /// <param name='creationDate'> Creation date. </param>
 /// <param name='modificationDate'> Modification date. </param>
 /// <param name='targetVertex'> Target vertex. </param>
 /// <param name='sourceVertex'> Source vertex. </param>
 /// <param name='properties'> Properties. </param>
 internal EdgeModel(Int32 id, UInt32 creationDate, UInt32 modificationDate, VertexModel targetVertex,
     VertexModel sourceVertex, PropertyContainer[] properties)
     : base(id, creationDate, properties)
 {
     TargetVertex = targetVertex;
     SourceVertex = sourceVertex;
     ModificationDate = modificationDate;
 }
Пример #5
0
 /// <summary>
 ///   Creates a new path element
 /// </summary>
 /// <param name="edge"> The edge. </param>
 /// <param name="edgePropertyId"> The edge property identifier. </param>
 /// <param name="direction"> The direction. </param>
 /// <param name="weight"> The weight. </param>
 public PathElement(EdgeModel edge, UInt16 edgePropertyId, Direction direction, Double weight = 0.0)
 {
     Edge = edge;
     EdgePropertyId = edgePropertyId;
     Direction = direction;
     Weight = weight;
     _sourceVertex = null;
     _targetVertex = null;
 }
Пример #6
0
        public void GetHashCodeUnitTest()
        {
            Assert.Inconclusive("TODO");

            int id = 0; // TODO: Initialize to an appropriate value
            uint creationDate = 0; // TODO: Initialize to an appropriate value
            PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value
            var target = new VertexModel(id, creationDate, properties); // TODO: Initialize to an appropriate value
            int expected = 0; // TODO: Initialize to an appropriate value
            int actual;
            actual = target.GetHashCode();
            Assert.AreEqual(expected, actual);
        }
Пример #7
0
 internal virtual AGraphElement CreateAGraphElement()
 {
     // TODO: Instantiate an appropriate concrete class.
     AGraphElement target = new VertexModel(0, 0, new PropertyContainer[2]
                                                      {
                                                          new PropertyContainer {PropertyId = 0, Value = 23},
                                                          new PropertyContainer {PropertyId = 1, Value = "42"},
                                                      });
     return target;
 }
Пример #8
0
 public Boolean Equals(VertexModel p)
 {
     // If parameter is null return false:
     return (object)p != null && ReferenceEquals(this, p);
 }
        /// <summary>
        /// Gets the frontier elements on an outgoing edge
        /// </summary>
        /// <param name="vertex">The vertex behind the frontier</param>
        /// <param name="edgepropertyFilter">The edge property filter</param>
        /// <param name="edgeFilter">The edge filter</param>
        /// <param name="vertexFilter">The vertex filter</param>
        /// <param name="alreadyVisited">The vertices that have been visited already</param>
        /// <returns>A number of frontier elements</returns>
        private static IEnumerable<FrontierElement> GetValidOutgoingEdges(
            VertexModel vertex,
            PathDelegates.EdgePropertyFilter edgepropertyFilter,
            PathDelegates.EdgeFilter edgeFilter,
            PathDelegates.VertexFilter vertexFilter,
            BigBitArray alreadyVisited)
        {
            var edgeProperties = vertex.GetOutgoingEdges();
            var result = new List<FrontierElement>();

            if (edgeProperties != null)
            {
                foreach (var edgeContainer in edgeProperties)
                {
                    if (edgepropertyFilter != null && !edgepropertyFilter(edgeContainer.EdgePropertyId, Direction.OutgoingEdge))
                    {
                        continue;
                    }

                    if (edgeFilter != null)
                    {
                        for (var i = 0; i < edgeContainer.Edges.Count; i++)
                        {
                            var aEdge = edgeContainer.Edges[i];
                            if (edgeFilter(aEdge, Direction.OutgoingEdge))
                            {
                                if (alreadyVisited.SetValue(aEdge.TargetVertex.Id, true))
                                {
                                    if (vertexFilter != null)
                                    {
                                        if (vertexFilter(aEdge.TargetVertex))
                                        {
                                            result.Add(new FrontierElement
                                            {
                                                EdgeDirection = Direction.OutgoingEdge,
                                                EdgeLocation = new EdgeLocation
                                                {
                                                    Edge = aEdge,
                                                    EdgePropertyId =
                                                        edgeContainer.EdgePropertyId
                                                },
                                                FrontierVertex = aEdge.TargetVertex
                                            });
                                        }
                                    }
                                    else
                                    {
                                        result.Add(new FrontierElement
                                        {
                                            EdgeDirection = Direction.OutgoingEdge,
                                            EdgeLocation = new EdgeLocation
                                            {
                                                Edge = aEdge,
                                                EdgePropertyId =
                                                    edgeContainer.EdgePropertyId
                                            },
                                            FrontierVertex = aEdge.TargetVertex
                                        });
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (vertexFilter != null)
                        {
                            for (var i = 0; i < edgeContainer.Edges.Count; i++)
                            {
                                var aEdge = edgeContainer.Edges[i];

                                if (alreadyVisited.SetValue(aEdge.TargetVertex.Id, true))
                                {
                                    if (vertexFilter(aEdge.TargetVertex))
                                    {
                                        result.Add(new FrontierElement
                                        {
                                            EdgeDirection = Direction.OutgoingEdge,
                                            EdgeLocation = new EdgeLocation
                                            {
                                                Edge = aEdge,
                                                EdgePropertyId =
                                                    edgeContainer.EdgePropertyId
                                            },
                                            FrontierVertex = aEdge.TargetVertex
                                        });
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (var i = 0; i < edgeContainer.Edges.Count; i++)
                            {
                                var aEdge = edgeContainer.Edges[i];
                                if (alreadyVisited.SetValue(aEdge.TargetVertex.Id, true))
                                {
                                    result.Add(new FrontierElement
                                    {
                                        EdgeDirection = Direction.OutgoingEdge,
                                        EdgeLocation = new EdgeLocation
                                        {
                                            Edge = aEdge,
                                            EdgePropertyId =
                                                edgeContainer.EdgePropertyId
                                        },
                                        FrontierVertex = aEdge.TargetVertex
                                    });
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Gets the local frontier corresponding to a vertex
        /// </summary>
        /// <param name="vertex">The vertex behind the local frontier</param>
        /// <param name="alreadyVisitedVertices">The vertices that have been visited already</param>
        /// <param name="edgepropertyFilter">The edge property filter</param>
        /// <param name="edgeFilter">The edge filter</param>
        /// <param name="vertexFilter">The vertex filter</param>
        /// <returns>The local frontier</returns>
        private static IEnumerable<FrontierElement> GetLocalFrontier(VertexModel vertex, BigBitArray alreadyVisitedVertices, 
            PathDelegates.EdgePropertyFilter edgepropertyFilter,
            PathDelegates.EdgeFilter edgeFilter,
            PathDelegates.VertexFilter vertexFilter)
        {
            var result = new List<FrontierElement>();

            result.AddRange(GetValidIncomingEdges(vertex, edgepropertyFilter, edgeFilter, vertexFilter, alreadyVisitedVertices));
            result.AddRange(GetValidOutgoingEdges(vertex, edgepropertyFilter, edgeFilter, vertexFilter, alreadyVisitedVertices));

            return result;
        }
Пример #11
0
        /// <summary>
        /// Get the valid edges of a vertex
        /// </summary>
        /// <param name="vertex">The vertex.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="edgepropertyFilter">The edge property filter.</param>
        /// <param name="edgeFilter">The edge filter.</param>
        /// <param name="vertexFilter">The target vertex filter.</param>
        /// <returns>Valid edges</returns>
        public static List<Tuple<UInt16, IEnumerable<EdgeModel>>> GetValidEdges(
            VertexModel vertex,
            Direction direction,
            PathDelegates.EdgePropertyFilter edgepropertyFilter,
            PathDelegates.EdgeFilter edgeFilter,
            PathDelegates.VertexFilter vertexFilter)
        {
            var edgeProperties = direction == Direction.IncomingEdge ? vertex.GetIncomingEdges() : vertex.GetOutgoingEdges();
            var result = new List<Tuple<ushort, IEnumerable<EdgeModel>>>();

            if (edgeProperties != null)
            {
                foreach (var edgeContainer in edgeProperties)
                {
                    if (edgepropertyFilter != null && !edgepropertyFilter(edgeContainer.EdgePropertyId, direction))
                    {
                        continue;
                    }

                    if (edgeFilter != null)
                    {
                        var validEdges = new List<EdgeModel>();

                        for (var i = 0; i < edgeContainer.Edges.Count; i++)
                        {
                            var aEdge = edgeContainer.Edges[i];
                            if (edgeFilter(aEdge, direction))
                            {
                                if (vertexFilter != null)
                                {
                                    if (
                                        vertexFilter(direction == Direction.IncomingEdge
                                                         ? aEdge.SourceVertex
                                                         : aEdge.TargetVertex))
                                    {
                                        validEdges.Add(aEdge);
                                    }
                                }
                                else
                                {
                                    validEdges.Add(aEdge);
                                }
                            }
                        }
                        result.Add(new Tuple<ushort, IEnumerable<EdgeModel>>(edgeContainer.EdgePropertyId, validEdges));
                    }
                    else
                    {
                        if (vertexFilter != null)
                        {
                            var validEdges = new List<EdgeModel>();

                            for (var i = 0; i < edgeContainer.Edges.Count; i++)
                            {
                                var aEdge = edgeContainer.Edges[i];
                                if (
                                    vertexFilter(direction == Direction.IncomingEdge
                                                     ? aEdge.SourceVertex
                                                     : aEdge.TargetVertex))
                                {
                                    validEdges.Add(aEdge);
                                }
                            }
                            result.Add(new Tuple<ushort, IEnumerable<EdgeModel>>(edgeContainer.EdgePropertyId, validEdges));
                        }
                        else
                        {
                            result.Add(new Tuple<ushort, IEnumerable<EdgeModel>>(edgeContainer.EdgePropertyId, edgeContainer.Edges));
                        }
                    }
                }
            }

            return result;
        }
Пример #12
0
        /// <summary>
        ///   Writes the vertex.
        /// </summary>
        /// <param name='vertex'> Vertex. </param>
        /// <param name='writer'> Writer. </param>
        private static void WriteVertex(VertexModel vertex, SerializationWriter writer)
        {
            writer.Write(SerializedVertex);
            WriteAGraphElement(vertex, writer);

            #region edges

            var outgoingEdges = vertex._outEdges;
            if (outgoingEdges == null)
            {
                writer.Write(0);
            }
            else
            {
                writer.Write(outgoingEdges.Count);
                foreach (var aOutEdgeProperty in outgoingEdges)
                {
                    writer.Write(aOutEdgeProperty.EdgePropertyId);
                    writer.Write(aOutEdgeProperty.Edges.Count);
                    foreach (var aOutEdge in aOutEdgeProperty.Edges)
                    {
                        writer.Write(aOutEdge.Id);
                    }
                }
            }

            var incomingEdges = vertex._inEdges;
            if (incomingEdges == null)
            {
                writer.Write(0);
            }
            else
            {
                writer.Write(incomingEdges.Count);
                foreach (var aIncEdgeProperty in incomingEdges)
                {
                    writer.Write(aIncEdgeProperty.EdgePropertyId);
                    writer.Write(aIncEdgeProperty.Edges.Count);
                    foreach (var aIncEdge in aIncEdgeProperty.Edges)
                    {
                        writer.Write(aIncEdge.Id);
                    }
                }
            }

            #endregion
        }
Пример #13
0
 public Boolean Equals(VertexModel p)
 {
     // If parameter is null return false:
     return((object)p != null && ReferenceEquals(this, p));
 }
Пример #14
0
        public Boolean TryGetVertex(out VertexModel result, Int32 id)
        {
            if (ReadResource())
            {
                result = _graphElements.GetElement(id) as VertexModel;

                FinishReadResource();

                return result != null;
            }

            throw new CollisionException();
        }
Пример #15
0
        public VertexModel CreateVertex(UInt32 creationDate, PropertyContainer[] properties = null)
        {
            if (WriteResource())
            {
                //create the new vertex
                var newVertex = new VertexModel(_currentId, creationDate, properties);

                //insert it
                _graphElements.SetValue(_currentId, newVertex);

                //increment the id
                Interlocked.Increment(ref _currentId);

                //Increase the vertex count
                VertexCount++;

                FinishWriteResource();

                return newVertex;
            }

            throw new CollisionException();
        }
Пример #16
0
        /// <summary>
        ///   Loads the vertex.
        /// </summary>
        /// <param name='reader'> Reader. </param>
        /// <param name='graphElements'> Graph elements. </param>
        /// <param name='edgeTodo'> Edge todo. </param>
        private static void LoadVertex(SerializationReader reader, AGraphElement[] graphElements,
                                       Dictionary<Int32, List<EdgeOnVertexToDo>> edgeTodo)
        {
            var id = reader.ReadInt32();
            var creationDate = reader.ReadUInt32();
            var modificationDate = reader.ReadUInt32();

            #region properties

            var propertyCount = reader.ReadInt32();
            PropertyContainer[] properties = null;

            if (propertyCount > 0)
            {
                properties = new PropertyContainer[propertyCount];
                for (var i = 0; i < propertyCount; i++)
                {
                    var propertyIdentifier = reader.ReadUInt16();
                    var propertyValue = reader.ReadObject();

                    properties[i] = new PropertyContainer {PropertyId = propertyIdentifier, Value = propertyValue};
                }
            }

            #endregion

            #region edges

            #region outgoing edges

            List<EdgeContainer> outEdgeProperties = null;
            var outEdgeCount = reader.ReadInt32();

            if (outEdgeCount > 0)
            {
                outEdgeProperties = new List<EdgeContainer>(outEdgeCount);
                for (var i = 0; i < outEdgeCount; i++)
                {
                    var outEdgePropertyId = reader.ReadUInt16();
                    var outEdgePropertyCount = reader.ReadInt32();
                    var outEdges = new List<EdgeModel>(outEdgePropertyCount);
                    for (var j = 0; j < outEdgePropertyCount; j++)
                    {
                        var edgeId = reader.ReadInt32();

                            EdgeModel edge = graphElements[edgeId] as EdgeModel;
                            if (edge != null)
                            {
                                outEdges.Add(edge);
                            }
                            else
                            {
                                var aEdgeTodo = new EdgeOnVertexToDo
                                {
                                    VertexId = id,
                                    EdgePropertyId = outEdgePropertyId,
                                    IsIncomingEdge = false
                                };

                                List<EdgeOnVertexToDo> todo;
                                if (edgeTodo.TryGetValue(edgeId, out todo))
                                {
                                    todo.Add(aEdgeTodo);
                                }
                                else
                                {
                                    edgeTodo.Add(edgeId, new List<EdgeOnVertexToDo> { aEdgeTodo });
                                }
                            }
                    }
                    outEdgeProperties.Add(new EdgeContainer(outEdgePropertyId, outEdges));
                }
            }

            #endregion

            #region incoming edges

            List<EdgeContainer> incEdgeProperties = null;
            var incEdgeCount = reader.ReadInt32();

            if (incEdgeCount > 0)
            {
                incEdgeProperties = new List<EdgeContainer>(incEdgeCount);
                for (var i = 0; i < incEdgeCount; i++)
                {
                    var incEdgePropertyId = reader.ReadUInt16();
                    var incEdgePropertyCount = reader.ReadInt32();
                    var incEdges = new List<EdgeModel>(incEdgePropertyCount);
                    for (var j = 0; j < incEdgePropertyCount; j++)
                    {
                        var edgeId = reader.ReadInt32();

                            EdgeModel edge = graphElements[edgeId] as EdgeModel;
                            if (edge != null)
                            {
                                incEdges.Add(edge);
                            }
                            else
                            {
                                var aEdgeTodo = new EdgeOnVertexToDo
                                {
                                    VertexId = id,
                                    EdgePropertyId = incEdgePropertyId,
                                    IsIncomingEdge = true
                                };

                                List<EdgeOnVertexToDo> todo;
                                if (edgeTodo.TryGetValue(edgeId, out todo))
                                {
                                    todo.Add(aEdgeTodo);
                                }
                                else
                                {
                                    edgeTodo.Add(edgeId, new List<EdgeOnVertexToDo> { aEdgeTodo });
                                }
                            }
                    }
                    incEdgeProperties.Add(new EdgeContainer(incEdgePropertyId, incEdges));
                }
            }

            #endregion

            #endregion

            graphElements[id] = new VertexModel(id, creationDate, modificationDate, properties, outEdgeProperties,
                                                     incEdgeProperties);
        }
Пример #17
0
        public void TryGetOutEdgeUnitTest()
        {
            Assert.Inconclusive("TODO");

            int id = 0; // TODO: Initialize to an appropriate value
            uint creationDate = 0; // TODO: Initialize to an appropriate value
            PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value
            var target = new VertexModel(id, creationDate, properties); // TODO: Initialize to an appropriate value
            ReadOnlyCollection<EdgeModel> result = null; // TODO: Initialize to an appropriate value
            ReadOnlyCollection<EdgeModel> resultExpected = null; // TODO: Initialize to an appropriate value
            ushort edgePropertyId = 0; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.TryGetOutEdge(out result, edgePropertyId);
            Assert.AreEqual(resultExpected, result);
            Assert.AreEqual(expected, actual);
        }
Пример #18
0
        public Boolean TryGetVertex(out VertexModel result, Int32 id)
        {
            if (ReadResource())
            {
                var success = _graphElements.TryGetElementOrDefault(out result, id);

                FinishReadResource();

                return success;
            }

            throw new CollisionException();
        }
Пример #19
0
        public void VertexModelConstructorUnitTest()
        {
            Assert.Inconclusive("TODO");

            int id = 0; // TODO: Initialize to an appropriate value
            uint creationDate = 0; // TODO: Initialize to an appropriate value
            PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value
            var target = new VertexModel(id, creationDate, properties);
        }