After many attempts, I stopped using AMPL.
The cabalistic nature of the language, the very poor documentation and the lack of artificial intelligence to help in code development make the effort overwhelming and hours are wasted trying to do things that are trivial in other languages. The straw that broke the camel’s back was the inability to transform a set of pairs {(i,j), (k,l),…} into a set indexed by its numerals from 1 to its cardinal.
How can it be that no AI is able to answer the question correctly?
Thanks
Hi Rafa,
Sorry to read that, it seems that you are trying to relabel a set in order to make set S = {(i,j), (k,l),…}
to become a set indexed from 1 to card(S), such that S[1] returns (i,j), and so on.
It would be better to know why you want to do that, or if that’s what you would expect.
Could you give more context on what you are trying to do, in order to identify the best way to write it?
If you have a set of pairs {(i,j), (k,l),…}, what is the sorting criteria? Sets in Ampl are unordered by default (since sets are not ordered by default in Maths or other Programming Languages). If the order is not important, why do you need to index it if you can just iterate?
There are actually many ways to do that, it all depends on what you try to express.
Ampl is a Modeling Language to write models naturally, however, this kind of preprocessing may better happen outside the model. I would strongly recommend you Amplpy to solve this kind of issues more effectively (through Python), and take advantage of Ampl’s syntax to just write the model. Writing in Amplpy is easier to maintain, more effectively.
“How can it be that no AI is able to answer the question correctly?”
AI tends to give positive answers to positive prompts. Either they are not good enough doing complex formulations, or you are giving the wrong prompt, and getting a “positive” and apparently fine reply. Everything looks possible when asking kindly to an AI, since hardly it will say that it does not know how to proceed.
By the way, I got a right answer to solve your problem asking a GenAI (at first attempt). The answer is correct but convoluted, so I would not recommend it without knowing how are you planning to write your model.
AI tools are really good at writing AMPL indeed, but when your model have some complex tricks, they usually over-complicate it. The same with any other topic you ask for, coding issues, suggestion, general questions…