Skip to content

Commit

Permalink
Merge branch 'Serious-senpai:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
khoint5304 authored Nov 28, 2023
2 parents 05fab80 + 8f5adce commit 5fa055f
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 33 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/compare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
problem="${{ github.event.comment.body }}"
problem=$(echo ${problem#"/d2d-compare"} | xargs)
echo -n "$problem" > input.txt
echo "$problem"
[[ "$problem" =~ ^[0-9]+$dot[0-9]+$dot[0-9]+$ ]]
exit $?
Expand Down Expand Up @@ -67,6 +68,9 @@ jobs:
name: Test on PR
runs-on: ubuntu-latest
needs: input-check
strategy:
matrix:
counter: [1, 2]

steps:
- name: Checkout PR branch
Expand All @@ -88,18 +92,21 @@ jobs:
--drone-config-mapping 3 3 3 3 \
--propagation-priority min-distance \
--pool-size 8 \
--dump pr-#${{ github.event.issue.number }}.json
--dump PR#${{ github.event.issue.number }}-run#${{ matrix.counter }}.json
- name: Upload solution
uses: actions/upload-artifact@v3
with:
name: solutions
path: pr-#${{ github.event.issue.number }}.json
path: PR#${{ github.event.issue.number }}-run#${{ matrix.counter }}.json

main-test:
name: Test on main
runs-on: ubuntu-latest
needs: input-check
strategy:
matrix:
counter: [1, 2]

steps:
- name: Checkout main branch
Expand All @@ -123,13 +130,13 @@ jobs:
--drone-config-mapping 3 3 3 3 \
--propagation-priority min-distance \
--pool-size 8 \
--dump main.json
--dump main-run#${{ matrix.counter }}.json
- name: Upload solution
uses: actions/upload-artifact@v3
with:
name: solutions
path: main.json
path: main-run#${{ matrix.counter }}.json

compare:
name: Compare solutions
Expand All @@ -152,30 +159,37 @@ jobs:
- name: Combine solutions and compare
run: |
export PYTHONPATH=$GITHUB_WORKSPACE
python scripts/d2d-compare.py pr-#${{ github.event.issue.number }}.json main.json
python scripts/d2d-compare.py PR#${{ github.event.issue.number }}-run#1.json PR#${{ github.event.issue.number }}-run#2.json main-run#1.json main-run#2.json
- name: Upload compare result
- name: Upload compare result as artifact
uses: actions/upload-artifact@v3
with:
name: solutions
path: compare.png

- name: Upload compare result to catbox.moe
run: |
url=$(curl -F "reqtype=fileupload" -F "fileToUpload=@compare.png" "https://catbox.moe/user/api.php")
errorcode=$?
echo "$url"
echo -n "$url" > url.txt
exit $errorcode
- name: Send completion notification
uses: actions/github-script@v7
with:
retries: 3
script: |
var fs = require("fs");
await fs.readFile(
"input.txt",
"utf-8",
function(error, data) {
await fs.readFile("input.txt", "utf-8", async function (error, input) {
if (error) throw error;
await fs.readFile("url.txt", "utf-8", async function (error, url) {
if (error) throw error;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.issue.number }},
body: `🎉 Comparison request for D2D problem \`${data.trim()}\` completed! You can view the workflow results [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).`,
body: `🎉 Comparison request for D2D problem \`${input.trim()}\` completed! You can view the workflow results [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).\n![compare.png](${url.trim()})`,
});
}
);
});
});
33 changes: 29 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ permissions:
contents: read

jobs:
python:
name: Python lint
autopep8:
name: Run autopep8
runs-on: ubuntu-latest

steps:
Expand All @@ -21,8 +21,33 @@ jobs:
- name: Install dependencies
run: pip install -r dev-requirements.txt

- name: Check code format
- name: Run autopep8
run: autopep8 --exit-code --diff -aaar .

- name: Check typings
mypy:
name: Run mypy
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: pip install -r dev-requirements.txt

- name: Run mypy
run: mypy .

