""" DS2501 Lab for DS2500 This week: We leverage the power of graphs to build a social network. Do not attempt this lab unless you have attended Tuesday's lecture or have watched the video. We can't...

1 answer below »
The start.py file is attached to display what functions must be used. Thank you for the assistance! Also I want it in ipynb format


""" DS2501 Lab for DS2500 This week: We leverage the power of graphs to build a social network. Do not attempt this lab unless you have attended Tuesday's lecture or have watched the video. We can't help you with the lab if you don't understand the basics of Graphs. """ from graph import Graph class SocialNetwork: def __init__(self): """ Class constructor """ self.g = Graph() def read_network(self, filename): """ Read pairs of friends from a file. e.g. 'John,Monica', etc. """ pass def add_person(self, name): """ Add a person to the network without giving them any friends """ pass def friend(self, name1, name2): """ Establish that two people are mutual friends """ pass def unfriend(self, name1, name2): """ Two people are no longer friends """ pass def recommend_friends(self, name): """Recommend friends for a particular person. Do this by finding that person’s friends, and all of the friends of those friends. Don’t recommend anyone who is already a friend! Don’t recommend a person more than once. And definitely don't recommend that a person be friends with themselves! """ pass def network_stats(self): """Generate some statistics about the network such as the number of users and the average number of friends per user. Return the stats as an attribute->value dictionary. """ pass def __repr__(self): """ Output the network as a string for printing """ return self.g.__repr__() def main(): net = SocialNetwork() net.read_network('friends.txt') print("The social network") print(net) print("Network statistics") print(net.network_stats()) print("Friend recommendations for Monica") print(net.recommend_friends('Monica')) net.unfriend('Monica', 'John') # extra credit print("\nFriend recommendations for Monica after unfriending John") # extra credit print(net.recommend_friends('Monica')) if __name__ == '__main__': main() Microsoft Word - social_networks.docx Social Networks DS2501: Lab for DS2500 (Rachlin) In this lab, we’ll implement a simple social-network class backed by the simple unweighted undirected Graph object we developed in class. To keep this simple, our social network will only keep track of usernames and which pairs of usernames are friends. No other profile information will be maintained. Your SocialNetwork class should implement the following methods by making appropriate calls to the Graph object. The Graph instance is the internal (hidden) state of the SocialNetwork object instance. Here are the methods you need to implement: • __init__: Your class constructor. • read_network: read a list of name pairs from a file and build the network • add_person: Add a person to the network without giving them any friends • friend: Establish that two people are mutual friends • get_friends: Find the friends of a specified person • recommend_friends: Recommend friends for a particular person. Do this by finding that person’s friends, and all of the friends of those friends. Don’t recommend anyone who is already a friend! Don’t recommend a person more than once. Generate friend recommendations for Monica. • network_stats: Generate some statistics about the network such as the number of users and the average number of friends per user. Return the stats as an attribute->value dictionary. Display the stats as part of your output. • __repr__: Print the network. (Just call the Graph.__repr__ method.) • unfriend EXTRA CREDIT: Two people are no longer friends. You will need to modify graph.py by implementing a remove_edge method. Show how Monica’s friend recommendations change after she unfriends John. SUBMIT: Your code: social_network.py (not a Jupyter Notebook) and a screen shot of your output. DON’T FORGET TO SUBMIT YOUR OUTPUT FOR FULL CREDIT. """ graph_simplified.py: A graph object for undirected unweighted graphs. NOTE: A simple unweighted undirected graph. No visualization, or advanced functions but you can print a representation. """ class Graph: """Graph class, for an undirected, unweighted graph with an adjacency list representation For an edge A-B, it appears in the adjaency list as A-B and B-A """ def __init__(self, V = [], E = []): """ Create a new graph from a list of verticies V and edges E. By default, the graph is undirected """ self.G = {} for v in V: self.add_vertex(v) for u, v in E: self.add_edge(u, v) def add_vertex(self, v): if v not in self.G: self.G[v] = set() def add_edge(self, u, v): # add vertices in case they don't already exist self.add_vertex(u) self.add_vertex(v) # add undirected edge (u,v) self.G[u].add(v) self.G[v].add(u) def remove_edge(self, u, v): """ Implement this to support unfriend in SocialNetwork """ pass def __getitem__(self, v): """ Return all vertices adjacent to v (overriding index operator!)""" return self.G.get(v, set()) def __repr__(self): graph_str = '' for v in self.G: graph_str += '['+v+'] => ' + str(self[v]) + '\n' return graph_str def is_adjacent(self,u,v): """ Test if u and v are adjacent """ return v in self[u] and u in self[v] def get_vertices(self): """ Get a list of all vertices in the graph """ return list(self.G.keys()) def get_edges(self): """ Return a list of edges in the graph. Each edge is a tuple (u,v) """ edges = [] for u in self.G: for v in self.G[u]: edges.append((u,v)) return edges def num_vertices(self): """ Return the number of vertices in the graph """ return len(self.G) def num_edges(self): """ Return the number of edges in the undirected graph """ total = 0 for v in self.G: total += self.deg(v) return total // 2 def deg(self,v): """ What is the degree of vertext v? i.e., how many other vertices are adjacent """ return len(self[v]) def main(): V = list("ABCDEFGH") E = [('A', 'B'), ('A', 'C'), ('A', 'G'), ('A', 'H'), ('B', 'C'), ('B', 'F'), ('C', 'D'), ('D', 'E'), ('E', 'F'), ('H', 'F')] g = Graph(V, E) print('\nUndirected Graph') print('|V|:', g.num_vertices()) print('|E|:', g.num_edges()) print('Adjacent to A:', g['A']) print(g) if __name__ == '__main__': main() John,Monica John,Byron John,Kevin Monica,Kevin Kevin,Michael Kevin,Vaishnavi Kevin,JohnPhilip Kevin,Romil
Answered 1 days AfterOct 27, 2021

Answer To: """ DS2501 Lab for DS2500 This week: We leverage the power of graphs to build a social network. Do...

Sathishkumar answered on Oct 29 2021
139 Votes
John,Monica
John,Byron
John,Kevin
Monica,Kevin
Kevin,Michael
Kevin,Vaishnavi
Kevin,JohnPhilip

Kevin,Romil
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here