Cell_Tower_Location_Optimization
Cell Tower Location Optimization¶
Copyright By PowCoder代写 加微信 powcoder
Import libraries
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
import seaborn as sns
import math
from scipy.linalg import null_space
from scipy.optimize import minimize
#setting display style
sns.set_style(‘whitegrid’)
%matplotlib inline
import warnings
#warnings.filterwarnings(“ignore”, category=ConvergenceWarning)
warnings.filterwarnings(“ignore”)
Define cell tower optimization problem
def celltowersetup(towers,side,s):
random.seed(s)
# generate bound constraints
# generate Radius of tower and their upper and lower bound
for i in range(towers):
# Radius is randomly generated between a unit of 1 to 2
R.append(random.random()+1)
# the upper and lower bound of the tower is the
# upper and lower bound of the field +/- Radius
# as the coverage of the tower should go outside of the field
temp = ((xL+R[i],xU-R[i]),(yL+R[i],yU-R[i]))
bnds +=(temp)
# randomly generate inital tower x and y coordiantes
x0 +=(side*random.random(),side*random.random())
return R,xL,xU,yL,yU,bnds,x0
def areaIntersect(x1,r1,x2,r2):
x1=np.transpose(np.asmatrix(x1))
x2=np.transpose(np.asmatrix(x2))
# make sure r1>r2 as convention
# calculate the distance between to tower
a=np.linalg.norm(x1-x2)
# if is 0, then return complete overlap
numberOfPoints=math.inf
# overlapping area is the area of the smaller circle
areatotal= math.pi*min(r1,r2)**2
return p,q,numberOfPoints,areatotal
# calculate intersection distance
x=0.5*(a+(r1**2-r2**2)/a)
# if the larger circle radius is less than the intersection distance
# then the two circles do not touch
if r1**2 < x**2:
# if sum of both radius is less than the separtion distance then
# those are not overlaping
if r1+r2