Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I will provide the code of the Vertex Coloring Algorithm and i need description of high level design with FSM diagrams and FSM table.And either

I will provide the code of the Vertex Coloring Algorithm and i need description of high level design with FSM diagrams and FSM table.And either give the pseudocode of actions or the pseudocode of the whole algorithm.The pictures are about Bully Algorithm. What i want is the same version of the FSM and FSM table of Vertex Coloring Algorithm that i will provide.
from mpi4py import MPI
import numpy as np
# MPI setup
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
n = comm.Get_size()
# Message types
IDLE =0
COLORED =1
TERMINATE =2
ROUND =0
UPDATE =1
ACK =2
DISCARD =3
ROVER =4
TERMINATE =5
# Spanning tree of graph
ROOT =0
A = np.array([[0,0,0,1,1,0,0,1],
[0,0,0,0,0,1,0,1],
[0,0,0,1,1,0,1,0],
[1,0,1,0,1,0,1,0],
[1,0,1,1,0,1,0,1],
[0,1,0,0,1,0,0,1],
[0,0,1,1,0,0,0,0],
[1,1,0,0,1,1,0,0]], dtype=int)
children =[[3],[],[4],[6],[7],[1],[2],[5]]
parents =[0,5,6,0,2,7,3,4]
# Process state and communication variables
state = IDLE
parent = parents[rank]
childs = set(children[rank])
neighs = indices_set = set(i for i, value in enumerate(A[rank]) if value ==1)
n_neighs = neighs.copy()
neighs_received = set()
rovers_received = set()
round_received = False
color =-1
banned_colors = set()
msg =[-1,-1, None] # sender, type, data
round =[-1, False] # round number, round over
# Function to find the smallest available color
def find_smallest_available_color():
global banned_colors
candidate_color =0
while candidate_color in banned_colors:
candidate_color +=1
return candidate_color
# Function to check if the process has the highest degree in not colored neighbors
def highest_degree_in_not_colored_neighbors():
global n_neighs
return not n_neighs or rank > max(n_neighs)
while state != TERMINATE:
round[1]= False
neighs_received.clear()
rovers_received.clear()
round_received = False
if rank ==0:
if state == COLORED:
term_msg = msg.copy()
term_msg[0], term_msg[1]= rank, TERMINATE
comm.send(obj=term_msg, dest=ROOT, tag=TERMINATE)
else:
round[0]+=1
round_msg = msg.copy()
round_msg[0], round_msg[1], round_msg[2]= rank, ROUND, round[0]
comm.send(obj=round_msg, dest=ROOT, tag=ROUND)
while not round[1]:
sender,_type, data = comm.recv()
if _type == ROUND:
round[0]= data
round_msg = msg.copy()
round_msg[0], round_msg[1], round_msg[2]= rank, ROUND, data
for child in childs:
comm.send(obj=round_msg, dest=child, tag=ROUND)
if state == COLORED:
discard_msg = msg.copy()
discard_msg[0], discard_msg[1]= rank, DISCARD
for neigh in neighs:
comm.send(obj=discard_msg, dest=neigh, tag=DISCARD)
else:
if highest_degree_in_not_colored_neighbors():
color = find_smallest_available_color()
state = COLORED
update_msg = msg.copy()
update_msg[0], update_msg[1], update_msg[2]= rank, UPDATE, color for neigh in n_neighs:
comm.send(obj=update_msg, dest=neigh, tag=UPDATE)
else:
discard_msg = msg.copy()
discard_msg[0], discard_msg[1]= rank, DISCARD
for neigh in neighs:
comm.send(obj=discard_msg, dest=neigh, tag=DISCARD)
round_received = True
elif _type == UPDATE:
neighs_received.add(sender)
ack_msg = msg.copy()
ack_msg[0], ack_msg[1]= rank, ACK
comm.send(obj=ack_msg, dest=sender, tag=ACK)
if state != COLORED:
n_neighs.remove(sender)
banned_colors.add(data)
elif _type == DISCARD:
neighs_received.add(sender)
elif _type == ACK:
neighs_received.add(sender)
elif _type == ROVER:
rovers_received.add(sender)
elif _type == TERMINATE:
if childs:
for child in childs:
term_msg = msg.copy()
term_msg[0], term_msg[1]= rank, TERMINATE
state = TERMINATE
break
# Check conditions for round completion
if round_received and neighs.issubset(neighs_received) and len(childs)== len(rovers_received):
rover_msg = msg.copy()
rover_msg[0], rover_msg[1]= rank, ROVER
comm.send(obj=rover_msg, dest=parent, tag=ROVER)
round[1]= True
print(f'I am rank {rank} and my color {color}')

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions