from modsim import *
def step(state, p1, p2):
"""Simulate one time step.
state: bikeshare State object
p1: probability of an Olin->Wellesley ride
p2: probability of a Wellesley->Olin ride
"""
if flip(p1):
bike_to_wellesley(state)
if flip(p2):
bike_to_olin(state)
from modsim import *
def bike_to_olin(state):
"""Move one bike from Wellesley to Olin.
state: bikeshare State object
"""
if state.wellesley == 0:
state.wellesley_empty += 1
return
state.wellesley -= 1
state.olin += 1
from modsim import *
def bike_to_wellesley(state):
"""Move one bike from Olin to Wellesley.
state: bikeshare State object
"""
if state.olin == 0:
state.olin_empty += 1
return
state.olin -= 1
state.wellesley += 1