CSCS530 Winter 2015

Complex Systems 530 - Computer Modeling of Complex Systems (Winter 2015)

View this repository on NBViewer

In [11]:
%matplotlib inline
import copy
import itertools

import numpy
import matplotlib.pyplot as plt
import pandas

import seaborn; seaborn.set()

# Import widget methods
from IPython.html.widgets import *


class classModel():
    def __init__(self):
        self.gridSize = 10
        self.numPeople = 25
        self.condoms = False
        self.space = numpy.zeros((self.gridSize, self.gridSize))
        self.personList = []
        self.window = 1
        
    def createPeople(self):
        for x in xrange(self.numPeople):
            self.personList.append(person())
            xloc = numpy.random.randint(self.gridSize)
            yloc = numpy.random.randint(self.gridSize)
            while self.space[xloc,yloc] == 1:
                xloc = numpy.random.randint(self.gridSize)
                yloc = numpy.random.randint(self.gridSize)
            person.locationx=xloc
            person.locationy=yloc
            self.space[xloc,yloc] = 1 
        personLocation = numpy.random.randint(self.numPeople)
        self.personList[personLocation].infected = True 

    def step(self):
        for person in self.personList:
            if person.infected == True:
                # Find neighbors
                row = person.locationx
                col = person.locationy
                neighbor_ps = [ ( x % self.gridSize, y % self.gridSize )
                                for x, y in itertools.product(range(row-1, row+1),
                                range(col-1, col+1))]
                print neighbor_ps
                
                # Infect neighbors based on whether or not there are condoms in the world
                
class person():
    def __init__(self):
        self.infected = False
        self.locationx = 0
        self.locationy = 0 


model = classModel() # create a model instance
model.createPeople() # create people for the model
model.step() # step through the model
[(9, 9), (9, 0), (0, 9), (0, 0)]
In [7]:
 
In [7]:
 
In [7]:
 
In [ ]: