Help! Offset syntax error and why ?

1,150 views
Skip to first unread message

Dale Petrovski

unread,
Aug 26, 2019, 8:17:17 AM8/26/19
to AMPL Modeling Language
Hi,

I'm new, don't have a clue how AMPL works. But have to do this for my exam. Why is this happening ? 

Thanks. 
Screenshot_1.jpg
Screenshot_2.jpg

AMPL Google Group

unread,
Aug 27, 2019, 10:27:31 AM8/27/19
to AMPL Modeling Language
1. Your main problem is with the indexing of this variable:

var carsator {ORCVOROVI, first(TIME)};

A variable needs to be indexed over sets, but "first(TIME)" is not a set -- it is a member of the set TIME (specifically, the first member). A set member is either a number or a character string, so it cannot be used where a set is required. You can write {first(TIME)} for the set that contains just the one member first(TIME), and thus it would be correct to write

var carsator {ORCVOROVI, {first(TIME)}};

But since there is only one member in the second set, maybe you don't need the second index and can simply define "var carsator {ORCVOROVI};".

2. After you get the error message, there's an "ampl?" prompt, which indicates that AMPL is still in the middle of processing the statement. A command like "reset;" typed at the "ampl?" prompt will not be executed. Press "Enter" once to return to the "ampl:" prompt and resume entering commands.


