<jupyter_start><jupyter_text>Group Members * <NAME>* <NAME> * <NAME>  Library Imports<jupyter_code>!pip install pint
from modsim import* 
import random  # Used for random bike selection 
import math    # Used for floor function
random.seed(7)  
import numpy as np<jupyter_output>Requirement already satisfied: pint in c:\python\python37\lib\site-packages (0.9)<jupyter_text>Helper Functions<jupyter_code>"""
* Checks to see if the bike is avaiable at the location or not.
"""
def check_avail(bikeLocation, target):
    for i in bikeLocation: 
        if i == target: 
            return True
    return False

"""
* Updates all counters and runs simulations for accidents happening, updating if necessary.
"""

def update_counters(numRides, broken, choice, p3):
    numRides[choice] += 1
    if(flip(p3)): 
        broken[choice]+=1
    if(numRides[choice]%100 == 0 and numRides[choice]>0):
        broken[choice]+=1

"""
* Models a bike leaving Queens Hall and going to Kiely Hall. 
"""

def bike_to_ky (bikeLocation, numRides, broken, p3):
      
    if not check_avail(bikeLocation, 1):
        return
    
    found = False
    while(not found):
        choice = random.randint(0, 9)
        if bikeLocation[choice] == 1:
            bikeLocation[choice]= 0
            update_counters(numRides, broken, choice, p3)
            break

"""
* Models a bike leaving Kiely Hall and going to Queen's Hall. 
"""
            
def bike_to_qh (bikeLocation, numRides, broken, p3):
    
    if not check_avail(bikeLocation, 0):
        return

    found = False
    while(not found):
        choice = random.randint(0, 9)
        if bikeLocation[choice] == 0:
            bikeLocation[choice]= 1
            update_counters(numRides, broken, choice, p3)
            break

"""
* Prints all list items horizontally, with a tab space b/w them. 
* Useful for debugging and displaying the status of the simulation.
"""

def print_list(list):
    for i in list:
        print(i, "\t", end = "")
    print("\n")

"""
* Returns the sum of all numbers in a list. 
"""    
    
def sum_list(list):
    val = 0
    for i in list:
        val += i 
    return val

def step (bikeLocation, numRides, broken, p1, p2, p3):
    if (flip(p1)):
        bike_to_ky(bikeLocation, numRides, broken, p3)
    if (flip(p2)):
        bike_to_qh(bikeLocation, numRides, broken, p3)<jupyter_output><empty_output><jupyter_text>Simulation<jupyter_code>def run_simulation(bikeLocation, numRides, broken, 
                   resultsBreaks, resultsRides, 
                   numSteps,
                   p1, p2, p3):
    for i in range(numSteps):
        step (bikeLocation, numRides, broken, p1, p2, p3)
        resultsBreaks[i] = sum_list(broken)
        resultsRides[i]  = sum_list(numRides)<jupyter_output><empty_output><jupyter_text>Variables and Simulation Configuration  bikeLocationSimulates the Rack at Kiely and Queens Hall * 0 --> Bike is at Kiely * 1 --> Bike is at Queens Hall<jupyter_code>bikeLocation = ([0,0,0,0,0,1,1,1,1,1])<jupyter_output><empty_output><jupyter_text>numRides * Tracks the number of time a specific bike has been ridden.<jupyter_code>numRides = ([0,0,0,0,0,0,0,0,0,0])<jupyter_output><empty_output><jupyter_text>numSteps * Determines how many minutes the simulation is run for.<jupyter_code>numSteps = 16800<jupyter_output><empty_output><jupyter_text>broken* Tracks the number of time a specific bike breaks.<jupyter_code>broken = ([0,0,0,0,0,0,0,0,0,0])<jupyter_output><empty_output><jupyter_text>resultsBreaks* Tracks cumulative breakings at a unit of time.<jupyter_code>resultsBreaks = TimeSeries()<jupyter_output><empty_output><jupyter_text>resultsRides* Tracks cumulative rides at a unit of time.<jupyter_code>resultsRides=TimeSeries()<jupyter_output><empty_output><jupyter_text>Probabilities * p1 : Probability of Ride to Kiely Hall * p2 : Probability of Riding to Queens Hall.  * p3 : Probability of an accident happening.<jupyter_code>p1 = .5
