Syntax error context: >>> data; <<< issue in NEOS, using AMPL

455 views Asked by At

I'm new to AMPL/NEOS and optimization problems in general. I have a mod file that looks like this:

PARAMETERS

param n; # number of observations

param p; # number of features

param ResponseVariable{i in 1..n}; # continuous response variable

param VectorofFeatures{i in 1..p}; # vector of features

DECISION VARIABLES

var IndependentTerm{i in 1..p}; #independent term

var VectorofCoefficients{i in 1..p}; #vector of coefficients

OBJECTIVE FUNCTION

minimize Function: sum {i in 1..p} (ResponseVariable[i]-(VectorofCoefficients[i]*VectorofFeatures[i]+IndependentTerm[i]))^2

#END OF FILE

and a data file that looks like this:

PARAMETERS

param n:= 50;

param p:= 6;

param ResponseVariable:= 1 24 2 21.6 3 34.7 4 33.4 5 36.2 6 28.7 7 22.9 8 27.1 9 16.5 10 18.9 11 15 12 18.9 13 21.7 14 20.4 15 18.2 16 19.9 17 23.1 18 17.5 19 20.2 20.18.2 21 13.6 22 19.6 23 15.2 24 14.5 25 15.6 26 13.9 27 16.6 28 14.8 29 18.4 30 21 31 12.7 32 14.5 33 13.2 34 13.1 35 13.5 36 18.9 37 20 38 21 39 24.7 40 30.8 41 34.9 42 26.6 43 25.3 44 24.7 45 21.2 46 19.3 47 20 48 16.6 49 14.4 50 19.4;

param VectorofFeatures: 1 2 3 4 5 6 := 1 0.00632 6.575 65.2 4.09 396.9 4.98 2 0.02731 6.421 78.9 4.9671 396.9 9.14 3 0.02729 7.185 61.1 4.9671 392.83 4.03 4 0.03237 6.998 45.8 6.0622 394.63 2.94 5 0.06905 7.147 54.2 6.0622 396.9 5.33 6 0.02985 6.43 58.7 6.0622 394.12 5.21 7 0.08829 6.012 66.6 5.5605 395.6 12.43 8 0.14455 6.172 96.1 5.9505 396.9 19.15 9 0.21124 5.631 100 6.0821 386.63 29.93 10 0.17004 6.004 85.9 6.5921 386.71 17.1 11 0.22489 6.377 94.3 6.3467 392.52 20.45 12 0.11747 6.009 82.9 6.2267 396.9 13.27 13 0.09378 5.889 39 5.4509 390.5 15.71 14 0.62976 5.949 61.8 4.7075 396.9 8.26 15 0.63796 6.096 84.5 4.4619 380.02 10.26 16 0.62739 5.834 56.5 4.4986 395.62 8.47 17 1.05393 5.935 29.3 4.4986 386.85 6.58 18 0.7842 5.99 81.7 4.2579 386.75 14.67 19 0.80271 5.456 36.6 3.7965 288.99 11.69 20 0.7258 5.727 69.5 3.7965 390.95 11.28 21 1.25179 5.57 98.1 3.7979 376.57 21.02 22 0.85204 5.965 89.2 4.0123 392.53 13.83 23 1.23247 6.142 91.7 3.9769 396.9 18.72 24 0.98843 5.813 100 4.0952 394.54 19.88 25 0.75026 5.924 94.1 4.3996 394.33 16.3 26 0.84054 5.599 85.7 4.4546 303.42 16.51 27 0.67191 5.813 90.3 4.682 376.88 14.81 28 0.95577 6.047 88.8 4.4534 306.38 17.28 29 0.77299 6.495 94.4 4.4547 387.94 12.8 30 1.00245 6.674 87.3 4.239 380.23 11.98 31 1.13081 5.713 94.1 4.233 360.17 22.6 32 1.35472 6.072 100 4.175 376.73 13.04 33 1.38799 5.95 82 3.99 232.6 27.71 34 1.15172 5.701 95 3.7872 358.77 18.35 35 1.61282 6.096 96.9 3.7598 248.31 20.34 36 0.06417 5.933 68.2 3.3603 396.9 9.68 37 0.09744 5.841 61.4 3.3779 377.56 11.41 38 0.08014 5.85 41.5 3.9342 396.9 8.77 39 0.17505 5.966 30.2 3.8473 393.43 10.13 40 0.02763 6.595 21.8 5.4011 395.63 4.32 41 0.03359 7.024 15.8 5.4011 395.62 1.98 42 0.12744 6.77 2.9 5.7209 385.41 4.84 43 0.1415 6.169 6.6 5.7209 383.37 5.81 44 0.15936 6.211 6.5 5.7209 394.46 7.44 45 0.12269 6.069 40 5.7209 389.39 9.55 46 0.17142 5.682 33.8 5.1004 396.9 10.21 47 0.18836 5.786 33.3 5.1004 396.9 14.15 48 0.22927 6.03 85.5 5.6894 392.74 18.8 49 0.25387 5.399 95.3 5.87 396.9 30.81 50 0.21977 5.602 62 6.0877 396.9 16.2;

#END OF FILE

Whenever I try to run them in NEOS, I keep getting the same error:

amplin, line 41 (offset 631): syntax error context: >>> data; <<< Error (2) in /opt/ampl/ampl -R amplin

The context is very vague to me, so I'm not really sure at what part of the data is it referring to. Does anybody else know?

1

There are 1 answers

1
Davi Doro On

I think you are getting this error because you forgot to end the objective function declaration with a semicolon. NEOS concatenates your model and input files togheter internally, putting a data; statement just after the model file. Since you have not properly end the objective function declaration, you got that error.

There are, however, other problems with your program, especially in the data file. Your data assignments are invalid. If you have a param collection VectorofCoefficients indexed over 1..6, the assignment statement should look like this:

param VectorofCoefficients =
  1 123
  2 456
  ...
  6 789;

More on AMPL data assignment: https://pifop.com/help/ampl_data_assignment.html