Skip to content

Commit

Permalink
Minor edit: propogation -> propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtch committed Dec 18, 2016
1 parent 33470a1 commit f684f05
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 77 deletions.
151 changes: 76 additions & 75 deletions location.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ def __init__(self, location = None):

self.city = location if location else random.choice(Location.calculator.locations)

def propogationDelayFrom(self, location):
return Location.calculator.getPropogation(self.city, location.city)
def propagationDelayFrom(self, location):
return Location.calculator.getPropagation(self.city, location.city)

class LocationCalculator(object):

def __init__(self):
self.propogations = {}
self.createPropogationMatrix()
self.propagations = {}
self.createPropagationMatrix()

def addPropogation(self, c1, c2, delay):
def addPropagation(self, c1, c2, delay):
pair = (c1, c2) if c1 < c2 else (c2, c1)
self.propogations[pair] = delay
self.propagations[pair] = delay

def getPropogation(self, c1, c2):
def getPropagation(self, c1, c2):
if c1 == c2:
return 5

pair = (c1, c2) if c1 < c2 else (c2, c1)
if pair in self.propogations:
return self.propogations[pair]
if pair in self.propagations:
return self.propagations[pair]

return None

Expand All @@ -47,73 +47,74 @@ def getPropogation(self, c1, c2):
"Washington"
}

def createPropogationMatrix(self):
self.addPropogation("Atlanta", "Austin", 24)
self.addPropogation("Atlanta", "Cambridge", 29)
self.addPropogation("Atlanta", "Chicago", 26)
self.addPropogation("Atlanta", "Denver", 38)
self.addPropogation("Atlanta", "New York", 24)
self.addPropogation("Atlanta", "Orlando", 11)
self.addPropogation("Atlanta", "Philadelphia", 22)
self.addPropogation("Atlanta", "San Francisco", 60)
self.addPropogation("Atlanta", "Seattle", 72)
self.addPropogation("Atlanta", "Washington", 19)

self.addPropogation("Austin", "Cambridge", 52)
self.addPropogation("Austin", "Chicago", 33)
self.addPropogation("Austin", "Denver", 25)
self.addPropogation("Austin", "New York", 45)
self.addPropogation("Austin", "Orlando", 28)
self.addPropogation("Austin", "Philadelphia", 46)
self.addPropogation("Austin", "San Francisco", 49)
self.addPropogation("Austin", "Seattle", 58)
self.addPropogation("Austin", "Washington", 40)

self.addPropogation("Cambridge", "Chicago", 27)
self.addPropogation("Cambridge", "Denver", 47)
self.addPropogation("Cambridge", "New York", 6)
self.addPropogation("Cambridge", "Orlando", 40)
self.addPropogation("Cambridge", "Philadelphia", 9)
self.addPropogation("Cambridge", "San Francisco", 76)
self.addPropogation("Cambridge", "Seattle", 72)
self.addPropogation("Cambridge", "Washington", 11)

self.addPropogation("Chicago", "Denver", 21)
self.addPropogation("Chicago", "New York", 20)
self.addPropogation("Chicago", "Orlando", 37)
self.addPropogation("Chicago", "Philadelphia", 18)
self.addPropogation("Chicago", "San Francisco", 50)
self.addPropogation("Chicago", "Seattle", 47)
self.addPropogation("Chicago", "Washington", 22)

self.addPropogation("Denver", "New York", 42)
self.addPropogation("Denver", "Orlando", 46)
self.addPropogation("Denver", "Philadelphia", 39)
self.addPropogation("Denver", "San Francisco", 30)
self.addPropogation("Denver", "Seattle", 34)
self.addPropogation("Denver", "Washington", 42)

self.addPropogation("New York", "Orlando", 35)
self.addPropogation("New York", "Philadelphia", 4)
self.addPropogation("New York", "San Francisco", 71)
self.addPropogation("New York", "Seattle", 68)
self.addPropogation("New York", "Washington", 5)

self.addPropogation("Orlando", "Philadelphia", 33)
self.addPropogation("Orlando", "San Francisco", 68)
self.addPropogation("Orlando", "Seattle", 81)
self.addPropogation("Orlando", "Washington", 30)

self.addPropogation("Philadelphia", "San Francisco", 68)
self.addPropogation("Philadelphia", "Seattle", 64)
self.addPropogation("Philadelphia", "Washington", 30)

