-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning according to pylint, small improvement of settings.parse_args
- Loading branch information
Showing
36 changed files
with
546 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ venv/ | |
build/ | ||
dist/ | ||
pymhlib.egg-info/ | ||
.vscode/.ropeproject/objectdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[TYPECHECK] | ||
ignored-classes=Namespace | ||
|
||
[FORMAT] | ||
max-line-length=120 | ||
|
||
[MESSAGES] | ||
disable=C0103 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# The default ``config.py`` | ||
# flake8: noqa | ||
|
||
|
||
def set_prefs(prefs): | ||
"""This function is called before opening the project""" | ||
|
||
# Specify which files and folders to ignore in the project. | ||
# Changes to ignored resources are not added to the history and | ||
# VCSs. Also they are not returned in `Project.get_files()`. | ||
# Note that ``?`` and ``*`` match all characters but slashes. | ||
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc' | ||
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc' | ||
# '.svn': matches 'pkg/.svn' and all of its children | ||
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o' | ||
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o' | ||
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject', | ||
'.hg', '.svn', '_svn', '.git', '.tox'] | ||
|
||
# Specifies which files should be considered python files. It is | ||
# useful when you have scripts inside your project. Only files | ||
# ending with ``.py`` are considered to be python files by | ||
# default. | ||
# prefs['python_files'] = ['*.py'] | ||
|
||
# Custom source folders: By default rope searches the project | ||
# for finding source folders (folders that should be searched | ||
# for finding modules). You can add paths to that list. Note | ||
# that rope guesses project source folders correctly most of the | ||
# time; use this if you have any problems. | ||
# The folders should be relative to project root and use '/' for | ||
# separating folders regardless of the platform rope is running on. | ||
# 'src/my_source_folder' for instance. | ||
# prefs.add('source_folders', 'src') | ||
|
||
# You can extend python path for looking up modules | ||
# prefs.add('python_path', '~/python/') | ||
|
||
# Should rope save object information or not. | ||
prefs['save_objectdb'] = True | ||
prefs['compress_objectdb'] = False | ||
|
||
# If `True`, rope analyzes each module when it is being saved. | ||
prefs['automatic_soa'] = True | ||
# The depth of calls to follow in static object analysis | ||
prefs['soa_followed_calls'] = 0 | ||
|
||
# If `False` when running modules or unit tests "dynamic object | ||
# analysis" is turned off. This makes them much faster. | ||
prefs['perform_doa'] = True | ||
|
||
# Rope can check the validity of its object DB when running. | ||
prefs['validate_objectdb'] = True | ||
|
||
# How many undos to hold? | ||
prefs['max_history_items'] = 32 | ||
|
||
# Shows whether to save history across sessions. | ||
prefs['save_history'] = True | ||
prefs['compress_history'] = False | ||
|
||
# Set the number spaces used for indenting. According to | ||
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's | ||
# unit-tests use 4 spaces it is more reliable, too. | ||
prefs['indent_size'] = 4 | ||
|
||
# Builtin and c-extension modules that are allowed to be imported | ||
# and inspected by rope. | ||
prefs['extension_modules'] = [] | ||
|
||
# Add all standard c-extensions to extension_modules list. | ||
prefs['import_dynload_stdmods'] = True | ||
|
||
# If `True` modules with syntax errors are considered to be empty. | ||
# The default value is `False`; When `False` syntax errors raise | ||
# `rope.base.exceptions.ModuleSyntaxError` exception. | ||
prefs['ignore_syntax_errors'] = False | ||
|
||
# If `True`, rope ignores unresolvable imports. Otherwise, they | ||
# appear in the importing namespace. | ||
prefs['ignore_bad_imports'] = False | ||
|
||
# If `True`, rope will insert new module imports as | ||
# `from <package> import <module>` by default. | ||
prefs['prefer_module_from_imports'] = False | ||
|
||
# If `True`, rope will transform a comma list of imports into | ||
# multiple separate import statements when organizing | ||
# imports. | ||
prefs['split_imports'] = False | ||
|
||
# If `True`, rope will remove all top-level import statements and | ||
# reinsert them at the top of the module when making changes. | ||
prefs['pull_imports_to_top'] = True | ||
|
||
# If `True`, rope will sort imports alphabetically by module name instead | ||
# of alphabetically by import statement, with from imports after normal | ||
# imports. | ||
prefs['sort_imports_alphabetically'] = False | ||
|
||
# Location of implementation of | ||
# rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general | ||
# case, you don't have to change this value, unless you're an rope expert. | ||
# Change this value to inject you own implementations of interfaces | ||
# listed in module rope.base.oi.type_hinting.providers.interfaces | ||
# For example, you can add you own providers for Django Models, or disable | ||
# the search type-hinting in a class hierarchy, etc. | ||
prefs['type_hinting_factory'] = ( | ||
'rope.base.oi.type_hinting.factory.default_type_hinting_factory') | ||
|
||
|
||
def project_opened(project): | ||
"""This function is called after opening the project""" | ||
# Do whatever you like here! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"editor.rulers": [120], | ||
"cSpell.words": [ | ||
"ALNS's", | ||
"MISP", | ||
"PBIG", | ||
"SSGA", | ||
"arange", | ||
"args", | ||
"binvec", | ||
"brutto", | ||
"categ", | ||
"categbase", | ||
"checkit", | ||
"dtype", | ||
"einsum", | ||
"elems", | ||
"equi", | ||
"fpsol", | ||
"groupby", | ||
"heapify", | ||
"heapq", | ||
"iinfo", | ||
"imap", | ||
"issubset", | ||
"itbest", | ||
"iter", | ||
"itertools", | ||
"lcps", | ||
"lfreq", | ||
"lnewinc", | ||
"mannwhitneyu", | ||
"med", | ||
"mh", | ||
"mknap", | ||
"mknapcb", | ||
"ndarray", | ||
"netto", | ||
"networkx", | ||
"pymhlib's", | ||
"rawdata", | ||
"roundagg", | ||
"roundaggmip", | ||
"sa", | ||
"scipy", | ||
"sdiv", | ||
"stdev", | ||
"subsetvec", | ||
"succ", | ||
"tciter", | ||
"tctime", | ||
"tobj", | ||
"ttime", | ||
"ttot", | ||
"typecheck", | ||
"unindented", | ||
"xover" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
Metadata-Version: 2.1 | ||
Name: mhlib | ||
Version: 0.1.0a0 | ||
Summary: Python mhlib - a toolbox for metaheuristics and hybrid optimization methods | ||
Home-page: https://github.com/ac-tuwien/pymhlib | ||
Author: Günther Raidl | ||
Author-email: raidl@ac.tuwien.ac.at | ||
License: GPL3 | ||
Description: ## Python `mhlib` - A Toolbox for Metaheuristics and Hybrid Optimization Methods | ||
|
||
_This project is still in early development, any feedback is much appreciated!_ | ||
|
||
Python `mhlib` is a collection of modules supporting the efficient implementation of metaheuristics | ||
and certain hybrid optimization approaches for solving primarily combinatorial optimization | ||
problems in Python 3.7+. | ||
|
||
![ ](mh.png) | ||
|
||
This Python `mhlib` version emerged from the | ||
[C++ `mhlib`](https://bitbucket.org/ads-tuwien/mhlib) to which it has certain similarities | ||
but also many differences. | ||
|
||
The main purpose of the library is to support rapid prototyping and teaching. | ||
While ultimately efficient implementations of such algorithms in compiled | ||
languages like C++ will likely be faster, the expected advantage of the Python | ||
implementation lies in the expected faster implementation. | ||
|
||
`mhlib` is developed primarily by the | ||
[Algorithms and Complexity Group of TU Wien](https://www.ac.tuwien.ac.at), | ||
Vienna, Austria, since 2019. | ||
|
||
#### Contributors: | ||
- [Günther Raidl](https://www.ac.tuwien.ac.at/raidl) (primarily responsible) | ||
- [Nikolaus Frohner](https://www.ac.tuwien.ac.at/nfrohner) | ||
- Thomas Jatschka | ||
- Daniel Obszelka | ||
- Andreas Windbichler | ||
|
||
### Installation | ||
|
||
Major versions of `mhlib` can be installed from `PyPI` via | ||
|
||
python3 -m pip install -U mhlib | ||
|
||
and development versions are available at https://github.com/ac-tuwien/pymhlib. | ||
|
||
### Major Components | ||
|
||
- **solution.py**: | ||
An abstract base class `Solution`that represents a candidate solution to an optimization problem and | ||
derived classes `VectorSolution`, `BinaryVectorSolution`, and `SetSolution` for solutions which are | ||
represented bei general fixed-length vectors, boolean vectors or sets of arbitrary elements. | ||
- **binvec_solution.py**: | ||
A more specific solution class `BinaryVectorSolution` for problems in which solutions are represented by | ||
fixed-length binary vectors. | ||
- **subsetvec_solution.py**: | ||
A more specific solution class `SubsetVectorSolution` for problems in which solutions are subsets of a | ||
larger set. The set is realized by an efficient numpy array which is split into two parts, | ||
the one with the included elements in sorted order and the one with the remaining elements. | ||
- **permutation_solution.py**: | ||
A more specific solution class `PermutationSolution` for problems in which solutions are permutations of a | ||
set of elements. | ||
- **scheduler.py**: | ||
A an abstract framework for single metaheuristics that rely on iteratively applying certain | ||
methods to a current solution. Modules like gvns.py and alns.py extend this abstract class towards | ||
more specific metaheuristics. | ||
- **gvns.py**: | ||
A framework for local search, iterated local search, (general) variable neighborhood | ||
search, GRASP, etc. | ||
- **alns.py**: | ||
A framework for adaptive large neighborhood search (ALNS). | ||
- **par_alns.py**: | ||
A multi-process implementation of the ALNS where destroy+repair operations are parallelized. | ||
- **population.py** | ||
A population class for population-based metaheuristics. | ||
- **pbig.py**: | ||
A population based iterated greedy (PBIG) algorithm. | ||
- **ssga.py**: | ||
A steady-state genetic algorithm (SSGA). | ||
- **sa.py**: | ||
A simulated annealing (SA) algorithm with geometric cooling. | ||
- **decision_diag.py**: | ||
A generic class for (relaxed) decision diagrams for combinatorial optimization. | ||
- **log.py**: | ||
Provides two logger objects, one for writing out general log information, which is typically | ||
written into a `*.out` file, and one for iteration-wise information, which is typically | ||
written into a `*.log` file. The latter is buffered in order to work also efficiently, e.g., | ||
on network drives and massive detailed log information. | ||
A class `LogLevel` is provided for indented writing of log information according to a current level, | ||
which might be used for hierarchically embedded components of a larger optimization framework, | ||
such as a local search that is embedded in a population-based approach. | ||
- **settings.py**: | ||
Allows for defining module-specific parameters directly in each module in an independent distributed | ||
way, while values for these parameters can be provided as program arguments or in | ||
configuration files. Most `pyhmlib` modules rely on this mechanism for their external parameters. | ||
|
||
Modules/scripts for analyzing results of many runs: | ||
|
||
- **multi_run_summary.py**: | ||
Collects essential information from multiple mhlib algorithm runs found in the respective out and log files | ||
and returns a corresponding pandas dataframe if used as a module or as a plain ASCII table when used as | ||
independent script. The module can be easily configured to extract also arbitrary application-specific data. | ||
|
||
- **aggregate_results.py**: | ||
Calculate grouped basic statistics for one or two dataframes/TSV files obtained e.g. from `multi-run-summary.py`. | ||
In particular, two test series with different algorithms or different settings can be statistically | ||
compared, including Wilcoxon signed rank tests. The module can be used as standalone script as well | ||
as module called, e.g., from a jupyter notebook. | ||
|
||
|
||
#### Demos | ||
|
||
For demonstration purposes, simple metaheuristic approaches are provided in the `demo` subdirectory for the following | ||
well-known combinatorial optimization problems. They can be startet by | ||
|
||
python3 -m mhlib.demos.<problem> ... | ||
|
||
where `<problem>` is one of the following and `...` represents further parameters that can be seen by providing | ||
the option `-h`. | ||
It is recommended to take such a demo as template | ||
for solving your own problem. | ||
|
||
- **`maxsat`**: maximum satisfiability problem based on `BinaryVectorSolution` | ||
- **`tsp`**: traveling salesperson problem based on `PermutationSolution` | ||
- **`qap`**: quadratic assignment problem based on `PermutationSolution` | ||
- **`vertex_cover`**: minimum vertex cover problem based on `SetSolution` | ||
- **`graph_coloring`**: graph coloring problem based on `VectorSolution` | ||
- **`misp`**: maximum (weighted) independent set problem based on `SubsetVectorSolution` | ||
- **`mkp`**: multidimensional 0-1 knapsack problem based on `SubsetVectorSolution` | ||
|
||
Shared code of these demos is found in the submodules `mhlib.demos.common` and `mhlib.demos.graphs`, | ||
test instance data in `mhlib.demos.data`. | ||
|
||
Moreover, `julia-maxsat.py` and `julia-maxsat.jl` demonstrate the integration with the Julia programming language. | ||
Implementing time-critical parts of an application in Julia may accelerate the code substantially. | ||
To run this demo, Julia must be set up correctly and Python's `julia` package must be installed. | ||
While this demo derives a whole solution class in Julia, `julia-maxsat2.py` is a variant where only two functions | ||
are realized in Julia. | ||
|
||
|
||
### Changelog | ||
|
||
Major changes over major releases: | ||
|
||
#### Version 0.1 | ||
- ALNS and parallel ALNS added | ||
- graph coloring, TSP, and minimum vertex cover demos added | ||
- population based iterated greedy and steady state genetic algorithms added | ||
- SA with geometric cooling added | ||
- demos.graphs introduced | ||
- demo for interfacing with Julia added | ||
- many smaller improvements, bug fixes, improvements in documentation | ||
|
||
#### Version 0.0.1 | ||
- Initial version | ||
|
||
Platform: UNKNOWN | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) | ||
Classifier: Operating System :: OS Independent | ||
Requires-Python: >=3.7 | ||
Description-Content-Type: text/markdown |
Oops, something went wrong.