Giter Club home page Giter Club logo

shortest-paths-rl's Introduction

shortest-paths-RL

Using reinforcement learning to find the shortest paths.

Requirements

  • numpy
  • networkx
  • matplotlib
  • imageio (optional, useful for generating the video/gif file to visualize)
  • imageio-ffmpeg (optional, useful for generating the video/gif file to visualize)

To install them, try:

pip3 install numpy networkx matplotlib imageio imageio-ffmpeg 

Notes

  • Please define the adjacent matrix for your problem. Note that the first row and the first column must correspond to the target state/node.
  • You may need to modify the parameters of the reinforcement learning algorithms in order to solve your problem more effectively.

Examples

Here, we define the adjacent matrix as follows:

D = [[0, 4, 0, 0, 0, 0, 0, 8, 0],
     [4, 0, 8, 0, 0, 0, 0, 11, 0],
     [0, 8, 0, 7, 0, 4, 0, 0, 3],
     [0, 0, 7, 0, 9, 14, 0, 0, 0],
     [0, 0, 0, 9, 0, 10, 0, 0, 0],
     [0, 0, 4, 14, 10, 0, 3, 0, 0],
     [0, 0, 0, 0, 0, 3, 0, 3, 4],
     [8, 11, 0, 0, 0, 0, 3, 0, 5],
     [0, 0, 3, 0, 0, 0, 4, 5, 0]]

So the graph is as follows:

problem_definition

1. value iteration

To run value iteration algorithm, run:

python shortest_path.py -s vi

or

python shortest_path.py -s value_iteration 

The result is as follows:

problem_definition

2. policy iteration

To run policy iteration algorithm, run:

python shortest_path.py -s pi

or

python shortest_path.py -s policy_iteration 

The result is as follows:

problem_definition

3. Sarsa

The start node has been set to node 3 in the code. To run Sarsa algorithm, run:

python shortest_path.py -s sarsa

The result is as follows:

sarsa

4. Sarsa(λ)

The start node has been set to node 3 in the code. To run Sarsa(λ) algorithm, run:

python shortest_path.py -s sarsa(lambda)

or

python shortest_path.py -s sarsa_lambda

The result is as follows:

sarsa_lambda

5. q-learning

The start node has been set to node 3 in the code. To run q-learning algorithm, run:

python shortest_path.py -s q-learning

The result is as follows:

q-learning

More details

More details can be seen in the code. You can also change the start node for Sarsa, Sarsa(λ) and q-learning algorithm.

shortest-paths-rl's People

Contributors

xgkkk 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.