Line | |
---|
1 | function [F,vars] = sort_internal(t,X,data);%ii,D,V); |
---|
2 | |
---|
3 | % Hack to figure out all the sorted variables, not just this index. |
---|
4 | % Sort is implemented in a slighlt different way (general feature in |
---|
5 | % future versions) that allows one element in an operator to modell all |
---|
6 | % elements. Reduces the number of calls to the operator code. |
---|
7 | |
---|
8 | ii = data.i; |
---|
9 | D = data.D; |
---|
10 | V = data.V; |
---|
11 | |
---|
12 | var_start = getvariables(t)-ii+1; |
---|
13 | n = length(X); |
---|
14 | var_end = getvariables(t)-ii+1 + n-1; |
---|
15 | vars = var_start:var_end; |
---|
16 | |
---|
17 | % Is this a location variable instead of the actuial sort variable. If so, |
---|
18 | % shift everything back to get the indicies of the sorted variables. |
---|
19 | if data.isthisloc == 1 |
---|
20 | vars = vars - n; |
---|
21 | end |
---|
22 | |
---|
23 | t = recover(vars); |
---|
24 | loc = recover(vars+n); |
---|
25 | |
---|
26 | [M,m] = derivebounds(X); |
---|
27 | X = reshape(X,1,n); |
---|
28 | |
---|
29 | % Standard model |
---|
30 | F = set(sum(D,1) == 1) + set(sum(D,2) == 1); |
---|
31 | F = F + set(t == sum(V,2)); |
---|
32 | F = F + set(diff(t) > 0); |
---|
33 | for i = 1:n |
---|
34 | di = D(i,:); |
---|
35 | vi = V(i,:); |
---|
36 | F = F + set(-(M-m)'.*(1-di) < X-vi < (M-m)'.*(1-di)); |
---|
37 | F = F + set(m'.*di < vi < M'.*di); |
---|
38 | end |
---|
39 | |
---|
40 | % Cuts |
---|
41 | F = F + set(X == sum(V,1)); |
---|
42 | F = F + set(sum(t) == sum(X)); |
---|
43 | |
---|
44 | % Definition of location |
---|
45 | F = F + set(loc == D*[(1:n)']) + set(1 <= loc <= n); |
---|
46 | |
---|
Note: See
TracBrowser
for help on using the repository browser.