Example #1
0
    // Finds an Edge given both of its vertices
    public EdgeIfc findsEdge(Vertex theSource,
                             Vertex theTarGet)
    {
        //dja: performance improvement
        //for( VertexIter vertexiter = GetVertices(); vertexiter.hasNext(); )
        // {
        //	Vertex v1 = vertexiter.next( );
        //	for( EdgeIter edgeiter = v1.GetEdges(); edgeiter.hasNext(); )
        //    {
        //          EdgeIfc theEdge = edgeiter.next();
        //		Vertex v2 = theEdge.GetOtherVertex( v1 );
        //	      if ( ( v1.GetName().Equals( theSource.GetName() ) &&
        //             v2.GetName().Equals( theTarGet.GetName() ) ) ||
        //               ( v1.GetName().Equals( theTarGet.GetName() ) &&
        //               v2.GetName().Equals( theSource.GetName() ) ) )
        //          return theEdge;
        //    }
        //}
        Vertex v1 = theSource;

        for (Iterator <EdgeIfc> edgeiter = v1.GetEdges(); edgeiter.hasNext();)
        {
            EdgeIfc theEdge = edgeiter.next();
            Vertex  v2      = theEdge.GetOtherVertex(v1);
            if ((v1.GetName().Equals(theSource.GetName()) &&
                 v2.GetName().Equals(theTarGet.GetName())) ||
                (v1.GetName().Equals(theTarGet.GetName()) &&
                 v2.GetName().Equals(theSource.GetName())))
            {
                return(theEdge);
            }
        }
        return(null);
    }
Example #2
0
        int CalculateTotalTo(Vertex supplier, EdgeType supplierWarehouseEdgeType, EdgeType moveToEdgeType, PropertyType howManyProperty, Vertex toVertex)
        {
            int total = 0;
            HashSet <Vertex>   excludeSet          = new HashSet <Vertex>();
            HashSet <EdgeType> edgeTypesToTraverse = new HashSet <EdgeType>();

            edgeTypesToTraverse.Add(moveToEdgeType);
            foreach (IEdge wareHouseEdge in supplier.GetEdges(supplierWarehouseEdgeType, Direction.Out))
            {
                Vertex supplierWareHouse = (Vertex)wareHouseEdge.GetVertex(Direction.In);
                var    allPaths          = supplierWareHouse.Traverse(10, true, Direction.Out, toVertex, edgeTypesToTraverse, null, null, null, excludeSet);
                foreach (List <Edge> path in allPaths)
                {
                    if (path.Count > 0)
                    {
                        total += (int)path.Last().GetProperty(howManyProperty); // last because that is all we care about in this simplified sample
                    }
                    foreach (Edge edge in path)
                    {
                        excludeSet.Add(edge.Tail);
                    }
                }
            }
            return(total);
        }
Example #3
0
 protected override void LoadChildren()
 {
     foreach (var property in _vertex.GetPropertyKeys())
     {
         base.Children.Add(new VertexPropertyViewModel(property, _vertex, this, m_session));
     }
     foreach (var edge in _vertex.GetEdges(Direction.Both))
     {
         base.Children.Add(new EdgeViewModel((Edge)edge, this, m_session));
     }
 }
Example #4
0
    public void DestoryIsolatedVertex()
    {
        foreach (KeyValuePair <Grid, Vertex <T> > keyValuePair in vertexDictionary)
        {
            Vertex <T> vertex = keyValuePair.Value;

            if (vertex.GetEdges().Count == 0)
            {
                vertexDictionary.Remove(keyValuePair.Key);
            }
        }
    }
Example #5
0
        private bool IdInEdge(int id, Vertex vertex)
        {
            bool found = false;

            for (int i = 0; i < vertex.GetEdgesListCount(); ++i)
            {
                if (vertex.GetEdges()[i].Destination.ID == id)
                {
                    found = true;
                }
            }

            return(found);
        }
Example #6
0
    private void VisitNeighbors(Vertex vertex)
    {
        foreach (Edge edge in vertex.GetEdges())
        {
            int    alt      = distances[vertex] + edge.GetDistance();
            Vertex neighbor = edge.GetNeighbor(vertex);

            if (alt < distances[neighbor])
            {
                distances[neighbor] = alt;
                previous[neighbor]  = vertex;
            }
        }
    }
