Skip to main content

Official Python Utilities for the CG:SHOP 2021 Optimization Competition.

We provide basic code to ease your participation in this year's challenge. Due to it popularity and simplicity, the choice has fallen on Python.

This python module allows you to easily read the instance and potentially convert them into an easier format. The JSON format is simple but it is very common and allows to easily add metadata. Further, this module allows you to verify your instances. It uses the same core as the server so if this code accepts your solution, so will our server.

The code is not perfect but we will work to improve this code during the competition. Feedback is welcome.

This time, the code is pure Python and should run on all machines. The source code will be soon published. We are currently deciding for the right platform (probably GitHub).

Features

  • Reading and writing instance files.
  • Reading and writing solution files.
  • Verifying solutions for feasibility.

The exact same implementation will be used on the submission server. Thus, if this library will accept your solution, so will the submission server.

Installation

The installation is trivial using pip.

pip install cgshop2021-pyutils

Note that you have to use _ instead of - when importing the module.

Maybe you need to add to --user flag to save the package into your home directory instead of the system's directory.

You will also be able to simply copy the source code into your code without any installation. However, please keep this library updated as there will probably be some forgotten corner cases. (Actually, at the time I am writing this, the code has not been properly tested as we had to prioritize instance generation and the server. Give us a few days.)

pip install cgshop2021-pyutils --upgrade

Reading the instances from the Zip

Best use the instance database. You simply download the .zip and then you can access all instances via

from cgshop2021_pyutils import InstanceDatabase
idb = InstanceDatabase("path/to/zip.zip")
for i in idb:
    print("Instance:", i)

Working with an instance

from cgshop2021_pyutils import Instance

i: Instance #just to enable typing

for r in range(i.number_of_robots):
    print("Robot", i, "starts at", i.start_of(r)," and has to go to ", i.target_of(r))

for o in i.obstacles:
    print(o, "is blocked")

Create a solution

from cgshop2021_pyutils import Solution, SolutionStep, SolutionZipWriter, Direction
from cgshop2021_pyutils import Instance

instance: Instance
solution = Solution(instance) 

# First time step in the solution
step_1 = SolutionStep()
step_1[2]=Direction.NORTH # Robot 2 moves north
step_1[1]=Direction.WEST # Robot 1 moves west
solution.add_step(step_1)

# Second time step in the solution
step_2 = SolutionStep()
step_2[0]=Direction.SOUTH # Robot 0 moves north
step_2[2]=Direction.WEST # Robot 2 moves west
solution.add_step(step_2)

print("Makespan:", solution.makespan)

print("SUM:", solution.total_moves)

Write solutions

You can easily write solutions to an uploadable zip.

from cgshop2021_pyutils import SolutionZipWriter, Solution
s1: Solution
s2: Solution
s3: Solution

with SolutionZipWriter("output.zip") as szw:
    szw.add_solution(s1)
    szw.add_solutions([s1, s2])

Validate your solution

Solutions can be validate via validate. This function does not return anything but will throw an exception if something is wrong. The exception will contain an explanation (by type and message).

from cgshop2021_pyutils import InstanceDatabase, ZipSolutionIterator, validate, ZipReaderError, InvalidSolutionError, SolutionEncodingError
idb = InstanceDatabase("path/to/instances.zip")
try:
    for solution in ZipSolutionIterator(idb)("/path/to/my_solutions.zip"):
        validate(solution)
except ZipReaderError as zre:
    print("Bad Zip:", zre)
except InvalidSolutionError as ise:
    print("Bad Solution:", ise)
except SolutionEncodingError as see:
    print("Bad Solution File:", see)

Version History

  • 0.0.1-0.0.5: Beta Versions
  • 0.1.0: First officially used version.
  • 0.1.1: Increased allowed zip size.

Metadata

Release files for cgshop2021-pyutils 0.1.1

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

Built distribution (wheel)

Table of built distributions (wheels) for cgshop2021-pyutils 0.1.1
File Interpreter ABI Platform Actions
cgshop2021_pyutils-0.1.1-py3-none-any.whl Python 3 none any Details for cgshop2021_pyutils-0.1.1-py3-none-any.whl

Release files / cgshop2021_pyutils-0.1.1-py3-none-any.whl

Download URL cgshop2021_pyutils-0.1.1-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cf9c6a62e2a3469ac1edf63bf867fc6b6b04bea71ae3b1a225ce7266561dd68
BLAKE2b-256 checksum
How to use checksums
f491e46cab7e59d625439fa3ad1ca7fe60b39508f1f42169d264c605253c2089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201103 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

Security for cgshop2021-pyutils 0.1.1

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.

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