Problem with AMPL and logical constraint _slogcon[1] is not an indicator constraint

4,787 views
Skip to first unread message

Paul

unread,
May 16, 2013, 5:18:38 PM5/16/13
to am...@googlegroups.com
var z {1..4} binary; # z[i] = 1 if the i-th border check is failed
param M {1..4} > 0; # maximum possible violation of the i-th border check
subject to borderCheck1 {i in 1..nb_rect, j in 1..nb_rect}: x2[i] <= x[j] + M[1]*z[1];
subject to borderCheck2 {i in 1..nb_rect, j in 1..nb_rect}: x2[j] <= x[i] + M[2]*z[2];
subject to borderCheck3 {i in 1..nb_rect, j in 1..nb_rect}: y2[i] <= y[j] + M[3]*z[3];
subject to borderCheck4 {i in 1..nb_rect, j in 1..nb_rect}: y2[j] <= y[i] + M[4]*z[4];
subject to passAtLeastOne: sum {i in 1..4} z[i] <= 3;

Directly or indirectly, disjunctions require the introduction of binary variables (or an equivalent adjustment of the branching mechanism) and force an LP to become a MILP. I'm not sure if there is a way to write a disjunction in AMPL and have it automatically converted to indicator constraints or have binary variables automatically introduced, but the above is how we old-timers do it. :-)

Robert Fourer

unread,
May 22, 2013, 2:41:49 PM5/22/13
to am...@googlegroups.com

The standard AMPL/CPLEX interface will accept certain kinds of logical constraints, but only if they are "indicator" constraints that have one of the two forms

 

   <binary-var> = 0  ==>  constraint

   <binary-var> = 1  ==>  constraint

 

where ==> means "implies", or equivalent constraints using <== or <==> in the obvious way.  Thus you could formulate your constraint as

 

   var xind {i in 1..nb_rect, j in 1..nb_rect} binary;

   var yind {i in 1..nb_rect, j in 1..nb_rect} binary;

 

   subj to xindDefn {i in 1..nb_rect, j in 1..nb_rect}: xind[i,j] = 1 ==> x2[i] <= x[j];

   subj to yindDefn {i in 1..nb_rect, j in 1..nb_rect}: yind[i,j] = 1 ==> y2[i] <= y[j];

 

   subj to borderCheck {i in 1..nb_rect, j in 1..nb_rect}:

      xind[i,j] + xind[j,i] + yind[i,j] + yind[j,i] >= 1;

 

Alternatively you can use the borderCheck constraint as you wrote it, by sending your model to the "ilogcp" interface to CPLEX -- see www.ampl.com/NEW/LOGIC for details, especially the "IBM ILOG CP with CPLEX" section.

 

Bob Fourer

am...@googlegroups.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of Jean Respen
Sent: Thursday, May 16, 2013 5:30 AM
To: am...@googlegroups.com
Subject: [AMPL 7023] Problem with AMPL and logical constraint _slogcon[1] is not an indicator constraint

 

Hello all,

 

The following constraint: 

 

subject to borderCheck {i in 1..nb_rect, j in 1..nb_rect}: x2[i] <= x[j] or x2[j] <= x[i] or y2[i] <= y[j] or y2[j] <= y[i]; (where x,x2,y,y2 are variables)

 

returns the following error from Cplex:

 

CPLEX 12.5.0.0: logical constraint _slogcon[1] is not an indicator constraint.

 

I read a few posts on this message, but can't find a workaround... Any idea?

 

Thanks, cheers,

 

Jean

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

imoca...@gmail.com

unread,
Aug 10, 2014, 12:10:07 PM8/10/14
to am...@googlegroups.com
Dear Sir;
 
a similar error happen to me,
 
I thought that the problem was in the first constraint. But it was in the last constraint in my model. I noticed that I only had written the left side of the inequality. Then I wrote the operator (>) and the right side; problem solved.

Robert Fourer

unread,
Aug 11, 2014, 2:13:57 AM8/11/14
to am...@googlegroups.com
The expression _slogcon[1] refers to the first "logical" constraint sent to the solver, which may not be the first constraint overall. In general, any constraint that is not a standard "range" constraint using <= or >= or = operators is treated as a logical constraint. You can use the command "print _slogconname[1];" to find out the AMPL name of the first logical constraint.