Example #7
0
        private void UpdateDijkstraVector(Vertex selectedVertex)
        {
            double totalWeight;

            foreach (Edge edge in selectedVertex.GetEdges())
            {
                if (!DijkstraValues[edge.Destination].IsDefinitive)
                {
                    totalWeight = DijkstraValues[selectedVertex].Weight + edge.Weight;

                    if (totalWeight < DijkstraValues[edge.Destination].Weight)
                    {
                        DijkstraValues[edge.Destination].Weight    = totalWeight;
                        DijkstraValues[edge.Destination].UpdatedBy = selectedVertex;
                    }
                }
            }
        }
Example #8
0
    // Finds an Edge given both of its vertices
    public EdgeIfc findsEdge(Vertex theSource,
                             Vertex theTarGet)
    {
        EdgeIfc theEdge;

        // dja: performance improvement
        //  for( Iterator<EdgeIfc> edgeiter = GetEdges(); edgeiter.hasNext(); )
        for (Iterator <EdgeIfc> edgeiter = theSource.GetEdges(); edgeiter.hasNext();)
        {
            theEdge = edgeiter.next();
            if ((theEdge.GetStart().GetName().Equals(theSource.GetName()) &&
                 theEdge.GetEnd().GetName().Equals(theTarGet.GetName())) ||
                (theEdge.GetStart().GetName().Equals(theTarGet.GetName()) &&
                 theEdge.GetEnd().GetName().Equals(theSource.GetName())))
            {
                return(theEdge);
            }
        }
        return(null);
    }
Example #9
0
        private List <Point> GetPoints(Vertex origin, Vertex destination)
        {
            List <Point> path = new List <Point>();

            foreach (Edge edge in origin.GetEdges())
            {
                if (edge.Destination.ID == destination.ID)
                {
                    path.Add(edge.Path[0]);

                    for (int i = 0; i < edge.Path.Count; i += 5)
                    {
                        path.Add(edge.Path[i]);
                    }

                    path.Add(edge.Path.Last());
                }
            }

            return(path);
        }
    private void SelectDestination(Vertex previousVertex)
    {
        if (previousVertex == null)
        {
            path = roads.GetPathToRandomTarget(position);
        }
        else
        {
            List <Vertex> filteredVertices = new List <Vertex>();

            foreach (Edge e in position.GetEdges())
            {
                Vertex neighbor = e.GetNeighbor(position);
                if (neighbor != previousVertex)
                {
                    filteredVertices.Add(neighbor);
                }
            }

            if (filteredVertices.Count == 0)
            {
                path = roads.GetPathToRandomTarget(position);
            }
            else
            {
                Vertex randomNeighbor = filteredVertices[Random.Range(0, filteredVertices.Count)];
                path = roads.GetPathToRandomTarget(randomNeighbor);
                path.Prepend(position);
                path.Prepend(previousVertex);
            }
        }

        path.Calculate();
        WaypointProgressTracker wpt = this.GetComponent <WaypointProgressTracker>();

        wpt.Setup(new WaypointCircuit(path.GetPath()));
    }
            private Boolean AppartientAuCorps(Component2 cp, Body2 corps, MateEntity2 m)
            {
                if (cp.Name2 != m.ReferenceComponent.Name2)
                {
                    return(false);
                }

                Edge e;

                if (m.ReferenceType2 == (int)swSelectType_e.swSelVERTICES)
                {
                    Vertex v = m.Reference;
                    e = v.GetEdges()[0];
                }
                else if (m.ReferenceType2 == (int)swSelectType_e.swSelEDGES)
                {
                    e = m.Reference;
                }
                else if (m.ReferenceType2 == (int)swSelectType_e.swSelFACES)
                {
                    e = m.Reference;
                }
                else
                {
                    return(false);
                }

                Body2 b = e.GetBody();

                if (b.Name == corps.Name)
                {
                    return(true);
                }

                return(false);
            }
 public IEnumerable <IEdge> GetEdges(Direction direction, params string[] labels)
 {
     return(Vertex.GetEdges(direction, labels));
 }
