baharev / sdopt-tearing

Exact and heuristic methods for tearing
https://sdopt-tearing.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
13 stars 5 forks source link
decomposition elimination numerical-methods python tearing

Exact and heuristic methods for tearing

Many of the implemented algorithms are described in the following academic papers:

See also Reproducing the results of the academic papers below.

The code is a work in progress

Some of the code will be contributed back to NetworkX wherever it is appropriate. The remaining part of the code will be released as a Python package on PyPI. In the meantime, the rpc_api.py is a good place to start looking. (rpc stands for remote procedure call; it can be called from Java or C++ through the json_io.py). The API in rpc_api.py takes a sparse matrix in coordinate format and returns the row and column permutation vectors.

Documentation of the demo application demo.py is available at sdopt-tearing.readthedocs.io.

While reading the code, please keep in mind that the code is a work in progress.

Reproducing the results of the minimum feedback arc set paper

The results of the paper An exact method for the minimum feedback arc set problem can be reproduced as follows.

Algorithms

Input graphs

The test graphs are given in plain text files. The *.edges file gives the edge list of the graph; the *.mfes file gives the minimum feedback edge set. The *.cycles file gives those cycles that are sufficient to include in the cycle matrix in order to prove the optimality of the minimum feedback edge set, and the *.lp encodes the corresponding integer linear program (a minimum set cover problem) in CPLEX LP file format. The *.mst file gives the optimal solution vector of this integer program, and can be used as a starting point as well.

The cycles in the *.cycles file are given one per line, and each line gives the node list of one cycle. For example the line
1 6 8 encodes the cycle of the edges (1, 6), (6, 8), (8, 1).

The graphs used for benchmarking are given in the following files.

Reproducing the results of the paper on optimal tearing

The algorithms are documented in the academic paper Ordering matrices to bordered lower triangular form with minimal border width.

The tests for checking correctness are in the test_<module name>.py modules. Cross-checking the ILP-based and the custom branch and bound algorithm is implemented in test_bb_ilp.py. Running these tests require Hypothesis, the QuickCheck for Python. (I am a big fan of property-based testing.)

Dependencies

The demo application has been tested with Python 2.7 and 3.5. The six, networkx, sympy, and namedlist packages are necessary; matplotlib, pydot (or pydot-ng), and pygraphviz are recommended but not required. However, if matplotlib is installed, then pydot (or pydot-ng) and pygraphviz are also required to run the demo.py application.

Computing the bipartite matching can easily become the bottleneck. In that case, MC21 from the Harwell Subroutine Library (HSL) is recommended. The wrapper code can be found under data/mc21/ with compilation instructions.

If you wish to run the exact algorithms based on integer programming, you will also need Gurobi. If you do not have Gurobi installed, the demo.py application will detect its absence, and simply skips those steps that would require the integer programming solver. The algorithms that use Gurobi have only been tested with Python 2.7.

Installing on Windows with PyGraphviz

Only Python 2.7 was tested on Mar 08, 2016. Python 2.7 and the dependencies were installed with Miniconda (released on Dec 17, 2015). Then graphviz was installed with the graphviz-2.38.msi installer. After installation the bin directory of graphviz was added to the PATH. Next, pygraphviz was installed from Unofficial Windows Binaries for Python Extension Packages as pip install pygraphviz-1.3.1-cp27-none-win32.whl. The matplotlib and pydot-ng packages were installed only after pygraphviz. The demo application works as expected.