If you write a constraint that consists only of an expression without any inequality or equality operator, then AMPL treats it as a logical constraint that is true if the expression takes a nonzero value and false if its value is zero. This is probably not what you intended. Most useful logical constraints use logical operators such as "or" or other operators described for example at www.ampl.com/resources/logic-and-constraint-programming-extensions/.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of imoca...@gmail.com
Sent: Sunday, August 10, 2014 11:10 AM
To: am...@googlegroups.com

dan...@newwaveconsulting.com

unread,
Oct 31, 2018, 8:03:40 AM10/31/18
to AMPL Modeling Language
Hi paul, 

I'm having a similar problem with this error. I'm not sure what the AMPL helper is saying to do so could you lend a helping eye?

Thanks,
Dan

AMPL Google Group

unread,
Oct 31, 2018, 1:32:24 PM10/31/18
to Ampl Modeling Language
AMPL accept indicator constraint of the form:

<binary-var> = 0 ==> constraint
<binary-var> = 1 ==> constraint
The following constraint violate the syntax


subject to borderCheck1 {i in 1..nb_rect, j in 1..nb_rect}: x2[i] <= x[j] + M[1]*z[1];

Because x2 is not a binary variable.

If you look at following constraints then they satisfy the requirements. Becuase xind and yind are binary variable and there is a constraint expression after the binary variable.

var xind {i in 1..nb_rect, j in 1..nb_rect} binary;
var yind {i in 1..nb_rect, j in 1..nb_rect} binary;


subj to xindDefn {i in 1..nb_rect, j in 1..nb_rect}: xind[i,j] = 1 ==> x2[i] <= x[j];
subj to yindDefn {i in 1..nb_rect, j in 1..nb_rect}: yind[i,j] = 1 ==> y2[i] <= y[j];


