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. By default, the best first search is set to minimize. To maximize, multiply your objective function by -1.

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

  • Backtracking Tree-Search: A toy Constraint Satisfaction Problem to find a solution via backtracking tree search as depicted in search visualization.
  • Graph Search: The classical Romanian Graph Problem solved with a goal state as depicted in search visualization. Note the use of __eq__ and __hash__ to enable graph-based search to handle state comparison and hashing.
  • A* Search: The classical A* Search between an initial and goal state using an admissible heuristic solved with best-first search to minimize the total cost as depicted in search visualization. Note the use of get_objective function for optimization.

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.2.tar.gz (24.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.2-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: explorateur-1.2.2.tar.gz
  • Upload date:
  • Size: 24.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.2.tar.gz
Algorithm Hash digest
SHA256 472d92fdedb88beed67a293e4e84012237f291336c2884b2c95bc34771ea71f7
MD5 111362c95fefc32b37e92cffc64b087e
BLAKE2b-256 43e45970deaa131156b05fcc9e8795d5eb569f8ee84629f62e72b02395c62597

See more details on using hashes here.

File details

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

File metadata

  • Download URL: explorateur-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 22.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 98b47eca75f7796d8a7e810b637f0a080e2c5ba910023c46e758bae6f73711d6
MD5 dd0f57bf859503dec8f3beb6a40dc9e6
BLAKE2b-256 0f9eda56b14e3940af648ba9e436f90eae38bbfd9c69a3f7e954aed7966dbf82

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