An implementation of Local Search algorithms based on single solution design
Project description
Local Search - Metaheuristic
Project GIT address: https://github.com/anduralex/LSpackage.git
This lib implements some algorithms described on the book “Metaheuristics - From Design to Implementation”, from El-Ghazali Talbi.
I am testing the lib and it is available via pip install.
At this moment, the implementation includes:
- Search
Local Search algorithms - Hill Climbing
Installation
Just get it:
pip install LSpackage
You will need to have pip installed on your system. On linux install the python-pip package.
Examples
LSpackage allows you to define problems and look for the solution with different strategies. A sample are in the hello_word.py.
The problem will try to create the string “HELLO WORLD” using localSearchAlg algorithm:
from code.models import SearchProblem
from code.local import hillClimbing,localSearchAlg,firstExpander
WORD = 'HELLO WORLD'
class HelloProblem(SearchProblem):
def actions(self, state):
if len(state) < len(WORD):
return list(' ABCDEFGHIJKLMNOPQRSTUVWXYZ')
else:
return []
def result(self, state, action):
return state+action
def value(self, state):
# how many correct letters there are?
count=sum(1 if state[i] == WORD[i] else 0
for i in range(min(len(WORD), len(state))))
return count
result = localSearchAlg(HelloProblem(initial_state=''),firstExpander)
print(result.state)
More detailed documentation
You can read the book “Metaheuristics - From Design to Implementation”, from El-Ghazali Talbi. Or for offline access, you can clone the project code repository and work with it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.