Error in Indexing and subscripts

237 views
Skip to first unread message

DINESH BABU

unread,
Apr 7, 2016, 8:55:02 AM4/7/16
to AMPL Modeling Language
Hi, 

I am getting error on using index and subscripts. Can anyone tell me how to solve it?

#param.dat 

set M := 1 2;

param:  hi    hf    xi    xf        vi   bi    mi    s     K       J        r    fo      qo      po        ttrop  ctrop       xh  yh   g_0   R_e      cdo    clmax  gamma  machdiverg  masatierra  ctegravitacional :=

     1  9000  0     0     20000     120  0.06  4909  21.5  0.073   -6.5e-3  287  288.15  1.1225  101.325   2670   3.2778e-4   0.7 0.2  9.81  6378000  0.023  1.4    1.4    0.88        5.9736e24   6.6742e-11  
     2  9000  0     0     20000     120  0.06  4909  21.5  0.073   -6.5e-3  287  288.15  1.1225  101.325   2670   3.2778e-4   0.7 0.2  9.81  6378000  0.023  1.4    1.4    0.88        5.9736e24   6.6742e-11  ;

First Code;

set M;

var Q {i in N, (j,l) in M: l>j} >=0, <=1;

Constraints:

Q1 {i in N, (j,l) in M: l>j}:      Q[j,l,i]*(x[j,i]-x[l,i]-dx)>=0;
Q2 {i in N, (j,l) in M: l>j}:      Q[j,l,i]*(x[l,i]-x[j,i]-dx)>=0;
Q3 {i in N, (j,l) in M: l>j}:      Q[j,l,i]*(h[j,i]-h[l,i]-dh)>=0;
Q4 {i in N, (j,l) in M: l>j}:      Q[j,l,i]*(h[l,i]-h[j,i]-dh)>=0;

Error;


Glider.ampl, line 88 (offset 1143):

2 indices for set of dimen 1

context:  var Q {i in N, (j,l) in  >>> M:  <<< l>j} >=0, <=1;


Glider.ampl, line 152 (offset 3770):

2 indices for set of dimen 1

context:  Q1 {i in N,(j,l) in  >>> M:  <<< l>j}:      Q[j,l,i]*(x[j,i]-x[l,i]-dx)>=0;


Glider.ampl, line 152 (offset 3784):

Q needs 2 subscripts, not 3

context:  Q1 {i in N,(j,l) in M: l>j}:       >>> Q[j,l,i] <<< *(x[j,i]-x[l,i]-dx)>=0;


Glider.ampl, line 153 (offset 3836):

2 indices for set of dimen 1

context:  Q2 {i in N,(j,l) in  >>> M:  <<< l>j}:      Q[j,l,i]*(x[l,i]-x[j,i]-dx)>=0;


Glider.ampl, line 153 (offset 3850):

Q needs 2 subscripts, not 3

context:  Q2 {i in N,(j,l) in M: l>j}:       >>> Q[j,l,i] <<< *(x[l,i]-x[j,i]-dx)>=0;


Glider.ampl, line 154 (offset 3902):

2 indices for set of dimen 1

context:  Q3 {i in N,(j,l) in  >>> M:  <<< l>j}:      Q[j,l,i]*(h[j,i]-h[l,i]-dh)>=0;


Glider.ampl, line 154 (offset 3916):

Q needs 2 subscripts, not 3

context:  Q3 {i in N,(j,l) in M: l>j}:       >>> Q[j,l,i] <<< *(h[j,i]-h[l,i]-dh)>=0;


Glider.ampl, line 155 (offset 3968):

2 indices for set of dimen 1

context:  Q4 {i in N,(j,l) in  >>> M:  <<< l>j}:      Q[j,l,i]*(h[l,i]-h[j,i]-dh)>=0;


Glider.ampl, line 155 (offset 3982):

Q needs 2 subscripts, not 3

context:  Q4 {i in N,(j,l) in M: l>j}:       >>> Q[j,l,i] <<< *(h[l,i]-h[j,i]-dh)>=0;


Second code;


var Q {i in N, j in M,l in O[j]: l>j} >=0, <=1;


constraints;


Q1 {i in N,j in M,l in O[j]: l>j}:      Q[j,l,i]*(x[j,i]-x[l,i]-dx)>=0;

Q2 {i in N,j in M,l in O[j]: l>j}:      Q[j,l,i]*(x[l,i]-x[j,i]-dx)>=0;

Q3 {i in N,j in M,l in O[j]: l>j}:      Q[j,l,i]*(h[j,i]-h[l,i]-dh)>=0;

Q4 {i in N,j in M,l in O[j]: l>j}:      Q[j,l,i]*(h[l,i]-h[j,i]-dh)>=0;


Error;


Glider.ampl, line 88 (offset 1146):

O is not defined

context:  var Q {i in N, j in M,l in  >>> O[j]:  <<< l>j} >=0, <=1;


Glider.ampl, line 152 (offset 3779):

O is not defined

context:  Q1 {i in N,j in M,l in  >>> O[j]:  <<< l>j}:      Q[j,l,i]*(x[j,i]-x[l,i]-dx)>=0;


Glider.ampl, line 153 (offset 3851):

O is not defined

context:  Q2 {i in N,j in M,l in  >>> O[j]:  <<< l>j}:      Q[j,l,i]*(x[l,i]-x[j,i]-dx)>=0;


Glider.ampl, line 154 (offset 3923):

O is not defined

context:  Q3 {i in N,j in M,l in  >>> O[j]:  <<< l>j}:      Q[j,l,i]*(h[j,i]-h[l,i]-dh)>=0;


Glider.ampl, line 155 (offset 3995):

O is not defined

context:  Q4 {i in N,j in M,l in  >>> O[j]:  <<< l>j}:      Q[j,l,i]*(h[l,i]-h[j,i]-dh)>=0;


How to defined the ¨O¨ as a set or var or param?

Thanks,

Dinesh.

 

Victor Zverovich

unread,
Apr 7, 2016, 9:59:35 AM4/7/16
to am...@googlegroups.com
You try to iterate M as a two-dimensional set

  (j,l) in M

but M is declared one-dimensional:

  set M;

You should either use a single index in iteration j in M or make M two-dimensional:

  set M dimen 2;

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 https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

DINESH BABU

unread,
Apr 7, 2016, 10:22:03 AM4/7/16
to AMPL Modeling Language
Hi Victor,

I can´t change M from one dimensional to two dimensional. The M is defined the no of aircraft. Example set M := 1 2; 

The main problem is keep distance between aircraft 1 and aircraft 2. So I need to  this constraints 

set M : 1 2;

   Q[i,j,l]*(x[1,i]-x[2,i]-dx)>=0;

param dx := 100;

That´s I am trying to use this two subscripts in constraints.

Q1 {i in N, (j,l) in M: l>j}:      Q[j,l,i]*(x[j,i]-x[l,i]-dx)>=0;

Q1 {i in N,j in M,l in O[j]: l>j}:      Q[j,l,i]*(x[j,i]-x[l,i]-dx)>=0;

But I am getting error in both subscripts. And I have attached my mode and data file for reference.
param.dat
Glider.ampl

Victor Zverovich

unread,
Apr 8, 2016, 11:51:12 AM4/8/16
to am...@googlegroups.com
Then what you need is probably iterating over M twice:

  i in M, j in M

instead of

  (i, j) in M

HTH,
Victor

DINESH BABU

unread,
Apr 8, 2016, 1:10:57 PM4/8/16
to AMPL Modeling Language
oh!! really thanks victor . I will try it and let you know. 

Regards,
Dinesh.
Reply all
Reply to author
Forward
0 new messages