Skip to content

Instantly share code, notes, and snippets.

import numpy as np
def calculate_q(k):
'''
Use a numerical root finder to determine q from the equation
q = exp(k*(q-1)).
'''
from scipy.optimize import root
return root(lambda q: q - np.exp(k * (q - 1)), 0).x[0]
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
from pylab import *
import networkx as nx
import numpy.random as rd
n = 15 #number of nodes
k = 3 # number of connections per node, to make (will increase as edges are added from each node)
def initialize():
import matplotlib
matplotlib.use('TkAgg')
from pylab import *
import networkx as nx
import random as rd
n = 30 # number of nodes
#k = 4 # number of neighbors of each node
def initialize():
#pull version
import matplotlib
matplotlib.use('TkAgg')
from pylab import *
import networkx as nx
import random as rd
import numpy as np
def initialize():
import numpy as np
import random as rd
import matplotlib.pyplot as plt
class TrafficSimulation():
def __init__(self, road_length, density, max_velocity, prob_slow, repetitions):
self.road_length = road_length
self.density = density
self.max_velocity = max_velocity
import numpy as np
import random as rd
class TrafficSimulation():
def __init__(self, road_length, density, max_velocity, prob_slow):
self.road_length = road_length
self.density = density
self.max_velocity = max_velocity
self.prob_slow = prob_slow
import matplotlib
matplotlib.use('TkAgg')
import pylab as PL
import random as RD
import scipy as SP
import numpy as np
RD.seed()
# Simple CA simulator in Python
#
# *** Hosts & Pathogens ***
#
# Copyright 2008-2012 Hiroki Sayama
# sayama@binghamton.edu
# Modified to run with Python 3
import matplotlib
#Exercise 11.3
import matplotlib
import fractions
from fractions import *
matplotlib.use('TkAgg')
from pylab import *
n = 100 # size of space: n x n
p = 0.1 # probability of initially panicky individuals
import random
from random import randint, choice
import numpy as np
import itertools
random.seed(1)
class Passenger():
def __init__(self, desired_floor = 0, current_floor = 0):