Hello, I want i to iterate over the last element of the set large_cav, and then j to iterate over the element always one ahead of i, since large_cav is an unordered set, unlike {1… (Nv-1)} is an ordered set that can be written as i in {1… (Nv-1)}, j in {(i+1)… Nv}, what do I do with the unordered set large_cav? By the way, large_cav is an increasing set
set large_cav ordered = A11 union A22 union A33 union B11 union B22 union B33 union C11 union C22 union C33 union D11 union D22 union D33;
Then you can use AMPL’s ordered set functions in defining your constraint (see section 5.6 Ordered sets in the chapter 5 of the AMPL book). The first member of large_cav will be given by first(large_cav), and the last member by last(large_cav).
So if the set is large_cav, how do we express the following set meaning, i in {1… (Nv-1)}, j in {(i+1)… Nv},
I should have clarified the matter more clearly.
large_cav is an unordered and non-arithmetic increasing set, and i want to traverse it using I and j, similar to the following loop
for i in large_cav[finall-1]
for j in large_cav[i+1]… large_cav[final]
large_cav[finall-1] The second to last element of the set large_cav, large_cav[final]
Is the last element, large_cav[i+1] means j goes one element ahead of i
If you want to talk about the last element of a set, the second-to-last element of at set, or the element j that is one after the element i of the set, then there needs to be some ordering defined on the set. Thus, you need to tell AMPL that you want it to define an ordering on large_cav. Then you can use AMPL’s ordered set functions:
The element that is one after element i in large_cav is member(i+1, large_cav)
The number of elements in large_cav is card(large_cav), and so the next-to-last element of large_cav is member(card(large_cav)-1, large_cav)
The last element of large_cav is last(large_cav).
I am not sure what ordering you want to have for large_cav, but if you want the elements to be ordered by increasing value, then large_cav should be defined like this:
set large_cav ordered by Integers = A11 union A22 union A33 union B11 union B22 union B33 union C11 union C22 union C33 union D11 union D22 union D33;
I’m sorry, I still didn’t give you a good description.
large_cav is a union, but
A11 union A22 union A33 union B11 union B22 union B33 union C11 union C22 union C33 union D11 union D22 union D33; It’s incremental, like:
{1,2} union {3,5}union {7,8,9} union {24,39}, so should I assume that large_cav is an ordered set?
Finally I can use functions to express constraints as follows
s.t. VehicleItoJfr {i in large_cav , j in large_cav , kk in I}:
(xf[i,kk] - xr[j,kk])^2 + (yf[i,kk] - yr[j,kk])^2 >= FourSqR;
But i and j should satisfy some constraints;
i does not traverse the last element of the set,
j needs to traverse the elements after i.
I found that using these functions seems to be unable to achieve this, do you have any ideas?
You can define large_cav with the words ordered by Integers in the definition, like this:
set large_cav ordered by Integers = A11 union A22 union A33 union B11 union B22 union B33 union C11 union C22 union C33 union D11 union D22 union D33;
When the set statement is written in this way, large_cav is treated by AMPL as an ordered set. Then you can use the ordering in your model. I do not know the details of your model, but I can give the following example that shows how the ordering may be used in constraint VehicleItoJfr :
param Nv = card(large_cav);
param FourSqR = 77.7;
set I = 1..3;
var xf {large_cav, I};
var xr {large_cav, I};
var yf {large_cav, I};
var yr {large_cav, I};
s.t. VehicleItoJfr {i in 1..Nv-1, j in i+1..Nv, kk in I}:
(xf[member(i,large_cav),kk] - xr[member(j,large_cav),kk])^2 +
(yf[member(i,large_cav),kk] - yr[member(j,large_cav),kk])^2 >= FourSqR;