Example #13
0
        static void Main(string[] args)
        {
            bool import   = args.Length > 0 && args[0].ToLower() == "-import";
            bool dirExist = Directory.Exists(s_systemDir);

            SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase = false;
            if (import || !dirExist)
            {
                if (dirExist)
                {
                    Directory.Delete(s_systemDir, true); // remove systemDir from prior runs and all its databases.
                }
                Directory.CreateDirectory(s_systemDir);
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    DataCache.MaximumMemoryUse = 12000000000;        // 12 GB, set this to what fits your case
                    SessionBase.BTreeAddFastTransientBatchSize = 10; // reduces memory usage
                    Vertex[] ratingVertices = new Vertex[10];
                    session.BeginUpdate();
                    session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.LZ4;
                    Graph g = new Graph(session);

                    // SCHEMA
                    VertexType   userType   = g.NewVertexType("User");
                    PropertyType genderType = userType.NewProperty("Gender", DataType.Integer, PropertyKind.Indexed);

                    VertexType   ratingType = g.NewVertexType("Rating");
                    PropertyType ratingValuePropertyType = ratingType.NewProperty("RatingValue", DataType.Integer, PropertyKind.Indexed);

                    EdgeType ratingEdgeType = g.NewEdgeType("UserToRating", true, userType, ratingType);

                    EdgeType     ratingOfType           = g.NewEdgeType("RatingOf", false, userType, userType);
                    PropertyType ratingEdgePropertyType = ratingOfType.NewProperty("Rating", DataType.Integer, PropertyKind.Indexed);

                    // DATA
                    using (FileStream stream = File.OpenRead(System.IO.Path.Combine(s_inputDataDir, "gender.dat")))
                    {
                        using (StreamReader file = new System.IO.StreamReader(stream))
                        {
                            string line;
                            int    lineNumber = 0;
                            while ((line = file.ReadLine()) != null)
                            {
                                lineNumber++;
                                string[] fields = line.Split(',');
                                Vertex   aUser  = userType.NewVertex();
                                aUser.SetProperty(genderType, (int)fields[1][0] == 'M' ? Gender.Male : fields[1][0] == 'F' ? Gender.Female : Gender.Unknown);
                            }
                            Console.WriteLine("Done importing " + lineNumber + " users");
                        }
                    }

                    using (FileStream stream = File.OpenRead(System.IO.Path.Combine(s_inputDataDir, "ratings.dat")))
                    {
                        using (StreamReader file = new System.IO.StreamReader(stream))
                        {
                            string line;
                            int    lineNumber = 0;
                            Vertex rater      = null;
                            int    raterId;
                            int    priorRaterId = -1;

                            while ((line = file.ReadLine()) != null)
                            {
                                lineNumber++;
                                if (lineNumber % 1000000 == 0)
                                {
                                    Console.WriteLine("Parsing rating # " + lineNumber);
                                }
                                string[] fields = line.Split(',');
                                raterId = int.Parse(fields[0]);
                                if (raterId != priorRaterId)
                                {
                                    rater = userType.GetVertex(raterId);
                                }
                                priorRaterId = raterId;
                                int    ratedId      = int.Parse(fields[1]);
                                int    rating       = int.Parse(fields[2]);
                                Vertex ratingVertex = ratingVertices[rating - 1];
                                if (ratingVertex == null)
                                {
                                    ratingVertex = ratingType.NewVertex();
                                    ratingVertex.SetProperty(ratingValuePropertyType, rating);
                                    ratingVertices[rating - 1] = ratingVertex;
                                }
                                Vertex rated     = userType.GetVertex(ratedId);
                                Edge   aRatingOf = ratingOfType.NewEdge(rater, rated);
                                aRatingOf.SetProperty(ratingEdgePropertyType, rating);
                                Edge userRating = ratingEdgeType.NewEdge(rated, ratingVertex);
                            }
                            Console.WriteLine("Done importing " + lineNumber + " ratings");
                        }
                    }
                    session.Commit();
                }
            }
            // Query
            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                session.BeginRead();
                Graph        g          = Graph.Open(session);
                VertexType   userType   = g.FindVertexType("User");
                PropertyType genderType = userType.FindProperty("Gender");

                VertexType   ratingType = g.FindVertexType("Rating");
                PropertyType ratingValuePropertyType = ratingType.FindProperty("RatingValue");

                EdgeType ratingEdgeType = g.FindEdgeType("UserToRating");

                EdgeType     ratingOfType           = g.FindEdgeType("RatingOf");
                PropertyType ratingEdgePropertyType = ratingOfType.FindProperty("Rating");
                // Complex queries
                int ct = 0;

