Answered step by step
Verified Expert Solution
Question
1 Approved Answer
when runnung adjacencygraphlist.py: from Edge import Edge from DirectedGraph import DirectedGraph from AdjacencyListVertex import AdjacencyListVertex class AdjacencyListGraph ( DirectedGraph ) : def _ _ init
when runnung adjacencygraphlist.py:
from Edge import Edge
from DirectedGraph import DirectedGraph
from AdjacencyListVertex import AdjacencyListVertex
class AdjacencyListGraphDirectedGraph:
def initself:
self.vertices
# Creates and adds a new vertex to the graph, provided a vertex with the
# same label doesn't already exist in the graph. Returns the new vertex on
# success, None on failure.
def addvertexself newvertexlabel:
if newvertexlabel not in vertexgetlabel for vertex in self.vertices:
newvertex AdjacencyListVertexnewvertexlabel
self.vertices.appendnewvertex
return newvertex
return None
# Adds a directed edge from the first to the second vertex. If the edge
# already exists in the graph, no change is made and False is returned.
# Otherwise the new edge is added and True is returned.
def adddirectededgeself fromvertex, tovertex:
fromvertexobj self.getvertexfromvertex
tovertexobj self.getvertextovertex
if fromvertexobj is None:
fromvertexobj self.addvertexfromvertex
if tovertexobj is None:
tovertexobj self.addvertextovertex
if tovertex in fromvertexobj.adjacent:
return False
fromvertexobj.adjacent.appendtovertex
return True
# Returns a list of edges with the specified fromvertex.
def getedgesfromself fromvertex:
fromvertexobj self.getvertexfromvertex
if fromvertexobj is not None:
return Edgefromvertex, tovertex for tovertex in fromvertexobj.adjacent
return
# Returns a list of edges with the specified tovertex.
def getedgestoself tovertex:
edges
for vertex in self.vertices:
if tovertex in vertex.adjacent:
edges.appendEdgevertexgetlabel tovertex
return edges
# Returns a vertex with a matching label, or None if no such vertex exists
def getvertexself vertexlabel:
for vertex in self.vertices:
if vertex.getlabel vertexlabel:
return vertex
return None
# Returns True if self graph has an edge from fromvertex to tovertex
def hasedgeself fromvertex, tovertex:
fromvertexobj self.getvertexfromvertex
if fromvertexobj is not None:
return tovertex in fromvertexobj.adjacent
return False
# Returns a list of vertex labels
def getvertexlabelsself:
return vertexgetlabel for vertex in self.vertices
I am runnung into this error:
Traceback most recent call last:
File usercodezylabunittestrunner.py line in
passed testcase.testpassedwriter
File usercodecodingroomsunittests.py line in testpassed
return test.executetestfeedback, GradingALGraph
File usercodeDirectedGraphTestpy line in execute
if not command.executetestfeedback, graph:
File usercodeGradingpy line in execute
Actual: joinvertexgetlabel for vertex in vertices
TypeError: sequence item : expected str instance, AdjacencyListVertex found
How can I fix this?
here is adjacentlistvertex.py
from Vertex import Vertex
class AdjacencyListVertexVertex:
# List of vertices adjacent to this vertex. For each vertex V in this list, V is
# adjacent to this vertex, meaning an edge from this vertex to V exists in the graph.
def initself label:
superinitlabel
self.adjacent
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started