Skip to content

Commit

Permalink
Merge pull request #29 from scipopt/alpha
Browse files Browse the repository at this point in the history
Version 0.4.0
  • Loading branch information
jurgen-lentz authored Feb 29, 2024
2 parents d769123 + b67b649 commit dcb84f0
Show file tree
Hide file tree
Showing 21 changed files with 2,361 additions and 1,996 deletions.
6 changes: 3 additions & 3 deletions .github/actions/setup-scipoptsuite-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
version:
description: "SCIPOptSuite version to install"
required: true
default: "8.1.0"
default: "9.0.0"

runs:
using: "composite"
Expand All @@ -17,6 +17,6 @@ runs:

- name: Install dependencies (SCIPOptSuite)
run: |
wget --quiet --timestamping --directory-prefix=$HOME https://scipopt.org/download/release/SCIPOptSuite-${{ inputs.version }}-Linux-ubuntu.deb
sudo apt-get install -y ~/SCIPOptSuite-${{ inputs.version }}-Linux-ubuntu.deb
wget --quiet --no-check-certificate https://github.com/scipopt/scip/releases/download/$(echo "v${{inputs.version}}" | tr -d '.')/SCIPOptSuite-${{ inputs.version }}-Linux-ubuntu20.deb
sudo apt-get update && sudo apt install -y ./SCIPOptSuite-${{ inputs.version }}-Linux-ubuntu20.deb
shell: bash
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
### Changed
### Removed

## v0.4.0
### Added
* added support for Windows
* added score plugin type
* added constraint classifier plugin type
* added variable classifier plugin type
* added class ConsPart
* added class VarPart
* added tests for score and classifier

## v0.3.1
### Update
* support cython 3.0.0
Expand Down
15 changes: 11 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Note that the latest PyGCGOpt version is usually only compatible with the latest

|SCIP| PySCIPOpt | GCG | PyGCGOpt
|----|----|----|----|
9.0 | | 3.6.0 | 0.4.0 |
8.1 | 4.4 | 3.5.5 | 0.3.0 |
8.0 | 4.0 | 3.5.0 | 0.1.0 |
7.0 | 3.x | - | - |
Expand All @@ -27,7 +28,7 @@ Note that the latest PyGCGOpt version is usually only compatible with the latest
4.0 | 1.2, 1.1 | - | - |
3.2 | 1.0 | - | - |