p2 = .5
p3 = 0.001<jupyter_output><empty_output><jupyter_text>Visual of the Setup<jupyter_code>print("Bike Locations (0 - Kiely, 1 - Queen's Hall): ")
print_list(bikeLocation)
print("Number of rides per bike: ")
print_list(numRides)
print("Number of times each bike broke: ")
print_list(broken)<jupyter_output>Bike Locations (0 - Kiely, 1 - Queen's Hall): 
0 	0 	0 	0 	0 	1 	1 	1 	1 	1 	

Number of rides per bike: 
0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	

Number of times each bike broke: 
0 	0 	0 	0 	0 	0 	0 	0 	0 	0<jupyter_text>Simulation and Config. Variables<jupyter_code>bikeLocation = ([0,0,0,0,0,1,1,1,1,1])
numRides = ([0,0,0,0,0,0,0,0,0,0])
broken = ([0,0,0,0,0,0,0,0,0,0])
numSteps = 16800
resultsBreaks = TimeSeries()
resultsRides=TimeSeries()
p1 = .5
p2 = .5
p3 = 0.001
run_simulation(bikeLocation, numRides, broken, resultsBreaks, resultsRides, numSteps, p1, p2, p3)<jupyter_output><empty_output><jupyter_text>Results With Respect To Minutes<jupyter_code>plot(resultsRides, label='Total Rides/Time')
decorate(title='Queens College Bikeshare',
         xlabel='Time Step (min)', 
         ylabel='Number of Rides')

plot(resultsBreaks, label='Total Breaks/Time')
decorate(title='Queens College Bikeshare',
         xlabel='Time Step (min)', 
         ylabel='Number of Breaks')<jupyter_output><empty_output><jupyter_text>Results With Respect to Weeks<jupyter_code>plt.xticks(range(0,20000, 4200))
xaxis_labels = ('Week 1','Week  2','Week  3','Week  4', 'Week  5')
xaxis_pos    = (range(0,20000, 4200))
plt.xticks(xaxis_pos, xaxis_labels)
plot(resultsRides, label='Total Rides/Time')
decorate(title='Queens College Bikeshare',
         xlabel='Time Step Weeks', 
         ylabel='Number of Rides')

plt.xticks(range(0,20000, 4200))
xaxis_labels = ('Week 1','Week  2','Week  3','Week  4', 'Week  5')
xaxis_pos    = (range(0,20000, 4200))
plt.xticks(xaxis_pos, xaxis_labels)
plot(resultsBreaks, label='Total Breaks/Time')
decorate(title='Queens College Bikeshare',
         xlabel='Time Step Weeks', 
         ylabel='Number of Breaks')
totalRides = sum_list(numRides)
totalBrokenBikes = sum_list(broken)
# One repair costs $20
costPerRide =  (totalBrokenBikes*20) / totalRides
print("The total number of rides for ALL bikes:\t", totalRides)
print("The total number of breaks for ALL bikes:\t", totalBrokenBikes)
print("The cost per ride comes out to be:\t\t$", costPerRide, "= ", math.ceil(costPerRide))<jupyter_output>The total number of rides for ALL bikes:	 16070
The total number of breaks for ALL bikes:	 173
The cost per ride comes out to be:		$ 0.21530802738021157 =  1
{'fraction_non_alphanumeric': 0.1173406862745098, 'fraction_numerical': 0.0389093137254902, 'mean_word_length': 4.026173979984604, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '536517', 'license': 'Apache-2.0', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2348, 'n_words': 609, 'path': 'Bikeshare-Model/Project-1-Bike-Share.ipynb', 'repo_name': 'mtkhawaja/Mathematical-Modelling', 'size': '6554'}