Hot answers tagged

7

AMPL assumes that a parameter takes only numerical values, unless you add the keyword symbolic to say that string values are also permitted. So your first statement should be param filename symbolic := "instance.txt"; Then you can use the string expression ("output" & filename) to specify a file that receives the output from a ...


6

Before implementing anything, you need to understand the equations. A good approach is to think in terms of resources. When handling capacity constraints, you are dealing with a load resource which is limited to the vehicle's capacity. When dealing with constraints linked to time, you need an extra resource for this. Each of these resources can be delt with ...


6

I don't think there is anything special in AMPL for doing this, but it can be done. Option 1 is to add a term to the objective that penalizes the sum of all variables. (I'm assuming that all variables are nonnegative.) This will encourage the solver to force your "free" variables to zero. The catch is that you have to multiply this term by a ...


6

To overwrite a file that you have previously been writing in an AMPL session, first close the file: close (OutputFile); Then use > to overwrite the file: print k > (OutputFile); This deletes the file and then opens a new, empty file with the same name. Note that once the file is open, > and >> both append to it. A complete description of ...


5

This should overwrite : k > (OutputFile); While this appends : k >> (OutputFile);


4

Try sum{(i,j) in ARCS} blablabla[i,j]


3

Here is the AMPL interpretation of @RobPratt's answer which works perfectly using the gurobi in my local pc: model; param n := 22; set NODES = 1..n; param degree {NODES} := 5; set NODE_PAIRS = {i in NODES, j in NODES: i < j}; var X {NODE_PAIRS} binary; var Y {(i,j) in NODE_PAIRS, k in NODES diff {i,j}} binary; subject to DegreeCon {k in NODES}: ...


3

Here is the SAS code that I used to obtain the results in the linked thread. Maybe it will help you correct your AMPL errors. In particular, note that you should declare each variable only once. proc optmodel; num n = 22; set NODES = 1..n; num degree {NODES} = 5; set NODE_PAIRS = {i in NODES, j in NODES: i < j}; var X {NODE_PAIRS} binary;...


3

Using the assignment operator := inside the loop is redefining h for each combination of k and j, which is an error. I assume that your actual data set will not have the same 2D data matrix for all (k, j) combinations (which is what your example here would do if it worked). You might want to look at Chapter 12 of the AMPL book, which discusses various ways ...


1

I am going to answer my own question. After I made the post, I realized the variable pi actually don't show up in the model though declared. It looks like this is the reason why the first way doesn't take effective in the 'solve' process while the second explicit way works.


Only top voted, non community-wiki answers of a minimum length are eligible