// Given a user id, and based on the rated profiles, find other users who have rated similarly on the same profiles, and find other profiles to recommend based on what those other users have rated
                Vertex someUser       = userType.GetVertex(1);
                var    similarRatings = (from Edge e in someUser.GetEdges(ratingOfType, Direction.Out)
                                         from Edge edge in e.Head.GetEdges(ratingOfType, Direction.Out)
                                         where someUser != edge.Head
                                         where ((int)e.GetProperty(ratingEdgePropertyType) == (int)edge.GetProperty(ratingEdgePropertyType))
                                         select edge.Tail).Distinct();

                var someUserRated = from Edge e in someUser.GetEdges(ratingOfType, Direction.Out)
                                    select e.Head;

                var recommendedProfles = from v in similarRatings
                                         from Edge e in v.GetEdges(ratingOfType, Direction.Out)
                                         where someUserRated.Contains(e.Head) == false
                                         select e.Head;

                Console.WriteLine("Some user's rated profiles");
                ct = 0;
                foreach (Vertex v in someUserRated)
                {
                    if (ct++ % 50 == 0) // don't print them all !
                    {
                        Console.WriteLine("User id: " + v.VertexId);
                    }
                }
                Console.WriteLine("Number of some user's rated profiles: " + ct);

                Console.WriteLine("Given a user id, and based on the rated profiles, find other users who have rated similarly on the same profiles");
                ct = 0;
                foreach (Vertex v in similarRatings)
                {
                    if (ct++ % 50 == 0) // don't print them all !
                    {
                        Console.WriteLine("User id: " + v.VertexId);
                    }
                }
                Console.WriteLine("Number of matching profiles: " + ct);

                Console.WriteLine("Given a user id, and based on the rated profiles, find other users who have rated similarly on the same profiles, and find other profiles to recommend based on what those other users have rated");
                ct = 0;
                foreach (Vertex v in recommendedProfles)
                {
                    if (ct++ % 5000 == 0) // don't print them all !
                    {
                        Console.WriteLine("User id: " + v.VertexId);
                    }
                }
                Console.WriteLine("Number of matching profiles: " + ct);

// Get all female users with less than 50 ratings
                Console.WriteLine();
                var females = from u in userType.GetVertices()
                              where ((Gender)u.GetProperty(genderType)) == Gender.Female
                              select u;
                var femalesLess50Ratings = from f in females
                                           where f.GetNumberOfEdges(ratingEdgeType, Direction.Out) < 50
                                           select f;
                Console.WriteLine("Female users with less than 50 ratings");
                ct = 0;
                foreach (Vertex f in femalesLess50Ratings)
                {
                    long count = f.GetNumberOfEdges(ratingEdgeType, Direction.Out);
                    if (ct++ % 5000 == 0) // don't print them all !
                    {
                        Console.WriteLine("User id: " + f.VertexId + "\tnumber of ratings: " + count);
                    }
                }
                Console.WriteLine("Number of females with fewer than 50 ratings: " + ct);
                Console.WriteLine();

// Get all male users with at least one 10 rating
                Console.WriteLine();
                var rated10vertex = (from v in ratingType.GetVertices()
                                     where ((int)v.GetProperty(ratingValuePropertyType)) == 10
                                     select v).First();

                var rated10 = (from e in rated10vertex.GetEdges(ratingEdgeType, Direction.In)
                               select e.GetVertex(Direction.Out)).Distinct();

                var rated10male = from Vertex v in rated10
                                  where ((Gender)v.GetProperty(genderType)) == Gender.Male
                                  select v;

                Console.WriteLine("Males with at least one 10 rating");
                ct = 0;
                foreach (Vertex v in rated10male)
                {
                    if (ct++ % 5000 == 0) // don't print them all !
                    {
                        Console.WriteLine("User id: " + v.VertexId);
                    }
                }
                Console.WriteLine("Number of males with at least one 10 rating: " + ct);
                Console.WriteLine();

