Skip to content

Commit 91f1923

Browse files
committed
Merge branch 'master' of https://github.com/scipopt/PySCIPOpt into AND-constraints
2 parents 178a850 + bc0e229 commit 91f1923

32 files changed

+548
-204
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
## Unreleased
44
### Added
5-
- Added support for knapsack constraints
65
- More support for AND-Constraints
6+
- Added support for knapsack constraints
7+
- Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests
8+
- Added SCIP_LOCKTYPE, addVarLocksType(), getNLocksDown(), getNLocksUp(), getNLocksDownType(), getNLocksUpType(), and tests
79
### Fixed
10+
- Raised an error when an expression is used when a variable is required
811
### Changed
912
### Removed
1013

INSTALL.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ Installation from PyPI
5656

5757
python -m pip install pyscipopt
5858

59+
To avoid interfering with system packages, it's best to use a [virtual environment](https://docs.python.org/3/library/venv.html).<br>
60+
<span style="color:orange">**Warning!**</span> This is mandatory in some newer configurations.
61+
62+
```bash
63+
python3 -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate pip install pyscipopt
64+
pip install pyscipopt
65+
```
66+
Remember to activate the environment (`source venv/bin/activate`) in each terminal session where you use PySCIPOpt.
67+
5968
Please note that if your Python version and OS version are in the combinations at the start of this INSTALL file then
6069
pip now automatically installs a pre-built version of SCIP. For these combinations, to use your own installation of SCIP,
6170
please see the section on building from source. For unavailable combinations this pip command will automatically

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@ See [CHANGELOG.md](https://github.com/scipopt/PySCIPOpt/blob/master/CHANGELOG.md
2323
Installation
2424
------------
2525

26-
The recommended installation method is via PyPI
26+
The recommended installation method is via [PyPI](https://pypi.org/project/PySCIPOpt/):
27+
28+
```bash
29+
pip install pyscipopt
30+
```
31+
32+
To avoid interfering with system packages, it's best to use a [virtual environment](https://docs.python.org/3/library/venv.html):
33+
2734
```bash
35+
python3 -m venv venv # creates a virtual environment called venv
36+
source venv/bin/activate # activates the environment. On Windows use: venv\Scripts\activate
2837
pip install pyscipopt
2938
```
39+
Remember to activate the environment (`source venv/bin/activate` or equivalent) in each terminal session where you use PySCIPOpt.
40+
Note that some configurations require the use of virtual environments.
3041

3142
For information on specific versions, installation via Conda, and guides for building from source,
3243
please see the [online documentation](https://pyscipopt.readthedocs.io/en/latest/install.html).

docs/extend.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Code contributions are very welcome and should comply to a few rules:
4444
- Before implementing a new PySCIPOpt feature, check whether the
4545
feature exists in SCIP. If so, implement it as a pure wrapper,
4646
mimicking SCIP whenever possible. If the new feature does not exist
47-
in SCIP but it is close to an existing one, consider if implementing
47+
in SCIP, but it is close to an existing one, consider if implementing
4848
that way is substantially convenient (e.g. Pythonic). If it does
4949
something completely different, you are welcome to pull your request
5050
and discuss the implementation.
@@ -77,7 +77,7 @@ API. By design, we distinguish different functions in PySCIPOPT:
7777
Ideally speaking, we want every SCIP function to be wrapped in PySCIPOpt.
7878

7979
**Convenience functions** are additional, non-detrimental features meant
80-
to help prototyping the Python way. Since these functions are not in
80+
to help prototype the Python way. Since these functions are not in
8181
SCIP, we wish to limit them to prevent difference in features between
8282
SCIP and PySCIPOPT, which are always difficult to maintain. A few
8383
convenience functions survive in PySCIPOpt when keeping them is

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ is not automatically deleted, and thus stops a new optimization call.
6060
Why can I not add a non-linear objective?
6161
=========================================
6262

63-
SCIP does not support non-linear objectives, however, an equivalent optimization
63+
SCIP does not support non-linear objectives. However, an equivalent optimization
6464
problem can easily be constructed by introducing a single new variable and a constraint.
6565
Please see :doc:`this page <tutorials/expressions>` for a guide.

docs/install.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ To install PySCIPOpt simply run the command:
2121
2222
pip install pyscipopt
2323
24+
To avoid interfering with system packages, it's best to use a `virtual environment <https://docs.python.org/3/library/venv.html>`.
25+
26+
.. warning::
27+
28+
Using a virtual environment is **mandatory** in some newer Python configurations
29+
to avoid permission and package conflicts.
30+
31+
.. code-block:: bash
32+
python3 -m venv venv
33+
source venv/bin/activate # On Windows use: venv\Scripts\activate
34+
pip install pyscipopt
35+
36+
Remember to activate the environment (``source venv/bin/activate``) in each terminal session where you use PySCIPOpt.
37+
2438
.. note:: For Linux users: PySCIPOpt versions newer than 5.1.1 installed via PyPI now require glibc 2.28+
2539

2640
For our build infrastructure we use `manylinux <https://github.com/pypa/manylinux>`_.

docs/similarsoftware.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Alternate MIP Solvers (with Python interfaces)
99

1010
In the following we will give a list of other mixed-integer optimizers with available python interfaces.
1111
As each solver has its own set of problem classes that it can solve we will use a table with reference
12-
keys to summarise these problem classes.
12+
keys to summarize these problem classes.
1313

1414
.. note:: This table is by no means complete.
1515

@@ -87,8 +87,8 @@ This is software that is built on PySCIPOpt
8787

8888
- `PyGCGOpt <https://github.com/scipopt/PyGCGOpt>`_: An extension of SCIP, using generic decompositions for solving MIPs
8989
- `GeCO <https://github.com/CharJon/GeCO>`_: Generators for Combinatorial Optimization
90-
- `scip-routing <https://github.com/mmghannam/scip-routing>`_: An exact VRPTW solver in Python
91-
- `PySCIPOpt-ML <https://github.com/Opt-Mucca/PySCIPOpt-ML>`_: Python interface to automatically formulate Machine Learning models into Mixed-Integer Programs
90+
- `scip-routing <https://github.com/mmghannam/scip-routing>`_: An exact VRPTW solver in Python
91+
- `PySCIPOpt-ML <https://github.com/Opt-Mucca/PySCIPOpt-ML>`_: Python interface to automatically formulate Machine Learning models into Mixed-Integer Programs
9292
- `SCIP Book <https://scipbook.readthedocs.io/en/latest/>`_: Mathematical Optimization: Solving Problems using SCIP and Python
9393

9494
Additional SCIP Resources

docs/tutorials/branchrule.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ whose LP solution is most fractional.
5858
5959
return {"result": SCIP_RESULT.BRANCHED}
6060
61-
Let's talk about some features of this branching rule. Currently we only explicitly programmed
61+
Let's talk about some features of this branching rule. Currently, we only explicitly programmed
6262
a single function, which is called ``branchexeclp``. This is the function that gets called
6363
when branching on an LP optimal solution. While this is the main case, it is not the only
6464
case that SCIP handles. What if there was an LP error at the node, or you are given a set of external
@@ -108,7 +108,7 @@ strong branching or obtain some strong branching information.
108108

109109
- What happens if a new primal solution is found and the bound is larger than the cutoff bound?
110110
- What happens if the bound for one of the children is above a cutoff bound?
111-
- If probing is enabled then one would need to handle new found bounds appropriately.
111+
- If probing is enabled then one would need to handle new-found bounds appropriately.
112112

113113
.. code-block:: python
114114

docs/tutorials/constypes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ constraint, you'd use the code:
134134
135135
SCIP also allows the creation of custom constraint handlers. These could be empty and just
136136
there to record data, there to provide custom handling of some user defined function, or they could be there to
137-
enforce a constraint that is incredibly inefficient to enforce via linear constraints.
137+
enforce a constraint that is incredibly inefficient to enforce via linear constraints.
138138
An example of such a constraint handler
139139
is presented in the lazy constraint tutorial for modelling the subtour elimination
140140
constraints :doc:`here </tutorials/lazycons>`
@@ -146,8 +146,8 @@ In a similar fashion to Variables with columns, see :doc:`this page </tutorials/
146146
constraints bring up an interesting feature of SCIP when used in the context of an LP.
147147
The context of an LP here means that we are after the LP relaxation of the optimization problem
148148
at some node. Is the constraint even in the LP?
149-
When you solve an optimization problm with SCIP, the problem is first transformed. This process is
150-
called presolve, and is done to accelerate the subsequent solving process. Therefore a constraint
149+
When you solve an optimization problem with SCIP, the problem is first transformed. This process is
150+
called presolve, and is done to accelerate the subsequent solving process. Therefore, a constraint
151151
that was originally created may have been transformed entirely, as the original variables that
152152
featured in the constraint have also been changed. Additionally, maybe the constraint was found to be redundant,
153153
i.e., trivially true, and was removed. The constraint is also much more general

docs/tutorials/cutselector.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ A cut selector in PySCIPOpt takes the following structure:
3333
"""
3434
:param cuts: the cuts which we want to select from. Is a list of scip Rows
3535
:param forcedcuts: the cuts which we must add. Is a list of scip Rows
36-
:param root: boolean indicating whether weare at the root node
36+
:param root: boolean indicating whether we are at the root node
3737
:param maxnselectedcuts: int which is the maximum amount of cuts that can be selected
3838
:return: sorted cuts and forcedcuts
3939
"""
@@ -58,14 +58,14 @@ To include a cut selector one would need to do something like the following code
5858
5959
The final argument of the ``includeCutsel`` function in the example above was the
6060
priority. If the priority is higher than all other cut selectors then it will be called
61-
first. In the case of some failure or non-success return code, then the second highest
61+
first. In the case of some failure or non-success return code, then the second-highest
6262
priority cut selector is called and so on.
6363

6464
Example Cut Selector
6565
======================
6666

6767
In this example we will program a cut selector that selects the 10 most
68-
efficacious cuts. Efficacy is the standard measure for cut quality and can be calcuated
68+
efficacious cuts. Efficacy is the standard measure for cut quality and can be calculated
6969
via SCIP directly.
7070

7171
.. code-block:: python

docs/tutorials/eventhandler.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The first argument is the model object and the second argument is the event that
5151
Adding Event Handlers with Classes
5252
==================================
5353

54-
If you need to store additional data in the event handler, you can create a custom event handler class that inherits from :code:`pyscipopt.Eventhdlr`.
54+
If you need to store additional data in the event handler, you can create a custom event handler class that inherits from :code:`pyscipopt.Eventhdlr`,
5555
and then include it in the model using the :code:`Model.includeEventHandler` method. The following is an example that stores the number of best solutions found:
5656

5757
.. code-block:: python

docs/tutorials/expressions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Non-Linear Objectives
2424
======================
2525

2626
While SCIP supports general non-linearities, it only supports linear objective functions.
27-
With some basic reformulation this is not a restriction however. Let's consider the general
27+
With some basic reformulation this is not a restriction, however. Let's consider the general
2828
optimization problem:
2929

3030
.. math::
@@ -118,7 +118,7 @@ Absolute (Abs)
118118
===============
119119

120120
Absolute values of expressions is supported by overloading how ``__abs__`` function of
121-
SCIP expression objects. Therefore one does not need to import any functions.
121+
SCIP expression objects. Therefore, one does not need to import any functions.
122122
Let's see an example for constructing the following constraint:
123123

124124
.. math::

docs/tutorials/heuristic.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ To include the heuristic in the SCIP model one would use the following code:
9797
9898
.. note:: The ``timingmask`` is especially important when programming your own heuristic. See
9999
`here <https://www.scipopt.org/doc/html/HEUR.php>`_ for information on timing options and how the affect
100-
when the heuristic can be called. Note also that heuristic are as other plugins, called in order of
100+
when the heuristic can be called. Note also that heuristics are, as other plugins, called in order of
101101
their priorities.
102102

103103
.. note:: When you create a SCIP solution object it is important that you eventually free the object.
104104
This is done by calling ``scip.freeSol(sol)``, although this is not necessary when the solution has been
105-
passed to ``scip.trySol(sol)`` with ``free=True`` (default behaviour).
105+
passed to ``scip.trySol(sol)`` with ``free=True`` (default behavior).
106106

docs/tutorials/lazycons.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Why use a Constraint Handler?
2424
=============================
2525

2626
SCIP does not have a lazy constraint plug-in, rather its definition of constraint is broad enough to
27-
naturally encompass lazy constraints already. Therefore the user must simply create an appropriate
27+
naturally encompass lazy constraints already. Therefore, the user must simply create an appropriate
2828
constraint handler.
2929

3030

@@ -48,8 +48,8 @@ integer programming formulation for the problem is:
4848
& & & x_{i,j} \in \{0,1\}, \quad \forall (i,j) \in \mathcal{V} \times \mathcal{V}
4949
5050
In the above formulation, the second set of constraints (marked with an \*) are called subtour elimination constraints.
51-
They are called such as a valid solution in absense of those constraints might consist of a collection
52-
of smaller cycles instead of a single large cycle. As the constraint set requires checking every subset of nodes
51+
They are called such as a valid solution in absence of those constraints might consist of a collection
52+
of smaller cycles instead of a single large cycle. As the constraint set requires checking every subset of nodes,
5353
there are exponentially many. Moreover, we know that most of the constraints are probably unnecessary,
5454
because it is clear from the objective that a minimum tour does not exist with a mini-cycle of nodes that are
5555
extremely far away from each other. Therefore, we want to model them as lazy constraints!
@@ -147,7 +147,7 @@ Now we will create the code on how to implement such a constraint handler.
147147
148148
# add subtour elimination constraint for each subtour
149149
for S in subtours:
150-
print("Constraint added!)
150+
print("Constraint added!")
151151
self.model.addCons(quicksum(x[i][j] for i in S for j in S if j>i) <= len(S)-1)
152152
consadded = True
153153
@@ -164,7 +164,7 @@ Now we will create the code on how to implement such a constraint handler.
164164
165165
In the above we've created our problem and custom constraint handler! We now need to actually
166166
add the constraint handler to the problem. After that, we can simply call ``optimize`` whenever we are ready.
167-
To add the costraint handler use something along the lines of the following:
167+
To add the constraint handler use something along the lines of the following:
168168

169169
.. code-block:: python
170170

docs/tutorials/logfile.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ how much memory is being used, and predicted amount of the tree search completed
226226
It should be mentioned that in the log file above there is a pause in between the branch-and-bound
227227
output and SCIP provides more presolve information. This is due to SCIP identifying that
228228
it is beneficial to start the branch-and-bound tree again but this time applying information
229-
it has learnt to the beginning of the search process. In the example above this is explained by the lines:
229+
it has learned to the beginning of the search process. In the example above this is explained by the lines:
230230

231231
.. code-block:: RST
232232
@@ -248,7 +248,7 @@ and finally the gap (the relative difference between the primal and dual bound).
248248
How to Redirect SCIP Output
249249
===========================
250250

251-
If you do not want this information output to your terminal than before calling ``optimize`` one can
251+
If you do not want this information output to your terminal, then before calling ``optimize`` one can
252252
call the following function:
253253

254254
.. code-block:: python

docs/tutorials/model.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ We can construct the optimization problem as follows:
3838
y = scip.addVar(vtype='C', lb=0, ub=None, name='y')
3939
z = scip.addVar(vtype='C', lb=0, ub=None, name='z')
4040
cons_1 = scip.addCons(x + y <= 5, name="cons_1")
41-
cons_2 = scip.addCons(y + z >= 3, name="cons_2")
42-
cons_3 = scip.addCons(x + y == 5, name="cons_3")
41+
cons_2 = scip.addCons(x + z >= 3, name="cons_2")
42+
cons_3 = scip.addCons(y + z == 4, name="cons_3")
4343
scip.setObjective(2 * x + 3 * y - 5 * z, sense="minimize")
4444
scip.optimize()
4545
4646
That's it! We've built the optimization problem defined above and we've optimized it.
4747
For how to read a Model from file see :doc:`this page </tutorials/readwrite>` and for best practices
4848
on how to create more variables see :doc:`this page </tutorials/vartypes>`.
4949

50-
.. note:: ``vtype='C'`` here refers to a continuous variables.
50+
.. note:: ``vtype='C'`` here refers to a continuous variable.
5151
Providing the lb, ub was not necessary as they default to (0, None) for continuous variables.
5252
Providing the name attribute is not necessary either but is good practice.
5353
Providing the objective sense was also not necessary as it defaults to "minimize".
@@ -173,7 +173,7 @@ You can find below a list of the available options, alongside their meaning.
173173
* - ``PARAMEMPHASIS.COUNTER``
174174
- to get feasible and "fast" counting process
175175
* - ``PARAMEMPHASIS.CPSOLVER``
176-
- to get CP like search (e.g. no LP relaxation)
176+
- to get CP-like search (e.g. no LP relaxation)
177177
* - ``PARAMEMPHASIS.EASYCIP``
178178
- to solve easy problems fast
179179
* - ``PARAMEMPHASIS.FEASIBILITY``
@@ -200,7 +200,7 @@ A SCIP Model can also be copied. This can be done with the following logic:
200200
201201
scip_alternate_model = Model(sourceModel=scip) # Assuming scip is a pyscipopt Model
202202
203-
This model is completely independent from the source model. The data has been duplicated.
203+
This model is completely independent of the source model. The data has been duplicated.
204204
That is, calling ``scip.optimize()`` at this point will have no effect on ``scip_alternate_model``.
205205

206206
.. note:: After optimizing users often struggle with reoptimization. To make changes to an

docs/tutorials/nodeselector.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ What is a Node Selector?
1717
========================
1818

1919
In the branch-and-bound tree an important question that must be answered is which node should currently
20-
be processed. That is, given a branch-and-bound tree in an intermediate state, select a a leaf node of the tree
20+
be processed. That is, given a branch-and-bound tree in an intermediate state, select a leaf node of the tree
2121
that will be processed next (most likely branched on). In SCIP this problem has its own plug-in,
2222
and thus custom algorithms can easily be included into the solving process!
2323

docs/tutorials/readwrite.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ what formats those are and the model types they're associated with.
5151

5252
.. note:: In general we recommend sharing files using the ``.mps`` extension when possible.
5353

54-
For a more human readable format for equivalent problems we recommend the ``.lp`` extension.
54+
For a more human-readable format for equivalent problems we recommend the ``.lp`` extension.
5555

5656
For general non-linearities that are to be shared with others we recommend the ``.osil`` extension.
5757

0 commit comments

Comments
 (0)