Example #1
0
        public HashSet <string> Calculate(string userid)
        {
            IQueryable <User> Users = dbContext.GetAllUsers();
            var vertices            = Users.Select(e => e.Id).ToArray();
            int counter             = 0;

            foreach (var user in Users)
            {
                foreach (var connection in user.UserFollow)
                {
                    counter++;
                }
            }
            var edges = new Tuple <string, string> [counter];

            counter = 0;
            foreach (var user in Users)
            {
                foreach (var connection in user.UserFollow)
                {
                    edges[counter] = Tuple.Create(user.Id, connection.UserBeingFollowedUserId);
                    counter++;
                }
            }
            var graph      = new Graph <string>(vertices, edges);
            var algorithms = new Algorithms();

            return(algorithms.BFS(graph, userid));
        }
Example #2
0
        public void MakeUserGraph()
        {
            IQueryable <User> Users = dbContext.GetAllUsers();

            foreach (var user in Users)
            {
                userGraph.addVertex(user.Id);
            }

            foreach (var user in Users)
            {
                foreach (var connection in user.UserFollow)
                {
                    try
                    {
                        var destUser = Users.FirstOrDefault(e => e.Id == connection.UserBeingFollowedUserId);
                        var weight   = WeightCalc(user, destUser);
                        userGraph.addEdge(connection.UserId, connection.UserBeingFollowedUserId, (int)weight);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            //var vertex =userGraph.find(1);
            //userGraph.shortestPath(vertex);
            //float[] distance = userGraph.Distance;
            //int[] prev = userGraph.Prev;
        }