// Get the first 10 male users who have rated at least 3 of the same profiles as the given user.
                Console.WriteLine("10 male users who have rated at least 3 of the same profiles as the given user");
                var males = from u in userType.GetVertices()
                            where ((Gender)u.GetProperty(genderType)) == Gender.Male
                            select u;

                var someUserHasRated = from Edge o in someUser.GetEdges(ratingOfType, Direction.Out)
                                       select o.Head;

                var first10withSame3ratedAs = from m in males
                                              where (from Edge r in m.GetEdges(ratingOfType, Direction.Out) select r.Head).Intersect(someUserHasRated).ToArray().Length >= 3
                                              select m;
                ct = 0;
                foreach (Vertex v in first10withSame3ratedAs)
                {
                    if (++ct > 10)
                    {
                        break;
                    }
                    Console.WriteLine("User id: " + v.VertexId);
                }
                Console.WriteLine();

                // Statistical queries
// Get the 20 profiles with the most ratings
                var top20mostRatings = (from v in userType.GetVertices()
                                        orderby v.GetNumberOfEdges(ratingEdgeType, Direction.Out) descending
                                        select v).Take(20);
                Console.WriteLine("20 profiles with the most ratings");
                ct = 0;
                foreach (Vertex v in top20mostRatings)
                {
                    int count = (int)v.GetNumberOfEdges(ratingEdgeType, Direction.Out);
                    Console.WriteLine("User id: " + v.VertexId + "\tnumber of ratings: " + count);
                }
                Console.WriteLine();

                var ratingsVertexEnum = from v in ratingType.GetVertices() orderby v.GetProperty(ratingValuePropertyType) descending select v;

                Vertex rating10Vertex = ratingsVertexEnum.First();
// Get the 20 best rated profiles regardless of gender
                var top = from u in userType.GetVertices()
                          let edgeCt = u.GetNumberOfEdges(ratingEdgeType, rating10Vertex, Direction.Out)
                                       orderby edgeCt descending
                                       select new { u, edgeCt };

                Console.WriteLine("20 best rated profiles regardless of gender");
                ct = 0;
                foreach (var v in top)
                {
                    if (++ct > 20)
                    {
                        break;
                    }
                    Console.WriteLine("User id: " + v.u.VertexId + "\t10 ratings: " + v.edgeCt);
                }
                Console.WriteLine();

// Get the 20 best rated males
                Console.WriteLine("20 best rated male profiles");
                var top20males = from u in userType.GetVertices()
                                 where ((Gender)u.GetProperty(genderType)) == Gender.Male
                                 let edgeCt = u.GetNumberOfEdges(ratingEdgeType, rating10Vertex, Direction.Out)
                                              orderby edgeCt descending
                                              select new { u, edgeCt };

                ct = 0;
                foreach (var v in top20males)
                {
                    if (++ct > 20)
                    {
                        break;
                    }
                    Console.WriteLine("Male User id: " + v.u.VertexId + " \t10 ratings: " + v.edgeCt);
                }
                Console.WriteLine();

// Get the 20 best rated females
                Console.WriteLine("20 best rated female profiles");
                var top20females = from u in userType.GetVertices()
                                   where ((Gender)u.GetProperty(genderType)) == Gender.Female
                                   let edgeCt = u.GetNumberOfEdges(ratingEdgeType, rating10Vertex, Direction.Out)
                                                orderby edgeCt descending
                                                select new { u, edgeCt };
                ct = 0;
                foreach (var v in top20females)
                {
                    if (++ct > 20)
                    {
                        break;
                    }
                    Console.WriteLine("Female User id: " + v.u.VertexId + "\t10 ratings: " + v.edgeCt);
                }
                session.Commit();
            }
        }
