{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A1 - Part B:*TooBike* (60/100 marks)\n", "\n", "## Overview\n", "You will be modifying and analysing a bikeshare model for...

1 answer below »
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A1 - Part B:*TooBike* (60/100 marks)\n",
"\n",
"## Overview\n",
"You will be modifying and analysing a bikeshare model for Toowoomba City Council (TCC). Your TCC bikeshare model will build on the bikeshare models presented in Chapters 2-4 of the *Modeling and Simulation in Python* textbook. \n",
"\n",
"### Toowoomba Bikeshare - *TooBike* \n",
"Toowoomba's reputation as a Garden City makes it a very popular tourist spot. TCC is interested in developing a bikeshare system for Toowoomba. Toowoomba's well-maintained bike trails and bikelanes on main streets are popular with residents and may also be popular with tourists.\n",
"\n",
"TCC wants to explore possible bike share scenarios which can accomadate both tourists and residents. For the inital *TooBike* trial, the council's financial advisors have agreed to fund **3 locations** and **45 bikes**. \n",
"\n",
"Modify the model functions and parameters below as necessary to support this bike share scenario.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Configure Jupyter so figures appear in the notebook\n",
"%matplotlib inline\n",
"\n",
"# Configure Jupyter to display the assigned value after an assignment\n",
"%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'\n",
"\n",
"# import functions from the modsim li
ary\n",
"from modsim import *\n",
"\n",
"# set the random number generator\n",
"np.random.seed(0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## B1: TooBike Model (20 marks)\n",
"Create a *TooBike* model with three bikeshare locations. Your model must include the functions listed below, modified as necessary to model 3 bikeshare locations instead of 2.\n",
"\n",
"The bikeshare model functions provided below were adapted from the Chapter 2 through Chapter 4 models. \n",
"\n",
"1. **Create as many new functions as necessary** to model travelling from->to for 3 bikeshare locations. The three locations are named: `TB1`, `TB2` and `TB3`. The `def bike_to_TB1_TB2(state)` function provided simulates a trip from `TB1` to `TB2`. \n",
"\n",
"2. For each of your *TooBike* functions, you are expected to **provide** an appropriate **Docstring** and **comments**. These should meet the guidelines discussed in Chapter 3 of *Modeling and Simulation in Python*. You should also provide appropriate comments for system parameters.\n",
"\n",
"3. **Complete the variable assignments** for `bike_system` and `trips`. Set the initial probability for all trips to `0.3`. The first bike station and trip have been provided for you. \n",
"\n",
"\n",
"\n",
"`def make_state(kwargs)`: \n",
" **More generalised version provided**: can simulate different bike system configurations without having to modify the function code. The initial system state is passed to the function in the parameter `kwargs`: a dictionary which contains **k**ey **w**ord **arg**ument**s**. The `kwargs` define the system's stations and theie initial distribution of bikes. \n",
" Review the `class ModSimSeries(pd.Series)` __init__ method in the imported `modsim.py` li
ary. The init method's option to allow key word arguments provides the flexibility to dynamically generate a State object. Use as is. Do not change function code.\n",
"\n",
"`def step(state, trips)`: \n",
" **More generalised version provided**: can simulate different bike system configurations without having to modify the functiton code. The trips parameter is a list of tuples: \n",
" `[(p1, bike_to_TB1_TB2), (p2, bike_to_TB2_TB1),...]`. Each tuple in the list provides the probability and the function to be called for each potential bike trip. Use as is. Do not change function code.\n",
" \n",
"`def run_simulation(state, trips, num_steps)`: \n",
" **More generalised version provided**. The `trips` parameter provides the probability and the function for each potential bike trip. Use as is. Do not change function code.\n",
"\n",
"`def check_first_empty(state)`:\n",
" **Extracted from `step()`** function so the step function could be generalised. This function checks the status of the model's bike stations. It sets the state.t_first_empty value as required. Update as required.\n",
"\n",
"`def bike_to_TB1_TB2(state)`: \n",
" **Create as many new functions as necessary** to model travelling from->to for 3 bikeshare locations. The function above will simulate a trip from `TB1` to `TB2`. Duplicate and update as required.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\" Update Variables and Functions as required \n",
" Simulate bikeshare system with 3 locations: TB1, TB2 and TB3. \n",
" Each station is allocated 15 bikes at the start of the simulation.\n",
"\"\"\" \n",
"\n",
"def make_state(kwargs):\n",
" \"\"\" Provide function Docstring and comments\n",
" \n",
" \"\"\" \n",
" state = State(kwargs)\n",
" return state\n",
"\n",
"def step(state, trips):\n",
" \"\"\" Provide function Docstring and comments\n",
" \n",
" \"\"\"\n",
" state.clock += 1\n",
"\n",
" for p, func in trips:\n",
" if flip(p):\n",
" func(state) \n",
" \n",
" if state.t_first_empty == -1:\n",
" check_first_empty(state)\n",
" \n",
" return\n",
"\n",
"def run_simulation(state, trips, num_steps):\n",
" \"\"\" Provide function Docstring and comments\n",
" \n",
" \"\"\"\n",
" for i in range(num_steps):\n",
" step(state, trips)\n",
" \n",
" return state\n",
"\n",
"\n",
"def check_first_empty(state):\n",
" \"\"\" Provide function Docstring and comments\n",
" \n",
" \"\"\"\n",
" if (???????) > 0:\n",
" state.t_first_empty = state.clock\n",
" \n",
" \n",
"def bike_to_TB1_TB2(state):\n",
" \"\"\" Provide function Docstring and comments\n",
" \n",
" \"\"\"\n",
" if state.TB1 == 0:\n",
" state.TB1_empty += 1\n",
" return\n",
" state.TB1 -= 1\n",
" state.TB2 += 1\n",
" \n",
"\n",
"##### \n",
"# Initial Bike system: 3 sites, 15 bikes each \n",
"bike_system = {'clock':0, 't_first_empty':-1, \n",
" 'resultsTB1':TimeSeries(),\n",
" 'resultsTB2':TimeSeries()\n",
" 'resultsTB3':TimeSeries(),\n",
" 'TB1':15, 'TB1_empty':0, ??????}\n",
"\n",
"########\n",
"# Update trips list to include a tuple for each possible bike trip.\n",
"# \n",
"# NOTE: The trips parameter must come after all of the function definitions.\n",
"# Each trip's tuple variable iincludes its bike function - bike_to_TB1_TB2.\n",
"# Therefore,
Answered 2 days AfterJul 18, 2022

Answer To: { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A1 - Part B:*TooBike* (60/100...

Jahir Abbas answered on Jul 20 2022
68 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here