--
Dr. Paras Tiwari
am...@googlegroups.com
{#HS:697722105-27496#}
--

You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



dan...@newwaveconsulting.com

unread,
Oct 31, 2018, 3:18:01 PM10/31/18
to AMPL Modeling Language
I'm sorry im still very new at AMPL Just started yesterday. So in my case with my objective function and the constraints as:

maximize obj; sum{f in F, c in C, i in I}: (Qic[i,c]*Bic[i,c] - Rfc[f,c]*Tfc[f,c] - Pif[i,f]*Nif[i,f]);
s.t. const_1 {f in F}: sum{i in I} (Lif[i,f]*Pif[i,f]) <= Hf[f]; #total labor hours for each factory
s.t. const_2 {f in F}: sum{i in I} (Mif[i,f]*Pif[i,f]) <= Kf[f]; #total machine hours for each factory
s.t. const_3 {i in I, f in F}: sum {I,F} (Xif[i,f]*Pif[i,f]) <= a[1]; #total materials for all factories and all cameras
s.t. const_4 {i in I, c in C}: Qic[i,c] <= Sic[i,c]; # Maximum product per customer assuming all products are sold
s.t. const_5 {f in F, c in C}: sum {F,C} Rfc[f,c] <= b[1];  # Maximum capacity for Special Inspection plant

i get the same 

ampl: include Project_1_Run.run;
Gurobi 8.0.0: logical constraint _slogcon[1] is not an indicator constraint.

how would I go about applying the constraints to my different variables?


On Thursday, May 16, 2013 at 5:18:38 PM UTC-4, Paul wrote:

AMPL Google Group

unread,
Oct 31, 2018, 4:37:33 PM10/31/18
to Ampl Modeling Language
You shouldn't be getting the logical constraint _slogcon[1] is not an indicator constraint error message. Make sure you are submitting the correct file to AMPL. But your following constraints don't seem right:


s.t. const_3 {i in I, f in F}: sum {I,F} (Xif[i,f]*Pif[i,f]) <= a[1]; #total materials for all factories and all cameras
s.t. const_5 {f in F, c in C}: sum {F,C} Rfc[f,c] <= b[1]; # Maximum capacity for Special Inspection plant

Why are you writing sum {I,F}(Xif[i,f]*Pif[i,f])? You have defined i and f before colon which a way to define a constraint. The const_3 ensures that the product of X and P is less than or equal to a[1] for each i in I and f in F. You can move the indices after the colon and write a sum expression but that will change the meaning of your constraint. Your style of writing sum{I,F} is not correct. You can define a constraint as follows:
s.t. Altconst_3 : sum {i in I, f in F} (Xif[i,f]*Pif[i,f]) <= a[1]; #total materials for all factories and all cameras

The Altconst_3 and const_3 have different meaning. The Altconst_3 takes the sum of the product of X and P and ensures that sum is less than or equal to a[1] , whereas const3 ensures each product(not sum) is less than or equals to a[1].

The same thing applies to const_5. Your const_1 and const_2 seems correct. If you still encounter the problem, you can send us your model and data file and we will run at our end.

Thanks,


--
Dr. Paras Tiwari
am...@googlegroups.com
{#HS:698084026-27554#}
--

dan...@newwaveconsulting.com

unread,
Oct 31, 2018, 11:20:49 PM10/31/18
to AMPL Modeling Language
Dr. Paras, thank you for your quick responses.
I've formulated this Linear program for a project and am trying to get the optimization of it to run however, it is getting stuck on the previous error. Attached is the LP I've formulated from the problem and dat/mod files.

Thanks,

On Thursday, May 16, 2013 at 5:18:38 PM UTC-4, Paul wrote:
Project_1_Data.dat
Project_1_Model.mod
Project_1_Run.run
IMG_2627.JPG

AMPL Google Group

unread,
Nov 1, 2018, 1:36:47 PM11/1/18
to Ampl Modeling Language
You have syntax error in your objective function. You should write your objective function as follows:


maximize obj: sum{f in F, c in C, i in I} (Qic[i,c]*Bic[i,c] - Rfc[f,c]*Tfc[f,c] - Pif[i,f]*Nif[i,f]);

--
Dr. Paras Tiwari
am...@googlegroups.com
{#HS:698326104-27582#}
--

David Csercsik

unread,
Jul 20, 2023, 5:58:33 PM7/20/23
to AMPL Modeling Language
Dear Dr. Paras, dear AMPL group,

I am also new to AMPL and get the same CPLEX error, and I can not figure out what's wrong (probably some syntax error).

I attach the .mod and .dat files.

If I expand the model I get:

maximize WELFARE:
        650*X[1] + 620*X[2] + 536*X[3] + 520*X[4] + 448*X[5] + 378*X[6] +
        366*X[7] - 495*X[8] - 477*X[9] - 627*X[10] - 627*X[11] - 354*X[12] -
        354*X[13];

subject to CONVEXITY[1]:X[1] + X[2] < 1;

subject to CONVEXITY[2]:X[3] + X[4] < 1;

subject to CONVEXITY[3]:X[6] + X[7] < 1;

subject to CONVEXITY[4]:X[8] + X[9] < 1;

subject to CONVEXITY[5]:X[10] + X[11] < 1;

subject to CONVEXITY[6]:X[12] + X[13] < 1;

subject to BALANCE[1,1]:
        10*X[1] - 9*X[8] - 11*X[10] = 0;
...

Which is suspicious, since there is no line break after the ':' in the convexity constraints.

Thank You
aggrEU_1.dat
aggrEU_1.mod

AMPL Google Group

unread,
Jul 23, 2023, 10:27:56 AM7/23/23
to AMPL Modeling Language
The parentheses around the CONVEXITY constraint -- a ( at the beginning of the constraint expression and a ) at the end -- are causing an error in processing the constraint. You can fix the problem by removing those parentheses, and also changing < to <= :

subject to CONVEXITY {i in conv_bid_sets} :
     sum {j in start_index[i]..end_index[i] }
	(X[j])<=1+eps;

In general, we recommend that you do not put parentheses around a whole constraint expression. Even when the constraint is handled properly, the extra parentheses only make it harder to read.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2307568743-118341#}
Reply all
Reply to author
Forward
0 new messages