Giter Site home page Giter Site logo

train-network's Introduction

Train Network Simulation

This project simulates a train network with multiple stations, connected with tracks, packages and trains. It calculates the optimal routes for train to pickup and deliver package based on the network configuration provided in a JSON file.

Installation

  1. Clone the repository
git clone https://github.com/mirzanorazman/train-network.git
cd train-network
  1. Install dependencies
npm install
  1. Compile TypeScript files
npx tsc

Running the simulation

  1. Create a network configuration file. This repo has two examples of a configuration file, network-simple.json and network-complex.json

  2. Run the simulation

node dist/main.js ./src/data/network-complex.json
  1. View the results
  • At the end of the simulation, the console will display the result which consist of train movements and the total time taken for the simulation to complete (in journeyTimeInMinutes unit)

Running the test

  • npm test

Requirements

  • Network input is a JSON file.
  • Console log output of the train operations.

Discussion

Optimization:

  1. The simulation uses a path finding algorithm called Dijkstra's algorithm to determine the shortest time taken for a train to travel between stations. Since the train network is a type of weighted graph, using Dijkstra's is more optimal in terms finding the shortest route (in time) than using the regular Breadth First Search algorithm.
  2. For the train-package assignments, I use a greedy approach by taking the closest train to a certain package for pickup.

train-network's People

Contributors

mirzanorazman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.