0% found this document useful (0 votes)
33 views

Implementation of Vector Clock

This document implements a vector clock algorithm. It takes the number of events on two sides as input. It initializes two lists to track the vector clocks for each side. It then takes input for the relation between events and updates the vector clocks based on happened-before relations, ensuring each entry is greater than or equal to the last. Finally, it prints the updated vector clocks.

Uploaded by

DEEPAK RAJ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Implementation of Vector Clock

This document implements a vector clock algorithm. It takes the number of events on two sides as input. It initializes two lists to track the vector clocks for each side. It then takes input for the relation between events and updates the vector clocks based on happened-before relations, ensuring each entry is greater than or equal to the last. Finally, it prints the updated vector clocks.

Uploaded by

DEEPAK RAJ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

IMPLEMENTATION OF VECTOR

CLOCK
E1 = int(input("Enter the no of event at Side 1:"))

E2 = int(input("Enter the no of event at Side 2:"))

L1 = []

L2 = []

rec = []

for i in range(E1):

L1.append([i+1,0]);

for j in range(E2):

L2.append([0,j+1])

for i in range(E1):

temp = list(map(int,input().split()))

rec.append(temp)

for i in range(E1):

for j in range(E2):

if(rec[i][j] == -1):

A,B = L1[i][1],L2[j][1]

L1[i][1] = max((L1[i][1]),(L2[j][1]))

if(A< B):

for k in range(i+1,E1):

L1[k][1] = L1[k-1][1]

elif(rec[i][j] == 1):

A,B = L1[i][0],L2[j][0]
L2[j][0] = max((L2[j][0]),L1[i][0])

if(B < A):

for k in range(j+1,E2):

L2[k][0] = L2[k-1][0]

print(*L1)

print(*L2)

OUTPUT:

You might also like