Skip to content

Commit be6bcda

Browse files
committed
SOCP docu #192
Section in the Modeling Guide
1 parent 533799c commit be6bcda

File tree

4 files changed

+78
-26
lines changed

4 files changed

+78
-26
lines changed

doc/rst/modeling-expressions.rst

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,43 @@ Certain nonlinear solvers, notably Knitro, handle complementarity constraints na
384384
cost[j] - sum {i in PROD} Price[i] * io[i,j];
385385
386386
387-
Nonlinear operators and functions
387+
388+
Set membership operator
388389
**********************************
389390

391+
- var *var-name* in *set-expr* ;
392+
Defines a variable that must be a member of a specified AMPL set,
393+
as given by the expression *set-expr*. All members of the set must be numbers.
394+
395+
This is the simplest use of ``in`` to restrict the domain of a set; more
396+
generally, the *in set-expr* phrase may appear in any ``var`` definition
397+
that does not contain an *=* phrase.
398+
399+
Before sending a problem to the solver interface, AMPL converts variable
400+
definitions of this kind to alternative definitions that do not use the
401+
``in`` operator. This may involve the definition of auxiliary binary
402+
variables and additional constraints. In the usual case where *set-expr*
403+
is a finite set, AMPL also defines suffixes ``.sos`` and ``.sosref`` which
404+
can be used by the solver interface to recognize variables and constraints
405+
that have been created to implement an ``in`` operator, and to support
406+
solvers that handle arbitrary variable domains by means of
407+
"special ordered sets of type 1". It is also possible to specify sets
408+
that contain continuous intervals -- and hence are infinite -- by using
409+
the AMPL expression *interval[expr1,expr2]*.
410+
411+
.. code-block:: ampl
412+
413+
var Buy {f in FOODS} in {0,10,30,45,55};
414+
415+
.. code-block:: ampl
416+
417+
var Ship {(i,j) in ARCS}
418+
in {0} union interval[min_ship,capacity[i,j]];
419+
420+
421+
390422
Quadratic and power operators
391-
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
423+
**********************************
392424

393425
- *expr1* * *expr2*
394426
*expr-valued:* Multiplication of *expr1* and *expr2*.
@@ -431,8 +463,34 @@ previously described. For example:
431463
c[i] * x[i] / (40 * b[i] * sum {j in J} x[j] / b[j]);
432464
433465
466+
Second-order cone programming (SOCP)
467+
**************************************
468+
469+
Some solvers can handle SOCP constraints: Mosek, Gurobi, COPT.
470+
SOCP constraints are recognized by MP drivers from their algebraic
471+
representations. Examples:
472+
473+
- Standard SOC:
474+
475+
.. code-block:: ampl
476+
477+
x[0] >= sqrt(x[1]^2 + … + x[n]^2);
478+
-5*x[0]^2 <= -x[1]^2 - … - x[n]^2, where x[0] >= 0;
479+
0.04 >= abs(x[1]);
480+
481+
- Rotated SOC (where x[0], x[1] >= 0):
482+
483+
.. code-block:: ampl
484+
485+
3*sqrt(5*x[0]*x[1]) >= 15*sqrt(10*x[2]^2 + … + 80*x[n]^2);
486+
2*x[0]*x[1] >= x[2]^2 + … + x[n]^2;
487+
488+
*Note:* Option `cvt:socp=0` results in second-order conic
489+
constraints being passed to the solver as quadratics.
490+
491+
434492
General nonlinear functions
435-
$$$$$$$$$$$$$$$$$$$$$$$$$$$
493+
**********************************
436494

437495
- log (*expr*), log10 (*expr*)
438496
*expr-valued:* The natural and base-10 logarithms of *expr*.
@@ -504,23 +562,3 @@ specifies 12 pieces for approximating the sin, cos, and exp functions in that ob
504562
x[1]^2 - 12*x[1] + 11 + 10*cos(pi*x[1]/2) +
505563
8*sin(pi*5*x[1]) - exp(-(x[2]-.5)^2/2)/sqrt(5);
506564
507-
508-
Set membership operator
509-
**********************************
510-
511-
- var *var-name* in *set-expr* ;
512-
Defines a variable that must be a member of a specified AMPL set, as given by the expression *set-expr*. All members of the set must be numbers.
513-
514-
This is the simplest use of ``in`` to restrict the domain of a set; more generally, the *in set-expr* phrase may appear in any ``var`` definition that does not contain an *=* phrase.
515-
516-
Before sending a problem to the solver interface, AMPL converts variable definitions of this kind to alternative definitions that do not use the ``in`` operator. This may involve the definition of auxiliary binary variables and additional constraints. In the usual case where *set-expr* is a finite set, AMPL also defines suffixes ``.sos`` and ``.sosref`` which can be used by the solver interface to recognize variables and constraints that have been created to implement an ``in`` operator, and to support solvers that handle arbitrary variable domains by means of "special ordered sets of type 1". It is also possible to specify sets that contain continuous intervals -- and hence are infinite -- by using the AMPL expression *interval[expr1,expr2]*.
517-
518-
.. code-block:: ampl
519-
520-
var Buy {f in FOODS} in {0,10,30,45,55};
521-
522-
.. code-block:: ampl
523-
524-
var Ship {(i,j) in ARCS}
525-
in {0} union interval[min_ship,capacity[i,j]];
526-

include/mp/flat/converter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,10 @@ class FlatConverter :
891891
if (ModelAPIAcceptsQuadraticCones())
892892
GetEnv().AddOption("cvt:socp passsocp socp",
893893
ModelAPIAcceptsQuadraticCones()>1 ?
894-
"0/1*: Recognize quadratic cones." :
895-
"0*/1: Recognize quadratic cones.",
894+
"0/1*: Recognize quadratic cones vs passing them "
895+
"as pure quadratic constraints." :
896+
"0*/1: Recognize quadratic cones vs passing them "
897+
"as pure quadratic constraints.",
896898
options_.passSOCPCones_, 0, 1);
897899
options_.passSOCPCones_ = ModelAPIAcceptsQuadraticCones()>1;
898900
GetEnv().AddOption("alg:relax relax",

solvers/copt/CHANGES.copt.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ Summary of recent updates to COPT for AMPL
22
==========================================
33

44

5+
## unreleased
6+
- Recognition of second-order conic constraints
7+
from algebraic representations and conversion into
8+
quadratic constraints; COPT appears to recognize
9+
second-order cones from quadratics.
10+
11+
512
## 20230207
613
- *Changes in the MP library*
714
- Updated to Copt 6.0.4, which includes bugfixes

test/end2end/scripts/python/Solver.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,12 @@ def _getAMPLOptionsName(self):
741741

742742
def __init__(self, exeName, timeout=None, nthreads=None, otherOptions=None):
743743
stags = {ModelTags.continuous, ModelTags.integer, ModelTags.binary,
744-
ModelTags.quadratic, ModelTags.quadratic_obj}
744+
ModelTags.quadratic, ModelTags.quadratic_obj,
745+
746+
ModelTags.socp, ## MP transforms cones to quadratics
747+
ModelTags.socp_hard_to_recognize
748+
749+
}
745750
super().__init__(exeName, timeout, nthreads, otherOptions, stags)
746751

747752

0 commit comments

Comments
 (0)