aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prelim.py139
1 files changed, 96 insertions, 43 deletions
diff --git a/prelim.py b/prelim.py
index 6a4b825..192ccca 100644
--- a/prelim.py
+++ b/prelim.py
@@ -1,37 +1,82 @@
+import pandas as pd
+import random as rand
+import string
+
"""
-priest ledger format
--------------------
-front #denotes the start of the actual ledger
-0/1,n,0/1,x #voted or not, ballot number, promised or not, adder multiplier
+===============================
+
+priest ledger format:
+voted or not, ballot number, promised or not, times led
+0/1,n,0/1,x
+
promised or not explanation: whether or not this priest has promised to not
respond to maxvote requests after this ballot
-adder multiplier explanation: (see doc for messenger)
+times led explanation: number of times she's been leader
+ (see doc for messenger)
+===============================
+
+priest messagebook format:
+(priests will track these for changes by messenger)
+
+from,code
+n,1/2/3
+
+codes (not leader):
+1: next ballot
+2: begin ballot
+3: successful ballot
+
+codes (leader):
+===============================
+
+sequence of code writing (may provide intuition for future folks):
+- skeleton
+- priest init
+- leader_main
+- god init
+- next_ballot
+- send_next_ballot
+===============================
"""
+
+
"""
-paxons are very religious; god controls anything and everything and the synod ritual
-lies in that domain (of anything and everything, that is)
-- literally creates leaders and priests ie initializes the objects
+paxons are very religious; god controls anything and everything
+
+- literally creates priests ie initializes the objects
- assigns ballot number ranges for each priest (so B1 is satisfied)
"""
class god:
- pass
+
+ num_priests = 0
+ priests = {}
+
+ def __init__(self, num_priests, num_ballots, offset=100):
+ self.num_priests = num_priests
+ self.num_ballots = num_ballots
+
+ #create and name the priests (quite godly)
+ for x in range(0, self.num_priests):
+ self.priests[x] = priest(name, (x+1)*offset)
+
"""
messenger relays messages to and from the leader and the priest
she accomplishes this by tracking the priests' ledger files for changes
-each priest (including the leader) has a personal messenger
+each priest (including the leader) has a personal messenger (instance)
"""
-class messenger():
+class messenger(god):
"""
leader messenger functions
"""
- def send_next_ballot():
+ def send_next_ballot(current_list, ballot_num):
pass
+
def send_begin_ballot():
pass
@@ -48,32 +93,59 @@ class messenger():
def send_vote():
pass
-
"""
priests are present (or not present) and vote (or not vote) for ballots proposed
by the leader
they record all ballots they have participated in in individual ledger files
-note: unique sets of numbers are created by an 'adder': starting from a base value,
-each priest determines next ballot number by adding adder*x where x is the number of
-ballots he's assigned numbers before the current ballot
+start offset is the offset by which a priest starts assigning ballot numbers when
+he is assigned leader to satisfy B1
+
+ex. priests (A, B, C) have offsets (100, 200, 300) (this assumes maximum of 99 ballots)
+leader sequence (determined randomly by god): A B A C B A
+resulting ballot numbers: 100 200 101 300 201 102
"""
-class priest(god, messenger):
+class priest(messenger):
+
+ def __init__(self, name, start_offset):
- def __init__(self, name, is_leader, adder):
self.name = name #write this name in the ledger in case it gets lost (ledger fileaname)
- self.is_leader = is_leader
self.messenger = messenger() #hire a messenger
- self.adder = adder
self.ledger = open("ledgers/" + self.name, "+")
+ self.offset = offset
+
+ #=====================leader functions===================
+ def leader_main():
+ times_led = self.ledger.at[self.ledger.shape[0]-1,'times_led'] #last col of last row of ledger
+ ballot_num = self.offset + times_led #B1 is satisfied assuming num_ballots < difference between offsets
- #if(self.is_leader):
-
-
+ self.next_ballot(ballot_num)
+ self.begin_ballot()
+
+ def next_ballot(ballot_num):
+ #randomly choose a number of priests: 40% - 100% of total priests
+ rand_num = random.randrange(num_priests*0.4, num_priests+1)
+ current_priests = random.sample(priests.keys(), rand_num)
+
+ #Send the nextBallot message to the priests and wait for their responses
+ messenger.send_next_ballot(current_list, ballot_num)
+
+ def begin_ballot():
+ #wait for all threads to respond
+ #send message to every priest indicating that his vote is requested
+
+ def evaluate():
+ pass
+ #check if the ballot was a success and note the decree if it was
+
+ #send the sucess message to all living priests
- #====================regular priest functions======================
+ #====================regular priest functions======================
+ def priest_main():
+ pass
+
def last_vote():
pass
#responding to a next_ballot request from the leader
@@ -91,25 +163,6 @@ class priest(god, messenger):
def on_success():
pass
#do something if the messenger brings the good news of a ballot success
-
- #=====================leader functions===================
- def next_ballot(ballot_num):
- pass
- #randomly choose a majority set of priests
-
- #send the nextBallot message to the priests and wait for their responses
-
- def begin_ballot():
- pass
- #send message to every priest indicating that his vote is requested
-
- def evaluate():
- pass
- #check if the ballot was a success and note the decree if it was
-
- #send the sucess message to all living priests
-
-