Initial checkin for pci optimization code
[optf/osdf.git] / osdf / optimizers / pciopt / 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 % Parameters and its assertions
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
22 % Number of cells/radios.
23 int: NUM_NODES;
24
25 % Maximum number of Physical Cell Identifiers to be assigned to the nodes.
26 int: NUM_PCIS;
27
28 % Number of edges between neighbor nodes. There is a edge (i,j) if and only
29 % if nodes i and j are neighbors, i.e., an user equipment (UE) can make
30 % handoff between i and j. Such edges are used to avoid **CONFLICTS**, i.e.,
31 % to guarantee that nodes i and j have different PCIs.
32 int: NUM_CONFLICT_EDGES;
33
34 % Each line represents an edge between direct neighbors as defined before.
35 array[1..NUM_CONFLICT_EDGES, 1..2] of int: CONFLICT_EDGES; 
36
37 % Number of undirect neighbor pairs (j, k) such that both j and k are direct
38 % neighbors of node i, i.e., (j, k) exits if and only if exists (i, j) and 
39 % (i, k). Nodes (i, k) can generate "confunsions" in the network if they have
40 % the same PCI. Such edges are used to avoid/minimize **CONFUSIONS**.
41 int: NUM_CONFUSION_EDGES;
42
43 % Each line represents an edge between undirect neighbors as defined before.
44 array[1..NUM_CONFUSION_EDGES, 1..2] of int: CONFUSION_EDGES; 
45
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 % Decision variables
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49
50 % Defines the PCI for each node.
51 array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
52
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 % Constraints
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 % Direct neighbors must have different PCIs for avoid **CONFLICTS**.
58 constraint 
59 forall(i in 1..NUM_CONFLICT_EDGES)(
60     pci[CONFLICT_EDGES[i, 1]] != pci[CONFLICT_EDGES[i, 2]]
61 );
62
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % Objective function
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67 % Total number of confusions.
68 var int: total_confusions =
69     sum([bool2int(pci[CONFUSION_EDGES[i, 1]] == pci[CONFUSION_EDGES[i, 2]])
70          | i in 1..NUM_CONFUSION_EDGES]);
71
72 % Minimize the total number of confusions.
73 solve :: int_search(pci, smallest, indomain_min, complete)
74 minimize total_confusions;
75
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % Output
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 output
81 ["PCI assigment"] ++ 
82 ["\nnode,pci"] ++
83 [
84     "\n" ++ show(node) ++ "," ++ show(pci[node])
85 | node in 0..NUM_NODES-1
86 ] ++
87
88 ["\n\nConfusions"] ++ 
89 ["\nTotal confusions: " ++ show(total_confusions)] ++
90 ["\nConfusion pairs"] ++
91 [
92     "\n" ++ show(CONFUSION_EDGES[i, 1]) ++ "," ++ show(CONFUSION_EDGES[i, 2])
93 | i in 1..NUM_CONFUSION_EDGES where 
94   fix(pci[CONFUSION_EDGES[i, 1]] == pci[CONFUSION_EDGES[i, 2]])
95 ]