# Declare numerical-sequence set in AMPL .dat file

Suppose I want an AMPL set to contain the integers 1 through 5. How can I declare this in the .dat file?

I can do it in the .mod file, like this:

things.mod:

set THINGS := 1..5;


Console:

ampl: model things.mod;
ampl: display THINGS;
set THINGS := 1 2 3 4 5;

ampl: display THINGS diff {2};
set THINGS diff  {2} := 1 3 4 5;


But now suppose I do this:

things.mod:

set THINGS;


things.dat:

set THINGS := 1..5;


Console:

ampl: model things.mod;
ampl: data things.dat;
ampl: display THINGS;
set THINGS := 1..5;

ampl: display THINGS diff {2};
set THINGS diff  {2} := 1..5;


AMPL seems to be treating 1..5 as a string rather than as an sequence of integers. Why, and how do I fix it?

• You read the AMPL documentation. And if that doesn't suffice, you post at the AMPL forum groups.google.com/forum/#!forum/ampl, which I believe to be much better suited than this forum for addressing an AMPL syntax question, which really isn't an O.R. question, despite AMPL being (among other things) an O.R. tool. If your question were comparing optimization modeling tools, that would be a different story. – Mark L. Stone Jun 3 '19 at 1:32
• @MarkL.Stone I did read the AMPL documentation, which offers no guidance on this question, as far as I can tell. If my question is on-topic here, then it's not really relevant if there is another site that might be better suited; I'd still like to ask it here. On the other hand, if you (or others) feel my question is off-topic, feel free to vote to close. I believe it is on-topic because AMPL is an OR tool, as you say, but my feelings won't be hurt if the community disagrees. – LarrySnyder610 Jun 3 '19 at 1:39
• I'd rather make a comment than downvote or close posts into oblivion. – Mark L. Stone Jun 3 '19 at 2:09
• One of the most useful threads on OR Exchange was a list of support forums and other resources for O.R. and optimization-related software. I suppose that would have to be Community Wiki to please the SE powers that be.If someone coud find that and post on OR SE, that would be a good starting point. – Mark L. Stone Jun 3 '19 at 2:16
• @MarkL.Stone That's fine, you can of course make a comment and close-vote if you want. If you're telling me that this question isn't on topic for OR.SE then a close-vote is a perfectly valid mechanism to indicate that. – LarrySnyder610 Jun 3 '19 at 2:32

The .. operator cannot be used in the data section (i.e. it won't be expanded, see the AMPL FAQ). What you can do is to declare the limits in the model, e.g.

param n;
set things := 1..n;


and define them in the data file

param n := 5;

• Yeah that is basically the approach I have used but it feels a bit like a workaround and I wondered if my syntax was just wrong in the .dat file. – LarrySnyder610 Jun 3 '19 at 2:01
• True, could be easier, but that's the way it seems to be right now. It just saw this, confirming that .. won't work in the data part: ampl.com/faqs/… – Marcus Ritt Jun 3 '19 at 2:04
• param n default 5; does what you'd expect; you can then change it in the data file, or not. – denis Nov 3 '19 at 16:47