Skip to content

Commit 38fb332

Browse files
authored
Merge pull request #914 from scipopt/dominiks_comments_for_docs
Add comments from dominik
2 parents 4979c99 + 0ca4f65 commit 38fb332

File tree

3 files changed

+81
-80
lines changed

3 files changed

+81
-80
lines changed

docs/tutorials/constypes.rst

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,29 @@ To create a standard linear or non-linear constraint use the command:
3838
# Non-linear constraint
3939
nonlinear_cons = scip.addCons(x * y + z == 1, name="nonlinear_cons")
4040
41-
What is a Row?
42-
================
4341
44-
In a similar fashion to Variables with columns, see :doc:`this page </tutorials/vartypes>`,
45-
constraints bring up an interesting feature of SCIP when used in the context of an LP.
46-
The context of an LP here means that we are after the LP relaxation of the optimization problem
47-
at some node. Is the constraint even in the LP?
48-
When you solve an optimization problm with SCIP, the problem is first transformed. This process is
49-
called presolve, and is done to accelerate the subsequent solving process. Therefore a constraint
50-
that was originally created may have been transformed entirely, as the original variables that
51-
featured in the constraint have also been changed. Additionally, maybe the constraint was found to be redundant,
52-
i.e., trivially true, and was removed. The constraint is also much more general
53-
than necessary, containing information that is not strictly necessary for solving the LP,
54-
and may not even be representable by linear constraints.
55-
Therefore, when representing a constraint in an LP, we use Row objects.
56-
Be warned however, that this is not necessarily a simple one-to-one matching. Some more complicated
57-
constraints may either have no Row representation in the LP or have multiple such rows
58-
necessary to best represent it in the LP. For a standard linear constraint the Row
59-
that represents the constraint in the LP can be found with the code:
42+
Quicksum
43+
========
6044

61-
.. code-block:: python
45+
It is very common that when constructing constraints one wants to use the inbuilt ``sum`` function
46+
in Python. For example, consider the common scenario where we have a set of binary variables.
6247

63-
row = scip.getRowLinear(linear_cons)
48+
.. code-block:: python
6449
65-
.. note:: Remember that such a Row representation refers only to the latest LP, and is
66-
best queried when access to the current LP is clear, e.g. when branching.
50+
x = [scip.addVar(vtype='B', name=f"x_{i}") for i in range(1000)]
6751
68-
From a Row object one can easily obtain information about the current LP. Some quick examples are
69-
the lhs, rhs, constant shift, the columns with non-zero coefficient values, the matching
70-
coefficient values, and the constraint handler that created the Row.
52+
A standard constraint in this example may be that exactly one binary variable can be active.
53+
To sum these varaibles we recommend using the custom ``quicksum`` function, as it avoids
54+
intermediate data structure and adds terms inplace. For example:
7155

7256
.. code-block:: python
7357
74-
lhs = row.getLhs()
75-
rhs = row.getRhs()
76-
constant = row.getConstant()
77-
cols = row.getCols()
78-
vals = row.getVals()
79-
origin_cons_name = row.getConsOriginConshdlrtype()
58+
scip.addCons(quicksum(x[i] for i in range(1000)) == 1, name="sum_cons")
8059
60+
.. note:: While this is often unnecessary for smaller models, for larger models it can have a substantial
61+
improvement on time spent in model construction.
62+
63+
.. note:: For ``prod`` there also exists an equivalent ``quickprod`` function.
8164

8265
Constraint Information
8366
======================
@@ -156,25 +139,42 @@ An example of such a constraint handler
156139
is presented in the lazy constraint tutorial for modelling the subtour elimination
157140
constraints :doc:`here </tutorials/lazycons>`
158141

159-
Quicksum
160-
========
142+
What is a Row?
143+
================
161144

162-
It is very common that when constructing constraints one wants to use the inbuilt ``sum`` function
163-
in Python. For example, consider the common scenario where we have a set of binary variables.
145+
In a similar fashion to Variables with columns, see :doc:`this page </tutorials/vartypes>`,
146+
constraints bring up an interesting feature of SCIP when used in the context of an LP.
147+
The context of an LP here means that we are after the LP relaxation of the optimization problem
148+
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
151+
that was originally created may have been transformed entirely, as the original variables that
152+
featured in the constraint have also been changed. Additionally, maybe the constraint was found to be redundant,
153+
i.e., trivially true, and was removed. The constraint is also much more general
154+
than necessary, containing information that is not strictly necessary for solving the LP,
155+
and may not even be representable by linear constraints.
156+
Therefore, when representing a constraint in an LP, we use Row objects.
157+
Be warned however, that this is not necessarily a simple one-to-one matching. Some more complicated
158+
constraints may either have no Row representation in the LP or have multiple such rows
159+
necessary to best represent it in the LP. For a standard linear constraint the Row
160+
that represents the constraint in the LP can be found with the code:
164161

165162
.. code-block:: python
166163
167-
x = [scip.addVar(vtype='B', name=f"x_{i}") for i in range(1000)]
168-
169-
A standard constraint in this example may be that exactly one binary variable can be active.
170-
To sum these varaibles we recommend using the custom ``quicksum`` function, as it avoids
171-
intermediate data structure and adds terms inplace. For example:
164+
row = scip.getRowLinear(linear_cons)
172165
173-
.. code-block:: python
166+
.. note:: Remember that such a Row representation refers only to the latest LP, and is
167+
best queried when access to the current LP is clear, e.g. when branching.
174168

175-
scip.addCons(quicksum(x[i] for i in range(1000)) == 1, name="sum_cons")
169+
From a Row object one can easily obtain information about the current LP. Some quick examples are
170+
the lhs, rhs, constant shift, the columns with non-zero coefficient values, the matching
171+
coefficient values, and the constraint handler that created the Row.
176172

177-
.. note:: While this is often unnecessary for smaller models, for larger models it can have a substantial
178-
improvement on time spent in model construction.
173+
.. code-block:: python
179174
180-
.. note:: For ``prod`` there also exists an equivalent ``quickprod`` function.
175+
lhs = row.getLhs()
176+
rhs = row.getRhs()
177+
constant = row.getConstant()
178+
cols = row.getCols()
179+
vals = row.getVals()
180+
origin_cons_name = row.getConsOriginConshdlrtype()

docs/tutorials/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ more detailed information see `this page <https://www.scipopt.org/doc/html/index
1111
:caption: Contents:
1212

1313
model
14-
logfile
15-
expressions
16-
readwrite
1714
vartypes
1815
constypes
16+
expressions
17+
readwrite
18+
logfile
1919
branchrule
2020
cutselector
2121
separator

docs/tutorials/vartypes.rst

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,39 @@ For the following let us assume that a Model object is available, which is creat
2121

2222
.. contents:: Contents
2323

24+
Variable Types
25+
===============
26+
27+
SCIP has four different types of variables:
28+
29+
.. list-table:: Variable Types
30+
:widths: 25 25 25
31+
:align: center
32+
:header-rows: 1
33+
34+
* - Variable Type
35+
- Abbreviation
36+
- Description
37+
* - Continuous
38+
- C
39+
- A continuous variable belonging to the reals with some lower and upper bound
40+
* - Integer
41+
- I
42+
- An integer variable unable to take fractional values in a solution with some lower and upper bound
43+
* - Binary
44+
- B
45+
- A variable restricted to the values 0 or 1.
46+
* - Implicit Integer
47+
- M
48+
- A variable that is continuous but can be inferred to be integer in any valid solution
49+
50+
The variable type can be queried from the Variable object.
51+
52+
.. code-block:: python
53+
54+
x = scip.addVar(vtype='C', name='x')
55+
assert x.vtype() == "CONTINUOUS"
56+
2457
Dictionary of Variables
2558
=========================
2659

@@ -95,38 +128,6 @@ Given a Model object, all added variables can be retrieved with the function:
95128
96129
scip_vars = scip.getVars()
97130
98-
Variable Types
99-
=================
100-
101-
SCIP has four different types of variables:
102-
103-
.. list-table:: Variable Types
104-
:widths: 25 25 25
105-
:align: center
106-
:header-rows: 1
107-
108-
* - Variable Type
109-
- Abbreviation
110-
- Description
111-
* - Continuous
112-
- C
113-
- A continuous variable belonging to the reals with some lower and upper bound
114-
* - Integer
115-
- I
116-
- An integer variable unable to take fractional values in a solution with some lower and upper bound
117-
* - Binary
118-
- B
119-
- A variable restricted to the values 0 or 1.
120-
* - Implicit Integer
121-
- M
122-
- A variable that is continuous but can be inferred to be integer in any valid solution
123-
124-
The variable type can be queried from the Variable object.
125-
126-
.. code-block:: python
127-
128-
x = scip.addVar(vtype='C', name='x')
129-
assert x.vtype() == "CONTINUOUS"
130131
131132
Variable Information
132133
=======================

0 commit comments

Comments
 (0)