Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This function is given to you, that you only do the methods findEuler and tryVisiting from Walk import Walk import sys import random import copy

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

This function is given to you, that you only do the methods findEuler and tryVisiting

from Walk import Walk import sys import random import copy sys.setrecursionlimit(100000) class Graph: 5 Graph objects can be used to work with undirected graphs. They are internally represented using adjacency matrices. DO NOT MODIFY THIS CLASS EXCEPT TO ADD CODE FOR FINDING EULER CIRCUITS DIRECTED = True UNDIRECTED = False seeded = False @classmethod def fromFile(cls, filename): WAYANANNYAWA Instantiates list of Graphs read from a file. The file has the following formato Each graph starts on a new line which contains two elements: "D" or "U" to specify whether the graph is directed or undirected The number of vertices in that graph Followed by one line for each row of the adjacency matrix of the graph: in each row the elements are separated by blanks. Note: When it encounters problems with the data fromFile stops reading the file and returns the correct information read up to that point. Parameters: str.filename: name of file containing graphs. Returns a list of Graphs described in the file. f = gpen(filename.com graphList = [] with fas lines: row = 0 for line in lines: if row == 0; entries = line.split() if len(entries) != 2: print("Error: First line of graph must have format 'D'L'U' Totalvertices") break if entries[@] == 'U': directed = Graph. UNDIRECTED else: directed = Graph.DIRECTED vertices = int(entries[1]) edges [] row += 1 elif row vertices: graphList.append(Graph(directed, vertices, edges)) row = 0 f.close() return graphList @classmethod def newRandomSimple (cls, seed, vertices, density): Instantiates.de...simple Graph_candom.uas specified bumparameters The graph wisundirected without loops or parallel edges... Parameters: int seed: seed for random_number generator int vertices: number of vertices in the Graph int density: the odds that there will be an edge between any two distinct vertices are 1/density Returns a new graph to specifications or None if they...can't be met... if vertices = i: self.totale += edges[i][j] # Verify that adjacency matrix is symmetric when graph is undirected if not directed: for i in range(vertices): for j in range(i + 1, vertices): if edges[i][j] != edges[J][i]: print("Error: adjacency matrix is not symmetric") self.inputMistakes = True if self.inputMistakes: self. total = 0 det clearVisited MAPRESEts visitedy, visitede, and un visitede matrices for a new visitation, for i in range( elf.totall): self.visited[i] = False for j in range(self.totalv): self.visitedE[i][j] = 0 self.unvisitedE[i][j] = self.edges[i][j] def __str__(self): "Returns a String representation of the graph which is a 2-D representation of the adjacency matrix of that graph." IF IT res = for range(self.totalv): for j in range(self.totalv 1): res += str(self.edges[i][j]) res += # # res += str(self.edges[i][self.totalv if j = and sourceV = 0 and destV

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

design a simple disciplinary and grievance procedure.

Answered: 1 week ago