Skip to content

Creating your own Task for a Battle

Henri Lotze edited this page Feb 24, 2023 · 2 revisions

Problems(tasks) are created as packages and are automatically imported by supplying their path to the battle executable.

The basic directory structure of a task is the following:

newtask
├── generator
│   └── Dockerfile
├── solver
│   └── Dockerfile
├── parser.py
├── problem.py
├── verifier.py
└── __init__.py

The problem.py file is the easiest to fill. It defines a new subclass of the abstract Problem class, imports the verifier and parser and sets a few parameters such as the smallest instance size on which the problem can be run.

The parser.py implements methods that are used for cleaning up whatever instance or solutions the solvers and generators produce, such that the verifier is able to semantically check them for correctness. Lines of the input that do not conform to the defined format should be handled, either by rejecting the complete instance or by removing them from the instance.

The verfier.py, as already mentioned, checks the input semantically. At least two functions need to be implemented: One that verifies that a solution is correct for an instance and one that verifies that a solvers solution is of a required quality (usually that its size is at least equal to that of the generator). The verifier should be able to handle the cases that an empty instance is given (the solution is automatically valid) or that an empty solution is given (the solution is automatically invalid).

In order to integrate a problem file, an __init__.py is required that contains an import of the class created in the problem.py file, renaming it to Problem:

from .problem import MyNewProblemClass as Problem 

In order to test the functionality of your problem implementation, it is recommended to create a dummy solver and generator in the problem directory. These can return the same instance and solution for each instance size, assuming the problem definition allows this. The solver and generator folders are also the default paths for solvers and generators of both teams if no other path is given.

If you want to execute a run on your newly created problem, execute

battle /path/to/newtask

There are a few example tasks in the algobattle-problems repository with task descriptions, if you want a reference for creating your own tasks.