Example #1
0
        /// <summary>
        ///   Removes an incoming edge
        /// </summary>
        /// <param name="edgePropertyId"> Edge property identifier. </param>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        internal void RemoveIncomingEdge(ushort edgePropertyId, EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                try
                {
                    if (_inEdges == null)
                    {
                        return;
                    }

                    for (var i = 0; i < _inEdges.Count; i++)
                    {
                        var aInEdge = _inEdges[i];
                        if (aInEdge.EdgePropertyId == edgePropertyId)
                        {
                            aInEdge.Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id);
                            break;
                        }
                    }
                }
                finally
                {
                    FinishWriteResource();
                }

                return;
            }

            throw new CollisionException(this);
        }
Example #2
0
        /// <summary>
        ///   Remove outgoing edge
        /// </summary>
        /// <param name="edgePropertyId"> The edge property identifier. </param>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        internal void RemoveOutGoingEdge(ushort edgePropertyId, EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                if (_outEdges == null)
                {
                    FinishWriteResource();

                    return;
                }

                for (var i = 0; i < _outEdges.Count; i++)
                {
                    var aOutEdge = _outEdges[i];
                    if (aOutEdge.EdgePropertyId == edgePropertyId)
                    {
                        aOutEdge.Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id);
                        break;
                    }
                }

                FinishWriteResource();

                return;
            }

            throw new CollisionException(this);
        }
Example #3
0
        /// <summary>
        ///   Removes an outgoing edge
        /// </summary>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        /// <returns> The edge property identifier where the edge was deleted </returns>
        internal List <UInt16> RemoveOutGoingEdge(EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                var result = new List <UInt16>();

                if (_outEdges == null)
                {
                    FinishWriteResource();

                    return(result);
                }

                for (var i = 0; i < _outEdges.Count; i++)
                {
                    if (_outEdges[i].Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id) > 0)
                    {
                        result.Add(_outEdges[i].EdgePropertyId);
                    }
                }

                FinishWriteResource();

                return(result);
            }

            throw new CollisionException(this);
        }
Example #4
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;
 }
Example #5
0
        public void EdgeModelConstructorUnitTest()
        {
            Assert.Inconclusive("TODO");

            int id = 0; // TODO: Initialize to an appropriate value
            uint creationDate = 0; // TODO: Initialize to an appropriate value
            VertexModel targetVertex = null; // TODO: Initialize to an appropriate value
            VertexModel sourceVertex = null; // TODO: Initialize to an appropriate value
            PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value
            var target = new EdgeModel(id, creationDate, targetVertex, sourceVertex, properties);
        }
Example #6
0
        /// <summary>
        ///   Adds the incoming edge.
        /// </summary>
        /// <param name='edgePropertyId'> Edge property identifier. </param>
        /// <param name='incomingEdge'> Incoming edge. </param>
        /// <exception cref='CollisionException'>Is thrown when the collision exception.</exception>
        internal void AddIncomingEdge(UInt16 edgePropertyId, EdgeModel incomingEdge)
        {
            if (WriteResource())
            {
                try
                {
                    if (_inEdges == null)
                    {
                        _inEdges = new List <EdgeContainer>();
                    }

                    var foundSth = false;

                    for (var i = 0; i < _inEdges.Count; i++)
                    {
                        var aInEdge = _inEdges[i];
                        if (aInEdge.EdgePropertyId == edgePropertyId)
                        {
                            aInEdge.Edges.Add(incomingEdge);
                            foundSth = true;
                            break;
                        }
                    }

                    if (!foundSth)
                    {
                        _inEdges.Add(new EdgeContainer(edgePropertyId, new List <EdgeModel> {
                            incomingEdge
                        }));
                    }
                }
                finally
                {
                    FinishWriteResource();
                }

                return;
            }

            throw new CollisionException(this);
        }
Example #7
0
        /// <summary>
        ///   Adds the out edge.
        /// </summary>
        /// <param name='edgePropertyId'> Edge property identifier. </param>
        /// <param name='outEdge'> Out edge. </param>
        /// <exception cref='CollisionException'>Is thrown when the collision exception.</exception>
        internal void AddOutEdge(UInt16 edgePropertyId, EdgeModel outEdge)
        {
            if (WriteResource())
            {
                if (_outEdges == null)
                {
                    _outEdges = new List <EdgeContainer>();
                }

                var foundSth = false;

                for (var i = 0; i < _outEdges.Count; i++)
                {
                    var aOutEdge = _outEdges[i];
                    if (aOutEdge.EdgePropertyId == edgePropertyId)
                    {
                        aOutEdge.Edges.Add(outEdge);

                        foundSth = true;

                        break;
                    }
                }

                if (!foundSth)
                {
                    _outEdges.Add(new EdgeContainer(edgePropertyId, new List <EdgeModel> {
                        outEdge
                    }));
                }

                FinishWriteResource();

                return;
            }


            throw new CollisionException(this);
        }