Example #14
0
    // Finds an Edge given both of its vertices
    public  EdgeIfc findsEdge( Vertex theSource,
                    Vertex theTarGet )
       {
        EdgeIfc theEdge;

	  // dja: performance improvement
      //  for( Iterator<EdgeIfc> edgeiter = GetEdges(); edgeiter.hasNext(); )
        for( Iterator<EdgeIfc> edgeiter = theSource.GetEdges(); edgeiter.hasNext(); )
         {
            theEdge = edgeiter.next();
            if ( ( theEdge.GetStart().GetName().Equals( theSource.GetName() ) &&
                  theEdge.GetEnd().GetName().Equals( theTarGet.GetName() ) ) ||
                 ( theEdge.GetStart().GetName().Equals( theTarGet.GetName() ) &&
                  theEdge.GetEnd().GetName().Equals( theSource.GetName() ) ) )
                return theEdge;
        }
        return null;
    }
Example #15
0
        // Queries
        public void doQueries()
        {
            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                session.BeginRead();
                Graph        g                       = Graph.Open(session); // it takes a while to open graph fresh from databases
                VertexType   userType                = g.FindVertexType("User");
                EdgeType     friendEdgeType          = g.FindEdgeType("Friend");
                PropertyType countryProperty         = userType.FindProperty("country");
                PropertyType incomeProperty          = userType.FindProperty("income");
                PropertyType friendshipStartProperty = friendEdgeType.FindProperty("start");

                Vertex someUser  = userType.GetVertex(1);
                Vertex someUser2 = userType.GetVertex(12282);

                var someUserFriends = from Edge e in someUser.GetEdges(friendEdgeType, Direction.Out)
                                      select e.Head;
                var            someUser3LevelNetwork = someUser.Traverse(3, true, Direction.Out);
                HashSet <Edge> edges = new HashSet <Edge>();
                Edge           edge  = (Edge)someUser.GetEdges(friendEdgeType, Direction.Out).Skip(1).First();
                edges.Add(edge);
                HashSet <EdgeType> edgeTypesToTraverse = new HashSet <EdgeType>();
                edgeTypesToTraverse.Add(friendEdgeType);
                // Find Shortest path between two given user ids
                List <List <Edge> > path = someUser.Traverse(4, false, Direction.Out, someUser2, edgeTypesToTraverse);
                Debug.Assert(path.Count > 0);
                var path2 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(41), edgeTypesToTraverse);
                HashSet <Vertex> vertices = new HashSet <Vertex>();
                vertices.Add(someUser2);
                var path3  = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, vertices);                // path must include vertices
                var path3b = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, vertices);          // path must NOT include vertices
                var path3c = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, edges);       // path must include edges
                var path3d = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges); // path must NOT include edges
                HashSet <PropertyType> vertexPropertyTypes = new HashSet <PropertyType>();
                vertexPropertyTypes.Add(incomeProperty);
                vertexPropertyTypes.Add(countryProperty);
                var path3e = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, vertexPropertyTypes);       // path must NOT include edges and at least one vertex in path must have property in propertyTypes
                var path3f = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, vertexPropertyTypes); // path must NOT include edges and no vertex in path must have any property in propertyTypes
                HashSet <PropertyType> edgePropertyTypes = new HashSet <PropertyType>();
                edgePropertyTypes.Add(friendshipStartProperty);
                var path3g = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, edgePropertyTypes);
                var path3h = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, null, edgePropertyTypes);
                var path3i = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, null, null, p => { object pv = p.GetProperty(countryProperty); return(pv != null && pv.Equals("Sweden")); });
                var path3j = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, null, null, null, p => { DateTime?pv = (DateTime?)p.GetProperty(friendshipStartProperty); return(pv != null && pv.Value.CompareTo(DateTime.Now) > 0); });
                var path4  = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(2798), edgeTypesToTraverse);
                var path5  = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(175), edgeTypesToTraverse);
                var path6  = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(1531), edgeTypesToTraverse);
                var path7  = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(1537), edgeTypesToTraverse);
                Console.WriteLine();

                // Get all the paths between two user ids
                var path8 = someUser.Traverse(4, true, Direction.Out, someUser2, edgeTypesToTraverse);
                path = someUser.Traverse(4, true, Direction.Out, userType.GetVertex(41), edgeTypesToTraverse);

                // Get the number of unique 2nd level friends a given user has (friends of my friends)

                var someUsers2ndLevelFriends = (from v in someUserFriends
                                                from Edge e in v.GetEdges(friendEdgeType, Direction.Out)
                                                select e.Head).Distinct();

                Console.WriteLine("unique 2nd level friends a given user has");
                int ct = 0;
                foreach (Vertex v in someUsers2ndLevelFriends)
                {
                    if (++ct % 100 == 0)
                    {
                        Console.WriteLine("User id: " + v.VertexId);
                    }
                }
                Console.WriteLine("Some user has: " + ct + " 2nd level friends");
                Console.WriteLine();

                // Get the top 10 users with most friends
                var top10mostFriends = from vertex in userType.GetTopNumberOfEdges(friendEdgeType, 10, Direction.Out)
                                       select vertex;
                Console.WriteLine("top 10 users with most friends");
                foreach (Vertex v in top10mostFriends)
                {
                    long count = v.GetNumberOfEdges(friendEdgeType, Direction.Out);
                    Console.WriteLine("User id: " + v.VertexId + "\t number of friends: " + count);
                }
                Console.WriteLine();
                session.Commit();
            }
        }
