Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Repeater Coordination


Published on

  • Be the first to comment

  • Be the first to like this

Repeater Coordination

  1. 1. Team 11427 Repeater Coordination February 14, 2010Contents1 Introduction 32 Restatement of the Problem 33 Assumptions 44 Formulating the Model 4 4.1 Approach 1: Genetic Algorithm Method . . . . . . . . . . . . . . . . . . . . . . . 4 4.2 Approach 2: Radial Iterative Method . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.3 Method Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Results 9 5.0.1 Varying Incrementing Angle . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.0.2 Varying Single Coverage Radius . . . . . . . . . . . . . . . . . . . . . . . 106 Future Method Extensions 107 Conclusion 138 References 149 Appendix 15 9.1 Radial Iterative Method in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 9.1.1 Main Fuction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 9.1.2 FindingFirstDenseCircle.R . . . . . . . . . . . . . . . . . . . . . . . . . . 16 9.1.3 FindingDensestPosition.R . . . . . . . . . . . . . . . . . . . . . . . . . . 17 9.1.4 DefiningIncrementsAroundCircle.R . . . . . . . . . . . . . . . . . . . . . 19 9.1.5 GraphingRepeaters.R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 9.1.6 InCaseNoLocationsAroundCircle.R . . . . . . . . . . . . . . . . . . . . . 19 9.2 Spatial Database Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1
  2. 2. Team 11427 21 IntroductionFirst we will discuss our interpretation of the problem statement, which is that we should find ameans of determining repeater locations that meet certain criteria. We will elaborate on these crite-ria and some of their implications. We then talk about some of the simplifications that we assumein order to facilitate progress.Our solution proposal consists of two methods for generating models based on information regard-ing the distribution of user positions and the limitations of the repeaters. We allow these parametersto vary in order to attack the widest possible range of scenarios.We begin by discussing the Radial Iterative Method, which works by placing an initial repeater nearthe greatest population density, and then placing subsequent repeaters along the coverage radiusof the existing repeaters so that the network formed is always connected. This method terminateswhen all users are covered.We then discuss our Genetic Algorithm Method, which works by treating the placement of re-peaters as an optimization problem that aims to minimize both the number of repeaters deployedand the number of users left without a connection.Both of these methods are very powerful and interesting, but can be relatively slow. In particular,the Radial Iterative method yields an increasingly better result with each iteration, but the GeneticAlgorithm method guarantees only that it will not yield a poorer result with each iteration. Wewill compare their strengths and weaknesses, and offer some additional optimizations. The SpatialDatabase optimization is especially effective at speeding up the Radial Iterative Method.We will then discuss what can be done in the future to extend our two techniques and tackle evenmore difficult repeater placement problems.2 Restatement of the ProblemOur interpretation of the problem statement is that we must find a list of repeaters such that: • The number of repeaters is minimized • All users in the landscape are within range of at least one repeater • The repeaters form a connected networkWe use the word connected here in the graph-theoretical sense, meaning that for any two repeatersU and V , a path should exist between U and V , even if an individual edge does not. When we saythat two repeaters share an edge, we mean that they are within broadcasting range of one another,and can communicate unambiguously. We assume that communication is bidirectional, and thuscommunication is transitive. That is, if repeater U can communicate to repeater V (U is connectedto V ), then any repeater W which has a path to U must also have a path to V , which implies that Wand V can communicate. Using this result, we infer that if the network of repeaters is connected,and every user is within range of at least one repeater, then all users can communicate.
  3. 3. Team 11427 3Therefore, given a distribution of users in the landscape and a maximum radius of coverage that arepeater can provide, our method will produce a list of repeater positions that satisfies the criterialaid out above.3 AssumptionsIn order to attack the problem statement effectively, we will make some simplifying assumptionsthat are listed below: • Planar terrain. We do not worry about line of sight or reception issues caused by elevation. This reduces the problem to a 2-dimensional issue. • The median of transfer of signals is constant. Therefore, there is no frequency change in transmitted signals. • Signal is transmitted with a constant maximum amplitude A. • After transmission, the amplitude is affected by a given decay function D(r). • Repeaters and users will only be able to accept signals with amplitude greater than or equal to εA. • The frequency bandwidth is 30 kHz. • Terrain is completely connected (no rivers, trees, or other blockades to stop placement of repeaters). • User distribution contains no gaps that would require more than one additional repeater to bridge them. • User positions follow a uniform distribution. • Repeater coverage radius is 10, 8, or 5 miles. • If two repeaters are in range of one another, then they can communicate unambiguously.4 Formulating the Model4.1 Approach 1: Genetic Algorithm MethodA Genetic Algorithm is a search tool for solving computationally complex optimization prob-lems. Genetic Algorithms (henceforth GAs) treat solutions to these problems as points in an n-dimensional vector space, where n is the number of real-valued parameters needed to solve theproblem.These vectors are encoded in meaningful ways, so that their efficacy as a potential solution can be
  4. 4. Team 11427 4consistently evaluated. GAs are not unlike Linear Programming, in that the algorithm navigatesaround the space of potential solution vectors until it converges on an optimal solution. GAs aredistinct from Linear Programming in that they are well-suited to optimizing non-linear problems,but they are not guaranteed to terminate except under highly synthetic conditions.Each vector in the solution space is treated as though it were the genome of some artificial or-ganism. Drawing loosely upon notions from Natural Selection, a GA must endow these solutionvectors (henceforth genomes) with some concept of mating or reproduction. GAs must also pro-vide some method for evaluating an organisms fitness in the environment. This is typically adomain-specific function capable of interpreting the genome vector and producing a real-valuedfitness score such that if Organism A is better suited to the environment than Organism B, thisfunction awards a lower fitness score to Organism A.The process typically proceeds in this fashion: once the problem in question has been studied thor-oughly, a suitable fitness function and genome encoding are chosen. The encoding of the genomedetermines the structure of the space in which the potential solutions lie. A suitably large popu-lation of organisms are selected at random from the solution space ( Note that in GA literature,organisms and their genomes are often treated interchangeably, because the morphology processmapping genomes to organisms is often 1:1. This is not the case in biology, and this is an importantdistinction to make between the two. In this paper, the word organism will be used in the contextof fitness evaluation and reproduction, and the word genome will be used only when referring tothe mechanics underlying those two processes.).Once a population is chosen, the GA iterates as follows: the fitness of each organism in the pop-ulation is evaluated. Organisms are then ranked by their fitness, and the fittest among them areassigned mates via some predetermined criterion, often related to the problem domain. The off-spring are inserted into a subsequent population, and often the parents are as well. Problems do nottypically arise from mating between parents and offspring, or among close relatives of any kind.This is another important distinction from biology.This process is repeated until the most fit organism in a population has a fitness score that crossesa given threshold. In ideal systems, this threshold is typically zero, and it indicates that a perfectsolution has been achieved. In more complex systems, the threshold will be raised slightly abovezero , and it is plain to see that the sequence of least fitness scores among the population aftereach successive iteration is non-increasing in GAs which include parent organisms in subsequentgenerations.In our case the genome was encoded as a sequences of 3-tuples (e, r, θ ) which have the followinginterpretation: Each 3-tuple corresponds to a Repeater, the (r,θ ) values denote its position on theplane, and the e value is interpreted as a Boolean value that determines whether or not the repeaterexists. For example,
  5. 5. Team 11427 5 (0.6, 1.0, 0.9)(0.4, 0.1, 0.8)(0.5, 0.2, 0.2)(0.2, 0.1, 0.9)(0.8, 0.3, 0.7)is a genome that we might see, albeit a rather short one. We can see that all the values lie on[0.0, 1.0]. Note that values in this range are closed under addition, as we will need that to begin thediscussion on mating. For each triplet, we first look at the value of the e coordinate. If this valueis less than 0.5, we interpret it to mean that the repeater in question does not exist. This is how wedetermine the number of repeaters that appear in our solutions.The (r,θ ) values determine the placement of the repeater on the plane via the following transfor-mation: (x, y) = (40miles ∗ r cos θ , 40miles ∗ r sin θ ). This is the standard transformation from polarcoordinates to Cartesian coordinates. We chose to encode the repeater position as polar values onthe unit circle so that we could guarantee that repeater values are never placed outside of the 40-mile radius for which we were to provide a solution.We elected to score fitness of our candidate solution organisms as follows: After the model isconstructed, we count the number of users not covered by a repeater, and then add the numberof repeaters. This encourages the GA to eek out an organism that minimizes the number of usersleft without coverage and the number of repeaters used. The trouble with optimizing these twovariables simultaneously is that it encourages the use of more repeaters to deal with clumps ofuncovered users rather than repositioning the existing repeaters. This barrier is overcome by oursecond method, presented elsewhere in this paper.4.2 Approach 2: Radial Iterative MethodWe have developed a method that defines the locations of repeaters one-by-one for any distributionof users (randomly generated), and therefore, also calculates the minimum number of repeaters forany distribution of users in a circular area with a 40 mile radius. Picture a circle with a repeaterin the center. Every repeater must be connected to at least one other repeater in a manner that theentire repeater system forms a connected graph. Thus, in this circle we are imagining, the farthestdistance away another repeater can be located is the single coverage radius (which refers to themaximum distance a signal can transmitted and then successfully received by another repeater).To minimize the number of repeaters required for the entire region, we maximize the distancebetween each repeater, but still require full coverage of users.We first find the single coverage area with the greatest population density, (or if available, a singlecoverage area with 100 users). Eliminate these ”covered” users from the ”uncovered” user list.Then with centers evenly distributed (points around edge are incremented by an angle θ∆ ) aroundthe circular edge of the first established coverage area, we again find the single coverage area withthe greatest population density. Repeat this process, eliminating ”uncovered” users each time, untilthere are no points left on the previous single coverage edge with any surrounding ”uncovered”users (let’s call this a dead end).When we reach a dead end, we refigure distances between all remaining uncovered users and allplaced repeaters. We then increment around the edge of the single coverage area of the repeater
  6. 6. Team 11427 6corresponding to the smallest distance to again find a most dense single coverage area. From here,we repeat the steps before the dead end. 1. Generate n data points sampled from some distribution (in our case, a uniform distribution with a minimum of zero miles and a maximum of 40 miles). Let these values be radial coordinates in a polar coordinate system. 2. Generate n data points sampled from some distribution (in our case, a uniform distribution with a minimum of zero radians and a maximum of 2π radians). Let these values be angle coordinates in a polar coordinate system. 3. Convert these polar coordinates to cartesian coordinates (x = r cos θ , y = r sin θ ). Call this set of points Pset . 4. Find the distance d between one point Pi and every point in Pset . 5. For every distance that is less than the single coverage radius, store the corresponding point in a set Pi,Around . 6. Repeat Steps 4-5 for every data point in Pset (for i ∈ {1, 2, ..., n}). 7. The Pi,Around containing the most points, but not more than 100, establishes the first single coverage area. 8. Store the corresponding point Pi as the first point in an array of repeaters R 9. Extract the points in the largest set Pi,Around from Pset . 10. Calculate the points along the edge of the previous single coverage area incremented by angle θ∆ . Call these points Ci , and the set of these points Cset . 11. Find the distance d between one point Ci and every point in Pset . 12. For every distance that is less than the single coverage radius, store the corresponding point in a set Ci,Around . 13. Repeat Steps 11-12 for every data point in Cset . 14. The Ci,Around containing the most points, but not more than 100, establishes a single coverage area. 15. Store the corresponding point Ci as a point in the array of repeaters R 16. Extract the points in the largest set Ci,Around from Pset .If we reach a dead end, 1. Find the distance ds between one point Pi in Pset and every point in R.
  7. 7. Team 11427 7 2. Let the repeater corresponding to the smallest distance ds be Rs (let the point from Pset corresponding to the smallest distance be called Ps ). From here, start back at Step 10 with Rs being the repeater centering the coverage area being incremented.If we reach a dead end and (ds − r) (from Step 2 immediately above) is greater than the singlecoverage radius r, 1. Find the point Cs around edge of single coverage area of Rs that is the least distance from the point Ps . 2. Establish a single coverage area centered at Cs and refer back to Step 10.4.3 Method OptimizationConsider a set of points in the plane, and then consider the difficulty that arises when we need tocalculate the nearest neighbors of a given point.Naively, we might store the set of points as an array, and then when we set out to determine the knearest neighbors of a given point p, we would need to evaluate the distance between p and eachpoint q in the array. This is problem is of complexity class O(n), and crops up quite frequently inalgorithms that place repeaters amongst the populations, and also in the routines that evaluate theeffectiveness of repeater placement. Another problem of this order lies in determining how manyusers are covered by a given repeater.Worse still is the problem of determining which regions of the 40-mile radius landscape have themost dense population. This is useful for influencing repeater placement, both in the GA techniqueand the Radial Iteration technique. Again, there is a straight-forward solution to this problem,which involves finding the distance from each user location to each other user location, and thentallying which user locations have the greatest number of neighbors within a radius that would besuitable for a repeater. This problem is of complexity O(n2 ).When we consider the case of 1,000 users in the landscape, these algorithms do not trouble us.However, they do not scale very well, and none of them terminated in a reasonable time when weconsidered the case of 10,000 users in the landscape. To address this scalability issue, we introducea Spatial Database.A Spatial Database (henceforth an SDB) is a data structure which is optimized for storing and re-trieving spatially oriented data. It reduces the number of elements which must be analyzed in orderto solve Nearest Neighbor or containment problems. It works by storing the x and y coordinates ofthe points in the plane in separate Binary Trees. We can then query the SDB for all elements whichlie in a given square specified by (x − r, x + r) X (y − r, y + r) so that the centroid of the square liesat (x,y) and the sides of the square measure 2r, where X denotes the cartesian cross product.
  8. 8. Team 11427 8We perform this query by doing an in-order traversal of the X Tree, in an attempt to collect allelements whose x-coordinate lies in (x − r, x + r). We then proceed likewise with the Y Tree. Theintersection of these two collections yields all items which are in the specified square, and this setis returned as the query result. In this sense, an SDB is roughly analogous to a Relational Database,in the sense that a query is issued and a set of results are returned.Of course, there exist even more efficient implementations of SDBs. There is extensive literatureon the subject of R-Trees, and special variants of this data structure (R*-Trees and R+-Trees) existto address specific performance concerns.In our implementation, we also provided a convenience function that returns all items in the SDBwhich are within a given radius r of a point p. This method works by issuing a query for thepoints in a square centered at p with side length 2r. A circle of radius r is naturally inscribed insuch a square. We then eliminate all the points not in that circle by testing each and ensuring thatits distance from p is less than r. This yields the set of all points in a circle of radius r centered at p.5 ResultsAll data in this section is derived from the Radial Iterative Method considering 1000 users. Thesolution varies with user distribution, single coverage radius r, and the incrementing angle θ∆ . Asnoted before, the radial iterative method does accommodate any distribution of users; however, wewill show results only found for a uniform distribution of users. Intuitively, it does make sensethat a uniform distribution of users will require the same or more repeaters to form a connectedgraph providing full coverage than any other other distribution. For any other distributions, thereare possibilities of user concentration in certain areas, which would either not change the minimumnumber of required repeaters or decrease that minimum number. Thus, the following results give anupper bound on the minimum number of repeaters necessary to accommodate 1000 simultaneoususers. In all graphs, the black dots denote the users, the green dots denote the repeaters, and thepurple circles show each corresponding single coverage area. We want to note that we did applythe RIM method to ten different uniform distributions of users. Seven out of those ten times, theminimum required number of repeaters was 39. The other three resulting number of repeaters was36, 48, and 40. (The answer is approximately the same for each case, even with different data setsthat are uniformly distributed.)5.0.1 Varying Incrementing AngleThrough experiment, we show that varying θ∆ does not significantly affect the solution. In Figures1, 2, and 3, , we hold the single coverage radius r to be 10 miles and vary θ∆ . The resulting minimum numbers of repeaters necessary (corresponding to Figures 1, 2, and 3)are 39, 38, and 39.
  9. 9. Team 11427 9 π Figure 1: The incrementing angle θ∆ = 12 .5.0.2 Varying Single Coverage RadiusVarying the single coverage radius r will obviously significantly affect the minimum number ofrepeaters. To form a connected graph, as r decreases, repeaters must be placed closer together, butstill cover the same area. Thus, a decrease in r will result in an increase in the minimum number πof repeaters, as demonstrated below. In Figures 1, 4, and 5, we hold θ∆ to be 12 . For comparison,refer to Figure 1 for r = 10. The resulting minimum numbers of repeaters necessary (corresponding to Figures 1, 4, and 5)are 39, 54, and 120.6 Future Method ExtensionsThere are many features that can be implemented in our methods that would better simulate realworld situations when faced with the repeater placement problem. We discuss a few of the exten-sions below.In real life situations, users are not positioned such that they follow a uniform distribution. Our cur-rent methods will handle distributions that are non-uniform but philosophical questions are broughtup when interpreting these results. The companies that create the repeaters have to analyze the costeffectiveness of covering rural areas where the population density is very small and disjoint from
  10. 10. Team 11427 10 π Figure 2: The incrementing angle θ∆ = 24 .larger populations. In some situations, many repeaters would have to be placed to reach a smallamount of users. This calls into question if these users should be supported. So, a penalizationcould be enforced for models that produce results such as these.When designing repeaters and devices to communicate with, one must decide on how sensitivethese mechanisms must be. In most cases, development and fabrication of more sensitive devicesis more expensive. Our methods parametrizes these so the values are arbitrary but the interpreta-tion should be taken into account when faced with the model. A feedback look and post processingalgorithm can be developed such that the cost effectiveness of designing more sensitive devices canbe assessed. If the cost is too high, our method can then be rerun to incorporate the sensitivity ofthe wanted repeaters. This would allow our methods to be usable from many different perspectives.Another extension we would like to discuss deals with the current decay function we parametrize.We assume that there is no frequency loss in our signals which is a very strict assumption. Wewould like to implement our decay function such that it takes into account both amplitude andfrequency of the propagating signals. This would mean that instead of only dealing with the at-tenuation of the amplitude, we would fully model the signal as a linear combination of sines andcosines and model the signal decay based on physical terrains and objects in a piece-wise fash-ion. This would allow us to model the signal as it interacts with walls, trees, water, and any otherphysical object we would like. This creates a realistic model because we rarely have a free-space,
  11. 11. Team 11427 11 π Figure 3: The incrementing angle θ∆ = 48 .line-of-sight signal between users and/or repeaters.Our last extension is very similar to the above extension but specifically deals with the spacialaspect of line-of-sight propagation between signals. If we place repeaters that are on opposingsides of a mountain and the signal is not strong enough to penetrate through the mountain (whichin many cases it will not be), then we have to place more repeaters further up the mountain sothat they can communicate with each. This breaks our current assumption that the network weare working on is planar. Our current distance metric does take into account a Z component sowe will not have to make changes to it (that component is initialized to 0 for every point and itconstant through out the method) but the landscape we place each user and repeater on will have tobe dynamically created in 3 dimensions. We would like to extend this model so that we can handlenon-planar landscapes such as mountainous regions. This would cause the number of repeatersplaced to increase but it is a real life situation that needs to be addressed.
  12. 12. Team 11427 12 Figure 4: The single coverage radius r = 8.7 ConclusionUsing the RIM, for a uniform distribution of users, we found that the minimum number of repeatersnecessary to accommodate 1000 simultaneous users is 39. We have shown that the repeater place-ment problem can be solved by using our two methods (RIM and GAM). Each method producesmodels based off of the assumptions that the method is provided. This allows us to quickly andefficiently create new models based off of the parameters we have concluded define this problem.For a small amount of users, the efficiency of our methods did not have a noticeable effect on com-putation time. However, when faced with a larger number of users, such as 10,000, our methodswere no longer efficient in solving the repeater placement problem. We hope to implement uniqueSpacial Database to combat this problem. Our efficiency will increase and be able to handle prob-lems of greater magnitude. Future analyses with our methods will scale with the number of userspresented and will yield models in an efficient amount time.
  13. 13. Team 11427 13 Figure 5: The single coverage radius r = 5.8 ReferencesRadio: • • Databases: • • • Algorithms: • algorithm
  14. 14. Team 11427 14 • /0262111705/ref=sr 1 1?ie=UTF8&qid=1297718108&sr=8-1 • =riccardo+poli+publications&source=bl&ots=frADq2rUuO&sig=Fk1vqlrSJx2w1v 6NVLLZEhqNrb0&hl=en&ei=jptZTa61BIy4tgecqoCUDQ&sa=X&oi=book result& ct=result&resnum=8&sqi=2&ved=0CFQQ6AEwBw#v=onepage&q&f=false9 Appendix9.1 Radial Iterative Method in R9.1.1 Main Fuctionsource("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/FindingFirstDeAngleOfIncrement=pi/48;NumIncrements <- 2*pi/AngleOfIncrement;k <- 2;l <- k;while((n!=0) & (n!=1) & (is.matrix(UserPoints) == TRUE)){source("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/DefiningIncremInputArray <- CirclePoints;source("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/FindingDensestif(MaxRowDimension[[1]] != 0 & MaxRowDimension[[2]] !=0){RepeaterLocations[[k]] <- InputArray[MaxRowDimension[[2]],];for(i in 1:MaxRowDimension[[1]]){if((DensestPoints[[2]][[i]]-(i-1)) == 1 & is.vector(UserPoints) == TRUE) {UserPoints <- UserPoints[[-1]];UserPoints <- UserPoints[-1];}else{UserPoints <- UserPoints[-(DensestPoints[[2]][[i]]-(i-1)),];}
  15. 15. Team 11427 15}source("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/GraphingRepeatk = k+1;l = k;}else{#In case there are no points around a circle....InputArray <- RepeaterArray;source("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/InCaseNoLocatil = MinDistance[[2]] + 1;}}if(is.vector(UserPoints) == TRUE & (length(UserPoints) == 0 | length(UserPoints) == 2) & (is.{RepeaterLocations[[k]] <- UserPoints;source("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/GraphingRepeatTotalNumOfRepeaters <- length(RepeaterLocations);print("Number of repeaters required: ");print(TotalNumOfRepeaters);}TotalNumOfRepeaters <- length(RepeaterLocations);print("Number of repeaters required: ");print(TotalNumOfRepeaters);9.1.2 FindingFirstDenseCircle.Rrm(RUsers, ThetaUsers, XUsers, YUsers, UserPoints, RepeaterLocations)#Uniform Distribution Samplingn=1000;RUsers <- runif(n, min=0, max=40);
  16. 16. Team 11427 16ThetaUsers <- runif(n, min=0, max=40);XUsers <- RUsers*cos(ThetaUsers);YUsers <- RUsers*sin(ThetaUsers);UnifUsers <- cbind(XUsers, YUsers);UserPoints <- cbind(XUsers, YUsers);r=10;FindDistance <- function(XCoordinate, YCoordinate, FixedXCoordinate, FixedYCoordinate){d = sqrt((XCoordinate-FixedXCoordinate)^2 + (YCoordinate-FixedYCoordinate)^2)}InputArray <- UserPoints;source("/Users/cmcknight14/Documents/Mathematical Modeling Contest Spring 2011/FindingDensestRepeaterLocations <- list();RepeaterLocations[[1]] <- InputArray[MaxRowDimension[[2]],];for(i in 1:MaxRowDimension[[1]]){UserPoints <- UserPoints[-(DensestPoints[[2]][[i]]-(i-1)),];}9.1.3 FindingDensestPosition.RLengthOfInputArray <- dim(InputArray)[[1]];n=dim(UserPoints)[[1]];DensestPoints <- matrix(list(), nrow=2, ncol=1);MaxRowDimension <- array(0,2);for(i in 1:LengthOfInputArray){PointsAroundAGivenPoint <- list();
  17. 17. Team 11427 17PointsAroundAGivenPointIndex <- list();for(j in 1:n){d <- FindDistance(UserPoints[j,1], UserPoints[j,2], InputArray[i,1], InputArray[i,2])if(d<=r){PointsAroundAGivenPoint <- rbind(PointsAroundAGivenPoint, UserPoints[j,]);PointsAroundAGivenPointIndex <- rbind(PointsAroundAGivenPointIndex, j);}}RowDimensions <- dim(PointsAroundAGivenPoint)[[1]];IsRowDimensionsNull <- is.null(RowDimensions);if(IsRowDimensionsNull == TRUE){RowDimensions <- 0;}if(IsRowDimensionsNull != TRUE){if(MaxRowDimension[[1]] < RowDimensions & RowDimensions <= 99){MaxRowDimension[[1]] = RowDimensions;MaxRowDimension[[2]] = i;DensestPoints[[1]] <- PointsAroundAGivenPoint;DensestPoints[[2]] <- PointsAroundAGivenPointIndex;}}if(MaxRowDimension[[1]] == 99){break;}}
  18. 18. Team 11427 189.1.4 DefiningIncrementsAroundCircle.RCirclePoints <- matrix(0, nrow=NumIncrements, ncol=2);for(i in 1:NumIncrements){CirclePoints[i,1] <- RepeaterLocations[[l-1]][1] + r*cos((i-1)*AngleOfIncrement);CirclePoints[i,2] <- RepeaterLocations[[l-1]][2] + r*sin((i-1)*AngleOfIncrement);}9.1.5 GraphingRepeaters.Rplot(1, 1, xlim=c(-40,40), ylim=c(-40,40), type="n", xlab="Horizontal Distance from Center ofAllUsers <- cbind(XUsers, YUsers);points(AllUsers, cex=1, pch=20, col="black")RepeaterArray <- RepeaterLocations[[1]];for(i in 2:length(RepeaterLocations)){RepeaterArray <- rbind(RepeaterArray, RepeaterLocations[[i]]);}points(RepeaterArray, cex=3, pch=20, col="green")#Drawing Circles Around Repeatersfor(i in 1: length(RepeaterLocations)){h = seq(floor(-r+RepeaterArray[i,1]), ceiling(r+RepeaterArray[i,1]), .001);TopOfCircle = sqrt(r^2 - (h - RepeaterArray[i,1])^2) + RepeaterArray[i,2];BottomOfCircle = -sqrt(r^2 - (h - RepeaterArray[i,1])^2) + RepeaterArray[i,2];lines(h, TopOfCircle, col="purple", na.rm=T);lines(h, BottomOfCircle, col="purple", na.rm=T);}9.1.6 InCaseNoLocationsAroundCircle.RLengthOfInputArray <- dim(InputArray)[[1]];n=dim(UserPoints)[[1]];DensestPoints <- matrix(list(), nrow=2, ncol=1);
  19. 19. Team 11427 19MinDistance <- c(40,0);for(i in 1:LengthOfInputArray){for(j in 1:n){d <- FindDistance(UserPoints[j,1], UserPoints[j,2], InputArray[i,1], InputArray[i,2])if(MinDistance[[1]] > d){MinDistance[[1]] = d;MinDistance[[2]] = i;}}}9.2 Spatial Database CodeHere we outline our implementation of a Spatial Database, and note some of its more interestingfeatures as they pertain to the problems that arise in determining where to place repeaters.package edu.apsu.ccr;import java.util.ArrayList;import java.util.Iterator;import java.util.SortedMap;import java.util.TreeMap;import java.util.Map.Entry;public class SpatialDatabase<T extends Localizable> { TreeMap<Double, T> xPos; TreeMap<Double, T> yPos; public SpatialDatabase() { this.xPos = new TreeMap<Double, T>(); this.yPos = new TreeMap<Double, T>(); }
  20. 20. Team 11427 20 public void put(double x, double y, T t) { xPos.put(new Double(x), t); yPos.put(new Double(y), t); } public void put(T t) { Point p = t.getPosition(); xPos.put(new Double(p.xPos), t); yPos.put(new Double(p.yPos), t); } public ArrayList<T> getItemsInRadius(Point p, double r) { SortedMap<Double, T> subsetX = xPos.subMap(new Double(p.xPos - r),new Double(p.xPos + r));SortedMap<Double, T> subsetY = yPos.subMap(new Double(p.yPos - r),new Double(p.yPos + r));ArrayList<T> itemsInRadius = new ArrayList<T>();ArrayList<T> intersection = intersectSortedMaps(subsetX,subsetY);for (int i = 0; i < intersection.size(); i++) {T v = intersection.get(i);if (p.getDistanceTo(v.getPosition()) < r) { itemsInRadius.add(v);}}
  21. 21. Team 11427 21return itemsInRadius;}public void addAll(ArrayList<T> items) {for (int i = 0; i < items.size(); i++) {T t = items.get(i);Point p = t.getPosition();this.put(p.xPos, p.yPos, t);}}public Iterator<Entry<Double, T>> getIterator() {return xPos.entrySet().iterator();}public int numItemsInRadius(Point p, double r) {return getItemsInRadius(p,r).size();}public void removeItems(ArrayList<T> items) {for (int i = 0; i < items.size(); i++) {T u = items.get(i);u.setComparator(Localizable.COMPARATOR_X);
  22. 22. Team 11427 22xPos.remove(u);u.setComparator(Localizable.COMPARATOR_Y);yPos.remove(u);}}public void removeItemsInRadius(Point p, double r) {this.removeItems(this.getItemsInRadius(p, r));}public int size() {return xPos.size();}private ArrayList<T> intersectSortedMaps(SortedMap<Double, T> a,SortedMap<Double, T> b){ArrayList<T> intersection = new ArrayList<T>();Iterator<Entry<Double, T>> itr = a.entrySet().iterator();while (itr.hasNext()) {
  23. 23. Team 11427 23T u =;if (b.containsValue(u)) { intersection.add(u);}}return intersection;}}