self.addPropogation("San Francsico", "Seattle", 60)
self.addPropogation("San Francsico", "Washington", 41)

self.addPropogation("Washington", "Seattle", 68)
def createPropagationMatrix(self):
self.addPropagation("Atlanta", "Austin", 24)
self.addPropagation("Atlanta", "Cambridge", 29)
self.addPropagation("Atlanta", "Chicago", 26)
self.addPropagation("Atlanta", "Denver", 38)
self.addPropagation("Atlanta", "New York", 24)
self.addPropagation("Atlanta", "Orlando", 11)
self.addPropagation("Atlanta", "Philadelphia", 22)
self.addPropagation("Atlanta", "San Francisco", 60)
self.addPropagation("Atlanta", "Seattle", 72)
self.addPropagation("Atlanta", "Washington", 19)

self.addPropagation("Austin", "Cambridge", 52)
self.addPropagation("Austin", "Chicago", 33)
self.addPropagation("Austin", "Denver", 25)
self.addPropagation("Austin", "New York", 45)
self.addPropagation("Austin", "Orlando", 28)
self.addPropagation("Austin", "Philadelphia", 46)
self.addPropagation("Austin", "San Francisco", 49)
self.addPropagation("Austin", "Seattle", 58)
self.addPropagation("Austin", "Washington", 40)

self.addPropagation("Cambridge", "Chicago", 27)
self.addPropagation("Cambridge", "Denver", 47)
self.addPropagation("Cambridge", "New York", 6)
self.addPropagation("Cambridge", "Orlando", 40)
self.addPropagation("Cambridge", "Philadelphia", 9)
self.addPropagation("Cambridge", "San Francisco", 76)
self.addPropagation("Cambridge", "Seattle", 72)
self.addPropagation("Cambridge", "Washington", 11)

self.addPropagation("Chicago", "Denver", 21)
self.addPropagation("Chicago", "New York", 20)
self.addPropagation("Chicago", "Orlando", 37)
self.addPropagation("Chicago", "Philadelphia", 18)
self.addPropagation("Chicago", "San Francisco", 50)
self.addPropagation("Chicago", "Seattle", 47)
self.addPropagation("Chicago", "Washington", 22)

self.addPropagation("Denver", "New York", 42)
self.addPropagation("Denver", "Orlando", 46)
self.addPropagation("Denver", "Philadelphia", 39)
self.addPropagation("Denver", "San Francisco", 30)
self.addPropagation("Denver", "Seattle", 34)
self.addPropagation("Denver", "Washington", 42)

self.addPropagation("New York", "Orlando", 35)
self.addPropagation("New York", "Philadelphia", 4)
self.addPropagation("New York", "San Francisco", 71)
self.addPropagation("New York", "Seattle", 68)
self.addPropagation("New York", "Washington", 5)

self.addPropagation("Orlando", "Philadelphia", 33)
self.addPropagation("Orlando", "San Francisco", 68)
self.addPropagation("Orlando", "Seattle", 81)
self.addPropagation("Orlando", "Washington", 30)

self.addPropagation("Philadelphia", "San Francisco", 68)
self.addPropagation("Philadelphia", "Seattle", 64)
self.addPropagation("Philadelphia", "Washington", 30)

self.addPropagation("San Francsico", "Seattle", 60)
self.addPropagation("San Francsico", "Washington", 41)

self.addPropagation("Washington", "Seattle", 68)

if __name__ == "__main__":
loc1 = Location("Washington")
loc2 = Location("Chicago")
print "Delay from " + loc1.city + " to " + loc2.city + " is " + str(loc1.propogationDelayFrom(loc2)) + " ms"
print "Delay from " + loc1.city + " to " + loc2.city + " is
" + str(loc1.propagationDelayFrom(loc2)) + " ms"
4 changes: 2 additions & 2 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def sendPacket(self, packet, loc1, loc2):
if random.random() < self.packet_loss_prob:
return 0

# Otherwise, return propogation delay
return loc1.propogationDelayFrom(loc2)
# Otherwise, return propagation delay
return loc1.propagationDelayFrom(loc2)

class TCP(Network):

Expand Down

0 comments on commit f684f05

Please sign in to comment.