Example #8
0
 /// <summary>
 /// Source vertex extractor.
 /// </summary>
 /// <returns>
 /// The source vertex.
 /// </returns>
 /// <param name='edge'>
 /// Edge.
 /// </param>
 private static VertexModel SourceVertexExtractor(EdgeModel edge)
 {
     return edge.SourceVertex;
 }
Example #9
0
        /// <summary>
        ///   Removes an outgoing edge
        /// </summary>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        /// <returns> The edge property identifier where the edge was deleted </returns>
        internal List<UInt16> RemoveOutGoingEdge(EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                var result = new List<UInt16>();

                if (_outEdges == null)
                {
                    FinishWriteResource();

                    return result;
                }

                for (var i = 0; i < _outEdges.Count; i++)
                {
                    if (_outEdges[i].Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id) > 0)
                    {
                        result.Add(_outEdges[i].EdgePropertyId);
                    }
                }

                FinishWriteResource();

                return result;
            }

            throw new CollisionException();
        }
Example #10
0
        /// <summary>
        ///   Remove outgoing edge
        /// </summary>
        /// <param name="edgePropertyId"> The edge property identifier. </param>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        internal void RemoveOutGoingEdge(ushort edgePropertyId, EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                if (_outEdges == null)
                {
                    FinishWriteResource();

                    return;
                }

                for (var i = 0; i < _outEdges.Count; i++)
                {
                    var aOutEdge = _outEdges[i];
                    if (aOutEdge.EdgePropertyId == edgePropertyId)
                    {
                        aOutEdge.Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id);
                        break;
                    }
                }

                FinishWriteResource();

                return;
            }

            throw new CollisionException();
        }
Example #11
0
        /// <summary>
        ///   Adds the out edge.
        /// </summary>
        /// <param name='edgePropertyId'> Edge property identifier. </param>
        /// <param name='outEdge'> Out edge. </param>
        /// <exception cref='CollisionException'>Is thrown when the collision exception.</exception>
        internal void AddOutEdge(UInt16 edgePropertyId, EdgeModel outEdge)
        {
            if (WriteResource())
            {
                if (_outEdges == null)
                {
                    _outEdges = new List<EdgeContainer>();
                }

                var foundSth = false;

                for (var i = 0; i < _outEdges.Count; i++)
                {
                    var aOutEdge = _outEdges[i];
                    if (aOutEdge.EdgePropertyId == edgePropertyId)
                    {
                        aOutEdge.Edges.Add(outEdge);

                        foundSth = true;

                        break;
                    }
                }

                if (!foundSth)
                {
                    _outEdges.Add(new EdgeContainer(edgePropertyId, new List<EdgeModel> {outEdge}));
                }

                FinishWriteResource();

                return;
            }

            throw new CollisionException();
        }
Example #12
0
 /// <summary>
 ///   Writes the edge.
 /// </summary>
 /// <param name='edge'> Edge. </param>
 /// <param name='writer'> Writer. </param>
 private static void WriteEdge(EdgeModel edge, SerializationWriter writer)
 {
     writer.Write(SerializedEdge);
     WriteAGraphElement(edge, writer);
     writer.Write(edge.SourceVertex.Id);
     writer.Write(edge.TargetVertex.Id);
 }
Example #13
0
        /// <summary>
        ///   Adds the incoming edge.
        /// </summary>
        /// <param name='edgePropertyId'> Edge property identifier. </param>
        /// <param name='incomingEdge'> Incoming edge. </param>
        /// <exception cref='CollisionException'>Is thrown when the collision exception.</exception>
        internal void AddIncomingEdge(UInt16 edgePropertyId, EdgeModel incomingEdge)
        {
            if (WriteResource())
            {
                try
                {
                    if (_inEdges == null)
                    {
                        _inEdges = new List<EdgeContainer>();
                    }

                    var foundSth = false;

                    for (var i = 0; i < _inEdges.Count; i++)
                    {
                        var aInEdge = _inEdges[i];
                        if (aInEdge.EdgePropertyId == edgePropertyId)
                        {
                            aInEdge.Edges.Add(incomingEdge);
                            foundSth = true;
                            break;
                        }
                    }

                    if (!foundSth)
                    {
                    _inEdges.Add(new EdgeContainer(edgePropertyId, new List<EdgeModel> {incomingEdge}));
                    }

                }
                finally
                {
                    FinishWriteResource();
                }

                return;
            }

            throw new CollisionException(this);
        }
Example #14
0
 /// <summary>
 /// Target vertex extractor.
 /// </summary>
 /// <returns>
 /// The target vertex.
 /// </returns>
 /// <param name='edge'>
 /// Edge.
 /// </param>
 private static VertexModel TargetVertexExtractor(EdgeModel edge)
 {
     return(edge.TargetVertex);
 }
Example #15
0
        public Boolean TryGetEdge(out EdgeModel result, Int32 id)
        {
            if (ReadResource())
            {
                var success = _graphElements.TryGetElementOrDefault(out result, id);

                FinishReadResource();

                return success;
            }

            throw new CollisionException();
        }
