diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57aa066..0831448 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,8 +42,9 @@ jobs: - name: Install and Build run: | - pip install . - python setup.py build + pip install build + python -m build + pip install dist/hygese*.whl - name: Test with pytest run: | diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5aba2d8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.15) + +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH "install prefix" FORCE) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +if(WIN32) + # MSBUILD toolchain names the shared library as hgscvrp.dll + # this forces it to use libhgscvrp.dll + set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "lib") +endif() + +project( + ${SKBUILD_PROJECT_NAME} + VERSION ${SKBUILD_PROJECT_VERSION} + LANGUAGES CXX +) + +set(CMAKE_CXX_STANDARD 17) + +include(FetchContent) +FetchContent_Declare( + hgscvrp + GIT_REPOSITORY https://github.com/vidalt/HGS-CVRP.git + GIT_TAG 1a927955cd2861a29d978f0d359d6e647db9319c +) +FetchContent_MakeAvailable(hgscvrp) + +# runtime library +if(CMAKE_HOST_WIN32) + install(TARGETS lib RUNTIME DESTINATION hygese) +else() + install(TARGETS lib LIBRARY DESTINATION hygese) +endif() diff --git a/hygese/hygese.py b/hygese/hygese.py index 53c763a..415f1ca 100644 --- a/hygese/hygese.py +++ b/hygese/hygese.py @@ -47,9 +47,13 @@ class CAlgorithmParameters(Structure): ("lambda", c_int), ("nbElite", c_int), ("nbClose", c_int), + ("nbIterPenaltyManagement", c_int), ("targetFeasible", c_double), + ("penaltyDecrease", c_double), + ("penaltyIncrease", c_double), ("seed", c_int), ("nbIter", c_int), + ("nbIterTraces", c_int), ("timeLimit", c_double), ("useSwapStar", c_int), ] @@ -62,9 +66,13 @@ class AlgorithmParameters: lambda_: int = 40 nbElite: int = 4 nbClose: int = 5 + nbIterPenaltyManagement: int = 100 targetFeasible: float = 0.2 + penaltyDecrease: float = 0.85 + penaltyIncrease: float = 1.2 seed: int = 0 nbIter: int = 20000 + nbIterTraces: int = 500 timeLimit: float = 0.0 useSwapStar: bool = True @@ -76,9 +84,13 @@ def ctypes(self) -> CAlgorithmParameters: self.lambda_, self.nbElite, self.nbClose, + self.nbIterPenaltyManagement, self.targetFeasible, + self.penaltyDecrease, + self.penaltyIncrease, self.seed, self.nbIter, + self.nbIterTraces, self.timeLimit, int(self.useSwapStar), ) diff --git a/pyproject.toml b/pyproject.toml index 7fd26b9..8704ab9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,14 @@ +[project] +name = "hygese" +version = "0.0.0.11" +authors = [{name = "Changhyun Kwon"}] +description = "Wrapper for the Hybrid Genetic Search algorithm for Capacitated Vehicle Routing Problems (HGS-CVRP)" +readme = {file = "README.md", content-type = "text/markdown"} +requires-python=">=3.10" + [build-system] -requires = ["setuptools"] -build-backend = "setuptools.build_meta" \ No newline at end of file +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[tool.scikit-build] +cmake.build-type = "Release" diff --git a/setup.py b/setup.py deleted file mode 100644 index ab02231..0000000 --- a/setup.py +++ /dev/null @@ -1,134 +0,0 @@ -from setuptools import setup, find_packages -from setuptools.command.build_ext import build_ext as _build_ext -from setuptools.command.build_py import build_py as _build_py -import subprocess -import os -import platform -from os.path import exists, join as pjoin -import shutil - -import urllib.request - -urlretrieve = urllib.request.urlretrieve - -# try: -# import urllib.request -# urlretrieve = urllib.request.urlretrieve -# except ImportError: # python 2 -# from urllib import urlretrieve - - -# read the contents of your README file -from pathlib import Path - -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - - -def _run(cmd, cwd): - subprocess.check_call(cmd, shell=True, cwd=cwd) - - -def _safe_makedirs(*paths): - for path in paths: - try: - os.makedirs(path) - except os.error: - pass - - -HGS_VERSION = "2.0.0" -HGS_SRC = f"https://github.com/vidalt/HGS-CVRP/archive/v{HGS_VERSION}.tar.gz" - -LIB_DIR = "lib" -BUILD_DIR = "lib/build" -BIN_DIR = "lib/bin" - - -def get_lib_filename(): - if platform.system() == "Linux": - lib_ext = "so" - elif platform.system() == "Darwin": - lib_ext = "dylib" - elif platform.system() == "Windows": - lib_ext = "dll" - else: - lib_ext = "so" - return f"libhgscvrp.{lib_ext}" - - -LIB_FILENAME = get_lib_filename() - - -def download_build_hgs(): - _safe_makedirs(LIB_DIR) - _safe_makedirs(BUILD_DIR) - hgs_src_tarball_name = "{}.tar.gz".format(HGS_VERSION) - hgs_src_path = pjoin(LIB_DIR, hgs_src_tarball_name) - urlretrieve(HGS_SRC, hgs_src_path) - _run(f"tar xzvf {hgs_src_tarball_name}", LIB_DIR) - _run( - f'cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../HGS-CVRP-{HGS_VERSION}', - BUILD_DIR, - ) - _run("make lib", BUILD_DIR) - - shutil.copyfile(f"{BUILD_DIR}/{LIB_FILENAME}", f"hygese/{LIB_FILENAME}") - - -# LIB_VERSION = "0.0.1" -# HGS_CVRP_WIN = f"https://github.com/chkwon/Libhgscvrp_jll.jl/releases/download/libhgscvrp-v{LIB_VERSION}%2B0/" + \ -# f"libhgscvrp.v{LIB_VERSION}.x86_64-w64-mingw32-cxx11.tar.gz" - -# def download_binary_hgs(): -# print(HGS_CVRP_WIN) - -# _safe_makedirs(LIB_DIR) -# dll_tarball_name = "win_bin.tar.gz" -# hgs_bin_path = pjoin(LIB_DIR, dll_tarball_name) -# urlretrieve(HGS_CVRP_WIN, hgs_bin_path) -# _run(f"tar xzvf {dll_tarball_name}", LIB_DIR) -# shutil.copyfile(f"{BIN_DIR}/{LIB_FILENAME}", f"hygese/{LIB_FILENAME}") - - -class BuildPyCommand(_build_py): - def run(self): - print("Build!!!!!! Run!!!!") - - if platform.system() == "Windows": - # download_binary_hgs() - download_build_hgs() - else: - download_build_hgs() - - _build_py.run(self) - - -setup( - name="hygese", - version="0.0.0.8", - description="A Python wrapper for the HGS-CVRP solver", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/chkwon/PyHygese", - author="Changhyun Kwon", - author_email="chkwon@gmail.com", - project_urls={ - "Bug Tracker": "https://github.com/chkwon/PyHygese/issues", - }, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - package_dir={"": "."}, - packages=find_packages(), - python_requires=">=3.6", - cmdclass={ - "build_py": BuildPyCommand, - }, - package_data={ - "": ["libhgscvrp.*"], - }, - install_requires=["numpy"], -)