Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DO IT FAST (in 30 minutes) PLEASE RUN THIS PYTHON CODE AND REMOVE ERROR'S ACCORDING TO THIS QUESTION Python program that applies the Combined Any

DO IT FAST (in 30 minutes)

PLEASE RUN THIS PYTHON CODE AND REMOVE ERROR'S ACCORDING TO THIS QUESTION

Python program that applies the Combined Any Colony Optimization and Dijkstra Algorithm in Finding Shortest path. Using the Python Pygame.

CODE : # Python program for Dijkstra's single # source shortest path algorithm. The program is with adjacency matrix representation of the graph

# Library for INT_MAX import sys

class Graph():

def __init__(self, vertices): self.V = vertices self.graph = [[0 for column in range(vertices)] for row in range(vertices)]

def printSolution(self, dist): print("Vertex tDistance from Source") for node in range(self.V): print(node, "t", dist[node])

# A utility function to find the vertex with # minimum distance value, from the set of vertices # not yet included in shortest path tree def minDistance(self, dist, sptSet):

# Initialize minimum distance for next node min = sys.maxsize

# Search not nearest vertex not in the # shortest path tree for v in range(self.V): if dist[v]

return min_index

# Function that implements Dijkstra's single source # shortest path algorithm for a graph represented # using adjacency matrix representation def dijkstra(self, src):

dist = [sys.maxsize] * self.V dist[src] = 0 sptSet = [False] * self.V

for cout in range(self.V):

# Pick the minimum distance vertex from # the set of vertices not yet processed. # u is always equal to src in first iteration u = self.minDistance(dist, sptSet)

# Put the minimum distance vertex in the # shortest path tree sptSet[u] = True

# Update dist value of the adjacent vertices # of the picked vertex only if the current # distance is greater than new distance and # the vertex in not in the shortest path tree for v in range(self.V): if self.graph[u][v] > 0 and sptSet[v] == False and dist[v] > dist[u] + self.graph[u][v]: dist[v] = dist[u] + self.graph[u][v]

self.printSolution(dist)

# Driver program g = Graph(9) g.graph = [[0, 4, 0, 0, 0, 0, 0, 8, 0], [4, 0, 8, 0, 0, 0, 0, 11, 0], [0, 8, 0, 7, 0, 4, 0, 0, 2], [0, 0, 7, 0, 9, 14, 0, 0, 0], [0, 0, 0, 9, 0, 10, 0, 0, 0], [0, 0, 4, 14, 10, 0, 2, 0, 0], [0, 0, 0, 0, 0, 2, 0, 1, 6], [8, 11, 0, 0, 0, 0, 1, 0, 7], [0, 0, 2, 0, 0, 0, 6, 7, 0] ]

g.dijkstra(0)image text in transcribed

M4/ 78 . 10 || IL13 14 15 17 9 10 12 | ID || 12 14 | 15 16 7 8 9 10 11 12 13 14 15 5 7 9 ID || 13 14 4578 ID 13 | 3 J) 0 \ 25 4 5 6 | 57KGD +23 st S 890

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions