Skip to main content

State space search

Project description

PyPI version fury.io PyPI license PRs Welcome Downloads



Explorateur

Explorateur is a Python library to conduct State-Space-Search (SSS), a powerful framework for solving problems that require search over a collection of states.

Explorateur performs generic state-space-search over problem-specific states and moves. The user defines the BaseState and BaseMove and the library drives the search for solutions.

The behavior of the search is controlled by the built-in Search Strategy and the Exploration Strategy and user-defined moves. Given an initial user state, Explorateur performs search moves iteratively until a stopping condition is reached.

Search Strategy

  • TreeSearch over open states,
  • GraphSearch over open states while also storing the closed states to avoid visiting duplicates.

Exploration Strategy

  • BreadthFirst in an uninformed fashion,
  • DepthFirst in an uninformed fashion,
  • BestFirst in an informed fashion with an objective function that evaluates the quality of a state.

Stopping Conditions

  • A termination state is found,
  • The search space is exhausted,
  • A stopping criterion such as max iterations, runtime limit, or max depth has been reached,
  • (Optionally) The given goal state is encountered.

Quick Start

To use Explorateur, you must define BaseState and BaseMove as in the template below.

from explorateur import Explorateur, BaseMove, BaseState, ExplorationType, SearchType


# Implement your Search Moves
class MyMove(BaseMove):

    def __init__(self):
        # TODO Your move object
        pass

    def __str__(self) -> str:
        # TODO Your move string, also used for node labels in DOT graph
        pass


# Implement your own Search State 
class MyState(BaseState):

    def __init__(self):
        # TODO Your problem-specific state representation
        super().__init__() # Make sure to initialize the base state!

    def get_moves(self) -> List[MyMove]:
        # TODO Your branching decisions as a list of moves
        pass

    def is_terminate(self, goal_state=None) -> bool:
        # TODO Is the current state a solution/termination?
        pass

    def execute(self, move: MyMove) -> bool:
        # TODO Execute the move on the state and return success flag
        pass

    def __str__(self) -> str:
        # TODO Your state string, also used for node labels in DOT graph
        pass

# Explarateur
explorer = Explorateur()

# Initial state
initial_state = MyState()

# Search for solutions
if explorer.search(initial_state,
                   goal_state=None,  # Optional goal state
                   exploration_type=ExplorationType.DepthFirst(),
                   search_type=SearchType.TreeSearch(),
                   is_solution_path=True,
                   dot_filename="tree_search_dfs.dot"):
    
    # Retrieve the solution state and the solution path
    # Dot graph file is also available for visualizing the search 
    print("Solution:", explorer.solution_state)
    print("Solution Path:", *explorer.solution_path, sep="\n<-")
else:
    print("No solution found!")

# Search statistics
print("Total Decisions:", explorer.num_decisions)
print("Total Failures:", explorer.num_failed_decisions)
print("Total Time:", explorer.total_time)

Examples

Installation

Explorateur can be installed from PyPI using pip install explorateur

Install from source
Alternatively, you can build a wheel package on your platform from scratch using the source code:
git clone https://github.com/skadio/explorateur.git
cd explorateur
pip install setuptools wheel # if wheel is not installed
python setup.py sdist bdist_wheel
pip install dist/explorateur-X.X.X-py3-none-any.whl
Test your setup
To confirm that cloning was successful, run the tests included in the project. All tests should pass.
git clone https://github.com/skadio/explorateur.git
cd explorateur
python -m unittest discover tests

To run a specific test from a given test file:

$ python -m unittest -v tests.<file_name>.<class_name>.<function_name>

For example:

$ python -m unittest -v tests.test_usage_example.UsageExampleTest.test_usage_example

To confirm that the installation was successful, try importing Explorateur after pip install explorateur

import explorateur
print(explorateur.__version__)

Support

Please submit bug reports and feature requests as Issues.

License

Explorateur is licensed under the Apache License 2.0.


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

explorateur-1.2.1.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

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

explorateur-1.2.1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file explorateur-1.2.1.tar.gz.

File metadata

  • Download URL: explorateur-1.2.1.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for explorateur-1.2.1.tar.gz
Algorithm Hash digest
SHA256 36daa09ed147ec3e4f1fdaa2d870fc0e4b2abf4657a8e2e266af9e9bb856484e
MD5 5dc3c2c2a9e387f42efa550a97b2c52e
BLAKE2b-256 8b0325e47210af68c3cbabcea72ca34d10901d1ce7c2f3ca8c74094e247014a4

See more details on using hashes here.

File details

Details for the file explorateur-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: explorateur-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for explorateur-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b1c46eaae56bbe54744fe1d38d111728a25060ab6af9710d23892afca9ec956
MD5 3ca182bb2d57b9c008554201caf3ce0d
BLAKE2b-256 0ce6fbca52f8ef79dbd58bfebccfa700dd8d0f0e10992a9707962e02320cc76f

See more details on using hashes here.

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