Syntax Error

2,170 views
Skip to first unread message

Debbie

unread,
Apr 10, 2015, 12:06:57 AM4/10/15
to am...@googlegroups.com
I'm a beginner with AMPL and I can't figure out how to clear up this syntax error at line 22 

param a{0..1};

param b{0..1};

param c{0..1};

param n;


var x {j in 0..n};

var y {j in 0..n};

var z {j in 0..n};


subject to X {j in 0..n} :

sum {j in 0..n} (x[j]) = a[1] - a[0];     ERROR!!!

subject to Y {j in 0..n} :

sum {j in 0..n} (y[j]) = b[1] - b[0];

subject to Z {j in 0..n} :

sum {j in 0..n} (z[j]) = c[1] - c[0]; 


minimize length: (sum {j in 1..n} (sqrt( ((x[j]-x[j-1])/(1/n))^2 +

((y[j]-y[j-1])/(1/n))^2 +

((z[j]-z[j-1])/(1/n))^2) + 10^-6) /n )


subject to speed {j in 1..n} :

sqrt( (x[j] - x[j-1])^2 + (y[j] - y[j-1])^2 + (z[j] - z[j-1])^2  + 10^-6) = sqrt( (x[j+1] - x[j])^2 + (y[j+1] - y[j])^2 + (z[j+1] - z[j])^2  + 10^-6)




data;


param a :=

0 0

1 1 ; 

param b := 

0 0

1 1 ; 

param c := 

0 0

1 1 ; 

param n := 1;


option minos_options "superbasic_limit=500";

solve;

display length;



I'm trying to find the shortest length between 2 points through a finite approximation method of the infinite dimensional problem.


All tips are welcomed!


Thank you!

Debbie

unread,
Apr 10, 2015, 12:10:32 AM4/10/15
to am...@googlegroups.com
The error message that comes out is this:

amplin, line 22 (offset 292):
	syntax error
context:  sum {j  >>> in  <<< 0..n} (x[j]) = abs( a[1] - a[0] );

 Error (2) in /opt/ampl/ampl -R amplin

victor.z...@gmail.com

unread,
Apr 10, 2015, 12:16:17 PM4/10/15
to am...@googlegroups.com

You are trying to redefine dummy index j in a nested indexing expression which is not allowed:

  subject to X {j in 0..n} :

  sum {j in 0..n} ...

To fix it use different names for dummy indices in the constraint indexing and in sum, e.g.

  subject to X {i in 0..n} :

  sum {j in 0..n} ...

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.

Indrajit Sen Gupta

unread,
Apr 10, 2015, 10:22:47 PM4/10/15
to am...@googlegroups.com
You might have to reformulate your problem since as Victor said you are using the same subscript twice (if you use "i", it needs to be used inside the constraints). Moreover you have missed out semi - colons at couple of places - after the objective function and after the speed constraint.
 
Regards,
Indrajit
Reply all
Reply to author
Forward
0 new messages