예제 #1
0
        public Model(VertexModel vmodel)// : this(Utilities.Convert(vmodel))
        {
            Tree = construct(vmodel, 0, Vector3.Zero, vmodel.All());

            Octree construct(VertexModel vm, int depth, Vector3 pos, List <int> possible)
            {
                float scale = (float)Math.Pow(0.5, depth);

                float[] verts       = new float[8];
                Vector3 center      = pos + Vector3.One * 0.5f * scale;
                float   centerValue = vm.DistanceAt(center, possible);

                //possible = vm.GetPossible(center, HalfSqrt3 * scale, possible);
                possible = vm.GetPossiblePrecomp(center, Math.Abs(centerValue) + HalfSqrt3 * scale, possible);
                for (int i = 0; i < 8; i++)
                {
                    verts[i] = vm.DistanceAt(pos + SdfMath.split(i).Vector *scale, possible);
                }
                Octree build = new Octree(verts);


                if (Math.Abs(centerValue) < scale * 2 && depth < MaxDepth)   // error(centerValue, build.Vertices, pos) > precision
                {
                    Octree[] children = new Octree[8];
                    for (int i = 0; i < 8; i++)
                    {
                        children[i] = construct(vm, depth + 1, pos + SdfMath.split(i).Vector *scale / 2, possible);
                    }
                    build.Children = children;
                }

                return(build);
            }
        }
예제 #2
0
 private static string WriteVertex(VertexModel vertex)
 {
     return($"{VERTEX}{DELIMITER}" +
            $"{vertex.Position.X.ToString(CultureInfo.InvariantCulture)}{DELIMITER}" +
            $"{vertex.Position.Y.ToString(CultureInfo.InvariantCulture)}{DELIMITER}" +
            $"{vertex.Position.Z.ToString(CultureInfo.InvariantCulture)}");
 }
예제 #3
0
파일: Fallen8.cs 프로젝트: ruo2012/fallen-8
        public VertexModel CreateVertex(UInt32 creationDate, PropertyContainer[] properties = null)
        {
            if (WriteResource())
            {
                try
                {
                    //create the new vertex
                    var newVertex = new VertexModel(_currentId, creationDate, properties);

                    //insert it
                    _graphElements.Add(newVertex);

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

                    //Increase the vertex count
                    VertexCount++;
                    return(newVertex);
                }
                finally
                {
                    FinishWriteResource();
                }
            }

            throw new CollisionException(this);
        }
예제 #4
0
    public override void Init()
    {
        this.model             = base.model as TriangleModel;
        model.verticesModelVec = new List <VertexModel>();

        for (int i = 0; i != model.view.transform.childCount; ++i)
        {
            VertexModel vertexModel = new VertexModel();

            vertexModel.componentsAssetID   = model.componentsAssetID;
            vertexModel.codeSnippetsAssetID = model.codeSnippetsAssetID;

            vertexModel.name   = "Vertex";
            vertexModel.parent = model;

            VertexView       vertexView       = model.view.transform.GetChild(i).gameObject.GetComponent_AutoAdd <VertexView>();
            VertexController vertexController = new VertexController();
            GameResourceManager.Instance.CombineMVC(vertexModel, vertexView, vertexController);

            vertexModel.OnPositionUpdated += InitTriangle;
            vertexModel.OnColorUpdated    += (Color => InitTriangle(Vector3.zero));

            model.verticesModelVec.Add(vertexModel);
        }

        InitTriangle(Vector3.zero);
    }
예제 #5
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);
                }));
            }
        }
예제 #6
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;
 }
예제 #7
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);
        }
        /// <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);
        }
예제 #9
0
        public void op_InequalityUnitTest()
        {
            Assert.Inconclusive("TODO");

            VertexModel a        = null;  // TODO: Initialize to an appropriate value
            VertexModel b        = null;  // TODO: Initialize to an appropriate value
            bool        expected = false; // TODO: Initialize to an appropriate value
            bool        actual;

            actual = (a != b);
            Assert.AreEqual(expected, actual);
        }
예제 #10
0
파일: Fallen8.cs 프로젝트: knocte/fallen-8
        public Boolean TryGetVertex(out VertexModel result, Int32 id)
        {
            if (ReadResource())
            {
                var success = _graphElements.TryGetElementOrDefault(out result, id);

                FinishReadResource();

                return(success);
            }

            throw new CollisionException();
        }
예제 #11
0
        public void GetLastVertexUnitTest()
        {
            Assert.Inconclusive("TODO");


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

            actual = target.GetLastVertex();
            Assert.AreEqual(expected, actual);
        }
예제 #12
0
        public Boolean TryGetVertex(out VertexModel result, Int32 id)
        {
            if (ReadResource())
            {
                result = _graphElements[id] as VertexModel;

                FinishReadResource();

                return(result != null);
            }

            throw new CollisionException(this);
        }
예제 #13
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
                });
            }
        }
예제 #14
0
        public void CreateVertexIntegrationTest()
        {
            Assert.Inconclusive("TODO.");

            IWrite target       = CreateIWrite();  // TODO: Initialize to an appropriate value
            uint   creationDate = 0;               // TODO: Initialize to an appropriate value

            PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value
            VertexModel         expected   = null; // TODO: Initialize to an appropriate value
            VertexModel         actual;

            actual = target.CreateVertex(creationDate, properties);
            Assert.AreEqual(expected, actual);
        }
예제 #15
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        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);
        }
예제 #16
0
        public void GetAllNeighborsUnitTest()
        {
            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
            List <VertexModel> expected = null;                         // TODO: Initialize to an appropriate value
            List <VertexModel> actual;

            actual = target.GetAllNeighbors();
            Assert.AreEqual(expected, actual);
        }
예제 #17
0
        public void TryGetVertexIntegrationTest()
        {
            Assert.Inconclusive("TODO.");

            IRead       target         = CreateIRead(); // TODO: Initialize to an appropriate value
            VertexModel result         = null;          // TODO: Initialize to an appropriate value
            VertexModel resultExpected = null;          // TODO: Initialize to an appropriate value
            int         id             = 0;             // TODO: Initialize to an appropriate value
            bool        expected       = false;         // TODO: Initialize to an appropriate value
            bool        actual;

            actual = target.TryGetVertex(out result, id);
            Assert.AreEqual(resultExpected, result);
            Assert.AreEqual(expected, actual);
        }
예제 #18
0
        private IReadOnlyList <VertexModel> GetVertices()
        {
            var verts  = _kernel.Vertices.ToArray();
            var models = new VertexModel[VertexCount];

            for (int i = 0; i < VertexCount; i++)
            {
                models[i] = new VertexModel
                {
                    Index    = i,
                    Position = verts[i].Position
                };
            }

            return(models);
        }
예제 #19
0
        public void GetValidEdgesUnitTest()
        {
            Assert.Inconclusive("TODO");

            VertexModel vertex    = null;                                     // TODO: Initialize to an appropriate value
            var         direction = new Direction();                          // TODO: Initialize to an appropriate value

            PathDelegates.EdgePropertyFilter edgepropertyFilter       = null; // TODO: Initialize to an appropriate value
            PathDelegates.EdgeFilter         edgeFilter               = null; // TODO: Initialize to an appropriate value
            PathDelegates.VertexFilter       vertexFilter             = null; // TODO: Initialize to an appropriate value
            List <Tuple <ushort, IEnumerable <EdgeModel> > > expected = null; // TODO: Initialize to an appropriate value
            List <Tuple <ushort, IEnumerable <EdgeModel> > > actual;

            actual = PathHelper.GetValidEdges(vertex, direction, edgepropertyFilter, edgeFilter, vertexFilter);
            Assert.AreEqual(expected, actual);
        }
예제 #20
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.WriteOptimized(SerializedVertex);
            WriteAGraphElement(vertex, writer);

            #region edges

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

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

            #endregion
        }
예제 #21
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);
                }));
            }
        }
예제 #22
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);
        }
