View the step-by-step solution to:

Question

Build a class MyGraph to implement a Graph ADT(Abstract Data Type) using Adjacency Matrix with the following

functions. I would encourage to use numpy library for matrix operations:




a.Make construction which takes a parameter n. The function should make an adjacency matrix of n x n 


size. 




b. Make function AddUndirectEdge which takes two parameters src and dst and make an undirected edge 


between src and dst. 




c. Make function AddDirectedEdge which takes two parameters src and dst and make a directed edge 


between src and dst. 




d. Make function AddUndirectWegihtEdge which takes three parameters src , dst, and w and make an 


undirected edge between src and dst with weight w.




e. Make function AddDirectedWegihtEdge which takes three parameters src , dst, and w and make a


directed edge between src and dst with weight w.




f. Make function IsEdge which takes two parameters src and dst and returns True if there is an edge 


between src and dst, otherwise returns false. 




g. Make function IsPath which takes two parameters src and dst and returns True if there is a path 


between src and dst, otherwise returns False.




h. Make function ReadGraph which takes a parameter filename to read the graph from the file and returns


an object of MyGraph instance to represent that graph.










The format of file is given below:




The first line of the file contains one integer N. The next N lines contain N integers separated by space




Example 1: A graph with three vertices




3


0 1 1


1 0 1


1 1 0




Example 2: A graph with 2 vertices




2


0 1


1 0




Example 3: a graph with three vertices 




3


0 5 0


4 0 2


3 2 0




@@@@@@@@@@@   Code Template:  @@@@@@@@@@@@




import numpy as np




class MyGraph:




  def __initialize__(self, n):


  pass




def AddUndirectEdge(self, src, dst):


  pass




  def AddDirectedEdge(self, src, dst):


  pass




  def AddUndirectWegihtEdge(self, src, dst, w):


  pass


 


  def AddDirectedWegihtEdge(self, src, dst, w):


  pass




  def IsEdge(self, src, dst):


  pass




  def IsPath(self, src, dst):


  pass




  def ReadGraph(filename):


  pass

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Object-Oriented Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors