Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AnArut96 committed Jul 17, 2024
0 parents commit 9efecf5
Show file tree
Hide file tree
Showing 20 changed files with 2,789 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
extend-ignore = E203,E266,E501,W503
max-line-length = 88
max-complexity = 18
select = B,C,E,F,W,T4,B9
mypy_config = .mypy.ini
37 changes: 37 additions & 0 deletions .github/workflows/gitlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Trigger Gitlab Pipeline
on:
push:
branches:
- main
paths:
- "k_means_ilp/**"
- "tests/**"
- "config/**"
- "poetry.lock"
pull_request:
paths:
- "k_means_ilp/**"
- "tests/**"
- "config/**"
- "poetry.lock"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
name: Trigger GitLab Pipeline
runs-on: ubuntu-latest
steps:
- name: Trigger Job
uses: digital-blueprint/gitlab-pipeline-trigger-action@v1
with:
host: 'gitlab.cs.uni-duesseldorf.de'
trigger_token: ${{ secrets.DEPLOY_TRIGGER_TOKEN }}
access_token: ${{ secrets.DEPLOY_ACCESS_TOKEN }}
id: '3102'
ref: 'main'
variables: |
{
"PROJECT": "k_means_ilp",
"GIT_HASH": "${{ github.event.pull_request.head.sha || github.sha }}"
}
50 changes: 50 additions & 0 deletions .github/workflows/mypy-flake-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Q&A and Tests

on:
push:
branches:
- main
paths:
- "k_means_ilp/**"
- "tests/**"
- "config/**"
- "poetry.lock"
pull_request:
paths:
- "k_means_ilp/**"
- "tests/**"
- "config/**"
- "poetry.lock"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.2 python3 -
poetry run pip install -U pip
poetry install --with dev
- name: Run MyPy
run: |
mkdir .mypy_cache
poetry run mypy --install-types --non-interactive k_means_ilp
- name: Run Flake8
run: |
poetry run flake8 k_means_ilp/
- name: Run Tests
run: |
poetry run python -m unittest discover tests -v
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Upload to PyPi

on:
release:
types: [published]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.2 python3 -
export PATH="/root/.local/bin:$PATH"
poetry run pip install -U pip
poetry install
- name: Publish package
run: poetry publish --build --username __token__ --password ${{ secrets.PYPI_TOKEN }}
166 changes: 166 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

.vscode/
.idea/
.DS_Store
9 changes: 9 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[mypy]
disallow_untyped_defs = True
disallow_untyped_calls = True
ignore_missing_imports = True
warn_no_return = True
warn_return_any = True
warn_unreachable = True
warn_unused_configs = True
exclude = _external
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: end-of-file-fixer
exclude: \\w+.pdf
- id: trailing-whitespace
exclude: \\w+.pdf
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: ["flake8-bugbear==21.4.3"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
args: ["--install-types", "--non-interactive"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Algorithms and Data Structures Group of the Heinrich Heine University Düsseldorf

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# K-Means-ILP

1. [Install poetry](https://python-poetry.org/docs/#installing-with-the-official-installer)
2. Install the dependencies
```bash
poetry install
```
3. Run the program
```bash
poetry run python -m kmeans_ilp --use-kmeanspp-solution --data-path test_30.csv --verbose --results-path test/test.json --k 3
```

Your `data-path` should be a file containing only the comma-separated data points.
28 changes: 28 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ilp_version: v4

branch_priorities: true
replace_min: true
branching_ilp: true
branching_levels: 5
fill_cluster_sizes: false

model_params:
TimeLimit: 28800
BarHomogeneous: 1
BarConvTol: 0.001
FeasibilityTol: 0.001
# Method: 2
# Crossover: 0
# NodeMethod: 2

bound_model_params:
TimeLimit: 1800
BarConvTol: 0.0001
FeasibilityTol: 0.0001
# Concurrent spin time: 9.02s (can be avoided by choosing Method=3)
Method: 3

# https://support.gurobi.com/hc/en-us/community/posts/4406728832145-Crossover-Takes-Long
# Method: 2
# Crossover: 0
# NodeMethod: 2
Empty file added k_means_ilp/__init__.py
Empty file.
Loading

0 comments on commit 9efecf5

Please sign in to comment.