--
Robert Fourer
am...@googlegroups.com
{#HS:939524304-53315#}

Dale Petrovski

unread,
Sep 3, 2019, 12:36:32 PM9/3/19
to AMPL Modeling Language

Screenshot_7.jpg

Screenshot_8.jpg

Thank you so much! I have couple of other problems, and cant complete this model. Can you help me with logical operators in this function.I added some screenshots. And here is complete function.

proba2.mod, line 30 (offset 2590):
syntax error
context:  sum {i in ORCVOROVI, j in DECVOROVI, t in TIME} reven[i,j]*loadflows[i,j,t]-sum {i in ORCVOROVI,j in DECVOROVI, t in TIME}(costload[i,j]*loadflows[i,j,t]+costempty[i,j]*emptyflows[j,i,t])- sum {i in ORCVOROVI, j in DECVOROVI, k  in TIME} loadflows[i,j,k] * (sum{t in TIME, t  >>> >  <<< k }(t-k)*owncost*alfa[i,j, t > k])+(emptyflows[j,i,k]*sum{t in TIME, t>k}(t-k)*owncost*beta[i,j, t > k])-sum{i in ORCVOROVI, t in TIME}hocoor[i]*carsinor[i,t,first(TIME)]-sum{j in

AMPL Google Group

unread,
Sep 4, 2019, 9:18:44 AM9/4/19
to AMPL Modeling Language
In an indexing expression, the logical condition must be preceded by a : symbol. So where the syntax error is, you should write

sum {t in TIME: t > k}


--
Robert Fourer
am...@googlegroups.com
{#HS:939524304-53315#}
On Tue, Sep 3, 2019 at 4:36 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Screenshot_7.jpgScreenshot_8.jpg

Thank you so much! I have couple of other problems, and cant complete this model. Can you help me with logical operators in this function.I added some screenshots. And here is complete function.

proba2.mod, line 30 (offset 2590):
syntax error
context: sum {i in ORCVOROVI, j in DECVOROVI, t in TIME} reven[i,j]*loadflows[i,j,t]-sum {i in ORCVOROVI,j in DECVOROVI, t in TIME}(costload[i,j]*loadflows[i,j,t]+costempty[i,j]*emptyflows[j,i,t])- sum {i in ORCVOROVI, j in DECVOROVI, k in TIME} loadflows[i,j,k] * (sum{t in TIME, t >>> > <<< k }(t-k)*owncost*alfa[i,j, t > k])+(emptyflows[j,i,k]*sum{t in TIME, t>k}(t-k)*owncost*beta[i,j, t > k])-sum{i in ORCVOROVI, t in TIME}hocoor*carsinor[i,t,first(TIME)]-sum{j in


уторак, 27. август 2019. 16.27.31 UTC+2, AMPL Google Group је написао/ла:
On Tue, Aug 27, 2019 at 2:27 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
1. Your main problem is with the indexing of this variable:

var carsator {ORCVOROVI, first(TIME)};

A variable needs to be indexed over sets, but "first(TIME)" is not a set -- it is a member of the set TIME (specifically, the first member). A set member is either a number or a character string, so it cannot be used where a set is required. You can write {first(TIME)} for the set that contains just the one member first(TIME), and thus it would be correct to write

var carsator {ORCVOROVI, {first(TIME)}};

But since there is only one member in the second set, maybe you don't need the second index and can simply define "var carsator {ORCVOROVI};".

2. After you get the error message, there's an "ampl?" prompt, which indicates that AMPL is still in the middle of processing the statement. A command like "reset;" typed at the "ampl?" prompt will not be executed. Press "Enter" once to return to the "ampl:" prompt and resume entering commands.


--
Robert Fourer
am...@googlegroups.com
Message has been deleted

Dale Petrovski

unread,
Sep 5, 2019, 8:12:05 AM9/5/19
to AMPL Modeling Language
Thank you. MOD works fine But i needed to change few things, so dat needs to change as well. Im missing something. 

param: demand :=

NN1 NM1 1 1 50  NN1 NM1 2 2 90  NN1 NM1 3 3 112 NN1 NM1 4 4 100 NN1 NM1 5 5 117 NN1 NM1 6 6 90  NN1 NM1 7 7 110
NN1 NM2 1 1 90  NN1 NM2 2 2 80  NN1 NM2 3 3 120 NN1 NM2 4 4 140 NN1 NM2 5 5 108 NN1 NM2 6 6 70  NN1 NM2 7 7 130
NN1 NM3 1 1 120 NN1 NM3 2 2 110 NN1 NM3 3 3 90  NN1 NM3 4 4 112 NN1 NM3 5 5 99  NN1 NM3 6 6 80  NN1 NM3 7 7 112
NN2 NM1 1 1 95  NN2 NM1 2 2 98  NN2 NM1 3 3 115 NN2 NM1 4 4 102 NN2 NM1 5 5 136 NN2 NM1 6 6 109 NN2 NM1 7 7 103
NN2 NM2 1 1 100 NN2 NM2 2 2 78  NN2 NM2 3 3 129 NN2 NM2 4 4 98  NN2 NM2 5 5 109 NN2 NM2 6 6 132 NN2 NM2 7 7 102
NN2 NM2 1 1 112 NN2 NM3 2 2 99  NN2 NM3 3 3 116 NN2 NM3 4 4 117 NN2 NM3 5 5 102 NN2 NM3 6 6 109 NN2 NM3 7 7 90
NN3 NM1 1 1 114 NN3 NM1 2 2 95  NN3 NM1 3 3 125 NN3 NM1 4 4 99  NN3 NM1 5 5 100 NN3 NM1 6 6 98  NN3 NM1 7 7 65
NN3 NM2 1 1 105 NN3 NM2 2 2 100 NN3 NM2 3 3 112 NN3 NM2 4 4 101 NN3 NM2 5 5 98  NN3 NM2 6 6 112 NN3 NM2 7 7 102
NN3 NM3 1 1 99  NN3 NM3 2 2 95  NN3 NM3 3 3 102 NN3 NM3 4 4 131 NN3 NM3 5 5 102 NN3 NM3 6 6 103 NN3 NM3 7 7 106;

1 item(s) missing in last line of table, which starts with "7"
context:  NN3 NM3 1 1 99  NN3 NM3 2 2 95  NN3 NM3 3 3 102 NN3 NM3 4 4 131 NN3 NM3 5 5 102 NN3 NM3 6 6 103 NN3 NM3 7 7 106 >>> ; <<<

AMPL Google Group

unread,
Sep 5, 2019, 11:25:05 AM9/5/19
to AMPL Modeling Language
Possibly the data for "demand" is not consistent with its definition, but this cannot be determined only from the information given.

To get help, post your model's definition of "demand" and of all sets and params that are used in the definition of "demand"; and also post the data for "demand" and for all sets and params used in the definition of "demand". You can attach model and data files if that is more convenient.


--
Robert Fourer
am...@googlegroups.com
{#HS:939524304-53315#}
On Thu, Sep 5, 2019 at 12:12 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you. MOD works fine But i needed to change few things, so dat needs to change as well. Im missing something.

param: demand :=

NN1 NM1 1 1 50 NN1 NM1 2 2 90 NN1 NM1 3 3 112 NN1 NM1 4 4 100 NN1 NM1 5 5 117 NN1 NM1 6 6 90 NN1 NM1 7 7 110
NN1 NM2 1 1 90 NN1 NM2 2 2 80 NN1 NM2 3 3 120 NN1 NM2 4 4 140 NN1 NM2 5 5 108 NN1 NM2 6 6 70 NN1 NM2 7 7 130
NN1 NM3 1 1 120 NN1 NM3 2 2 110 NN1 NM3 3 3 90 NN1 NM3 4 4 112 NN1 NM3 5 5 99 NN1 NM3 6 6 80 NN1 NM3 7 7 112
NN2 NM1 1 1 95 NN2 NM1 2 2 98 NN2 NM1 3 3 115 NN2 NM1 4 4 102 NN2 NM1 5 5 136 NN2 NM1 6 6 109 NN2 NM1 7 7 103
NN2 NM2 1 1 100 NN2 NM2 2 2 78 NN2 NM2 3 3 129 NN2 NM2 4 4 98 NN2 NM2 5 5 109 NN2 NM2 6 6 132 NN2 NM2 7 7 102
NN2 NM2 1 1 112 NN2 NM3 2 2 99 NN2 NM3 3 3 116 NN2 NM3 4 4 117 NN2 NM3 5 5 102 NN2 NM3 6 6 109 NN2 NM3 7 7 90
NN3 NM1 1 1 114 NN3 NM1 2 2 95 NN3 NM1 3 3 125 NN3 NM1 4 4 99 NN3 NM1 5 5 100 NN3 NM1 6 6 98 NN3 NM1 7 7 65
NN3 NM2 1 1 105 NN3 NM2 2 2 100 NN3 NM2 3 3 112 NN3 NM2 4 4 101 NN3 NM2 5 5 98 NN3 NM2 6 6 112 NN3 NM2 7 7 102
NN3 NM3 1 1 99 NN3 NM3 2 2 95 NN3 NM3 3 3 102 NN3 NM3 4 4 131 NN3 NM3 5 5 102 NN3 NM3 6 6 103 NN3 NM3 7 7 106;

1 item(s) missing in last line of table, which starts with "7"
context: NN3 NM3 1 1 99 NN3 NM3 2 2 95 NN3 NM3 3 3 102 NN3 NM3 4 4 131 NN3 NM3 5 5 102 NN3 NM3 6 6 103 NN3 NM3 7 7 106 >>> ; <<<

среда, 04. септембар 2019. 15.18.44 UTC+2, AMPL Google Group је написао/ла:

On Thu, Sep 5, 2019 at 12:06 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you. Mod file works. I changed few things, so i needed to change dat as well. Three params with 4 subscripts. Something is missing, and i dont see it.

Screenshot_9.jpgScreenshot_10.jpg


среда, 04. септембар 2019. 15.18.44 UTC+2, AMPL Google Group је написао/ла:
On Wed, Sep 4, 2019 at 1:18 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
In an indexing expression, the logical condition must be preceded by a : symbol. So where the syntax error is, you should write

sum {t in TIME: t > k}


--
Robert Fourer
am...@googlegroups.com

Dale Petrovski

unread,
Sep 13, 2019, 5:23:23 PM9/13/19
to AMPL Modeling Language

Screenshot_2.jpg

Thank you! Now i have trouble with one of the constraints of the model. Really don't know what to do, its not ampl it's logical problem. I posted mod and dat here. I know dat is weird, alfa, beta are proportions of cars that will arrive in different period of time. Example 1 1 cars arrive in dest. on the same day, 1 2, the day after and so on...  0 1 and 0 in TIME is for unmet demand from the observation period before TIME.
datasmanjeno.dat
modkaotacan.mod

AMPL Google Group

unread,
Sep 14, 2019, 10:14:02 AM9/14/19
to AMPL Modeling Language
Do you see why the constraint unmetdemand['NN1','NM1',0] reduces to 0 = 19? If not, you should look at the constraint expression a little more carefully, and the reason will become clear. Probably you will want to fix the problem by indexing this constraint over {i in ORYARDS, j in DEYARDS, t in TIME: t > 0}.


--
Robert Fourer
am...@googlegroups.com
{#HS:939524304-53315#}
On Fri, Sep 13, 2019 at 9:23 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Screenshot_2.jpg

Thank you! Now i have trouble with one of the constraints of the model. Really don't know what to do, its not ampl it's logical problem. I posted mod and dat here. I know dat is weird, alfa, beta are proportions of cars that will arrive in different period of time. Example 1 1 cars arrive in dest. on the same day, 1 2, the day after and so on... 0 1 and 0 in TIME is for unmet demand from the observation period before TIME.

четвртак, 05. септембар 2019. 17.25.05 UTC+2, AMPL Google Group је написао/ла:

On Thu, Sep 5, 2019 at 3:24 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Possibly the data for "demand" is not consistent with its definition, but this cannot be determined only from the information given.

To get help, post your model's definition of "demand" and of all sets and params that are used in the definition of "demand"; and also post the data for "demand" and for all sets and params used in the definition of "demand". You can attach model and data files if that is more convenient.


--
Robert Fourer
am...@googlegroups.com

Dale Petrovski

unread,
Sep 15, 2019, 2:59:50 PM9/15/19
to AMPL Modeling Language
Robert you are the best!! Thank you so much. Working on other stuff, may have questions later. :)
Reply all
Reply to author
Forward
0 new messages