Example #16
0
    private void SnapPoints(Vertex point, Edge edge)
    {
        // Don't snap if the neighboring nodes already have three edges
        if (edge.node.GetEdges().Count() <= 3 ||
            edge.opposite == null ||
            edge.opposite.node.GetEdges().Count() <= 3)
        {
            return;
        }

        // There are issues with this when snapping near the edge of the map
        if (point.GetEdges().Any(x => x.opposite == null) ||
            edge.destination.GetEdges().Any(x => x.opposite == null))
        {
            return;
        }

        // Delete the edges
        edges.Remove(edge);

        // Delete the other point
        vertices.Remove(new Vector3(edge.destination.position.x, 0, edge.destination.position.z));

        var otherEdges = edge.destination.GetEdges().ToList();

        // Update everything to point to the first point
        if (point.leavingEdge == edge)
        {
            point.leavingEdge = edge.opposite.next;
        }

        if (edge.node.startEdge == edge)
        {
            edge.node.startEdge = edge.previous;
        }

        edge.next.previous = edge.previous;
        edge.previous.next = edge.next;

        // Update the opposite edge as well
        if (edge.opposite?.node.GetEdges().Count() > 3)
        {
            // Delete edge
            edges.Remove(edge.opposite);

            // Update pointers
            edge.opposite.next.previous = edge.opposite.previous;
            edge.opposite.previous.next = edge.opposite.next;

            if (edge.opposite.node.startEdge == edge.opposite)
            {
                edge.opposite.node.startEdge = edge.opposite.previous;
            }
        }

        foreach (var otherEdge in otherEdges)
        {
            if (otherEdge.opposite != null)
            {
                otherEdge.opposite.destination = point;
            }
        }
    }
Example #17
0
 public IEnumerable <IEdge> GetEdges(Direction direction, params string[] labels)
 {
     return(new PartitionEdgeIterable(Vertex.GetEdges(direction, labels), PartitionInnerTinkerGrapĥ));
 }
Example #18
0
 int CalculateTotalTo(Vertex supplier, EdgeType supplierWarehouseEdgeType, EdgeType moveToEdgeType, PropertyType howManyProperty, Vertex toVertex)
 {
   int total = 0;
   HashSet<Vertex> excludeSet = new HashSet<Vertex>();
   HashSet<EdgeType> edgeTypesToTraverse = new HashSet<EdgeType>();
   edgeTypesToTraverse.Add(moveToEdgeType);
   foreach (IEdge wareHouseEdge in supplier.GetEdges(supplierWarehouseEdgeType, Direction.Out))
   {
     Vertex supplierWareHouse = (Vertex)wareHouseEdge.GetVertex(Direction.In);
     var allPaths = supplierWareHouse.Traverse(10, true, Direction.Out, toVertex, edgeTypesToTraverse, null, null, null, excludeSet);
     foreach (List<Edge> path in allPaths)
     {
       if (path.Count > 0)
         total += (int)path.Last().GetProperty(howManyProperty); // last because that is all we care about in this simplified sample
       foreach (Edge edge in path)
       {
         excludeSet.Add(edge.Tail);
       }
     }
   }
   return total;
 }