def removeVarWithLowPotency(scenario, allCEVarList):
    hataSRD = MathUtil.HataSRDModel()

    maxDistanceCEAndClients = []

    for ce in scenario.cm.ceList:
        clientDistanceList = []

        for ceClient in ce.clientList:
            distanceBetween = MathUtil.calculateDistanceBetweenGeoPoints(
                ce.geoPoint, ceClient.geoPoint)
            clientDistanceList.append(distanceBetween)

        maxClientDistance = max(clientDistanceList)
        maxDistanceCEAndClients.append(maxClientDistance)

    newCEVarList = []

    for ceVar in allCEVarList:
        ceVarNameSplit = ceVar.name.split('_')

        ceId = int(ceVarNameSplit[1])
        cePotency = int(ceVarNameSplit[3])

        ceAntenna = scenario.cm.ceList[ceId].antenna
        channelFrequency = next(c.frequency for c in scenario.channels
                                if (c.channelNumber == ce.channel))

        ceSignalDistance = hataSRD.getDistance(ceAntenna, channelFrequency,
                                               cePotency, -60)

        if (ceSignalDistance >= maxDistanceCEAndClients[ceId]):
            newCEVarList.append(ceVar)

    return newCEVarList
def getInterferenceList(scenario, allCEVarList):
    hataSRD = MathUtil.HataSRDModel()
    interferenceList = []

    for ceVar in allCEVarList:
        ceVarNameSplit = ceVar.name.split('_')

        ceId = int(ceVarNameSplit[1])
        ceChannel = int(ceVarNameSplit[2])
        cePotency = int(ceVarNameSplit[3])

        ce = scenario.cm.ceList[ceId]
        channel = next(c for c in scenario.channels
                       if c.channelNumber == ceChannel)
        ceSignalDistance = hataSRD.getDistance(ce.antenna, channel.frequency,
                                               cePotency, -60)

        ceTotalInterference = 0.0
        ceInterferenceList = []

        for otherCEVar in allCEVarList:
            otherCEVarNameSplit = otherCEVar.name.split('_')

            otherCEId = int(otherCEVarNameSplit[1])
            otherCEChannel = int(otherCEVarNameSplit[2])

            if (otherCEId != ceId):
                otherCE = scenario.cm.ceList[otherCEId]
                distanceBetweenCEs = MathUtil.calculateDistanceBetweenGeoPoints(
                    ce.geoPoint, otherCE.geoPoint)
                signalLevel = MathUtil.dbm2Double(
                    hataSRD.getSignalLevel(ce.antenna, channel.frequency,
                                           cePotency, distanceBetweenCEs))

                if (ceSignalDistance >= distanceBetweenCEs):
                    if (otherCEChannel == ceChannel):
                        signalLevel = 1.0 * signalLevel
                        ceTotalInterference += signalLevel
                        ceInterferenceList.append(signalLevel)
                    elif (otherCEChannel
                          == (ceChannel - 1)) or (otherCEChannel
                                                  == (ceChannel + 1)):
                        signalLevel = 0.7 * signalLevel
                        ceTotalInterference += signalLevel
                        ceInterferenceList.append(signalLevel)
                    elif (otherCEChannel
                          == (ceChannel - 2)) or (otherCEChannel
                                                  == (ceChannel + 2)):
                        signalLevel = 0.3 * signalLevel
                        ceTotalInterference += signalLevel
                        ceInterferenceList.append(signalLevel)

        interferenceList.append(
            (ceVar, ceTotalInterference, ceInterferenceList))

    return interferenceList
def visualize(scenario, resultCEList, result_fig_path, vis_id):
    hataSRD = MathUtil.HataSRDModel()

    cePointsList = []
    ceChannelList = []
    cePotencyList = []
    ceSignalDistanceList = []

    for resultCE in resultCEList:
        channelFrequency = next(c.frequency for c in scenario.channels
                                if (c.channelNumber == resultCE.channel))

        cePointsList.append(
            MathUtil.latlon_to_xyz(resultCE.geoPoint.latitude,
                                   resultCE.geoPoint.longitude))
        ceChannelList.append(resultCE.channel)
        cePotencyList.append(resultCE.potency)
        ceSignalDistanceList.append([
            hataSRD.getDistance(resultCE.antenna, channelFrequency,
                                resultCE.potency, -60)
        ])

    point_scaler = MinMaxScaler(feature_range=(0, 1))
    cePointsList = point_scaler.fit_transform(cePointsList)

    distance_scaler = MinMaxScaler(feature_range=(0, 1))
    ceSignalDistanceList = distance_scaler.fit_transform(ceSignalDistanceList)

    cmap = plt.get_cmap('jet', 13)
    radius = createRadiusList(0.2)

    circleList = []
    circleLegendList = []

    for i in range(0, len(cePointsList)):
        circle = plt.Circle((cePointsList[i][0], cePointsList[i][1]),
                            radius[cePotencyList[i] - 1],
                            color=cmap(ceChannelList[i] - 1),
                            alpha=0.75)

        circleList.append(circle)
        circleLegendList.append("CE_" + str(i) + "_" +
                                str(resultCEList[i].channel) + "_" +
                                str(resultCEList[i].potency))

    fig, ax = plt.subplots()
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])

    for i in range(0, len(circleList)):
        ax.add_patch(circleList[i])

    ax.legend(circleList,
              circleLegendList,
              loc='center left',
              bbox_to_anchor=(1, 0.5),
              fontsize='xx-small')

    plt.xlim((-0.1, 1.1))
    plt.ylim((-0.1, 1.1))
    plt.savefig(os.path.join(result_fig_path, "result_" + vis_id + ".png"),
                dpi=500)
    plt.close()