Example #16
0
        public Boolean TryGetEdge(out EdgeModel result, Int32 id)
        {
            if (ReadResource())
            {
                result = _graphElements.GetElement(id) as EdgeModel;

                FinishReadResource();

                return result != null;
            }

            throw new CollisionException();
        }
Example #17
0
        public EdgeModel CreateEdge(Int32 sourceVertexId, UInt16 edgePropertyId, Int32 targetVertexId,
                                    UInt32 creationDate, PropertyContainer[] properties = null)
        {
            if (WriteResource())
            {
                EdgeModel outgoingEdge = null;

                var sourceVertex = _graphElements.GetElement(sourceVertexId) as VertexModel;
                var targetVertex = _graphElements.GetElement(targetVertexId) as VertexModel;

                //get the related vertices
                if (sourceVertex != null && targetVertex != null)
                {
                    outgoingEdge = new EdgeModel(_currentId, creationDate, targetVertex, sourceVertex, properties);

                    //add the edge to the graph elements
                    _graphElements.SetValue(_currentId, outgoingEdge);

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

                    //add the edge to the source vertex
                    sourceVertex.AddOutEdge(edgePropertyId, outgoingEdge);

                    //link the vertices
                    targetVertex.AddIncomingEdge(edgePropertyId, outgoingEdge);

                    //increase the edgeCount
                    EdgeCount++;
                }

                FinishWriteResource();

                return outgoingEdge;
            }

            throw new CollisionException();
        }
Example #18
0
        /// <summary>
        ///   Removes an incoming edge
        /// </summary>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        /// <returns> The edge property identifier where the edge was deleted </returns>
        internal List<UInt16> RemoveIncomingEdge(EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                try
                {
                    var result = new List<UInt16>();

                    if (_inEdges == null)
                    {
                        return result;
                    }

                    for (var i = 0; i < _inEdges.Count; i++)
                    {
                        if (_inEdges[i].Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id) > 0)
                        {
                            result.Add(_inEdges[i].EdgePropertyId);
                        }
                    }
                    return result;
                }
                finally
                {
                    FinishWriteResource();
                }

            }

            throw new CollisionException(this);
        }
Example #19
0
        /// <summary>
        ///   Removes an incoming edge
        /// </summary>
        /// <param name="edgePropertyId"> Edge property identifier. </param>
        /// <param name="toBeRemovedEdge"> The to be removed edge </param>
        internal void RemoveIncomingEdge(ushort edgePropertyId, EdgeModel toBeRemovedEdge)
        {
            if (WriteResource())
            {
                try
                {
                    if (_inEdges == null)
                    {
                        return;
                    }

                    for (var i = 0; i < _inEdges.Count; i++)
                    {
                        var aInEdge = _inEdges[i];
                        if (aInEdge.EdgePropertyId == edgePropertyId)
                        {
                            aInEdge.Edges.RemoveAll(_ => _.Id == toBeRemovedEdge.Id);
                            break;
                        }
                    }
                }
                finally
                {
                    FinishWriteResource();
                }

                return;
            }

            throw new CollisionException(this);
        }
Example #20
0
 /// <summary>
 /// Target vertex extractor.
 /// </summary>
 /// <returns>
 /// The target vertex.
 /// </returns>
 /// <param name='edge'>
 /// Edge.
 /// </param>
 private static VertexModel TargetVertexExtractor(EdgeModel edge)
 {
     return edge.TargetVertex;
 }
Example #21
0
        /// <summary>
        ///   Loads the edge.
        /// </summary>
        /// <param name='reader'> Reader. </param>
        /// <param name='graphElements'> Graph elements. </param>
        /// <param name='sneakPeaks'> Sneak peaks. </param>
        private static void LoadEdge(SerializationReader reader, AGraphElement[] graphElements,
                                     ref List<EdgeSneakPeak> sneakPeaks)
        {
            var id = reader.ReadInt32();
            var creationDate = reader.ReadUInt32();
            var modificationDate = reader.ReadUInt32();

            #region properties

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

            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

            var sourceVertexId = reader.ReadInt32();
            var targetVertexId = reader.ReadInt32();

            VertexModel sourceVertex = graphElements[sourceVertexId] as VertexModel;
            VertexModel targetVertex = graphElements[targetVertexId] as VertexModel;

            if (sourceVertex != null && targetVertex != null)
            {
                graphElements[id] = new EdgeModel(id, creationDate, modificationDate, targetVertex,sourceVertex, properties);
            }
            else
            {
                sneakPeaks.Add(new EdgeSneakPeak
                                   {
                                       CreationDate = creationDate,
                                       Id = id,
                                       ModificationDate = modificationDate,
                                       Properties = properties,
                                       SourceVertexId = sourceVertexId,
                                       TargetVertexId = targetVertexId
                                   });
            }
        }
Example #22
0
 /// <summary>
 /// Source vertex extractor.
 /// </summary>
 /// <returns>
 /// The source vertex.
 /// </returns>
 /// <param name='edge'>
 /// Edge.
 /// </param>
 private static VertexModel SourceVertexExtractor(EdgeModel edge)
 {
     return(edge.SourceVertex);
 }