Updating code for pci-anr optimization calls
[optf/osdf.git] / osdf / optimizers / pciopt / solver / min_confusion_inl.mzn
1 % -------------------------------------------------------------------------
2 %   Copyright (c) 2018 AT&T Intellectual Property
3 %
4 %   Licensed under the Apache License, Version 2.0 (the "License");
5 %   you may not use this file except in compliance with the License.
6 %   You may obtain a copy of the License at
7 %
8 %       http://www.apache.org/licenses/LICENSE-2.0
9 %
10 %   Unless required by applicable law or agreed to in writing, software
11 %   distributed under the License is distributed on an "AS IS" BASIS,
12 %   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 %   See the License for the specific language governing permissions and
14 %   limitations under the License.
15 %
16 % -------------------------------------------------------------------------
17 %
18
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20 % Parameters and its assertions
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23 % Number of cells/radios.
24 int: NUM_NODES;
25
26 % Maximum number of Physical Cell Identifiers to be assigned to the nodes.
27 int: NUM_PCIS;
28
29 % Number of edges between neighbor nodes. There is a edge (i,j) if and only
30 % if nodes i and j are neighbors, i.e., an user equipment (UE) can make
31 % handoff between i and j. Such edges are used to avoid **COLLISION**, i.e.,
32 % to guarantee that nodes i and j have different PCIs.
33 int: NUM_NEIGHBORS;
34
35 % Each line represents an edge between direct neighbors as defined before.
36 array[1..NUM_NEIGHBORS, 1..2] of int: NEIGHBORS;
37
38 % Number of undirect neighbor pairs (j, k) such that both j and k are direct
39 % neighbors of node i, i.e., (j, k) exits if and only if exists (i, j) and
40 % (i, k). Nodes (i, k) can generate "confunsions" in the network if they have
41 % the same PCI. Such edges are used to avoid/minimize **CONFUSIONS**.
42 int: NUM_SECOND_LEVEL_NEIGHBORS;
43
44 % Each line represents an edge between undirect neighbors as defined before.
45 array[1..NUM_SECOND_LEVEL_NEIGHBORS, 1..2] of int: SECOND_LEVEL_NEIGHBORS;
46
47 % Number of ignorable neighbor links. Such links can be ignored during
48 % optimization if needed.
49 int: NUM_IGNORABLE_NEIGHBOR_LINKS;
50
51 % The links that can be ignored if needed. Each line represents the two ends
52 % of the links, like the previous structures.
53 array[1..NUM_IGNORABLE_NEIGHBOR_LINKS, 1..2] of int: IGNORABLE_NEIGHBOR_LINKS;
54
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 % Decision variables
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59 % Defines the PCI for each node.
60 array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
61
62 array[1..NUM_IGNORABLE_NEIGHBOR_LINKS] of var 0..1: used_ignorables;
63
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 % Constraints
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68 % Direct neighbors must have different PCIs for avoid **COLLISION**.
69 % Forced links.
70 constraint
71 forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
72     where
73         NEIGHBORS[i, 1] != IGNORABLE_NEIGHBOR_LINKS[j, 1] \/
74         NEIGHBORS[i, 2] != IGNORABLE_NEIGHBOR_LINKS[j, 2]
75 )(
76     pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
77 );
78
79
80 % Ignorable links.
81 constraint
82 forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
83     where
84         NEIGHBORS[i, 1] == IGNORABLE_NEIGHBOR_LINKS[j, 1] /\
85         NEIGHBORS[i, 2] == IGNORABLE_NEIGHBOR_LINKS[j, 2]
86 )(
87     used_ignorables[j] >= bool2int(pci[NEIGHBORS[i, 1]] == pci[NEIGHBORS[i, 2]])
88 );
89
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 % Objective function
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 % Total number of confusions.
95 var int: total_confusions =
96     sum([bool2int(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] ==
97                   pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
98          | i in 1..NUM_SECOND_LEVEL_NEIGHBORS]);
99
100 % Total number of used ignorables links.
101 var int: total_used_ignorables = sum(used_ignorables);
102
103 solve :: int_search(pci, smallest, indomain_min, complete)
104
105 % Minimize the total number of confusions.
106 %minimize total_confusions;
107
108 % Minimize the total number of confusions first,
109 % then the number of used ignorables links.
110 minimize (2 * NUM_IGNORABLE_NEIGHBOR_LINKS * total_confusions) +
111          total_used_ignorables;
112
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % Output
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117 output
118 ["PCI assigment"] ++
119 ["\nnode,pci"] ++
120 [
121     "\n" ++ show(node) ++ "," ++ show(pci[node])
122 | node in 0..NUM_NODES-1
123 ] ++
124 ["\n\nTotal used ignorables links: " ++ show(total_used_ignorables)] ++
125 ["\nUsed ignorables links: "] ++
126 [
127     "\n" ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 1]) ++
128     ","  ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 2])
129     | i in 1..NUM_IGNORABLE_NEIGHBOR_LINKS where fix(used_ignorables[i] > 0)
130 ] ++
131 ["\n\nConfusions"] ++
132 ["\nTotal confusions: " ++ show(total_confusions)] ++
133 ["\nConfusion pairs"] ++
134 [
135     "\n" ++ show(SECOND_LEVEL_NEIGHBORS[i, 1]) ++ "," ++
136     show(SECOND_LEVEL_NEIGHBORS[i, 2])
137     | i in 1..NUM_SECOND_LEVEL_NEIGHBORS where
138       fix(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] == pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
139 ]
140