Merge "Unique field moved to vnf policy"
[optf/osdf.git] / apps / pci / optimizers / solver / min_confusion.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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 % Decision variables
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50
51 % Defines the PCI for each node.
52 array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
53
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 % Constraints
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57
58 % Direct neighbors must have different PCIs for avoid **COLLISION**.
59 constraint
60 forall(i in 1..NUM_NEIGHBORS)(
61     pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
62 );
63
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 % Objective function
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68 % Total number of confusions.
69 var int: total_confusions =
70     sum([bool2int(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] ==
71                   pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
72          | i in 1..NUM_SECOND_LEVEL_NEIGHBORS]);
73
74 % Minimize the total number of confusions.
75 solve :: int_search(pci, smallest, indomain_min, complete)
76 minimize total_confusions;
77
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % Output
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81
82 output
83 ["PCI assigment"] ++
84 ["\nnode,pci"] ++
85 [
86     "\n" ++ show(node) ++ "," ++ show(pci[node])
87 | node in 0..NUM_NODES-1
88 ] ++
89
90 ["\n\nConfusions"] ++
91 ["\nTotal confusions: " ++ show(total_confusions)] ++
92 ["\nConfusion pairs"] ++
93 [
94     "\n" ++ show(SECOND_LEVEL_NEIGHBORS[i, 1]) ++ "," ++
95     show(SECOND_LEVEL_NEIGHBORS[i, 2])
96 | i in 1..NUM_SECOND_LEVEL_NEIGHBORS where
97   fix(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] == pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
98 ]