Package: pymhlib
pymhlib- A Toolbox for Metaheuristics and Hybrid Optimization MethodsThis project is still in early development, any feedback is much appreciated!pymhlibis 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+.This Pythonmhlibversion emerged from theC++mhlibto which it has certain similarities
but also many differences.Note that there also exists a more recent efficientJulia-implementationof this libraries,
following a similar design concept:Julia MHLib.jlThe main purpose of the library is to support rapid prototyping and teaching.
While ultimately efficient implementations of such algorithms in compiled
languages like Julia or C++ will in general be much faster, an advantage of
the Python implementation lies in the possibly quicker development cycle.pymhlibis developed primarily by theAlgorithms and Complexity Group of TU Wien,
Vienna, Austria, since 2019.Contributors:Günther Raidl(primarily responsible)Nikolaus FrohnerThomas JatschkaDaniel ObszelkaAndreas WindbichlerInstallationMajor versions ofpymhlibcan be installed fromPyPIviapython3 -m pip install -U pymhliband development versions are available athttps://github.com/ac-tuwien/pymhlib.Major Componentssolution.py:
An abstract base classSolutionthat represents a candidate solution to an optimization problem and
derived classesVectorSolution,BinaryVectorSolution, andSetSolutionfor solutions which are
represented bei general fixed-length vectors, boolean vectors or sets of arbitrary elements.binvec_solution.py:
A more specific solution classBinaryVectorSolutionfor problems in which solutions are represented by
fixed-length binary vectors.subsetvec_solution.py:
A more specific solution classSubsetVectorSolutionfor 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 classPermutationSolutionfor 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.pyA 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*.outfile, and one for iteration-wise information, which is typically
written into a*.logfile. The latter is buffered in order to work also efficiently, e.g.,
on network drives and massive detailed log information.
A classLogLevelis 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. Mostpymhlibmodules rely on this mechanism for their external parameters.Modules/scripts for analyzing results of many runs:multi_run_summary.py:
Collects essential information from multiplepymhlibalgorithm runs found in the respective out and log files
and returns a corresponding pandasDataFrameif 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. frommulti-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.DemosFor demonstration purposes, simple metaheuristic approaches are provided in thedemosubdirectory for the following
well-known combinatorial optimization problems. They can be started bypython3 -m pymhlib.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 onBinaryVectorSolutiontsp: traveling salesperson problem based onPermutationSolutionqap: quadratic assignment problem based onPermutationSolutionvertex_cover: minimum vertex cover problem based onSetSolutiongraph_coloring: graph coloring problem based onVectorSolutionmisp: maximum (weighted) independent set problem based onSubsetVectorSolutionmkp: multidimensional 0-1 knapsack problem based onSubsetVectorSolutionShared code of these demos is found in the submodulespymhlib.demos.commonandpymhlib.demos.graphs,
test instance data inpymhlib.demos.data.Moreover,julia-maxsat.pyandjulia-maxsat.jldemonstrate 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'sjuliapackage must be installed.
While this demo derives a whole solution class in Julia,julia-maxsat2.pyis a variant where only two functions
are realized in Julia.ChangelogMajor changes in releases:Version 0.1.5bug fix insettings: repeatedparse_settings` now resets former settings correctlybug fix incommon.py/run_optimization: seed now correctly passed toadd_general_arguments_and_parse_settingsautomatic installation of required other packages fixedVersion 0.1.4cleaning according to pylint warningssettings.parse_args may now be called multiple timesVersion 0.1.3bug fix in 2-opt neighborhood search of permutation representationVersion 0.1.2directory renamed to pymhlib to correspond to module namebug fix in Metropolis criterion of ALNSboolean arguments must now be specified in the command line as any other parameterVersion 0.1.1basic functionality testtests/test_all.pyfor all problems and
algorithms addedpolishing, minor fixesVersion 0.1.0ALNS and parallel ALNS addedgraph coloring, TSP, and minimum vertex cover demos addedpopulation based iterated greedy and steady state genetic algorithms addedSA with geometric cooling addeddemos.graphs introducedmhlib renamed to pymhlibdemo for interfacing with Julia addedmany smaller improvements, bug fixes, improvements in documentationVersion 0.0.1Initial version