-
-
Notifications
You must be signed in to change notification settings - Fork 1
Python-Bindings #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Python-Bindings #85
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ecf8050
feat: python bindings first version
d-krupke 2d72128
test: first test case, ci: added python testing ci, feat: renamed obj…
d-krupke ffbc274
feat: safe-guarding against wrong usage.
d-krupke 842e761
chores: refactored the package and improved documentation
d-krupke f8a8527
chores: Sepearate readme for the python bindings.
d-krupke 352b030
fix: only building python module when skbuild is set
d-krupke e9e1660
fix: Trying to fix the solution handling
d-krupke 22f44b8
fix: SPDX stuff
d-krupke 1835d2d
fix: SPDX stuff
d-krupke e0bbfae
fix: SPDX stuff
d-krupke d2654dd
Merge pull request #1 from d-krupke/dev
d-krupke 5c953b1
fix: trying to fix compilation issue with fpic and fmt
d-krupke fbcf854
fix: getting rid of the stupid shadowing warnings
d-krupke 7e2d42a
fix: removing badly copied comment
d-krupke ca1e9d5
docs: added install docs
d-krupke 1c7f0f2
chores: just a little improved docs before merge.
d-krupke c8fd47a
Minor cosmetic changes
c4v4 c98a0fa
+ `DualState` (dua solution, called "state" to avoid confusion)
c4v4 07a899b
Trying to fix python pinding after last commit
c4v4 7f7848c
fix: fixing renamed bindings
d-krupke 07f5060
Removed import and CPM
c4v4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| name: Test Python-bindings on Linux | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.10", "3.12"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install flake8 pytest | ||
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
| - name: Lint with flake8 | ||
| run: | | ||
| # stop the build if there are Python syntax errors or undefined names | ||
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
| - name: build and install | ||
| run: | | ||
| pip install --verbose . | ||
| - name: Test with pytest | ||
| run: | | ||
| pytest -s test |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: 2025 Dominik Krupke <krupked@gmail.com> | ||
| SPDX-License-Identifier: MIT | ||
| --> | ||
|
|
||
| # Python Bindings for the AC-CFT Set Cover Heuristic | ||
|
|
||
|
|
||
|
|
||
| ## Install | ||
|
|
||
| We will publish the package on PyPI soon. For now, you can install the package by cloning the repository and running the following command in the root directory: | ||
|
|
||
| ```bash | ||
| pip install --verbose . | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| To use the `SetCoverSolver`, first create an instance of the solver. You can then add sets with their respective costs and solve the set cover problem. The solver will find the optimal selection of sets that covers all elements at the minimum cost. | ||
|
|
||
| Here is an example: | ||
|
|
||
| ```python | ||
| from pyaccft import SetCoverSolver | ||
|
|
||
| solver = SetCoverSolver() | ||
| # Add sets with their respective costs | ||
| solver.add_set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], cost=10) | ||
| solver.add_set([0, 1, 2, 3, 4, 5], cost=5) | ||
| solver.add_set([0, 1, 2, 3, 4], cost=4) | ||
| solver.add_set([6, 7, 8, 9], cost=4) | ||
|
|
||
| # Solve the set cover problem | ||
| solver.solve() | ||
|
|
||
| # Retrieve and print the solution | ||
| solution = solver.get_solution() | ||
| print("The following sets have been selected:", solution) | ||
| print("The cost of the solution is:", solver.get_cost()) | ||
| print("The lower bound of the solution is:", solver.get_lower_bound()) | ||
| ``` | ||
|
|
||
| Ensure that all elements are zero-indexed and that every element between 0 and the maximum element appears in at least one set for a feasible solution. | ||
|
|
||
| ## Configuration | ||
|
|
||
| You can configure the solver by setting the following parameters in `solve`: | ||
|
|
||
| - seed (int): Seed for the random number generator. Default is 0. | ||
| - time_limit (int): Time limit in seconds. Default is 0 (no limit). | ||
| - verbose (int): Verbosity level. Default is 2. | ||
| - epsilon (float): Epsilon value for objective comparisons. Default is 0.999. | ||
| - heur_iters (int): Number of iterations for the heuristic phase. Default is 250. | ||
| - alpha (float): Relative fixing fraction increment. Default is 1.1. | ||
| - beta (float): Relative cutoff value to terminate Refinement. Default is 1.0. | ||
| - abs_subgrad_exit (float): Minimum LBs delta to trigger subgradient termination. Default is 1.0. | ||
| - rel_subgrad_exit (float): Minimum LBs gap to trigger subgradient termination. Default is 0.001. | ||
| - use_unit_costs (bool): Solve the given instance setting columns cost to one. Default is False. | ||
|
|
This file contains hidden or 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,11 @@ | ||
| # SPDX-FileCopyrightText: 2025 Dominik Krupke <krupked@gmail.com> | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| [build-system] | ||
| requires = [ | ||
| "setuptools", | ||
| "scikit-build>=0.17.3", | ||
| "cmake>=3.23", | ||
| "ninja", | ||
| ] | ||
| build-backend = "setuptools.build_meta" |
This file contains hidden or 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,33 @@ | ||
| # SPDX-FileCopyrightText: 2025 Dominik Krupke <krupked@gmail.com> | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from setuptools import find_packages | ||
| from skbuild import setup | ||
|
|
||
|
|
||
| def readme(): | ||
| """ | ||
| :return: Content of README.md | ||
| """ | ||
|
|
||
| with Path("README.py.md").open() as file: | ||
| return file.read() | ||
|
|
||
|
|
||
| setup( # https://scikit-build.readthedocs.io/en/latest/usage.html#setup-options | ||
| name="pyaccft", | ||
| version="0.0.1", | ||
| author="TODO", | ||
| license="LICENSE", | ||
| description="Pybinding for accft", | ||
| long_description=readme(), | ||
| long_description_content_type="text/markdown", | ||
| packages=find_packages("src"), # Include all packages in `./src`. | ||
| package_dir={"": "src"}, # The root for our python package is in `./src`. | ||
| python_requires=">=3.10", # lowest python version supported. | ||
| install_requires=[ # Python Dependencies | ||
| ], | ||
| cmake_minimum_required_version="3.23", | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.