Matching with regular expressions

7 views
Skip to first unread message

vm4...@yahoo.com

unread,
Nov 29, 2015, 12:42:00 PM11/29/15
to AMPL Modeling Language

Hi, I am fairly new to AMPL and am having an issue.  I am trying to evaluate a set of 5 binary numbers in a constraint.  I want to prevent two sets of ones in the same row coming up (i.e. 10101 is ok, but 11011, 11100 is a violation).

My constraint is:
subject to c01 {b in 1..B}: match(sum{a in 1..A}t[a,b,1]&sum{a in 1..A}t[a,b,2]&sum{a in 1..A}t[a,b,3]&sum{a in 1..A}t[a,b,4]&sum{a in 1..A}t[a,b,5],'111|11011') = 0;

When I copy and paste the match evaluation in AMPL, I get the following:
ampl: display {b in 1..B}: match(sum{a in 1..A}t[a,b,1]&sum{a in 1..A}t[a,b,2]&sum{a in 1..A}t[a,b,3]&sum{a in 1..A}t[a,b,4]&sum{a in 1..A}t[a,b,5],'111|11011');
match
(sum{a in 1 .. A} t[a,1,1] & sum{a in 1 .. A} t[a,1,2] & sum{a in 1
   
.. A} t[a,1,3] & sum{a in 1 .. A} t[a,1,4] & sum{a in 1 .. A} t[a,1,5],
 
'111|11011') = 0

match
(sum{a in 1 .. A} t[a,2,1] & sum{a in 1 .. A} t[a,2,2] & sum{a in 1
   
.. A} t[a,2,3] & sum{a in 1 .. A} t[a,2,4] & sum{a in 1 .. A} t[a,2,5],
 
'111|11011') = 2

match
(sum{a in 1 .. A} t[a,3,1] & sum{a in 1 .. A} t[a,3,2] & sum{a in 1
   
.. A} t[a,3,3] & sum{a in 1 .. A} t[a,3,4] & sum{a in 1 .. A} t[a,3,5],
 
'111|11011') = 0

match
(sum{a in 1 .. A} t[a,4,1] & sum{a in 1 .. A} t[a,4,2] & sum{a in 1
   
.. A} t[a,4,3] & sum{a in 1 .. A} t[a,4,4] & sum{a in 1 .. A} t[a,4,5],
 
'111|11011') = 3

match
(sum{a in 1 .. A} t[a,5,1] & sum{a in 1 .. A} t[a,5,2] & sum{a in 1
   
.. A} t[a,5,3] & sum{a in 1 .. A} t[a,5,4] & sum{a in 1 .. A} t[a,5,5],
 
'111|11011') = 0

Based on my data, that is what I would expect to see.  But the model seems not to evaluate the same.  When I display the constraint, I see something different

ampl: display c01;
c01 [*] :=
 1  0
 2  0
 3  0
 4  0
 5  0
;
 
 

c01[2] and c01[4] should violate this constraint, but somehow, they evaluate to 0.  I have tried using both gurobi and cplex, and I have turned off presolve, but none of these things make a difference.  What am I missing?

Victor Zverovich

unread,
Nov 30, 2015, 6:26:19 PM11/30/15
to am...@googlegroups.com
The command "display c01" shows current values of the constraints dual variables, not the values of the constraint expressions (or their parts). You can display the "body" of the constraint with the following command:

  display c01.body;

Note, however, that the string expression "sum{a in 1..A}t[a,b,1]& ... " is evaluated with the current values of variables before the problem is sent to the solver, so it will have no effect during optimization.

HTH,
Victor

--
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.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages