Skip to main content

RL environment for solving shortest or longest route problems

Project description

Route-Gym

An openai gym that allows agent to solve shortest and longest route problems.

These simples are simple for humans, and can be computed easily by hand using Dijkstra's algorithm and its variants like A* (computation time permitting). As we work towards AGI, it is of my opinion that our complicated general-purpose algorithms should be asked to solve these simple problems. If convergence is slow, or if the supposedly "general" algorithm can't solve it easily, it is safe to say that that algorithm should be reworked.

Quickstart

env = ShortestRouteEnv(nx.frucht_graph(), 0, 5, random_weights=(1,10))
env.render()    # optionnal
done = False
# you might want to give the adjacency matrix to the policy
policy = ?
rew = 0
position = origin
while not done:
    action = policy.predict(position)
    position, reward, done, _ = env.step(action)
    end.render()    # optionnal
    rew += reward
print("Final reward:", rew)
print("Dijkstra's reward:", env.graph.dijkstra_rew)

What is provided in this gym?

The environment:

The two environments are based neton OpenAI's gym.

The environment can be called using routegym.env.ShortestRouteEnv or the equivalent for the longest route version.

The environments have a render function you can use to display the environment's state. In it, the blue path on the graph's arcs represents Dijkstra's path. This only works for ShortestRouteEnv.

The environments receive a networkx graph, an origin, a goal, and random weight boundaries (if need be) as part of their constructor.

You can also set the make_horizon flag to True to transform the graph into a finite-horizon problem. Be warned that this should only be used on smaller graphs: this generates a tree out of all the possible paths the agent can take from origin to goal and merges them into a single graph. Needless to say, the big O of this thing is enormous! This flag should only be used for toy examples.

The Graph class

The environments use a custom graph class as a backend. A typical user should not need to interact with this class.

But this class does calculate the Dijkstra solution for the problem. If you want to compare your algorithm's performance to Dijkstra's, you can use env.graph.dijkstra_path to get Dijkstra's path, or env.graph.dijkstra_rew to get Dijkstra's reward.

The validate script

This is an internal test, but it is provided as a courtesy to the users. You can get inspiration from that script, either as a tutorial on how to use this package, or as a way to generate many environments, etc.

You can view it in routegym.validate.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

route-gym-0.0.11.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

route_gym-0.0.11-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file route-gym-0.0.11.tar.gz.

File metadata

  • Download URL: route-gym-0.0.11.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for route-gym-0.0.11.tar.gz
Algorithm Hash digest
SHA256 3fe41d7a5211c068181ac6eb5e99fb6bb2701d5f952e603190607f3b2479f8fc
MD5 7aca1dbda40b82187e6077fb6f142566
BLAKE2b-256 edd92c466078fcd89271c4f904b2a82daf52756b212fc4e83b5ab4a476835132

See more details on using hashes here.

File details

Details for the file route_gym-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: route_gym-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for route_gym-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a0576bdf42771e0827b05aee16edde406c0ef01bdc533a586181503752e4a8a4
MD5 5dbd458e81a3c39bf353764817f83f92
BLAKE2b-256 b122d1fc6e68b37722d4b5102f6f1c1c67bccba8ab24f536cb4d0f7182e813aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page