Change to support PCI unchangeable cells
[optf/osdf.git] / apps / pci / optimizers / 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 % ids of cells for which the pci should remain unchanged
56 set of int: PCI_UNCHANGEABLE_CELLS;
57
58 % This array has the original pcis of all the cells. array is indexed by the ids
59 % of the cell. eg. ORIGINAL_PCIS[3] returns the pci of cell whose id is 3.
60 % ids start from 0
61 array[1..NUM_NODES] of 0..NUM_PCIS-1: ORIGINAL_PCIS;
62
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % Decision variables
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67 % Defines the PCI for each node.
68 array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
69
70 array[1..NUM_IGNORABLE_NEIGHBOR_LINKS] of var 0..1: used_ignorables;
71
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % Constraints
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76 % fixed pci cells
77 constraint
78 if(length(PCI_UNCHANGEABLE_CELLS) !=0) then
79 forall(i in PCI_UNCHANGEABLE_CELLS)(
80     pci[i] == ORIGINAL_PCIS[i+1]
81 )
82 endif;
83
84 % Direct neighbors must have different PCIs for avoid **COLLISION**.
85 % Forced links.
86 constraint
87 forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
88     where
89         NEIGHBORS[i, 1] != IGNORABLE_NEIGHBOR_LINKS[j, 1] \/
90         NEIGHBORS[i, 2] != IGNORABLE_NEIGHBOR_LINKS[j, 2]
91 )(
92     pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
93 );
94
95
96 % Ignorable links.
97 constraint
98 forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
99     where
100         NEIGHBORS[i, 1] == IGNORABLE_NEIGHBOR_LINKS[j, 1] /\
101         NEIGHBORS[i, 2] == IGNORABLE_NEIGHBOR_LINKS[j, 2]
102 )(
103     used_ignorables[j] >= bool2int(pci[NEIGHBORS[i, 1]] == pci[NEIGHBORS[i, 2]])
104 );
105
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % Objective function
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
110 % Total number of confusions.
111 var int: total_confusions =
112     sum([bool2int(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] ==
113                   pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
114          | i in 1..NUM_SECOND_LEVEL_NEIGHBORS]);
115
116 % Total number of used ignorables links.
117 var int: total_used_ignorables = sum(used_ignorables);
118
119 solve :: int_search(pci, smallest, indomain_min, complete)
120
121 % Minimize the total number of confusions.
122 %minimize total_confusions;
123
124 % Minimize the total number of confusions first,
125 % then the number of used ignorables links.
126 minimize (2 * NUM_IGNORABLE_NEIGHBOR_LINKS * total_confusions) +
127          total_used_ignorables;
128
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % Output
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
133 output
134 ["PCI assigment"] ++
135 ["\nnode,pci"] ++
136 [
137     "\n" ++ show(node) ++ "," ++ show(pci[node])
138 | node in 0..NUM_NODES-1
139 ] ++
140 ["\n\nTotal used ignorables links: " ++ show(total_used_ignorables)] ++
141 ["\nUsed ignorables links: "] ++
142 [
143     "\n" ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 1]) ++
144     ","  ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 2])
145     | i in 1..NUM_IGNORABLE_NEIGHBOR_LINKS where fix(used_ignorables[i] > 0)
146 ] ++
147 ["\n\nConfusions"] ++
148 ["\nTotal confusions: " ++ show(total_confusions)] ++
149 ["\nConfusion pairs"] ++
150 [
151     "\n" ++ show(SECOND_LEVEL_NEIGHBORS[i, 1]) ++ "," ++
152     show(SECOND_LEVEL_NEIGHBORS[i, 2])
153     | i in 1..NUM_SECOND_LEVEL_NEIGHBORS where
154       fix(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] == pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
155 ]
156