diff options
author | Varma, Vikas <vv8305@att.com> | 2018-09-19 00:39:03 -0400 |
---|---|---|
committer | Vikas Varma <vv8305@att.com> | 2018-09-19 05:00:05 +0000 |
commit | 276119f2d54b2e8f49b8595ecfcc6545aeb77fef (patch) | |
tree | fd39c9b061e00a79d867e860a030020f7b0af571 /osdf | |
parent | ce6ac9833b9d91dfe9fdd4a0346a641c0c246d90 (diff) |
Initial checkin for pci optimization code
Change-Id: I6fe8ad471f8ad68a964664b910f02bd8a9766639
Signed-off-by: Varma, Vikas <vv8305@att.com>
Issue-ID: OPTFRA-342
Diffstat (limited to 'osdf')
-rw-r--r-- | osdf/config/base.py | 6 | ||||
-rw-r--r-- | osdf/models/api/pciOptimizationRequest.py | 48 | ||||
-rw-r--r-- | osdf/models/api/pciOptimizationResponse.py | 40 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/__init__.py | 0 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/configdb.py | 65 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/pci_opt_processor.py | 84 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/solver/__init__.py | 0 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/solver/min_confusion.mzn | 95 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/solver/no_conflicts_no_confusion.mzn | 86 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/solver/optimizer.py | 82 | ||||
-rw-r--r-- | osdf/optimizers/pciopt/solver/pci_utils.py | 39 |
11 files changed, 542 insertions, 3 deletions
diff --git a/osdf/config/base.py b/osdf/config/base.py index 29376a5..fbe9315 100644 --- a/osdf/config/base.py +++ b/osdf/config/base.py @@ -18,14 +18,14 @@ import os -import osdf.config.loader as config_loader import osdf.config.credentials as creds +import osdf.config.loader as config_loader from osdf.utils.programming_utils import DotDict config_spec = { "deployment": os.environ.get("OSDF_CONFIG_FILE", "config/osdf_config.yaml"), "core": "config/common_config.yaml" - } +} osdf_config = DotDict(config_loader.all_configs(**config_spec)) @@ -33,4 +33,4 @@ http_basic_auth_credentials = creds.load_credentials(osdf_config) dmaap_creds = creds.dmaap_creds() -creds_prefixes = {"so": "so", "cm": "cmPortal"} +creds_prefixes = {"so": "so", "cm": "cmPortal", "pcih": "pciHMS"} diff --git a/osdf/models/api/pciOptimizationRequest.py b/osdf/models/api/pciOptimizationRequest.py new file mode 100644 index 0000000..47b4eba --- /dev/null +++ b/osdf/models/api/pciOptimizationRequest.py @@ -0,0 +1,48 @@ +# ------------------------------------------------------------------------- +# 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 .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 CellInfo(OSDFModel): + """Information specific to CellInfo """ + networkId = StringType(required=True) + cellIdList = ListType(StringType(required=True)) + trigger = StringType() + + +class PCIOptimizationAPI(OSDFModel): + """Request for PCI optimization """ + requestInfo = ModelType(RequestInfo, required=True) + cellInfo = ModelType(CellInfo, required=True) diff --git a/osdf/models/api/pciOptimizationResponse.py b/osdf/models/api/pciOptimizationResponse.py new file mode 100644 index 0000000..876c380 --- /dev/null +++ b/osdf/models/api/pciOptimizationResponse.py @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------- +# 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 .common import OSDFModel + + +class PCISolution(OSDFModel): + cellId = StringType(required=True) + pci = IntType(required=True) + + +class Solution(OSDFModel): + networkId = StringType(required=True) + pciSolutions = ListType(ListType(ModelType(PCISolution), 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/osdf/optimizers/pciopt/__init__.py b/osdf/optimizers/pciopt/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/osdf/optimizers/pciopt/__init__.py diff --git a/osdf/optimizers/pciopt/configdb.py b/osdf/optimizers/pciopt/configdb.py new file mode 100644 index 0000000..bebc5c0 --- /dev/null +++ b/osdf/optimizers/pciopt/configdb.py @@ -0,0 +1,65 @@ +# ------------------------------------------------------------------------- +# 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 datetime import datetime as dt + +from osdf.logging.osdf_logging import debug_log +from osdf.utils.interfaces import RestClient + + +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 = {} + config = osdf_config.deployment + local_config = osdf_config.core + uid, passwd = config['configDbUserName'], config['configDbPassword'] + req_id = req_object['requestInfo']['requestId'] + transaction_id = req_object['requestInfo']['transactionId'] + headers = dict(transaction_id=transaction_id) + + network_id = req_object['cellInfo']['networkId'] + + cell_list_response['network_id'] = network_id + + rc = RestClient(userid=uid, passwd=passwd, method="GET", log_func=debug_log.debug, headers=headers) + + cell_list_url = '{}/{}?networkId={}'.format(config['configDbUrl'], config['configDbGetCellListUrl'], network_id) + + cell_list_resp = rc.request(raw_response=True, url=cell_list_url) + cell_resp = cell_list_resp.json() + ts = dt.strftime(dt.now(), '%Y-%m-%dT%H:%M:%S%z') + + cell_list = [] + count = 0 + for cell_id in cell_resp: + cell_info = {'cell_id': cell_id, 'id': count} + nbr_list_url = '{}/{}?cellId={}&ts={}'.format(config['configDbUrl'], config['configDbGetNbrListUrl'], cell_id, + ts) + nbr_list_raw = rc.request(url=nbr_list_url, raw_response=True) + cell_info['nbr_list'] = nbr_list_raw.json() + cell_list.append(cell_info) + count += 1 + + cell_list_response['cell_list'] = cell_list + return cell_resp, cell_list_response diff --git a/osdf/optimizers/pciopt/pci_opt_processor.py b/osdf/optimizers/pciopt/pci_opt_processor.py new file mode 100644 index 0000000..030128e --- /dev/null +++ b/osdf/optimizers/pciopt/pci_opt_processor.py @@ -0,0 +1,84 @@ +# ------------------------------------------------------------------------- +# 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 requests import RequestException + +from osdf.logging.osdf_logging import metrics_log, MH, error_log +from osdf.models.api.pciOptimizationResponse import PCIOptimizationResponse, Solution, PCISolution +from osdf.operation.error_handling import build_json_error_body +from osdf.utils.interfaces import get_rest_client +from .configdb import request as config_request +from .solver.optimizer import pci_optimize as optimize +from .solver.pci_utils import get_cell_id, get_pci_value + +""" +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: + rc = get_rest_client(request_json, service="pcih") + req_id = request_json["requestInfo"]["requestId"] + transaction_id = request_json['requestInfo']['transactionId'] + cell_info_list, network_cell_info = config_request(request_json, osdf_config, flat_policies) + + pci_response = PCIOptimizationResponse() + pci_response.transactionId = transaction_id + pci_response.requestId = req_id + pci_response.requestStatus = 'success' + pci_response.solutions = Solution() + pci_response.solutions.networkId = request_json['cellInfo']['networkId'] + pci_response.solutions.pciSolutions = [] + + for cell in request_json['cellInfo']['cellIdList']: + pci_solution = optimize(cell['cellId'], network_cell_info, cell_info_list) + error_log.error(pci_solution) + sol = pci_solution[0]['pci'] + for k, v in sol.items(): + response = PCISolution() + response.cellId = get_cell_id(network_cell_info, k) + response.pci = get_pci_value(network_cell_info, v) + pci_response.solutions.pciSolutions.append(response) + + 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: + error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc())) + return + + try: + metrics_log.info(MH.calling_back_with_body(req_id, rc.url, 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())) diff --git a/osdf/optimizers/pciopt/solver/__init__.py b/osdf/optimizers/pciopt/solver/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/osdf/optimizers/pciopt/solver/__init__.py diff --git a/osdf/optimizers/pciopt/solver/min_confusion.mzn b/osdf/optimizers/pciopt/solver/min_confusion.mzn new file mode 100644 index 0000000..803f914 --- /dev/null +++ b/osdf/optimizers/pciopt/solver/min_confusion.mzn @@ -0,0 +1,95 @@ +% ------------------------------------------------------------------------- +% 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 **CONFLICTS**, i.e., +% to guarantee that nodes i and j have different PCIs. +int: NUM_CONFLICT_EDGES; + +% Each line represents an edge between direct neighbors as defined before. +array[1..NUM_CONFLICT_EDGES, 1..2] of int: CONFLICT_EDGES; + +% 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_CONFUSION_EDGES; + +% Each line represents an edge between undirect neighbors as defined before. +array[1..NUM_CONFUSION_EDGES, 1..2] of int: CONFUSION_EDGES; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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 **CONFLICTS**. +constraint +forall(i in 1..NUM_CONFLICT_EDGES)( + pci[CONFLICT_EDGES[i, 1]] != pci[CONFLICT_EDGES[i, 2]] +); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Objective function +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Total number of confusions. +var int: total_confusions = + sum([bool2int(pci[CONFUSION_EDGES[i, 1]] == pci[CONFUSION_EDGES[i, 2]]) + | i in 1..NUM_CONFUSION_EDGES]); + +% 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(CONFUSION_EDGES[i, 1]) ++ "," ++ show(CONFUSION_EDGES[i, 2]) +| i in 1..NUM_CONFUSION_EDGES where + fix(pci[CONFUSION_EDGES[i, 1]] == pci[CONFUSION_EDGES[i, 2]]) +] diff --git a/osdf/optimizers/pciopt/solver/no_conflicts_no_confusion.mzn b/osdf/optimizers/pciopt/solver/no_conflicts_no_confusion.mzn new file mode 100644 index 0000000..19fabb9 --- /dev/null +++ b/osdf/optimizers/pciopt/solver/no_conflicts_no_confusion.mzn @@ -0,0 +1,86 @@ +% ------------------------------------------------------------------------- +% 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 **CONFLICTS**, i.e., +% to guarantee that nodes i and j have different PCIs. +int: NUM_CONFLICT_EDGES; + +% Each line represents an edge between direct neighbors as defined before. +array[1..NUM_CONFLICT_EDGES, 1..2] of int: CONFLICT_EDGES; + +% 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_CONFUSION_EDGES; + +% Each line represents an edge between undirect neighbors as defined before. +array[1..NUM_CONFUSION_EDGES, 1..2] of int: CONFUSION_EDGES; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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 **CONFLICTS**. +constraint +forall(i in 1..NUM_CONFLICT_EDGES)( + pci[CONFLICT_EDGES[i, 1]] != pci[CONFLICT_EDGES[i, 2]] +); + +% Undirect neighbors must have different PCIs for avoid **CONFUSIONS**. +constraint +forall(i in 1..NUM_CONFUSION_EDGES)( + pci[CONFUSION_EDGES[i, 1]] != pci[CONFUSION_EDGES[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/osdf/optimizers/pciopt/solver/optimizer.py b/osdf/optimizers/pciopt/solver/optimizer.py new file mode 100644 index 0000000..e9fcb0d --- /dev/null +++ b/osdf/optimizers/pciopt/solver/optimizer.py @@ -0,0 +1,82 @@ +# ------------------------------------------------------------------------- +# 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 itertools + +import os +import pymzn + +from osdf.logging.osdf_logging import debug_log +from .pci_utils import get_id + +BASE_DIR = os.path.dirname(__file__) +MZN_FILE_NAME = os.path.join(BASE_DIR, 'no_conflicts_no_confusion.mzn') + + +def pci_optimize(cell_id, network_cell_info, cell_info_list): + debug_log.debug("Cell ID {} ".format(cell_id)) + dzn_data = {} + dzn_data['NUM_NODES'] = len(cell_info_list) + dzn_data['NUM_PCIS'] = len(cell_info_list) + + conflict_edges = get_conflict_edges(cell_id, network_cell_info) + + dzn_data['NUM_CONFLICT_EDGES'] = len(conflict_edges) + dzn_data['CONFLICT_EDGES'] = conflict_edges + + confusion_edges = get_confusion_edges(cell_id, network_cell_info) + + dzn_data['NUM_CONFUSION_EDGES'] = len(confusion_edges) + dzn_data['CONFUSION_EDGES'] = confusion_edges + + return solve(dzn_data) + +def solve(dzn_data): + return pymzn.minizinc(MZN_FILE_NAME, data=dzn_data) + + +def get_conflict_edges(cell_id, network_cell_info): + conflict_edges = [] + for cell in network_cell_info['cell_list']: + + if cell_id == cell['cell_id']: + add_to_conflict_edges(network_cell_info, cell, conflict_edges) + return conflict_edges + + +def add_to_conflict_edges(network_cell_info, cell, conflict_edges): + cell_id = cell['cell_id'] + for nbr in cell.get('nbr_list', []): + conflict_edges.append([get_id(network_cell_info, cell_id), get_id(network_cell_info, nbr['cellId'])]) + + + +def get_confusion_edges(cell_id, network_cell_info): + confusion_edges = [] + for cell in network_cell_info['cell_list']: + if cell_id == cell['cell_id']: + return add_to_confusion_edges(network_cell_info, cell) + return confusion_edges + + +def add_to_confusion_edges(network_cell_info, cell): + cell_id = cell['cell_id'] + nbr_list = [] + for nbr in cell.get('nbr_list', []): + nbr_list.append(get_id(network_cell_info, nbr['cellId'])) + return [list(elem) for elem in list(itertools.combinations(nbr_list, 2))] diff --git a/osdf/optimizers/pciopt/solver/pci_utils.py b/osdf/optimizers/pciopt/solver/pci_utils.py new file mode 100644 index 0000000..71b5dd2 --- /dev/null +++ b/osdf/optimizers/pciopt/solver/pci_utils.py @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------- +# 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 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['cellId']: + return j['pciValue'] + return None |