ampl

Constraint in AMPL with matrix


How can I make a constraint with a matrix in AMPL where the next position has to be less than the current position? I need something like x[i,j]<=x[i,j+1], but I don't know how to put that in the AMPL program. I'd already tried this: subject to prioridade{i in SEM}: {j in PROD-1} d[i,j]<=d[i,j+1], and the solver returned me this:

    syntax error
context:  {j in  >>> PROD- <<< 1} d[i,j]<=d[i,j+1]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Checking ampl.mod for gurobi_options...
Checking ampl.com for gurobi_options...
Executing AMPL.
processing data.
processing commands.
Executing on prod-exec-1.neos-server.org
 Error (2) in /opt/ampl/ampl -R amplin```

Solution

  • The syntax of your constraint declaration is not valid AMPL. More specifically, the {j in PROD-1} part is out of place, so the processor doesn't know what it is.

    Assuming PROD is a parameter, I'm guessing you want something like this:

    subject to prioridade{i in SEM, j in 1..PROD-1}: d[i,j] <= d[i,j+1];
    

    If PROD is a set, that will not work, because PROD-1 makes no sense. Next time you post a question, make sure you say what are the model entities of your program. Better yet, share the whole code, or at least the relevant parts of it.

    I can see you are new to AMPL, so I recommend reading some basic AMPL introduction, such as this. Also, since you are using NEOS, you may want to take a look at the PIFOP IDE, where you can use NEOS directly from your browser.

    Disclaimer: I'm the developer that tool.