Skip to main content

This package implements the mathematical model of the "Multi Port Stowage Planning" (MPSP) problem, introduced in Avriel et al. 1998, as a reinforcement learning environment using the Gymnasium API.

The Env class has the following input parameters:

  • R (int): number of rows
  • C (int): number of columns
  • N (int): number of ports

The env observations consist of a dictionary with the one hot encoded bay, and the upper triangular part of the transportation matrix as a flattened array.

Screenshot from the environment. The left matrix is the bay, and the right matrix is the transportation matrix. "x" denotes blocking containers. The reward decreases by one for each reshuffle necessitated by the agents stowage plan.

Note that since the mathematical model disregards any stability constraints, the env automatically swaps the column order in a lexocographic manor, based on the containers in the columns. This reduces the state space, by a factor of almost $C!$. Furthmore, the transportation matrix, is reshifted up and to the left, for each port, to reduce the state space even further. This means that from the point of view of the agent, it never leaves the first port.

When using the environment, you should call env.close() before exiting your program, to avoid memory leaks.

Minimal usage with Stable Baselines:

from MPSPEnv import Env
from sb3_contrib.ppo_mask import MaskablePPO

train_env = Env(R=8, C=4, N=5)

model = MaskablePPO(
    "MultiInputPolicy",
    train_env
)

model.learn(
    total_timesteps=1e6,
    progress_bar=True
)

train_env.close()

If you wish to try the env yourself, placing containers using keys 0-3 and removing containers using keys 4-7, you can use the following script:

from MPSPEnv import Env
import pygame, numpy as np


def get_action_from_key(key):
    return key - pygame.K_0 if pygame.K_0 <= key <= pygame.K_7 else None


if __name__ == "__main__":
    env = Env(3, 4, 6)
    env.reset()

    while True:
        env.render()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                env.close()
                exit()
            elif (
                event.type == pygame.KEYDOWN
                and (action := get_action_from_key(event.key)) is not None
            ):
                _, reward, done, _, _ = env.step(action)
                if done:
                    env.render()
                    pygame.time.wait(1000)
                    env.close()
                    exit()

        pygame.time.wait(10)

Metadata

Release files for MPSPEnv 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MPSPEnv 0.1.5
File Size Uploaded Provenance Actions
mpspenv-0.1.5.tar.gz 15.2 kB Without provenance Details for mpspenv-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for MPSPEnv 0.1.5
File Interpreter ABI Platform Actions
MPSPEnv-0.1.5-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details for MPSPEnv-0.1.5-cp311-cp311-macosx_14_0_arm64.whl

Total release size: 39.2 kB

Release files / mpspenv-0.1.5.tar.gz

Download URL mpspenv-0.1.5.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f01bcfe408f402e4645a0434147dd5a28da1968aa864328785ac9b88d1936368
BLAKE2b-256 checksum
How to use checksums
9e6c8f48ef839406538f092a4ef468776dc41f827081339353b06112fa58e8fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release files / MPSPEnv-0.1.5-cp311-cp311-macosx_14_0_arm64.whl

Download URL MPSPEnv-0.1.5-cp311-cp311-macosx_14_0_arm64.whl
Size 24.0 kB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
ecb42d24382140ce09adc4dfb8158798de941988d1b2667d70920dfcca1a75a1
BLAKE2b-256 checksum
How to use checksums
ba12488a5604d9395dda21701f019d1e0d97e1b440b4d753def60883968a4db5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Security for MPSPEnv 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page