We recommend installing PyGCGOpt and its Python dependencies in a [Python virtual environment](https://docs.python.org/3/tutorial/venv.html). In short, you can create a virtual environment and activate it with the following commands on Linux and macOS:
We recommend installing PyGCGOpt and its Python dependencies in a [Python virtual environment](https://docs.python.org/3/tutorial/venv.html). In short, you can create a virtual environment and activate it with the following commands on Linux, macOS and Windows:
```
python3.9 -m venv venv
source venv/bin/activate
Expand All @@ -48,14 +49,18 @@ To install the SCIPOptSuite from source, you need to [install SCIP and GCG using
As an example, from the root directory of the source distribution of the SCIPOptSuite, you can run the following commands to build and install locally:
```
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DSHARED=on -DCMAKE_INSTALL_PREFIX=./install -DGCG_DEV_BUILD=on -DZIMPL=OFF -DIPOPT=OFF -DPAPILO=OFF
cmake .. -DCMAKE_BUILD_TYPE=Debug -DSHARED=on -DCMAKE_INSTALL_PREFIX=./install -DGCG_DEV_BUILD=ON -DZIMPL=OFF -DIPOPT=OFF -DPAPILO=OFF
make -j4 && make install
```

If SCIP and GCG are not installed in the global path, you need to specify the install location using the environment variable `SCIPOPTDIR` before you can install PySCIPOpt and PyGCGOpt:

`export SCIPOPTDIR=<path_to_install_dir>`

- On Linux and macOS:\
`export SCIPOPTDIR=<path_to_install_dir>`
- On Windows:\
`set SCIPOPTDIR=<path_to_install_dir>` (**cmd**, **Cmder**, **WSL**)\
`$Env:SCIPOPTDIR = "<path_to_install_dir>"` (**powershell**)

`SCIPOPTDIR` needs to have a subdirectory `lib` that contains the
library, e.g. `libscip.so` and `libgcg.so` (for Linux) and a subdirectory `include` that
contains the corresponding header files:
Expand All @@ -78,6 +83,8 @@ To make the shared libraries available at runtime for PySCIPOpt and PyGCGOpt, yo
`export LD_LIBRARY_PATH=<path_to_install_dir>/lib`
- On macOS:
`export DYLD_FALLBACK_LIBRARY_PATH=<path_to_install_dir>/lib`
- On Windows:
`set PATH=%PATH%;<path_to_install_dir>\bin`


## Installing PySCIPOpt from PyPI
Expand Down
8 changes: 8 additions & 0 deletions docs/api/classifier.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Classifier
**********

.. autoclass:: pygcgopt.gcg.ConsClassifier
:members:

.. autoclass:: pygcgopt.gcg.VarClassifier
:members:
5 changes: 4 additions & 1 deletion docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ API Reference
.. toctree::

model.rst
classifier.rst
decomposition.rst
detprobdata.rst
detector.rst
pricingsolver.rst
partition.rst
pricingsolver.rst
score.rst
8 changes: 8 additions & 0 deletions docs/api/partition.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Partition
*********

.. autoclass:: pygcgopt.gcg.ConsPart
:members:

.. autoclass:: pygcgopt.gcg.VarPart
:members:
5 changes: 5 additions & 0 deletions docs/api/score.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Score
*****

.. autoclass:: pygcgopt.gcg.Score
:members:
34 changes: 18 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
# assume that SCIP is installed on the system
includedirs.append(os.path.abspath(os.path.join(optdir, 'include')))

# Current release of GCG has broken folder structure when installed. All GCG sources *should* be in a `gcg` subfolder in the sources. Until this is fixed, we need to include the `gcg` folder so that imports work.
if os.path.exists(os.path.join(gcgoptdir, 'include')) and not os.path.exists(os.path.join(gcgoptdir, 'include', 'graph')):
includedirs.append(os.path.abspath(os.path.join(gcgoptdir, 'include', 'gcg')))
if not gcgoptdir:
if platform.system() == 'Linux':
includedirs.append("/usr/include/gcg")
Expand All @@ -32,21 +29,27 @@


# determine scip library
if os.path.exists(os.path.join(scipoptdir, 'lib/shared/libscipsolver.so')):
if os.path.exists(os.path.join(scipoptdir, "lib", "shared", "libscip.so")):
# SCIP seems to be created with make
sciplibdir = os.path.abspath(os.path.join(scipoptdir, 'lib/shared'))
sciplibname = 'scipsolver'
extra_compile_args.append('-DNO_CONFIG_HEADER')
sciplibdir = os.path.abspath(os.path.join(scipoptdir, "lib", "shared"))
sciplibname = "scip"
extra_compile_args.append("-DNO_CONFIG_HEADER")
# the following is a temporary hack to make it compile with SCIP/make:
extra_compile_args.append("-DTPI_NONE") # if other TPIs are used, please modify
else:
# assume that SCIP is installed on the system
sciplibdir = os.path.abspath(os.path.join(scipoptdir, 'lib'))
sciplibname = 'scip'
if platform.system() in ['Windows']:
sciplibname = 'libscip'
sciplibdir = os.path.abspath(os.path.join(scipoptdir, "lib"))
sciplibname = "libscip" if platform.system() in ["Windows"] else "scip"

# setup gcg library
gcglibdir = os.path.abspath(os.path.join(gcgoptdir, "lib"))
gcglibname = "gcg"
# determine gcg library
if os.path.exists(os.path.join(gcgoptdir, "lib", "shared", "libgcg.so")):
# SCIP seems to be created with make
gcglibdir = os.path.abspath(os.path.join(gcgoptdir, "lib", "shared"))
gcglibname = "gcg"
else:
# assume that SCIP is installed on the system
gcglibdir = os.path.abspath(os.path.join(gcgoptdir, "lib"))
gcglibname = "libgcg" if platform.system() in ["Windows"] else "gcg"

print('Using SCIP library <%s> at <%s>.' % (sciplibname, sciplibdir))
print('Using GCG library <%s> at <%s>.' % (gcglibname, gcglibdir))
Expand Down Expand Up @@ -82,8 +85,7 @@

ext = '.pyx' if use_cython else '.cpp'

if platform.system() == 'Darwin':
extra_compile_args.append("-std=c++11")
extra_compile_args.append("-std=c++11")

extensions = [Extension('pygcgopt.gcg', [os.path.join(packagedir, 'gcg'+ext)],
include_dirs=includedirs,
Expand Down
76 changes: 42 additions & 34 deletions src/pygcgopt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.3.1'
__version__ = '0.4.0'

# required for Python 3.8 on Windows
import os
Expand All @@ -7,39 +7,47 @@
os.add_dll_directory(os.path.join(os.getenv('SCIPOPTDIR').strip('"'), 'bin'))

# Expose pyscipopt object through pygcgopt
from pyscipopt import multidict
from pyscipopt import Benders
from pyscipopt import Benderscut
from pyscipopt import Branchrule
from pyscipopt import Nodesel
from pyscipopt import Conshdlr
from pyscipopt import Eventhdlr
from pyscipopt import Heur
from pyscipopt import Presol
from pyscipopt import Pricer
from pyscipopt import Prop
from pyscipopt import Sepa
from pyscipopt import LP
from pyscipopt import Expr
from pyscipopt import quicksum
from pyscipopt import quickprod
from pyscipopt import exp
from pyscipopt import log
from pyscipopt import sqrt
from pyscipopt import SCIP_RESULT
from pyscipopt import SCIP_PARAMSETTING
from pyscipopt import SCIP_PARAMEMPHASIS
from pyscipopt import SCIP_STATUS
from pyscipopt import SCIP_STAGE
from pyscipopt import SCIP_PROPTIMING
from pyscipopt import SCIP_PRESOLTIMING
from pyscipopt import SCIP_HEURTIMING
from pyscipopt import SCIP_EVENTTYPE
from pyscipopt import SCIP_LPSOLSTAT
from pyscipopt import SCIP_BRANCHDIR
from pyscipopt import SCIP_BENDERSENFOTYPE
from pyscipopt import SCIP_ROWORIGINTYPE
from pyscipopt import multidict
from pyscipopt import Benders
from pyscipopt import Benderscut
from pyscipopt import Branchrule
from pyscipopt import Nodesel
from pyscipopt import Conshdlr
from pyscipopt import Eventhdlr
from pyscipopt import Heur
from pyscipopt import Presol
from pyscipopt import Pricer
from pyscipopt import Prop
from pyscipopt import Sepa
from pyscipopt import LP
from pyscipopt import Expr
from pyscipopt import quicksum
from pyscipopt import quickprod
from pyscipopt import exp
from pyscipopt import log
from pyscipopt import sqrt
from pyscipopt import SCIP_RESULT
from pyscipopt import SCIP_PARAMSETTING
from pyscipopt import SCIP_PARAMEMPHASIS
from pyscipopt import SCIP_STATUS
from pyscipopt import SCIP_STAGE
from pyscipopt import SCIP_PROPTIMING
from pyscipopt import SCIP_PRESOLTIMING
from pyscipopt import SCIP_HEURTIMING
from pyscipopt import SCIP_EVENTTYPE
from pyscipopt import SCIP_LPSOLSTAT
from pyscipopt import SCIP_BRANCHDIR
from pyscipopt import SCIP_BENDERSENFOTYPE
from pyscipopt import SCIP_ROWORIGINTYPE

# export user-relevant objects
from pygcgopt.gcg import Model, Detector, PricingSolver
from pygcgopt.gcg import Model
from pygcgopt.gcg import Detector
from pygcgopt.gcg import PricingSolver
from pygcgopt.gcg import ConsClassifier
from pygcgopt.gcg import VarClassifier
from pygcgopt.gcg import Score
from pygcgopt.gcg import PY_GCG_PRICINGSTATUS as GCG_PRICINGSTATUS
from pygcgopt.gcg import PY_CONS_DECOMPINFO as CONS_DECOMPINFO
from pygcgopt.gcg import PY_VAR_DECOMPINFO as VAR_DECOMPINFO
from pygcgopt.gcg import PY_USERGIVEN as USERGIVEN
34 changes: 34 additions & 0 deletions src/pygcgopt/consclassifier.pxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cdef class ConsClassifier:
"""Base class of the Constraint Classifier Plugin"""
cdef public Model model
cdef public str name

def freeConsClassifier(self):
'''calls destructor and frees memory of constraint classifier'''
pass

def classify(self, conss, partition):
pass

cdef SCIP_RETCODE PyConsClassifierFree(SCIP* scip, GCG_CONSCLASSIFIER* consclassifier) noexcept with gil:
cdef GCG_CLASSIFIERDATA* consclassifierdata
consclassifierdata = GCGconsClassifierGetData(consclassifier)
py_consclassifier = <ConsClassifier>consclassifierdata
py_consclassifier.freeConsClassifier()
Py_DECREF(py_consclassifier)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsClassifierClassify(SCIP* scip, GCG_CONSCLASSIFIER* consclassifier, SCIP_Bool transformed) noexcept with gil:
cdef GCG_CLASSIFIERDATA* consclassifierdata
consclassifierdata = GCGconsClassifierGetData(consclassifier)
py_consclassifier = <ConsClassifier>consclassifierdata
if transformed:
detprobdata = py_consclassifier.model.getDetprobdataPresolved()
else:
detprobdata = py_consclassifier.model.getDetprobdataOrig()
conss = detprobdata.getRelevantConss()
partition = detprobdata.createConsPart(py_consclassifier.name, 0, len(conss))
py_consclassifier.classify(conss, partition)
print("Consclassifier {0} yields a classification with {1} different constraint classes".format(partition.getName(), partition.getNClasses()))
detprobdata.addConsPartition(partition)
return SCIP_OKAY
Loading

0 comments on commit dcb84f0

Please sign in to comment.