Skip to content

Commit

Permalink
visualizing leaders vs non-leaders separately now
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo Biswas committed Apr 27, 2016
1 parent 221ebef commit ce20dc2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions datk/core/algs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
from distalgs import *
#Leader Election Algorithms for Ring networks:

class LCR(Synchronous_Algorithm):
class Leader_Election_Synchronous_Algorithm(Synchronous_Algorithm):
def draw(self,network):
vals = network.draw(node_coloring = True)
for p in network.processes:
v = vals[p.UID] # IMPORTANT: check to make sure this is right!
# if self.has(p, "decided"):
if p.state['status'] == "leader":
plt.plot( [v[0]], [v[1]], 'ro' )

else: # non-leader
plt.plot( [v[0]], [v[1]], 'bo' )

# else:
# plt.plot( [v[0]], [v[1]], 'go' )

plt.show()

class LCR(Leader_Election_Synchronous_Algorithm):
"""The LeLann, Chang and Roberts algorithm for Leader Election in a Synchronous Ring Network
Each Process sends its identifier around the ring.
Expand Down Expand Up @@ -42,6 +59,8 @@ def trans_i(self, p, msgs):
self.set(p, "send", None)
if self.r == p.state['n']: p.terminate(self)



class AsyncLCR(Asynchronous_Algorithm):
"""The LeLann, Chang and Roberts algorithm for Leader Election in an Asynchronous Ring Network
Expand Down Expand Up @@ -292,10 +311,9 @@ def trans_i(self, p, msgs):
p.terminate(self)

#TODO: Synchronous TimeSlice
class SynchTimeSlice(Synchronous_Algorithm):
class SynchTimeSlice(Leader_Election_Synchronous_Algorithm):
"""The TimeSlice algorithm in a Synchronous Ring Network """
def msgs_i(self, p):
print "nattar paneer"
msg = self.get(p, "send")
if msg:
if (self.r - 1)/p.state['n'] == msg.content-1:
Expand All @@ -317,12 +335,14 @@ def trans_i(self, p, msgs):
if (self.r - 1)/p.state['n'] == msg.content-1 and not self.has(p,"decided"):
self.set(p, 'decided', None)
self.output(p,"status", "non-leader")

self.set(p,"send", msg)

else:
self.set(p,"send",None)
p.terminate(self)


class SynchVariableSpeeds(Synchronous_Algorithm):
pass

Expand Down

0 comments on commit ce20dc2

Please sign in to comment.