Programming paradigms

Your second assignment asks you to design a program to solve a problem. (With thanks to Matt Cooper who suggested this term’s problem) Suppose we have some mountainous piece of terrain. Md it’s expressed as a function of x and y: // You’ll be given this function def height(x:Double. y:Double):Double = ??? That could be a mathematical function, or it could be looking it up on an actual map. Md we want to find the location and height of the highest peak in the terrain. How do we do this? There may be several peaks, but we want to find the highest one: Mathematically, this is an optimisation problem, and they can’t always be solved analytically — sometimes we have to search. The way you’re asked to search in this assignment is by using a particle swarm optimisation.(PS0). PSOs attempt to mimic the way swarms of animals can solve problems Imagine a thousand ants crawling over the terrain, each exploring for the highest point in its vicinity. We create some number (say, 1000) particles, at random locations on the terrain. Each panicle has a position and a velocity. Md then we run a loop at each step of the loop: each panicle’s v elodty is updated based on an equation that takes into account the highest point it has seen, and the highest point the whole system has seen so far. each particle’s position is updated based on its velocity Let’s give you the equations we will use. If we denote that: and y represent the particle’s current position, vx and v represent the x and y components of the particle’s velocity rt , r2 .13 , etc represent random numbers between 0 and 1 lx and ly represent the location of the highest point seen by this particle for local) gx and gy represent the location of the highest point seen by the entire system (g for global) Then at each step, we will update each particle’s velocity to be vx (0.5 vx + 2 r1 ( lx – x ) +2 r2 ( gx – x vy.— (OS vy +2 r3 ( ly- y)+2r4 (gy- y) So that the v e °cities involved don’t become too great. we will etamp’v x and vy to the range —1 to 1. By this we mean that if either vx or vy is below —I then we set it to —1, and if either is larger than 1 then we set it to 1 , otherwise we leave them as is. Next, the position of each particle is updated by the rule
x x + vx yi” +vY After each iteration the highest seen value, and its location, (or each particle and (or the whole particle system are updated, if needed. Let the loop run for a large number of iterations, and chart where the particles are, and how the “highest points seen” for the system and for each particle change from iteration to iteration. You will need to keep some additional data structures (probably mutable Buffers) to keep the history of the “highest points seen” (or charting. Your code Your code should include a README.txt file explaining your design, and the code should be commented. Your program needs to: Implement the panicle swarm optimisation Run a simulation with a configurable number of particles Log to standard out at each step of the loop: the best location seen so far the location of the five highest particles Chan in the UI the height of the panicles the positions of the panicles, marking the highest known point in red Please note, you will be given a little Jay aFX UI code to draw the squares, You can call Java code from Scala. On Turing. you would need to ensure you are using the Oracle JDK in order to run Jay aFx. Instructions will be given closer to time for this.
Submission To submit, please: run ./sbt clean to remove generated files like class files. zip the entire directory (not just your source code, but the entire directory including build.sbt. so it will work as a project when unzipped), and Submit the zip file to Moodie.

READ ALSO :   Management and Organisations in a Global Environment