Skip to content
LasseNatvig edited this page Jun 2, 2022 · 57 revisions

Download Sourcecode

Clone the git repository like this:

$ git clone [email protected]:EECS-NTNU/fomo.git

This requires that you have set up ssh keys on your github account.

Installation

On Linux, run the following commands to install python dependencies:

$ sudo apt install python3-tk libasound2-dev python3-pil.imagetk

$ pip3 install shapely numpy progress matplotlib tensorflow geopy pandas sklearn gurobipy PySimpleGUI beepy jsonpickle

On Windows (Win 10, or Win 11), the code is running with the following setup:

  • Python 3.9.6 64-bit (Other variants may work, but do not use 3.10)
  • Visual Studio Code with standard setup for python. It provides excellent editor and debugging functionalities. The same pip3 install commands are run from the VS code terminal

Example Simulation

Look at the file main.py. This file sets up an example simulation, runs it and visualizes the result. On Linux, go to the source code directory and execute the python script like this:

$ ./main.py

Using Windows and VS code, open main.py and press F5 to start with debugging, or Ctrl+F5 to start without debugging.

Source Code Organization

The system is divided into the following main parts:

  • Global settings (file settings.py)
  • Initial state generation (subdirectory init_state)
  • Ideal state calculation (subdirectory ideal_state)
  • Event simulator (subdirectory sim)
  • Policy (subdirectory policy)
  • Visualization (subdirectory visualization)
  • GUI dashboard (subdirectory GUI)

Implementing a new Policy

Create a class that inherits the Policy class found in policy/policy.py. The get_best_action() method must be reimplemented by your subclass and is responsible for returning the next action for the given service vehicle. The method gets a reference to the simulator object, from which all simulator state can be obtained.

Some useful functions and objects found through the simulator object:

  • simul.day(): Return current day
  • simul.hour(): Return current hour
  • simul.state: State-object representing the entire city bike state (sim/State.py)
  • simul.state.vehicles: List of all service vehicles (sim/Vehicle.py)
  • simul.state.stations: List of all stations (sim/Station.py)
  • simul.state.depots: List of all depots (sim/Depot.py)
  • simul.state.get_all_scooters(): List of all bikes and electric scooters (sim/Bike.py and sim/Scooter.py)
  • simul.state.get_distance(): Get distance between two stations
  • simul.state.get_trip_speed(): Get average bike speed between two stations

Investigating Simulation Results

Your simulation object has a member metrics (sim/Metric.py) where various data about the simulation is collected.

Using the GUI dashboard (optional)

The dashboard was developed as an aid for testing of various simulators and components. It is currently an incomplete prototype, and can be modified and extended after concrete wishes from users. Many of the FOMO simulator operations take several minutes, and for operations that take more than 1-2 seconds a sound signal is given upon completion. The flag settings.USER_INTERFACE_MODE must be set to "GUI" to start the dashboard.

IMAGE of GUI will appear here

Details on GUI functionality and limitations

Source code organization

The GUI dashboard subsystem consists of the following main parts:

  • GUI main loop (file dashboard.py)
  • GUI layout (file GUI_layout.py)
  • GUI command and script handler (file script.py)
  • GUI helper functions (file GUIhelpers.py)
  • script storage (subdirectory scripts)
  • logg-file storage (file loggFiles)

Limitations in current prototype

Clone this wiki locally