{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e68f7f84-3887-4464-99e2-9c759a4d778d", "metadata": {}, "outputs": [], "source": [ "#You don't need to change anything in this block, although the modules need to be installed to run this notebook\n", "\n", "#We import numpy to handle vectors and some math\n", "import numpy as np\n", "\n", "#We import pandas to create a data frame of the experiment data\n", "#Such a table can later be used for plotting our results\n", "import pandas as pd\n", "\n", "#We import bokeh to create a small application that plots our stored results\n", "from bokeh.themes import Theme\n", "from bokeh.io import show, output_notebook, curdoc\n", "from bokeh.plotting import figure\n", "from bokeh.transform import linear_cmap, factor_cmap\n", "from bokeh.palettes import Spectral6\n", "from bokeh.models import ColumnDataSource, Slider, Column, Toggle\n", "from bokeh.server import callbacks" ] }, { "cell_type": "code", "execution_count": 2, "id": "66e49112-405a-4e42-8346-37209a3eeff9", "metadata": {}, "outputs": [], "source": [ "#You don't need to change anything in this block\n", "\n", "def get_initial_followers_state():\n", " '''Generates the state of follower particles for t0'''\n", " followers_positions = 2 * (np.random.rand(num_followers, 2) - 0.5)\n", " followers_velocities = np.zeros((num_followers, 2))\n", " return followers_positions, followers_velocities\n", "\n", "def get_leader_position(t):\n", " '''Generates the position of the leader based on input time'''\n", " step_size = leader_speed\n", " distance_covered = step_size * t\n", " \n", " circle_radius = 1\n", " circle_circumference = 2 * circle_radius * np.pi\n", " percent_circle_completed = distance_covered / circle_circumference\n", " radians = percent_circle_completed * 2 * np.pi\n", " \n", " leader_x = np.sin(radians)\n", " leader_y = np.cos(radians)\n", " return np.array([leader_x, leader_y])\n", "\n", "def magnitude(vector):\n", " '''Returns the magnitude of a vector'''\n", " return np.linalg.norm(vector)\n", "\n", "def distance_between(position, goal):\n", " '''Returns the distance between two points'''\n", " return magnitude(goal - position)\n", "\n", "def vector_towards(position, goal):\n", " '''Returns the vector that points from the position to the goal'''\n", " return goal - position\n", "\n", "def direction_towards(position, goal):\n", " '''Returns a vector pointing from the position towards the goal with magnitude 1'''\n", " return (goal - position) / magnitude(goal - position)\n", "\n", "def to_dataframe(t, followers_positions, leader_position):\n", " '''Converts the particle state at one timestep to a dataframe'''\n", " df = pd.DataFrame()\n", " df['t'] = np.repeat(t, num_followers + 1)\n", " df['type'] = np.append(np.repeat('Follower', num_followers), 'Leader')\n", " df['x'] = np.append(followers_positions[:, 0], leader_position[0])\n", " df['y'] = np.append(followers_positions[:, 1], leader_position[1])\n", " return df" ] }, { "cell_type": "code", "execution_count": 3, "id": "13963669-d1ce-4d3d-8aa3-17e17fe3df9e", "metadata": {}, "outputs": [], "source": [ "#Here we define the possible force functions (attraction / repulsion)\n", "#You can play around with the parameters of the functions or create your own functions\n", " \n", "def force_random(followers_positions, leader_position, d=0.7, k_followers=0.01, k_leader=0.5): \n", " '''Force function with linear attraction and distance proportional, random offset'''\n", " force = np.zeros((num_followers, 2))\n", " \n", " for i in range(num_followers):\n", " vector_to_leader = vector_towards(followers_positions[i], leader_position)\n", " force[i] += k_leader * (d - np.random.rand(2)) * vector_to_leader\n", " \n", " for j in range(num_followers):\n", " if i == j:\n", " continue\n", " vector_to_follower_j = vector_towards(followers_positions[i], followers_positions[j])\n", " force[i] += k_followers * (d - np.random.rand(2)) * vector_to_follower_j\n", " return force\n", "\n", "def force_simple_comfortable_distance(followers_positions, leader_position, d=0.5, k_followers=0.1, k_leader=0.5): \n", " '''Force function to keep a comfortable distance with linear attraction and repulsion'''\n", " force = np.zeros((num_followers, 2))\n", " \n", " for i in range(num_followers):\n", " distance_to_leader = distance_between(followers_positions[i], leader_position)\n", " direction_to_leader = direction_towards(followers_positions[i], leader_position)\n", " leader_force = k_leader * (distance_to_leader - d) * direction_to_leader\n", " \n", " cohesion_force = 0\n", " for j in range(num_followers):\n", " if i == j:\n", " continue\n", " distance_to_follower_j = distance_between(followers_positions[i], followers_positions[j])\n", " direction_to_follower_j = direction_towards(followers_positions[i], followers_positions[j])\n", " cohesion_force += k_followers * (distance_to_follower_j - d) * direction_to_follower_j\n", " \n", " force[i] = leader_force + cohesion_force\n", " return force" ] }, { "cell_type": "code", "execution_count": 4, "id": "c73b5de4-dbe6-4cd3-b5f8-97c2f04bfe03", "metadata": {}, "outputs": [], "source": [ "#You don't need to change anything in this block\n", "\n", "def update(followers_positions, followers_velocities, leader_position):\n", " '''Calculates new positions and velocities based on the state given as input'''\n", " new_velocities = inertia * followers_velocities + force_function(followers_positions, leader_position)\n", " new_positions = followers_positions + new_velocities\n", " return new_positions, new_velocities\n", "\n", "def run():\n", " '''Iterates over all time steps, updates the particle states, and writes each state to a dataframe'''\n", " data = []\n", " leader_position = get_leader_position(0)\n", " followers_positions, followers_velocities = get_initial_followers_state()\n", " data.append(to_dataframe(0, followers_positions, leader_position))\n", " \n", " for t in range(1, num_time_steps, 1):\n", " leader_position = get_leader_position(t)\n", " followers_positions, followers_velocities = update(followers_positions, followers_velocities, leader_position)\n", " data.append(to_dataframe(t, followers_positions, leader_position))\n", " \n", " return pd.concat(data)" ] }, { "cell_type": "code", "execution_count": 5, "id": "00df4831-389b-4c29-be4f-40bc00107bd1", "metadata": {}, "outputs": [], "source": [ "#You don't need to change anything in this block\n", "\n", "def bokeh_app(doc):\n", " '''Defining a small application to plot dataframes generated from the run function'''\n", " def callback_update():\n", " if toggle.active:\n", " slider.value += 1\n", " if slider.value > num_time_steps:\n", " slider.value = 0\n", " source.data = ColumnDataSource.from_df(df.loc[df.t.eq(slider.value)])\n", " \n", " toggle = Toggle(label=\"Play/Stop\")\n", " slider = Slider(start=0, end=num_time_steps-1, title=\"t\", value=0)\n", " \n", " source = ColumnDataSource(df.loc[df.t.eq(0)]) \n", " plot = figure(x_range=(-2.0,2.0), y_range=(-2.0,2.0))\n", " plot.circle(size=20, radius=0.05, alpha=0.75, source=source, x='x', y='y', color=factor_cmap('type', Spectral6, ['Follower', 'Leader']))\n", " \n", " layout = Column(slider, toggle, plot)\n", " \n", " doc.add_root(layout)\n", " doc.add_periodic_callback(callback_update, 50)\n", " doc.theme = Theme(json= {\n", " \"attrs\" : \n", " {\n", " \"Figure\" : \n", " {\n", " \"background_fill_color\" : \"#FAFAFA\",\n", " \"outline_line_color\" : \"white\",\n", " \"toolbar_location\" : \"above\",\n", " \"height\" : 500,\n", " \"width\" : 500\n", " },\n", " \"Grid\" : \n", " {\n", " \"grid_line_dash\" : [6, 4],\n", " \"grid_line_color\" : \"white\"\n", " }\n", " }\n", " })" ] }, { "cell_type": "code", "execution_count": 6, "id": "6c3fee9e-04fa-408c-b336-8a18a7bbd1d5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " \n", " Loading BokehJS ...\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "(function(root) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " const force = true;\n", "\n", " if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n", " root._bokeh_onload_callbacks = [];\n", " root._bokeh_is_loading = undefined;\n", " }\n", "\n", "const JS_MIME_TYPE = 'application/javascript';\n", " const HTML_MIME_TYPE = 'text/html';\n", " const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n", " const CLASS_NAME = 'output_bokeh rendered_html';\n", "\n", " /**\n", " * Render data to the DOM node\n", " */\n", " function render(props, node) {\n", " const script = document.createElement(\"script\");\n", " node.appendChild(script);\n", " }\n", "\n", " /**\n", " * Handle when an output is cleared or removed\n", " */\n", " function handleClearOutput(event, handle) {\n", " const cell = handle.cell;\n", "\n", " const id = cell.output_area._bokeh_element_id;\n", " const server_id = cell.output_area._bokeh_server_id;\n", " // Clean up Bokeh references\n", " if (id != null && id in Bokeh.index) {\n", " Bokeh.index[id].model.document.clear();\n", " delete Bokeh.index[id];\n", " }\n", "\n", " if (server_id !== undefined) {\n", " // Clean up Bokeh references\n", " const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n", " cell.notebook.kernel.execute(cmd_clean, {\n", " iopub: {\n", " output: function(msg) {\n", " const id = msg.content.text.trim();\n", " if (id in Bokeh.index) {\n", " Bokeh.index[id].model.document.clear();\n", " delete Bokeh.index[id];\n", " }\n", " }\n", " }\n", " });\n", " // Destroy server and session\n", " const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n", " cell.notebook.kernel.execute(cmd_destroy);\n", " }\n", " }\n", "\n", " /**\n", " * Handle when a new output is added\n", " */\n", " function handleAddOutput(event, handle) {\n", " const output_area = handle.output_area;\n", " const output = handle.output;\n", "\n", " // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n", " if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n", " return\n", " }\n", "\n", " const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", "\n", " if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n", " toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n", " // store reference to embed id on output_area\n", " output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", " }\n", " if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", " const bk_div = document.createElement(\"div\");\n", " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", " const script_attrs = bk_div.children[0].attributes;\n", " for (let i = 0; i < script_attrs.length; i++) {\n", " toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n", " toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n", " }\n", " // store reference to server id on output_area\n", " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", " }\n", " }\n", "\n", " function register_renderer(events, OutputArea) {\n", "\n", " function append_mime(data, metadata, element) {\n", " // create a DOM node to render to\n", " const toinsert = this.create_output_subarea(\n", " metadata,\n", " CLASS_NAME,\n", " EXEC_MIME_TYPE\n", " );\n", " this.keyboard_manager.register_events(toinsert);\n", " // Render to node\n", " const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", " render(props, toinsert[toinsert.length - 1]);\n", " element.append(toinsert);\n", " return toinsert\n", " }\n", "\n", " /* Handle when an output is cleared or removed */\n", " events.on('clear_output.CodeCell', handleClearOutput);\n", " events.on('delete.Cell', handleClearOutput);\n", "\n", " /* Handle when a new output is added */\n", " events.on('output_added.OutputArea', handleAddOutput);\n", "\n", " /**\n", " * Register the mime type and append_mime function with output_area\n", " */\n", " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", " /* Is output safe? */\n", " safe: true,\n", " /* Index of renderer in `output_area.display_order` */\n", " index: 0\n", " });\n", " }\n", "\n", " // register the mime type if in Jupyter Notebook environment and previously unregistered\n", " if (root.Jupyter !== undefined) {\n", " const events = require('base/js/events');\n", " const OutputArea = require('notebook/js/outputarea').OutputArea;\n", "\n", " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", " register_renderer(events, OutputArea);\n", " }\n", " }\n", " if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n", " root._bokeh_timeout = Date.now() + 5000;\n", " root._bokeh_failed_load = false;\n", " }\n", "\n", " const NB_LOAD_WARNING = {'data': {'text/html':\n", " \"
\\n\"+\n", " \"

\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"

\\n\"+\n", " \"\\n\"+\n", " \"\\n\"+\n", " \"from bokeh.resources import INLINE\\n\"+\n", " \"output_notebook(resources=INLINE)\\n\"+\n", " \"\\n\"+\n", " \"
\"}};\n", "\n", " function display_loaded() {\n", " const el = document.getElementById(\"1002\");\n", " if (el != null) {\n", " el.textContent = \"BokehJS is loading...\";\n", " }\n", " if (root.Bokeh !== undefined) {\n", " if (el != null) {\n", " el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n", " }\n", " } else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(display_loaded, 100)\n", " }\n", " }\n", "\n", " function run_callbacks() {\n", " try {\n", " root._bokeh_onload_callbacks.forEach(function(callback) {\n", " if (callback != null)\n", " callback();\n", " });\n", " } finally {\n", " delete root._bokeh_onload_callbacks\n", " }\n", " console.debug(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(css_urls, js_urls, callback) {\n", " if (css_urls == null) css_urls = [];\n", " if (js_urls == null) js_urls = [];\n", "\n", " root._bokeh_onload_callbacks.push(callback);\n", " if (root._bokeh_is_loading > 0) {\n", " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " root._bokeh_is_loading = css_urls.length + js_urls.length;\n", "\n", " function on_load() {\n", " root._bokeh_is_loading--;\n", " if (root._bokeh_is_loading === 0) {\n", " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", " run_callbacks()\n", " }\n", " }\n", "\n", " function on_error(url) {\n", " console.error(\"failed to load \" + url);\n", " }\n", "\n", " for (let i = 0; i < css_urls.length; i++) {\n", " const url = css_urls[i];\n", " const element = document.createElement(\"link\");\n", " element.onload = on_load;\n", " element.onerror = on_error.bind(null, url);\n", " element.rel = \"stylesheet\";\n", " element.type = \"text/css\";\n", " element.href = url;\n", " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", " document.body.appendChild(element);\n", " }\n", "\n", " for (let i = 0; i < js_urls.length; i++) {\n", " const url = js_urls[i];\n", " const element = document.createElement('script');\n", " element.onload = on_load;\n", " element.onerror = on_error.bind(null, url);\n", " element.async = false;\n", " element.src = url;\n", " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.head.appendChild(element);\n", " }\n", " };\n", "\n", " function inject_raw_css(css) {\n", " const element = document.createElement(\"style\");\n", " element.appendChild(document.createTextNode(css));\n", " document.body.appendChild(element);\n", " }\n", "\n", " const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\"];\n", " const css_urls = [];\n", "\n", " const inline_js = [ function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", "function(Bokeh) {\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " if (root.Bokeh !== undefined || force === true) {\n", " for (let i = 0; i < inline_js.length; i++) {\n", " inline_js[i].call(root, root.Bokeh);\n", " }\n", "if (force === true) {\n", " display_loaded();\n", " }} else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!root._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " root._bokeh_failed_load = true;\n", " } else if (force !== true) {\n", " const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n", " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", " }\n", " }\n", "\n", " if (root._bokeh_is_loading === 0) {\n", " console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(css_urls, js_urls, function() {\n", " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(window));" ], "application/vnd.bokehjs_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n const NB_LOAD_WARNING = {'data': {'text/html':\n \"
\\n\"+\n \"

\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"

\\n\"+\n \"\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"
\"}};\n\n function display_loaded() {\n const el = document.getElementById(\"1002\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\"];\n const css_urls = [];\n\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {\n }\n ];\n\n function run_inline_js() {\n if (root.Bokeh !== undefined || force === true) {\n for (let i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\nif (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));" }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.bokehjs_exec.v0+json": "", "text/html": [ "" ] }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "server_id": "4f609db662484bcea0b2995e1893ddea" } }, "output_type": "display_data" } ], "source": [ "#Here we define some global parameters used in the above functions\n", "#You can change these and observe how the behavior changes\n", "\n", "num_followers = 10\n", "leader_speed = 0.1\n", "num_time_steps = 100\n", "inertia = 0.0\n", "force_function = force_random\n", "#force_function = force_simple_comfortable_distance\n", "\n", "df = run() #Generate the dataframe for plotting\n", "\n", "output_notebook() #Tell bokeh to render things inside this notebook\n", "show(bokeh_app) #Start the small bokeh plotting application" ] }, { "cell_type": "code", "execution_count": null, "id": "ff4c2bae-7b32-4a8e-9acb-a643ba457742", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }