@@ -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
8265Constraint Information
8366======================
@@ -156,25 +139,42 @@ An example of such a constraint handler
156139is presented in the lazy constraint tutorial for modelling the subtour elimination
157140constraints :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()
0 commit comments