Skip to content

Commit

Permalink
Faster and uglier implementation of the bidirectional algorithm for v…
Browse files Browse the repository at this point in the history
…1.0 (#70)

* Merge master into dev, Add boost docker image and example #65

* Clean up boost Dockerfile, disable boost-python

* Add r_c_shortest_paths runner for Beasley benchmarks #65

* Update table with real comparison #65

* Refactor benchmark parsing

* Add WIP

* Change to wall clock time

* Update python interface, fix timer

* Spell checks, fix python example

* Add unittest #69

* 'Refactored by Sourcery' (#71)

Co-authored-by: Sourcery AI <>

* Rework digraph to use LEMON

- Changed internal handling of nodes from std::string to int. This requires converting nodes to integers before passing to the algorithm. Python interface unchanged
- Add Bellman-Ford to preprocessing (still WIP)
- Run benchmarks again for #65 and #66

* Add sudo to install script for linux

* Add lemon include dir explicitly

* Remove quotations for SWIG

* Update README.md

* Specify windows lemon installation dir

* Add check step to lemon installation

* Add explicit types for preprocessing, remove lemon check

* Cast reverse digraph explicitly

* Fix lambda expression to correct type

* Remove unused member (indicator of primal bound)

* Add lemon to test libraries

* Link lemon with bidirectional

* Add lemon license, makefile and update docker build

* Fix #69, clean up tests

* Update docs, fix #68

* Update docs and workflows

* Add dev requirement

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
torressa and sourcery-ai[bot] authored May 4, 2021
1 parent ffa3379 commit 432ee0c
Show file tree
Hide file tree
Showing 75 changed files with 5,731 additions and 1,876 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/*
build*/*
examples/


*.pyc
*.sw*
24 changes: 5 additions & 19 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,14 @@ assignees: ''
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
Steps to reproduce the behavior. Include minimal working example if available.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
- OS: [e.g. Linux, Windows, ...]
- Version [e.g. v1.0.0-alpha]

**Additional context**
Add any other context about the problem here.
**Suggestions**
How would you suggest the problem be fixed?
5 changes: 5 additions & 0 deletions .github/workflows/macos_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Install LEMON
run: |
cp tools/docker/scripts/install_lemon .
chmod u+x install_lemon
./install_lemon
- name: Configure
run: cmake -S . -Bbuild -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=OFF -DBUILD_SHARED_LIBS=OFF
- name: Build
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/macos_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
- uses: actions/checkout@v2
- name: Swig install
run: brew install swig
- name: Install LEMON
run: |
cp tools/docker/scripts/install_lemon .
chmod u+x install_lemon
./install_lemon
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
Expand Down
19 changes: 16 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: PyPI Release

on:
push:
branches:
- master
release:
types:
- published


# TODO add windows as per:
Expand All @@ -21,6 +21,11 @@ jobs:
- uses: actions/checkout@v2
- name: Swig install
run: brew install swig
- name: Install LEMON
run: |
cp tools/docker/scripts/install_lemon .
chmod u+x install_lemon
./install_lemon
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -68,6 +73,14 @@ jobs:
echo "$((Get-Item .).FullName)/swigwin-4.0.2" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Check swig
run: swig -version
- name: Install LEMON 1.3.1
run: |
(New-Object System.Net.WebClient).DownloadFile("http://lemon.cs.elte.hu/pub/sources/lemon-1.3.1.zip","lemon-1.3.1.zip");
Expand-Archive .\lemon-1.3.1.zip .;
cd lemon-1.3.1;
cmake -S. -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DLEMON_ENABLE_GLPK=NO -DLEMON_ENABLE_COIN=NO -DLEMON_ENABLE_ILOG=NO;
cmake --build build --config Release --target ALL_BUILD -- /verbosity:normal /maxcpucounte;
cmake --build build --config Release --target INSTALL -- /verbosity:normal /maxcpucount
- name: Configure
run: cmake -S. -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=ON -DBUILD_TESTING=ON -DPython3_ROOT_DIR=$env:pythonLocation -DPython_ROOT_DIR=$env:pythonLocation -DPython3_FIND_STRATEGY=LOCATION -DPython3_FIND_REGISTRY=LAST
- name: Build
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ubuntu_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install LEMON
run: |
cp tools/docker/scripts/install_lemon .
chmod u+x install_lemon
sudo ./install_lemon
- name: Configure
run: cmake -S . -Bbuild -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=OFF -DBUILD_SHARED_LIBS=OFF
- name: Build
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ubuntu_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install LEMON
run: |
cp tools/docker/scripts/install_lemon .
chmod u+x install_lemon
sudo ./install_lemon
- name: Configure
run: cmake -S . -Bbuild -DBUILD_TESTING=ON -DBUILD_PYTHON=ON -DBUILD_SHARED_LIBS=ON
- name: Install rtds-action
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ubuntu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install LEMON
run: |
cp tools/docker/scripts/install_lemon .
chmod u+x install_lemon
sudo ./install_lemon
- name: Configure
run: |
echo $pythonLocation
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/windows_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
(New-Object System.Net.WebClient).DownloadFile("http://prdownloads.sourceforge.net/swig/swigwin-4.0.2.zip","swigwin-4.0.2.zip");
Expand-Archive .\swigwin-4.0.2.zip .;
echo "$((Get-Item .).FullName)/swigwin-4.0.2" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Install LEMON 1.3.1
run: |
(New-Object System.Net.WebClient).DownloadFile("http://lemon.cs.elte.hu/pub/sources/lemon-1.3.1.zip","lemon-1.3.1.zip");
Expand-Archive .\lemon-1.3.1.zip .;
cd lemon-1.3.1;
cmake -S. -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DLEMON_ENABLE_GLPK=NO -DLEMON_ENABLE_COIN=NO -DLEMON_ENABLE_ILOG=NO;
cmake --build build --config Release --target ALL_BUILD -- /verbosity:normal /maxcpucounte;
cmake --build build --config Release --target INSTALL -- /verbosity:normal /maxcpucount
- name: Check swig
run: swig -version
- name: Check cmake
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/windows_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jobs:
echo "$((Get-Item .).FullName)/swigwin-4.0.2" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Check swig
run: swig -version
- name: Install LEMON 1.3.1
run: |
(New-Object System.Net.WebClient).DownloadFile("http://lemon.cs.elte.hu/pub/sources/lemon-1.3.1.zip","lemon-1.3.1.zip");
Expand-Archive .\lemon-1.3.1.zip .;
cd lemon-1.3.1;
cmake -S. -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DLEMON_ENABLE_GLPK=NO -DLEMON_ENABLE_COIN=NO -DLEMON_ENABLE_ILOG=NO;
cmake --build build --config Release --target ALL_BUILD -- /verbosity:normal /maxcpucounte;
cmake --build build --config Release --target INSTALL -- /verbosity:normal /maxcpucount
- name: Configure
run: cmake -S. -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=ON -DBUILD_TESTING=ON -DPython3_ROOT_DIR=$env:pythonLocation -DPython_ROOT_DIR=$env:pythonLocation -DPython3_FIND_STRATEGY=LOCATION -DPython3_FIND_REGISTRY=LAST
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
python:
version: 3.7
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.dev.txt

submodules:
exclude: all
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [v1.0.0]

### Changed

- Graph implementation replaced with [LEMON](https://lemon.cs.elte.hu/trac/lemon). This brings significant improvement.

### Added
- Benchmarks against boost's r_c_shortest_paths (#65)

### Fixed
- Issues #66, #68, #69, #72

## [v1.0.0-alpha]

### Changed

Rewrite of the bidirectional algorithm in C++ interfaced with Python using SWIG.
Expand Down Expand Up @@ -236,7 +250,9 @@ path using `networkx.shortest_simple_paths`.
- Docstring modifications to include maths.
- Updated README.

[unreleased]: https://github.com/torressa/cspy/compare/v0.1.2...HEAD
[unreleased]: https://github.com/torressa/cspy/compare/v1.0.0...HEAD
[v1.0.0]: https://github.com/torressa/cspy/compare/v1.0.0-alpha...v1.0.0
[v1.0.0-alpha]: https://github.com/torressa/cspy/compare/v0.1.2...v1.0.0-alpha
[v0.1.2]: https://github.com/torressa/cspy/compare/v0.1.1...v0.1.2
[v0.1.1]: https://github.com/torressa/cspy/compare/v0.1.0...v0.1.1
[v0.1.0]: https://github.com/torressa/cspy/compare/v0.0.14...v0.1.0
Expand Down
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ endif()
project(
cspy
VERSION 1.0.0
DESCRIPTION alpha
LANGUAGES CXX)
message(STATUS "project: ${PROJECT_NAME}")
message(STATUS "version: ${PROJECT_VERSION}")
Expand Down Expand Up @@ -112,6 +111,19 @@ message(STATUS "Build Python: ${BUILD_PYTHON}")
# option(BUILD_DOTNET "Build .NET Library" OFF) message(STATUS "Build Java:
# ${BUILD_JAVA}") message(STATUS "Build .Net: ${BUILD_DOTNET}")

include(FetchContent)
set(FETCHCONTENT_QUIET OFF)

# TODO: download and install lemon with FetchContent

# FetchContent_Declare(lemon URL
# http://lemon.cs.elte.hu/pub/sources/lemon-1.3.1.tar.gz)
# option(LEMON_ENABLE_GLPK NO) option(LEMON_ENABLE_COIN NO)
# option(LEMON_ENABLE_ILOG NO) option(LEMON_ENABLE_SOPLEX NO)
# FetchContent_MakeAvailable(lemon)

find_package(LEMON REQUIRED)

enable_testing()
include(cpp)

Expand All @@ -127,12 +139,11 @@ endif()
include(python)

if(NOT BUILD_PYTHON)
# Prevent overriding the parent project's compiler/linker settings on Windows
set(FETCHCONTENT_QUIET OFF)
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
Expand Down
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Run unit tests
all:
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake --build build --config Release --target all -v
cd build && ctest --verbose

# Run benchmarks
benchmark:
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \
-DBENCHMARK_TESTS=ON
cmake --build build --config Release --target all -v
cd build && ctest --verbose

# Build and test python interface
python:
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \
-DBUILD_PYTHON=ON -DBUILD_SHARED_LIBS=ON
cmake --build build --config Release --target all -v
cd build && ctest --verbose -R python_unittest

# Run benchmarks using boost (as well as cspy)
benchmarks_boost:
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \
-DBENCHMARK_TESTS=ON -DBENCHMARK_BOOST=ON -DBUILD_SHARED_LIBS=OFF
cmake --build build --config Release --target all -v
cd build && ctest --verbose

clean:
rm -rf build
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,43 @@ void wrap() {
- [`jpath`](examples/jpath) : Simple example showing the necessary graph adptations and the use of custom resource extension functions.
## Running the tests
## Building
### Prerequisites
### Docker
- Docker, docker-compose
Using docker, docker-compose is the easiest way.
To run the tests first, clone the repository into a path in your machine `~/path/newfolder` by running
```none
git clone https://github.com/torressa/cspy.git ~/path/newfolder
```
### Running the Cpp tests

#### Running the Cpp tests

```
cd ~/path/newfolder/tools/dev
./build
```

### Running the Python tests
#### Running the Python tests

```
cd ~/path/newfolder/tools/dev
./build -c -p
```

### Locally

Requirements:

- CMake (>=v3.14)
- Standard C++ toolchain
- [LEMON](https://lemon.cs.elte.hu/trac/lemon) installed (see [`tools/docker/scripts/install_lemon`](tools/docker/scripts/install_lemon))
- Python (>=3.6)

Then use the [`Makefile`] e.g. `make` in the root dir runs the unit tests

## License

This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
Expand All @@ -203,7 +215,7 @@ After that feel free to send a pull request.

If you have a question or need help, feel free to raise an issue explaining it.

Alternatively, email me at `[email protected]`.
Alternatively, email me at `[email protected]`.

## Citing

Expand Down
Loading

0 comments on commit 432ee0c

Please sign in to comment.