flake8:
name: Run flake8
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: pip install -r dev-requirements.txt

- name: Run flake8
run: flake8 .
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Tabu search technique for solving optimization problems. TSP problems are taken from [TSPLIB](http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95).

## Setup
- It is highly recommended to create a virtual environment by running `python -m venv .venv`
- It is highly recommended to create a virtual environment by running `python3 -m venv .venv`
- Install dependencies for running the optimizers
```
$ pip install -r requirements.txt
Expand All @@ -16,11 +16,3 @@ $ pip install -r requirements.txt
```
$ pip install -r dev-requirements.txt
```
- Codes must be formatted using [autopep8](https://pypi.org/project/autopep8). Run `autopep8` at the root of the repository
```
$ autopep8 -aaair .
```
- Codes must pass the [mypy](https://pypi.org/project/mypy) type-checking.
```
$ mypy .
```
2 changes: 1 addition & 1 deletion d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ def _ideal_distance_key(pareto_costs: Dict[Tuple[float, ...], int], candidate: d
print(f"Saved solution to {namespace.dump!r}")

if len(errors) > 0:
raise ValueError(f"Some calculations were incorrect:\n" + "\n".join(errors))
raise ValueError("Some calculations were incorrect:\n" + "\n".join(errors))
5 changes: 4 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ cycler==0.12.1
Deprecated==1.2.14
dill==0.3.7
exceptiongroup==1.2.0
flake8==6.1.0
fonttools==4.45.1
future==0.18.3
grapheme==0.6.0
iniconfig==2.0.0
kiwisolver==1.4.5
matplotlib==3.8.2
mccabe==0.7.0
mypy==1.7.0
mypy-extensions==1.0.0
numpy==1.26.2
packaging==23.2
Pillow==10.1.0
pluggy==1.3.0
pycodestyle==2.11.1
pymoo==0.6.1
pyflakes==3.1.0
pymoo==0.6.1.1
pyparsing==3.1.1
pytest==7.4.3
python-dateutil==2.8.2
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ matplotlib==3.8.2
numpy==1.26.2
packaging==23.2
Pillow==10.1.0
pymoo==0.6.1
pymoo==0.6.1.1
pyparsing==3.1.1
python-dateutil==2.8.2
scipy==1.11.4
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ exclude_also =
def __repr__
raise NotImplementedError
return NotImplemented

[flake8]
extend-ignore = E501
exclude = .git,.venv,__pycache__,__init__.py
2 changes: 1 addition & 1 deletion ts/abc/multi_ob/solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def tabu_search(
current = [initial]
candidate_costs = {initial.cost()} if plot_pareto_front else None
if len(initial.cost()) != 2:
message = f"Cannot plot the Pareto front when the number of objectives is not 2"
message = "Cannot plot the Pareto front when the number of objectives is not 2"
raise ValueError(message)

with Pool(pool_size) as pool:
Expand Down
5 changes: 2 additions & 3 deletions ts/tsp/solutions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations
from multiprocessing import pool

import itertools
import random
import re
from math import sqrt
from multiprocessing import pool
from multiprocessing import pool as p
from os import path
from typing import Any, Callable, ClassVar, Final, List, Optional, Tuple, Union, TYPE_CHECKING

Expand Down Expand Up @@ -81,7 +80,7 @@ def path(self) -> Tuple[int, ...]:
def cost(self) -> float:
return self._cost

def post_optimization(self, *, pool: pool.Pool, pool_size: int, use_tqdm: bool, logger: Optional[Callable[[str], Any]]) -> TSPPathSolution:
def post_optimization(self, *, pool: p.Pool, pool_size: int, use_tqdm: bool, logger: Optional[Callable[[str], Any]]) -> TSPPathSolution:
result = self
iterations: Union[Tuple[SingleObjectiveNeighborhood[TSPPathSolution, Any], ...], tqdm[SingleObjectiveNeighborhood[TSPPathSolution, Any]]] = self.get_neighborhoods()
if use_tqdm:
Expand Down

0 comments on commit 5fa055f

Please sign in to comment.