aboutsummaryrefslogtreecommitdiffstats
path: root/apps/pci
diff options
context:
space:
mode:
Diffstat (limited to 'apps/pci')
-rw-r--r--apps/pci/__init__.py0
-rw-r--r--apps/pci/models/__init__.py0
-rw-r--r--apps/pci/models/api/__init__.py0
-rw-r--r--apps/pci/models/api/pciOptimizationRequest.py56
-rw-r--r--apps/pci/models/api/pciOptimizationResponse.py46
-rw-r--r--apps/pci/optimizers/__init__.py2
-rw-r--r--apps/pci/optimizers/config/__init__.py0
-rw-r--r--apps/pci/optimizers/config/config_client.py37
-rw-r--r--apps/pci/optimizers/config/configdb.py51
-rw-r--r--apps/pci/optimizers/config/cps.py72
-rw-r--r--apps/pci/optimizers/config_request.py55
-rw-r--r--apps/pci/optimizers/pci_opt_processor.py132
-rw-r--r--apps/pci/optimizers/solver/__init__.py0
-rw-r--r--apps/pci/optimizers/solver/min_confusion.mzn98
-rw-r--r--apps/pci/optimizers/solver/min_confusion_inl.mzn156
-rw-r--r--apps/pci/optimizers/solver/ml_model.py72
-rw-r--r--apps/pci/optimizers/solver/no_conflicts_no_confusion.mzn103
-rw-r--r--apps/pci/optimizers/solver/optimizer.py179
-rw-r--r--apps/pci/optimizers/solver/pci_utils.py47
19 files changed, 1106 insertions, 0 deletions
diff --git a/apps/pci/__init__.py b/apps/pci/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/pci/__init__.py
diff --git a/apps/pci/models/__init__.py b/apps/pci/models/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/pci/models/__init__.py
diff --git a/apps/pci/models/api/__init__.py b/apps/pci/models/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/pci/models/api/__init__.py
diff --git a/apps/pci/models/api/pciOptimizationRequest.py b/apps/pci/models/api/pciOptimizationRequest.py
new file mode 100644
index 0000000..2aa22f1
--- /dev/null
+++ b/apps/pci/models/api/pciOptimizationRequest.py
@@ -0,0 +1,56 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+from schematics.types import BaseType, StringType, URLType, IntType
+from schematics.types.compound import ModelType, ListType, DictType
+
+from osdf.models.api.common import OSDFModel
+
+
+class RequestInfo(OSDFModel):
+ """Info for northbound request from client such as SO"""
+ transactionId = StringType(required=True)
+ requestId = StringType(required=True)
+ callbackUrl = URLType(required=True)
+ callbackHeader = DictType(BaseType)
+ sourceId = StringType(required=True)
+ requestType = StringType(required=True)
+ numSolutions = IntType()
+ optimizers = ListType(StringType(required=True))
+ timeout = IntType()
+
+
+class ANRInfo(OSDFModel):
+ cellId = StringType(required=True)
+ removeableNeighbors = ListType(StringType())
+
+
+class CellInfo(OSDFModel):
+ """Information specific to CellInfo """
+ networkId = StringType(required=True)
+ cellIdList = ListType(StringType(required=True))
+ anrInputList = ListType(ModelType(ANRInfo))
+ fixedPCICells = ListType(StringType())
+ priorityTreatmentCells = ListType(StringType())
+ trigger = StringType()
+
+
+class PCIOptimizationAPI(OSDFModel):
+ """Request for PCI optimization """
+ requestInfo = ModelType(RequestInfo, required=True)
+ cellInfo = ModelType(CellInfo, required=True)
diff --git a/apps/pci/models/api/pciOptimizationResponse.py b/apps/pci/models/api/pciOptimizationResponse.py
new file mode 100644
index 0000000..019a43a
--- /dev/null
+++ b/apps/pci/models/api/pciOptimizationResponse.py
@@ -0,0 +1,46 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+from schematics.types import StringType, IntType
+from schematics.types.compound import ModelType, ListType
+
+from osdf.models.api.common import OSDFModel
+
+
+class PCISolution(OSDFModel):
+ cellId = StringType(required=True)
+ pci = IntType(required=True)
+
+
+class ANRSolution(OSDFModel):
+ cellId = StringType(required=True)
+ removeableNeighbors = ListType(StringType())
+
+
+class Solution(OSDFModel):
+ networkId = StringType(required=True)
+ pciSolutions = ListType(ListType(ModelType(PCISolution), min_size=1))
+ anrSolutions = ListType(ListType(ModelType(ANRSolution), min_size=1))
+
+
+class PCIOptimizationResponse(OSDFModel):
+ transactionId = StringType(required=True)
+ requestId = StringType(required=True)
+ requestStatus = StringType(required=True)
+ statusMessage = StringType()
+ solutions = ModelType(Solution, required=True)
diff --git a/apps/pci/optimizers/__init__.py b/apps/pci/optimizers/__init__.py
new file mode 100644
index 0000000..35bc5a0
--- /dev/null
+++ b/apps/pci/optimizers/__init__.py
@@ -0,0 +1,2 @@
+from apps.pci.optimizers.config import configdb
+from apps.pci.optimizers.config import cps
diff --git a/apps/pci/optimizers/config/__init__.py b/apps/pci/optimizers/config/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/pci/optimizers/config/__init__.py
diff --git a/apps/pci/optimizers/config/config_client.py b/apps/pci/optimizers/config/config_client.py
new file mode 100644
index 0000000..7e5a737
--- /dev/null
+++ b/apps/pci/optimizers/config/config_client.py
@@ -0,0 +1,37 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2021 Wipro Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+
+class ConfigClient(object):
+
+ subclasses = {}
+
+ @classmethod
+ def register_subclass(cls, type):
+ def decorator(subclass):
+ cls.subclasses[type] = subclass
+ return subclass
+
+ return decorator
+
+ @classmethod
+ def create(cls, type):
+ if type not in cls.subclasses:
+ raise ValueError('Bad config client type {}'.format(type))
+
+ return cls.subclasses[type]()
diff --git a/apps/pci/optimizers/config/configdb.py b/apps/pci/optimizers/config/configdb.py
new file mode 100644
index 0000000..cfc7ce1
--- /dev/null
+++ b/apps/pci/optimizers/config/configdb.py
@@ -0,0 +1,51 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2021 Wipro Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+from datetime import datetime as dt
+import uuid
+
+from apps.pci.optimizers.config.config_client import ConfigClient
+from osdf.config.base import osdf_config
+from osdf.logging.osdf_logging import debug_log
+from osdf.utils.interfaces import RestClient
+
+
+@ConfigClient.register_subclass('configdb')
+class ConfigDb(ConfigClient):
+
+ def __init__(self):
+ self.config = osdf_config.deployment
+ uid, passwd = self.config['configDbUserName'], self.config['configDbPassword']
+ headers = dict(transaction_id=str(uuid.uuid4()))
+ self.rc = RestClient(userid=uid, passwd=passwd, method="GET", log_func=debug_log.debug, headers=headers)
+
+ def get_cell_list(self, network_id):
+ ts = dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S%z')
+ cell_list_url = '{}/{}/{}/{}'.format(self.config['configDbUrl'],
+ self.config['configDbGetCellListUrl'], network_id, ts)
+ return self.rc.request(raw_response=True, url=cell_list_url).json()
+
+ def get_nbr_list(self, network_id, cell_id):
+ ts = dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S%z')
+ nbr_list_url = '{}/{}/{}/{}'.format(self.config['configDbUrl'],
+ self.config['configDbGetNbrListUrl'], cell_id, ts)
+ response = self.rc.request(url=nbr_list_url, raw_response=True).json()
+
+ debug_log.debug("cell_id {} nbr_list {}".format(cell_id, response.get('nbrList')))
+
+ return response.get('nbrList', [])
diff --git a/apps/pci/optimizers/config/cps.py b/apps/pci/optimizers/config/cps.py
new file mode 100644
index 0000000..9cf1b1f
--- /dev/null
+++ b/apps/pci/optimizers/config/cps.py
@@ -0,0 +1,72 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2021 Wipro Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+import json
+
+from apps.pci.optimizers.config.config_client import ConfigClient
+from osdf.config.base import osdf_config
+from osdf.logging.osdf_logging import debug_log
+from osdf.utils.interfaces import RestClient
+
+
+@ConfigClient.register_subclass('cps')
+class Cps(ConfigClient):
+
+ def __init__(self):
+ self.config = osdf_config.deployment
+ username, password = self.config['cpsUsername'], self.config['cpsPassword']
+ headers = {
+ "Content-Type": "application/json",
+ "Accept": "application/json"
+ }
+ self.rc = RestClient(userid=username, passwd=password, method="POST",
+ log_func=debug_log.debug, headers=headers)
+
+ def get_cell_list(self, network_id):
+ cell_list_url = '{}/{}'.format(self.config['cpsUrl'], self.config['cpsCellListUrl'])
+ data = {
+ 'inputParameters': {
+ 'regionId': network_id
+ }
+ }
+ response = self.rc.request(url=cell_list_url, data=json.dumps(data))
+ debug_log.debug("cell list response {}".format(response))
+ return sorted([x['idNRCellCU'] for x in response.get('NRCellCU')])
+
+ def get_nbr_list(self, network_id, cell_id):
+ nbr_list_url = '{}/{}'.format(self.config['cpsUrl'], self.config['cpsNbrListUrl'])
+ data = {
+ 'inputParameters': {
+ 'regionId': network_id,
+ 'idNRCellCU': cell_id
+ }
+ }
+ response = self.rc.request(url=nbr_list_url, data=json.dumps(data))
+ debug_log.debug("nbr list response {}".format(response))
+ nbr_list = []
+ for cell_relation in response.get('NRCellRelation'):
+ nbr = {
+ 'targetCellId': cell_relation['attributes']['nRTCI'],
+ 'pciValue': int(cell_relation['attributes']['nRPCI']),
+ 'ho': cell_relation['attributes']['isHOAllowed']
+ }
+ nbr_list.append(nbr)
+
+ debug_log.debug("cell_id {} nbr_list {}".format(cell_id, nbr_list))
+
+ return nbr_list
diff --git a/apps/pci/optimizers/config_request.py b/apps/pci/optimizers/config_request.py
new file mode 100644
index 0000000..f62641d
--- /dev/null
+++ b/apps/pci/optimizers/config_request.py
@@ -0,0 +1,55 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+from apps.pci.optimizers.config.config_client import ConfigClient
+
+
+def request(req_object, osdf_config, flat_policies):
+ """Process a configdb request from a Client (build Conductor API call, make the call, return result)
+
+ :param req_object: Request parameters from the client
+ :param osdf_config: Configuration specific to OSDF application (core + deployment)
+ :param flat_policies: policies related to PCI Opt (fetched based on request)
+ :return: response from ConfigDB (accounting for redirects from Conductor service
+ """
+ cell_list_response = {}
+
+ network_id = req_object['cellInfo']['networkId']
+
+ cell_list_response['network_id'] = network_id
+
+ config = osdf_config.deployment
+
+ config_client = ConfigClient.create(config['configClientType'])
+
+ cell_resp = config_client.get_cell_list(network_id)
+
+ cell_list = []
+ count = 0
+ for cell_id in cell_resp:
+ cell_info = {
+ 'cell_id': cell_id,
+ 'id': count,
+ 'nbr_list': config_client.get_nbr_list(network_id, cell_id)
+ }
+ cell_list.append(cell_info)
+ count += 1
+
+ cell_list_response['cell_list'] = cell_list
+
+ return cell_resp, cell_list_response
diff --git a/apps/pci/optimizers/pci_opt_processor.py b/apps/pci/optimizers/pci_opt_processor.py
new file mode 100644
index 0000000..a58d2f4
--- /dev/null
+++ b/apps/pci/optimizers/pci_opt_processor.py
@@ -0,0 +1,132 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+import traceback
+
+from onaplogging.mdcContext import MDC
+from requests import RequestException
+
+from apps.pci.optimizers.config_request import request as config_request
+from apps.pci.optimizers.solver.optimizer import pci_optimize as optimize
+from apps.pci.optimizers.solver.pci_utils import get_cell_id
+from apps.pci.optimizers.solver.pci_utils import get_pci_value
+from osdf.logging.osdf_logging import error_log
+from osdf.logging.osdf_logging import metrics_log
+from osdf.logging.osdf_logging import MH
+from osdf.operation.error_handling import build_json_error_body
+from osdf.utils.interfaces import get_rest_client
+from osdf.utils.mdc_utils import mdc_from_json
+
+"""
+This application generates PCI Optimization API calls using the information received from PCI-Handler-MS, SDN-C
+and Policy.
+"""
+
+
+def process_pci_optimation(request_json, osdf_config, flat_policies):
+ """Process a PCI request from a Client (build config-db, policy and API call, make the call, return result)
+
+ :param req_object: Request parameters from the client
+ :param osdf_config: Configuration specific to OSDF application (core + deployment)
+ :param flat_policies: policies related to pci (fetched based on request)
+ :return: response from PCI Opt
+ """
+ try:
+ mdc_from_json(request_json)
+ rc = get_rest_client(request_json, service="pcih")
+ req_id = request_json["requestInfo"]["requestId"]
+ cell_info_list, network_cell_info = config_request(request_json, osdf_config, flat_policies)
+ pci_response = get_solutions(cell_info_list, network_cell_info, request_json)
+
+ metrics_log.info(MH.inside_worker_thread(req_id))
+ except Exception as err:
+ error_log.error("Error for {} {}".format(req_id, traceback.format_exc()))
+
+ try:
+ body = build_json_error_body(err)
+ metrics_log.info(MH.sending_response(req_id, "ERROR"))
+ rc.request(json=body, noresponse=True)
+ except RequestException:
+ MDC.put('requestID', req_id)
+ error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc()))
+ raise err
+
+ try:
+ metrics_log.info(MH.calling_back_with_body(req_id, rc.url, pci_response))
+ error_log.error("pci response: {}".format(str(pci_response)))
+ rc.request(json=pci_response, noresponse=True)
+ except RequestException: # can't do much here but log it and move on
+ error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc()))
+
+
+def get_solutions(cell_info_list, network_cell_info, request_json):
+ status, pci_solutions, anr_solutions = build_solution_list(cell_info_list, network_cell_info, request_json)
+ return {
+ "transactionId": request_json['requestInfo']['transactionId'],
+ "requestId": request_json["requestInfo"]["requestId"],
+ "requestStatus": "completed",
+ "statusMessage": status,
+ "solutions": {
+ 'networkId': request_json['cellInfo']['networkId'],
+ 'pciSolutions': pci_solutions,
+ 'anrSolutions': anr_solutions
+ }
+ }
+
+
+def build_solution_list(cell_info_list, network_cell_info, request_json):
+ status = "success"
+ req_id = request_json["requestInfo"]["requestId"]
+ pci_solutions = []
+ anr_solutions = []
+ try:
+ opt_solution = optimize(network_cell_info, cell_info_list, request_json)
+ if opt_solution == 'UNSATISFIABLE':
+ status = 'inconsistent input'
+ return status, pci_solutions, anr_solutions
+ else:
+ pci_solutions = build_pci_solution(network_cell_info, opt_solution['pci'])
+ anr_solutions = build_anr_solution(network_cell_info, opt_solution.get('removables', {}))
+ except RuntimeError:
+ error_log.error("Failed finding solution for {} {}".format(req_id, traceback.format_exc()))
+ status = "failed"
+ return status, pci_solutions, anr_solutions
+
+
+def build_pci_solution(network_cell_info, pci_solution):
+ pci_solutions = []
+ for k, v in pci_solution.items():
+ old_pci = get_pci_value(network_cell_info, k)
+ if old_pci != v:
+ response = {
+ 'cellId': get_cell_id(network_cell_info, k),
+ 'pci': v
+ }
+ pci_solutions.append(response)
+ return pci_solutions
+
+
+def build_anr_solution(network_cell_info, removables):
+ anr_solutions = []
+ for k, v in removables.items():
+ response = {
+ 'cellId': get_cell_id(network_cell_info, k),
+ 'removeableNeighbors': list(map(lambda x: get_cell_id(network_cell_info, x), v))
+ }
+ anr_solutions.append(response)
+ return anr_solutions
diff --git a/apps/pci/optimizers/solver/__init__.py b/apps/pci/optimizers/solver/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/pci/optimizers/solver/__init__.py
diff --git a/apps/pci/optimizers/solver/min_confusion.mzn b/apps/pci/optimizers/solver/min_confusion.mzn
new file mode 100644
index 0000000..ff56c18
--- /dev/null
+++ b/apps/pci/optimizers/solver/min_confusion.mzn
@@ -0,0 +1,98 @@
+% -------------------------------------------------------------------------
+% Copyright (c) 2018 AT&T Intellectual Property
+%
+% Licensed under the Apache License, Version 2.0 (the "License");
+% you may not use this file except in compliance with the License.
+% You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+% See the License for the specific language governing permissions and
+% limitations under the License.
+%
+% -------------------------------------------------------------------------
+%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Parameters and its assertions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Number of cells/radios.
+int: NUM_NODES;
+
+% Maximum number of Physical Cell Identifiers to be assigned to the nodes.
+int: NUM_PCIS;
+
+% Number of edges between neighbor nodes. There is a edge (i,j) if and only
+% if nodes i and j are neighbors, i.e., an user equipment (UE) can make
+% handoff between i and j. Such edges are used to avoid **COLLISION**, i.e.,
+% to guarantee that nodes i and j have different PCIs.
+int: NUM_NEIGHBORS;
+
+% Each line represents an edge between direct neighbors as defined before.
+array[1..NUM_NEIGHBORS, 1..2] of int: NEIGHBORS;
+
+% Number of undirect neighbor pairs (j, k) such that both j and k are direct
+% neighbors of node i, i.e., (j, k) exits if and only if exists (i, j) and
+% (i, k). Nodes (i, k) can generate "confunsions" in the network if they have
+% the same PCI. Such edges are used to avoid/minimize **CONFUSIONS**.
+int: NUM_SECOND_LEVEL_NEIGHBORS;
+
+% Each line represents an edge between undirect neighbors as defined before.
+array[1..NUM_SECOND_LEVEL_NEIGHBORS, 1..2] of int: SECOND_LEVEL_NEIGHBORS;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Decision variables
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Defines the PCI for each node.
+array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Constraints
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Direct neighbors must have different PCIs for avoid **COLLISION**.
+constraint
+forall(i in 1..NUM_NEIGHBORS)(
+ pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
+);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Objective function
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Total number of confusions.
+var int: total_confusions =
+ sum([bool2int(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] ==
+ pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
+ | i in 1..NUM_SECOND_LEVEL_NEIGHBORS]);
+
+% Minimize the total number of confusions.
+solve :: int_search(pci, smallest, indomain_min, complete)
+minimize total_confusions;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Output
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+output
+["PCI assigment"] ++
+["\nnode,pci"] ++
+[
+ "\n" ++ show(node) ++ "," ++ show(pci[node])
+| node in 0..NUM_NODES-1
+] ++
+
+["\n\nConfusions"] ++
+["\nTotal confusions: " ++ show(total_confusions)] ++
+["\nConfusion pairs"] ++
+[
+ "\n" ++ show(SECOND_LEVEL_NEIGHBORS[i, 1]) ++ "," ++
+ show(SECOND_LEVEL_NEIGHBORS[i, 2])
+| i in 1..NUM_SECOND_LEVEL_NEIGHBORS where
+ fix(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] == pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
+]
diff --git a/apps/pci/optimizers/solver/min_confusion_inl.mzn b/apps/pci/optimizers/solver/min_confusion_inl.mzn
new file mode 100644
index 0000000..e677e27
--- /dev/null
+++ b/apps/pci/optimizers/solver/min_confusion_inl.mzn
@@ -0,0 +1,156 @@
+% -------------------------------------------------------------------------
+% Copyright (c) 2018 AT&T Intellectual Property
+%
+% Licensed under the Apache License, Version 2.0 (the "License");
+% you may not use this file except in compliance with the License.
+% You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+% See the License for the specific language governing permissions and
+% limitations under the License.
+%
+% -------------------------------------------------------------------------
+%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Parameters and its assertions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Number of cells/radios.
+int: NUM_NODES;
+
+% Maximum number of Physical Cell Identifiers to be assigned to the nodes.
+int: NUM_PCIS;
+
+% Number of edges between neighbor nodes. There is a edge (i,j) if and only
+% if nodes i and j are neighbors, i.e., an user equipment (UE) can make
+% handoff between i and j. Such edges are used to avoid **COLLISION**, i.e.,
+% to guarantee that nodes i and j have different PCIs.
+int: NUM_NEIGHBORS;
+
+% Each line represents an edge between direct neighbors as defined before.
+array[1..NUM_NEIGHBORS, 1..2] of int: NEIGHBORS;
+
+% Number of undirect neighbor pairs (j, k) such that both j and k are direct
+% neighbors of node i, i.e., (j, k) exits if and only if exists (i, j) and
+% (i, k). Nodes (i, k) can generate "confunsions" in the network if they have
+% the same PCI. Such edges are used to avoid/minimize **CONFUSIONS**.
+int: NUM_SECOND_LEVEL_NEIGHBORS;
+
+% Each line represents an edge between undirect neighbors as defined before.
+array[1..NUM_SECOND_LEVEL_NEIGHBORS, 1..2] of int: SECOND_LEVEL_NEIGHBORS;
+
+% Number of ignorable neighbor links. Such links can be ignored during
+% optimization if needed.
+int: NUM_IGNORABLE_NEIGHBOR_LINKS;
+
+% The links that can be ignored if needed. Each line represents the two ends
+% of the links, like the previous structures.
+array[1..NUM_IGNORABLE_NEIGHBOR_LINKS, 1..2] of int: IGNORABLE_NEIGHBOR_LINKS;
+
+% ids of cells for which the pci should remain unchanged
+set of int: PCI_UNCHANGEABLE_CELLS;
+
+% This array has the original pcis of all the cells. array is indexed by the ids
+% of the cell. eg. ORIGINAL_PCIS[3] returns the pci of cell whose id is 3.
+% ids start from 0
+array[1..NUM_NODES] of 0..NUM_PCIS-1: ORIGINAL_PCIS;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Decision variables
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Defines the PCI for each node.
+array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
+
+array[1..NUM_IGNORABLE_NEIGHBOR_LINKS] of var 0..1: used_ignorables;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Constraints
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% fixed pci cells
+constraint
+if(length(PCI_UNCHANGEABLE_CELLS) !=0) then
+forall(i in PCI_UNCHANGEABLE_CELLS)(
+ pci[i] == ORIGINAL_PCIS[i+1]
+)
+endif;
+
+% Direct neighbors must have different PCIs for avoid **COLLISION**.
+% Forced links.
+constraint
+forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
+ where
+ NEIGHBORS[i, 1] != IGNORABLE_NEIGHBOR_LINKS[j, 1] \/
+ NEIGHBORS[i, 2] != IGNORABLE_NEIGHBOR_LINKS[j, 2]
+)(
+ pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
+);
+
+
+% Ignorable links.
+constraint
+forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
+ where
+ NEIGHBORS[i, 1] == IGNORABLE_NEIGHBOR_LINKS[j, 1] /\
+ NEIGHBORS[i, 2] == IGNORABLE_NEIGHBOR_LINKS[j, 2]
+)(
+ used_ignorables[j] >= bool2int(pci[NEIGHBORS[i, 1]] == pci[NEIGHBORS[i, 2]])
+);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Objective function
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Total number of confusions.
+var int: total_confusions =
+ sum([bool2int(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] ==
+ pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
+ | i in 1..NUM_SECOND_LEVEL_NEIGHBORS]);
+
+% Total number of used ignorables links.
+var int: total_used_ignorables = sum(used_ignorables);
+
+solve :: int_search(pci, smallest, indomain_min, complete)
+
+% Minimize the total number of confusions.
+%minimize total_confusions;
+
+% Minimize the total number of confusions first,
+% then the number of used ignorables links.
+minimize (2 * NUM_IGNORABLE_NEIGHBOR_LINKS * total_confusions) +
+ total_used_ignorables;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Output
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+output
+["PCI assigment"] ++
+["\nnode,pci"] ++
+[
+ "\n" ++ show(node) ++ "," ++ show(pci[node])
+| node in 0..NUM_NODES-1
+] ++
+["\n\nTotal used ignorables links: " ++ show(total_used_ignorables)] ++
+["\nUsed ignorables links: "] ++
+[
+ "\n" ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 1]) ++
+ "," ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 2])
+ | i in 1..NUM_IGNORABLE_NEIGHBOR_LINKS where fix(used_ignorables[i] > 0)
+] ++
+["\n\nConfusions"] ++
+["\nTotal confusions: " ++ show(total_confusions)] ++
+["\nConfusion pairs"] ++
+[
+ "\n" ++ show(SECOND_LEVEL_NEIGHBORS[i, 1]) ++ "," ++
+ show(SECOND_LEVEL_NEIGHBORS[i, 2])
+ | i in 1..NUM_SECOND_LEVEL_NEIGHBORS where
+ fix(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] == pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
+]
+
diff --git a/apps/pci/optimizers/solver/ml_model.py b/apps/pci/optimizers/solver/ml_model.py
new file mode 100644
index 0000000..c239be8
--- /dev/null
+++ b/apps/pci/optimizers/solver/ml_model.py
@@ -0,0 +1,72 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+import json
+
+from apps.pci.optimizers.solver.pci_utils import get_id
+from osdf.adapters.dcae import des
+from osdf.adapters.dcae.des import DESException
+from osdf.config.base import osdf_config
+from osdf.logging.osdf_logging import error_log
+
+
+class MlModel(object):
+ def __init__(self):
+ self.config = osdf_config.core['PCI']
+
+ def get_additional_inputs(self, dzn_data, network_cell_info):
+ """Add/update additional info to the existing models.
+
+ The method returns nothing. Instead, it modifies the dzn_data
+ :params: dzn_data: map with data for the optimization
+ """
+ self.compute_ml_model(dzn_data, network_cell_info)
+
+ def compute_ml_model(self, dzn_data, network_cell_info):
+ average_ho_threshold = self.config['ML']['average_ho_threshold']
+ latest_ho_threshold = self.config['ML']['latest_ho_threshold']
+
+ fixed_cells = set()
+ for cell in network_cell_info['cell_list']:
+ cell_id = cell['cell_id']
+ average_ho, latest_ho = self.get_ho_details(cell['cell_id'])
+ if average_ho > average_ho_threshold or latest_ho > latest_ho_threshold:
+ fixed_cells.add(get_id(network_cell_info, cell_id))
+
+ fixed_cells.update(dzn_data.get('PCI_UNCHANGEABLE_CELLS', []))
+ dzn_data['PCI_UNCHANGEABLE_CELLS'] = fixed_cells
+
+ def get_ho_details(self, cell_id):
+ service_id = self.config['DES']['service_id']
+ request_data = self.config['DES']['filter']
+ request_data['cell_id'] = cell_id
+ try:
+ result = des.extract_data(service_id, json.dumps(request_data))
+ except DESException as e:
+ error_log.error("Error while calling DES {}".format(e))
+ return 0, 0
+
+ if not result:
+ return 0, 0
+
+ ho_list = []
+ for pm_data in result:
+ ho = pm_data['overallHoAtt']
+ ho_list.append(ho)
+
+ return sum(ho_list) / len(ho_list), ho_list[0]
diff --git a/apps/pci/optimizers/solver/no_conflicts_no_confusion.mzn b/apps/pci/optimizers/solver/no_conflicts_no_confusion.mzn
new file mode 100644
index 0000000..f059d4a
--- /dev/null
+++ b/apps/pci/optimizers/solver/no_conflicts_no_confusion.mzn
@@ -0,0 +1,103 @@
+% -------------------------------------------------------------------------
+% Copyright (c) 2018 AT&T Intellectual Property
+%
+% Licensed under the Apache License, Version 2.0 (the "License");
+% you may not use this file except in compliance with the License.
+% You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+% See the License for the specific language governing permissions and
+% limitations under the License.
+%
+% -------------------------------------------------------------------------
+%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Parameters and its assertions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Number of cells/radios.
+int: NUM_NODES;
+
+% Maximum number of Physical Cell Identifiers to be assigned to the nodes.
+int: NUM_PCIS;
+
+% Number of edges between neighbor nodes. There is a edge (i,j) if and only
+% if nodes i and j are neighbors, i.e., an user equipment (UE) can make
+% handoff between i and j. Such edges are used to avoid **COLLISIONS**, i.e.,
+% to guarantee that nodes i and j have different PCIs.
+int: NUM_NEIGHBORS;
+
+% Each line represents an edge between direct neighbors as defined before.
+array[1..NUM_NEIGHBORS, 1..2] of int: NEIGHBORS;
+
+% Number of undirect neighbor pairs (j, k) such that both j and k are direct
+% neighbors of node i, i.e., (j, k) exits if and only if exists (i, j) and
+% (i, k). Nodes (i, k) can generate "confunsions" in the network if they have
+% the same PCI. Such edges are used to avoid/minimize **CONFUSIONS**.
+int: NUM_SECOND_LEVEL_NEIGHBORS;
+
+% Each line represents an edge between undirect neighbors as defined before.
+array[1..NUM_SECOND_LEVEL_NEIGHBORS, 1..2] of int: SECOND_LEVEL_NEIGHBORS;
+
+% ids of cells for which the pci should remain unchanged
+set of int: PCI_UNCHANGEABLE_CELLS;
+
+% This array has the original pcis of all the cells. array is indexed by the ids
+% of the cell. eg. ORIGINAL_PCIS[3] returns the pci of cell whose id is 3.
+% ids start from 0
+% array[0..NUM_NODES-1] of 0..NUM_PCIS-1: ORIGINAL_PCIS;
+array[1..NUM_NODES] of 0..NUM_PCIS-1: ORIGINAL_PCIS;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Decision variables
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Defines the PCI for each node.
+array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Constraints
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+constraint
+if(length(PCI_UNCHANGEABLE_CELLS) !=0) then
+forall(i in PCI_UNCHANGEABLE_CELLS)(
+ pci[i] == ORIGINAL_PCIS[i+1]
+)
+endif;
+
+
+% Direct neighbors must have different PCIs for avoid **COLLISION**.
+constraint
+forall(i in 1..NUM_NEIGHBORS)(
+ pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
+);
+
+% Undirect neighbors must have different PCIs for avoid **CONFUSIONS**.
+constraint
+forall(i in 1..NUM_SECOND_LEVEL_NEIGHBORS)(
+ pci[SECOND_LEVEL_NEIGHBORS[i, 1]] != pci[SECOND_LEVEL_NEIGHBORS[i, 2]]
+);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Objective function
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Just satisfy the problem.
+solve :: int_search(pci, smallest, indomain_min, complete) satisfy;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Output
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+output
+["node,pci\n"] ++
+[
+ show(node) ++ "," ++ show(pci[node]) ++ "\n"
+| node in 0..NUM_NODES-1
+]
diff --git a/apps/pci/optimizers/solver/optimizer.py b/apps/pci/optimizers/solver/optimizer.py
new file mode 100644
index 0000000..13298ed
--- /dev/null
+++ b/apps/pci/optimizers/solver/optimizer.py
@@ -0,0 +1,179 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+# Copyright (C) 2020 Wipro Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+from collections import defaultdict
+import itertools
+import os
+import pymzn
+
+from apps.pci.optimizers.solver.ml_model import MlModel
+from apps.pci.optimizers.solver.pci_utils import get_id
+from apps.pci.optimizers.solver.pci_utils import mapping
+from osdf.config.base import osdf_config
+
+BASE_DIR = os.path.dirname(__file__)
+cell_id_mapping = dict()
+id_cell_mapping = dict()
+
+
+def pci_optimize(network_cell_info, cell_info_list, request_json):
+ global cell_id_mapping, id_cell_mapping
+ cell_id_mapping, id_cell_mapping = mapping(network_cell_info)
+ original_pcis = get_original_pci_list(network_cell_info)
+ unchangeable_pcis = get_ids_of_fixed_pci_cells(request_json['cellInfo'].get('fixedPCICells', []))
+ neighbor_edges = get_neighbor_list(network_cell_info)
+ second_level_edges = get_second_level_neighbor(network_cell_info)
+ ignorable_links = get_ignorable_links(network_cell_info, request_json)
+ anr_flag = is_anr(request_json)
+
+ dzn_data = build_dzn_data(cell_info_list, ignorable_links, neighbor_edges, second_level_edges, anr_flag,
+ original_pcis, unchangeable_pcis)
+
+ ml_enabled = osdf_config.core['PCI']['ml_enabled']
+ if ml_enabled:
+ MlModel().get_additional_inputs(dzn_data, network_cell_info)
+
+ return build_pci_solution(dzn_data, ignorable_links, anr_flag)
+
+
+def get_ids_of_fixed_pci_cells(fixed_pci_list):
+ fixed_pci_ids = set()
+ for cell in fixed_pci_list:
+ fixed_pci_ids.add(cell_id_mapping[cell])
+ return fixed_pci_ids
+
+
+def get_cell_id_pci_mapping(network_cell_info):
+ original_pcis = dict()
+ for cell in network_cell_info['cell_list']:
+ for nbr in cell['nbr_list']:
+ if cell_id_mapping[nbr['targetCellId']] not in original_pcis:
+ original_pcis[cell_id_mapping[nbr['targetCellId']]] = nbr['pciValue']
+ return original_pcis
+
+
+def get_original_pci_list(network_cell_info):
+ cell_id_pci_mapping = get_cell_id_pci_mapping(network_cell_info)
+ original_pcis_list = []
+ for i in range(len(cell_id_pci_mapping)):
+ original_pcis_list.append(cell_id_pci_mapping.get(i))
+ return original_pcis_list
+
+
+def build_pci_solution(dzn_data, ignorable_links, anr_flag):
+ mzn_solution = solve(get_mzn_model(anr_flag), dzn_data)
+ if mzn_solution == 'UNSATISFIABLE':
+ return mzn_solution
+ solution = {'pci': mzn_solution[0]['pci']}
+
+ if anr_flag:
+ removables = defaultdict(list)
+ used_ignorables = mzn_solution[0]['used_ignorables']
+ index = 0
+ for i in ignorable_links:
+ if used_ignorables[index] > 0:
+ removables[i[0]].append(i[1])
+ index += 1
+ solution['removables'] = removables
+ return solution
+
+
+def build_dzn_data(cell_info_list, ignorable_links, neighbor_edges, second_level_edges, anr_flag, original_pcis,
+ unchangeable_pcis):
+ dzn_data = {
+ 'NUM_NODES': len(cell_info_list),
+ 'NUM_PCIS': len(cell_info_list),
+ 'NUM_NEIGHBORS': len(neighbor_edges),
+ 'NEIGHBORS': get_list(neighbor_edges),
+ 'NUM_SECOND_LEVEL_NEIGHBORS': len(second_level_edges),
+ 'SECOND_LEVEL_NEIGHBORS': get_list(second_level_edges),
+ 'PCI_UNCHANGEABLE_CELLS': unchangeable_pcis,
+ 'ORIGINAL_PCIS': original_pcis
+ }
+ if anr_flag:
+ dzn_data['NUM_IGNORABLE_NEIGHBOR_LINKS'] = len(ignorable_links)
+ dzn_data['IGNORABLE_NEIGHBOR_LINKS'] = get_list(ignorable_links)
+ return dzn_data
+
+
+def get_mzn_model(anr_flag):
+ if anr_flag:
+ mzn_model = os.path.join(BASE_DIR, 'min_confusion_inl.mzn')
+ else:
+ mzn_model = os.path.join(BASE_DIR, 'no_conflicts_no_confusion.mzn')
+ return mzn_model
+
+
+def is_anr(request_json):
+ return 'pci-anr' in request_json["requestInfo"]["optimizers"]
+
+
+def get_list(edge_list):
+ array_list = []
+ for s in edge_list:
+ array_list.append([s[0], s[1]])
+ return sorted(array_list)
+
+
+def solve(mzn_model, dzn_data):
+ return pymzn.minizinc(mzn=mzn_model, data=dzn_data)
+
+
+def get_neighbor_list(network_cell_info):
+ neighbor_list = set()
+ for cell in network_cell_info['cell_list']:
+ add_to_neighbor_list(network_cell_info, cell, neighbor_list)
+ return neighbor_list
+
+
+def add_to_neighbor_list(network_cell_info, cell, neighbor_list):
+ for nbr in cell.get('nbr_list', []):
+ host_id = cell['id']
+ nbr_id = get_id(network_cell_info, nbr['targetCellId'])
+ if nbr_id and host_id != nbr_id:
+ neighbor_list.add((host_id, nbr_id))
+
+
+def get_second_level_neighbor(network_cell_info):
+ second_neighbor_list = set()
+ for cell in network_cell_info['cell_list']:
+ comb_list = build_second_level_list(network_cell_info, cell)
+ for comb in comb_list:
+ if comb[0] and comb[1]:
+ second_neighbor_list.add((comb[0], comb[1]))
+ return sorted(second_neighbor_list)
+
+
+def build_second_level_list(network_cell_info, cell):
+ second_nbr_list = []
+ for nbr in cell.get('nbr_list', []):
+ second_nbr_list.append(get_id(network_cell_info, nbr['targetCellId']))
+ return [list(elem) for elem in list(itertools.combinations(second_nbr_list, 2))]
+
+
+def get_ignorable_links(network_cell_info, request_json):
+ ignorable_list = set()
+ anr_input_list = request_json["cellInfo"].get('anrInputList', [])
+ if anr_input_list:
+ for anr_info in anr_input_list:
+ cell_id = get_id(network_cell_info, anr_info['cellId'])
+ anr_removable = anr_info.get('removeableNeighbors', [])
+ for anr in anr_removable:
+ ignorable_list.add((cell_id, get_id(network_cell_info, anr)))
+ return ignorable_list
diff --git a/apps/pci/optimizers/solver/pci_utils.py b/apps/pci/optimizers/solver/pci_utils.py
new file mode 100644
index 0000000..7db3a6f
--- /dev/null
+++ b/apps/pci/optimizers/solver/pci_utils.py
@@ -0,0 +1,47 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+def mapping(network_cell_info):
+ cell_id_mapping= dict()
+ id_cell_mapping = dict()
+ for i in network_cell_info['cell_list']:
+ cell_id_mapping[i['cell_id']] = i['id']
+ id_cell_mapping[i['id']] = i['cell_id']
+ return cell_id_mapping, id_cell_mapping
+
+def get_id(network_cell_info, cell_id):
+ for i in network_cell_info['cell_list']:
+ if i['cell_id'] == cell_id:
+ return i['id']
+ return None
+
+
+def get_cell_id(network_cell_info, id):
+ for i in network_cell_info['cell_list']:
+ if i['id'] == id:
+ return i['cell_id']
+ return None
+
+
+def get_pci_value(network_cell_info, id):
+ cell_id = get_cell_id(network_cell_info, id)
+ for i in network_cell_info['cell_list']:
+ for j in i['nbr_list']:
+ if cell_id == j['targetCellId']:
+ return j['pciValue']
+ return None