예제 #23
0
    public override void Init()
    {
        // DO NOT trigger base init, or it will create component for texture quad

        this.model = base.model as TextureQuadModel;

        verticesPos      = new Vector3[4];
        verticesTexcoord = new Vector2[4];
        indexes          = new int[6] {
            0, 3, 2, 0, 2, 1
        };

        model.verticesModelVec = new List <VertexModel>();

        for (int i = 0; i != model.view.transform.childCount; ++i)
        {
            // TODO: refactor
            int         index       = i;
            VertexModel vertexModel = new VertexModel();
            vertexModel.componentsAssetID   = model.componentsAssetID; // set the vertex components id
            vertexModel.codeSnippetsAssetID = model.codeSnippetsAssetID;
            vertexModel.name   = "Vertex";
            vertexModel.parent = model;

            VertexView       vertexView       = model.view.transform.GetChild(i).gameObject.GetComponent_AutoAdd <VertexView>();
            VertexController vertexController = new VertexController();
            GameResourceManager.Instance.CombineMVC(vertexModel, vertexView, vertexController);

            vertexModel.OnPositionUpdated += ((pos) => UpdateVertexPos(index, pos));
            vertexModel.OnTexcoordUpdated += ((texcoord) => UpdateVertexTexcoord(index, texcoord));
            model.verticesModelVec.Add(vertexModel);
        }

        for (int i = 0; i != model.view.transform.childCount; ++i)
        {
            verticesPos[i]      = model.verticesModelVec[i].position;
            verticesTexcoord[i] = model.verticesModelVec[i].texcoord;
        }
        UpdateVertexData();
    }
예제 #24
0
파일: GraphControl.cs 프로젝트: Jo3-16/ORM
 private VertexControl GetVertexControlFromVertexModel(VertexModel vertexModel)
 {
     return(Children.OfType <VertexControl>().SingleOrDefault(c => Equals(vertexModel, c.Vertex)));
 }
예제 #25
0
파일: GraphControl.cs 프로젝트: Jo3-16/ORM
 private void OnToggleExpand(VertexModel vertex, bool expand)
 {
     expandedVertex = vertex;
     ToggleExpand(vertex.VertexId, expand);
 }
예제 #26
0
파일: GraphControl.cs 프로젝트: Jo3-16/ORM
 private void OnAddVertex(VertexModel parent)
 {
     AddVertex(parent.VertexId);
 }
        /// <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);
        }
예제 #28
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);
        }
예제 #29
0
        /// <summary>
        ///   Loads the graph elements.
        /// </summary>
        /// <param name='graphElements'> Graph elements of Fallen-8. </param>
        /// <param name='graphElementStreams'> Graph element streams. </param>
        private static void LoadGraphElements(AGraphElement[] graphElements, List <String> graphElementStreams)
        {
            var edgeTodo = new Dictionary <Int32, List <EdgeOnVertexToDo> >();
            var result   = new List <List <EdgeSneakPeak> >(graphElementStreams.Count);

            //create the major part of the graph elements
            for (var i = 0; i < graphElementStreams.Count; i++)
            {
                result.Add(LoadAGraphElementBunch(graphElementStreams[i], graphElements, edgeTodo));
            }

            foreach (var aEdgeSneakPeakList in result)
            {
                foreach (var aSneakPeak in aEdgeSneakPeakList)
                {
                    VertexModel sourceVertex = graphElements[aSneakPeak.SourceVertexId] as VertexModel;
                    VertexModel targetVertex = graphElements[aSneakPeak.TargetVertexId] as VertexModel;
                    if (sourceVertex != null && targetVertex != null)
                    {
                        graphElements[aSneakPeak.Id] =
                            new EdgeModel(
                                aSneakPeak.Id,
                                aSneakPeak.CreationDate,
                                aSneakPeak.ModificationDate,
                                targetVertex,
                                sourceVertex,
                                aSneakPeak.Properties);
                    }
                    else
                    {
                        throw new Exception(String.Format("Corrupt savegame... could not create the edge {0}", aSneakPeak.Id));
                    }
                }
            }

            foreach (var aKV in edgeTodo)
            {
                EdgeModel edge = graphElements[aKV.Key] as EdgeModel;
                if (edge != null)
                {
                    foreach (var aTodo in aKV.Value)
                    {
                        VertexModel interestingVertex = graphElements[aTodo.VertexId] as VertexModel;
                        if (interestingVertex != null)
                        {
                            if (aTodo.IsIncomingEdge)
                            {
                                interestingVertex.AddIncomingEdge(aTodo.EdgePropertyId, edge);
                            }
                            else
                            {
                                interestingVertex.AddOutEdge(aTodo.EdgePropertyId, edge);
                            }
                        }
                        else
                        {
                            Logger.LogError(String.Format("Corrupt savegame... could not get the vertex {0}", aTodo.VertexId));
                        }
                    }
                }
                else
                {
                    Logger.LogError(String.Format("Corrupt savegame... could not get the edge {0}", aKV.Key));
                }
            }
        }
예제 #30
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);
        }