Skip to main content

Python implementation of the ROAR-NET API Specification

Project description

ROAR-NET API - Python

This repository contains a library with the python implementation of the ROAR-NET API Specification and several algorithms. You can find the full specification in the roar-net-api-spec repository.

Contents

This library contains protocol types for all operations in the specification, and several algorithms that are currently supported by the specification.

Protocol types

Protocol types for the operations in the ROAR-NET API Specification are defined in the module roar_net_api.operations. For example, the operation apply_move is defined in a protocol SupportsApplyMove.

This library considers an object-oriented approach, such that operations should be implemented by a class of the first argument type. For example, for the operation:

apply_move(Move, Solution) -> Solution

we consider that it should be implemented as part of the class Move, which means that the protocol type is defined as:

SolutionT = TypeVar("SolutionT")

class SupportsApplyMove(Protocol[SolutionT]):
    def apply_move(self, solution: SolutionT) -> SolutionT: ...

Algorithms

We support several algorithms that can be implemented following the ROAR-NET API Specification. You can find the algorithms in the module roar_net_api.algorithms. Here is the current list of supported algorithms:

  • Beam search: beam_search
  • Best improvement: best_improvement
  • First improvement: first_improvement
  • GRASP: grasp
  • Greedy construction: greedy_construction
  • Random local search: rls
  • Simulated annealing: sa

Using

Adding it to your project

To use this library add it to your project. For example, to add it to a uv project you can do:

uv add roar-net-api

Alternatively, you can add it to a requirements.txt file or install it with pip manually.

Implement a model

To implement a model, we recommend that you take advantage of python type hints to warn you about potential issues. For example, if you would like your problem class to support the operations empty_solution and constructive_neighbourhood, you can inherit from the protocol types for these operations to get type checking, for example:

from roar_net_api.operations import (
  SupportsEmptySolution,
  SupportsConstructiveNeighbourhood
)

class ConstructiveNeighbourhood:
  ...

class Solution:
  ...

class Problem(
  SupportsEmptySolution[Solution],
  SupportsConstructiveNeighbourhood[ConstructiveNeighbourhood]
):
  def empty_solution(self) -> Solution:
    ...

  def constructive_neighbourhood(self) -> ConstructiveNeighbourhood:
    ...

where ... would be for your implementation.

If you do this, your editor/IDE can inform you of potential issues in the implementation.

For a full example, see the tsp.py file in the examples folder, which implements a model for the travelling salesman problem that can be solved by all algorithms.

Development

This library targets Python 3.11, in order to support the latest version of pypy which allows for faster execution of algorithms. As such, make sure to test your changes with the latest version of pypy.

The project is managed with uv, please follow the instructions on their website to install it.

The code is checked with the following linters:

  • ruff
  • mypy in strict mode

Pull requests are checked against these linters.

Copyright and license

Copyright and licence information is declared for each file using the REUSE Specification Version 3.3. Use of any material must comply with its licence.

Acknowledgments

This specification is based upon work from COST Action Randomised Optimisation Algorithms Research Network (ROAR-NET), CA22137, supported by COST (European Cooperation in Science and Technology).

COST (European Cooperation in Science and Technology) is a funding agency for research and innovation networks. Our Actions help connect research initiatives across Europe and enable scientists to grow their ideas by sharing them with their peers. This boosts their research, career and innovation.


COST and European Union Logos

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

roar_net_api-0.1.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

roar_net_api-0.1.0-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: roar_net_api-0.1.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for roar_net_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5c581c7988400869455e8e4b637a604650612ddcb412d9e73438034a3ecc8f8d
MD5 b29d407fd766dc71a1007ea8bafdd2ba
BLAKE2b-256 2b67634ffcefe452719e89fb438209bd20b8ac0b8b11bf501d174d7a1f3b02f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for roar_net_api-0.1.0.tar.gz:

Publisher: publish.yml on roar-net/roar-net-api-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: roar_net_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for roar_net_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f46378cbec2d11767a41680d824237694c064acdc86fb836cd5deb81193c092
MD5 68d9cc2f4e2674db6857e0dee314597f
BLAKE2b-256 621db801640ba0d168f37f74a31a49f047b51e1d8e43f2f62ab1771d4f5444ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for roar_net_api-0.1.0-py3-none-any.whl:

Publisher: publish.yml on roar-net/roar-net-api-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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