Displaying Binary matrix in AMPL

17 views
Skip to first unread message

khan

unread,
Jan 21, 2017, 7:18:53 AM1/21/17
to AMPL Modeling Language
Dear All, 

I am trying to print this binary matrix in AMPL using the following code. But when I display it gives me this:

Executing on neos-7.neos-server.org
c = 11

A :=
1 2    1
1 6    1
1 9    1
1 11   1
2 3    1
2 6    1
2 7    1
2 9    1
2 10   1
2 11   1
3 4    1
3 7    1
3 8    1
3 9    1
3 10   1
3 11   1
4 5    1
4 8    1
4 10   1
4 11   1
;

No variables declared.



AMPL MOD FILE:

param n:=4;
param c:=(n^2/2)+(n/2)+1;
param A {1..n,1..c} binary, default 0;

for {i in 1..n} 
{let A[i,i+1] := 1;}
for {i in 1..n-1} 
{let A[i,n+i+1] := 1;
      let A[i+1,n+i+1] := 1;}
for {i in 1..n-2}
{let A[i,n+i+4]:=1;
let A[i+1,n+i+4]:=1;
let A[i+2,n+i+4]:=1;}
for {i in 1..n-3}
{let A[i,n+i+6]:=1;
let A[i+1,n+i+6]:=1;
let A[i+2,n+i+6]:=1;
let A[i+3,n+i+6]:=1;}

AMPL DATA FILE:
data;
display c;
display A;



khan

unread,
Jan 21, 2017, 7:28:52 AM1/21/17
to AMPL Modeling Language
okay I got the solution for this: 

I used like that and it works;

option display_1col 0, display_transpose -10;

display A;

khan

unread,
Jan 21, 2017, 8:11:19 AM1/21/17
to AMPL Modeling Language

But its not displaying the first col of zeros. Whats arong? Output is here below:

A [*,*]
:   2   3   4   5   6   7   8   9  10  11    :=
1   1   .   .   .   1   .   .   1   .   1
2   .   1   .   .   1   1   .   1   1   1
3   .   .   1   .   .   1   1   1   1   1
4   .   .   .   1   .   .   1   .   1   1
;

Robert Fourer

unread,
Jan 21, 2017, 9:28:36 AM1/21/17
to am...@googlegroups.com
When you define param A to be "default 0" then AMPL doesn't normally assign the 0 values until A is used by a "solve". As a result, if you "display A" before solving, you will see only the nonzero values that have been assigned so far. You can force all the zeros to be displayed, even before solving, by giving a more explicit display statement:

display {i in 1..n, j in 1..c} A[i,j];

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages