Skip to content

Instantly share code, notes, and snippets.

@mikepsn
Last active September 9, 2016 10:02
Show Gist options
  • Save mikepsn/0e70af7382208b81e824e013eeacba5f to your computer and use it in GitHub Desktop.
Save mikepsn/0e70af7382208b81e824e013eeacba5f to your computer and use it in GitHub Desktop.
Early prototype for a subscription/observer pattern based simulation architecture from 1997.
"""
A very early prototype for a client/server push/observer type architecture
for a multi-agent simulation I was developing. Some of the ideas were
prototyped in Python 1.4 back in 1997-1998 (from memory).
The actual system was implemented in C++.
(c) Michael Papasimeon, 1998
"""
__author__ = 'mikepsn'
######################################
# SubscriptionInfo Class
######################################
class SubscriptionInfo:
def __init__(self):
self.subscribed = false
self.filterId = 0
# odata -> inherited class should add output data
def getSubscribed(self):
return self.subscribed
def setSubscribed(self, value):
self.subscribed = value
def getFilterId(self):
return self.filterId
def setFilterId(self, value):
self.filterId = value
######################################
# SubscriptionMatrix Class
######################################
class SubscriptionMatrix:
def __init__(self):
self.table = [[]]
def getElement(self, i, j):
if (i < len(self.table) and j < len(self.table[0])):
return self.table[i][j]
else:
raise IndexError
def setElement(self, i, j, value):
if (i < len(self.table) and j < len(self.table[0])):
self.table[i][j] = value
else:
raise IndexError
def addRow(self):
row_length = len(self.table[0])
new_row = []
for i in range(row_length):
new_row.append(i)
self.table.append(new_row)
def addColumn(self):
column_height = len(self.table)
for i in range(column_height):
self.table[i].append(i)
def printMatrix(self):
for i in range(len(self.table)):
print self.table[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment