Skip to main content

Python simulation of a driving challange. Compatible with the Gymnasium API standard.

Project description

ProgGrid Traffic Gym (pgtg)

A driving simulation on a grid with procedural generated maps and traffic. Compatible with the Gymnasium API standard.

Installation

pip install pgtg

Usage

The easiest way to use pgtg is to create the environment with gymnasium:

import pgtg
env = gymnasium.make("pgtg-v0")

The package relies on import side-effects to register the environment name so, even though the package is never explicitly used, its import is necessary to access the environment.

If you want to access the environment constructor directly this is also possible:

from pgtg import PGTGEnv
env = PGTGEnv()

Environment

ProgGrid Traffic Gym procedurally generates a map consisting of multiple preconstructed tiles or loads a map from a file. The goal is to drive from the start of the map to the end. The navigation task is not part of this environment, instead a shortest path is provided and marked on the map.

The environment is highly customizable, see the constructor documentation for more info.

Action Space

ProgGrid Traffic Gym has a Discrete(9) action space.

Value Meaning
0 accelerate left and up
1 accelerate left
2 accelerate left and down
3 accelerate up
4 don't accelerate
5 accelerate down
6 accelerate right and up
7 accelerate right
8 accelerate right and down

Observation Space

ProgGrid Traffic Gym has a Dict observation space that shows the 9x9 area the agent currently is inside.

Key Type Explanation
"position" MultiDiscrete The x and y position of the agent within the observation window.
"velocity" Box The velocity of the agent is x and y direction.
"map" Dict The 9x9 are of the map the agent is currently inside. The keys are the name of the features ("walls", "goals", "ice", "broken road", "sand", and "traffic"). Each item is a MultiBinary that encodes that feature as a hot one encoding.

Most reinforcement learning implementations can't deal with Dict observations, thus it might be necessary to flatten the observations. This is easily doable with the gymnasium.wrappers.FlattenObservation wrapper:

from gymnasium.wrappers import FlattenObservation
env = FlattenObservation(env)

Reward

Crossing a subgoal is rewarded with +100 / number of subgoals as is finishing the whole map. Moving into a wall or traffic is punished with -100 and ends the episode. Standing still or moving to a already visited position can also penalized but is not per default. The reward values for each of this can be customized.

Render modes

Name Explanation
human render() returns None but a pygame window showing the environment is opened automatically when step() is called.
rgb_array render() returns a np.array representing a image.
pil_image render() returns a PIL.Image.Image, useful for displaying inside jupiter notebooks.

Obstacles

Name Effect
Ice When driving over a square with ice, there is a chance the agent moves in a random direction instead of the expected one.
Sand When driving over sand the agent is slowed, as the velocity is reset to 0 every step.
Broken road When driving over broken road, there is a chance for the agent to get a flat tire. This slows the agent down, as the velocity is reset to 0 every step. A flat tire lasts until the end of the episode.

Version History

  • v0: initial release

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

pgtg-0.1.0.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

pgtg-0.1.0-py3-none-any.whl (54.8 kB view details)

Uploaded Python 3

File details

Details for the file pgtg-0.1.0.tar.gz.

File metadata

  • Download URL: pgtg-0.1.0.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.0 Windows/10

File hashes

Hashes for pgtg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a7d3c0f9978fda104905bc70264be07b147dde1e5ceadc2b178572f754f710dc
MD5 6b9821e91f72fbd38c44c44af6205d1c
BLAKE2b-256 427814917954a0f47aa20b0f9769e462ac5675cbc752d8abb0e8fc0bee1b30c0

See more details on using hashes here.

File details

Details for the file pgtg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pgtg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 54.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.0 Windows/10

File hashes

Hashes for pgtg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51cdedd81add5779fba68d2924833d7484c7f5e9ac94340403f4ecf81a4385a8
MD5 0f70c7cbb0c2a3d7a3578c14ae559f9c
BLAKE2b-256 fa935814fa2fea4411534182f35e3273fa02030cc72e51ff559a0cd43450c915

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