In this assignment, you will design a multithreaded Java program, ensuring both thread safety and sufficient concurrency for it to function well. This builds on the problem presented in the parallel computing solution from the first assignment.
You will implement a multithreaded water flow simulator (Fig.1) that shows how water on a terrain flows downhill, accumulating in basins and flowing off the edge of the terrain.
Figure 1. The main GUI window for the water flow simulator. Note that this mockup is missing the required year counter.
The user interface to display the results of this simulation should have the following behaviour:
You should create a class to represent water on the terrain, where the water depth at each terrain grid position is encoded as an integer. Each water unit corresponds to a depth of 0.01m (e.g., a water value of 5 means a depth of 0.05m). A single timestep of simulation should operate as follows:
Your simulation should be carried out by 4 threads, each responsible for a portion of the permuted list of grid positions. These should synchronise on each timestep. That is, no thread should be allowed to start the next timestep of simulation before all others are complete. For correctness your program should exhibit “fluid conservation”. Water can only be created through user mouse input and destroyed by reaching the boundary. The simulation itself is only responsible for moving water over the terrain.
You are provided with skeleton code for the assignment (package Flow). When executed, this skeleton provides an incomplete GUI interface with none of the buttons. It will display the underlying terrain but does not include any simulation or display of the overlying water. You must build on the skeleton, improving, adding threading and ensuring thread safety when necessary. You must use appropriate synchronization and your solution should allow for maximal concurrency: operations should not be serialized unless necessary.
Your program must take a single command-line parameter: <intput_file>
This encodes data for the landscape in the same format as used for the first assignment.
Your program needs to have a reset, pause, play, and end button to control the state of the simulation. There also needs to be a display of the current timestep. None of this functionality is available in the skeleton.
The GUI needs to display the results of the simulation as it occurs. Ideally, the rendering of the landscape and water should occur at a faster rate than the simulation to ensure that none of the detail is missed by the user.
2.4 Code Architecture
When extending the code, you are expected to follow the Model-View-Controller pattern (shown in Fig. 3) for user interfaces. This very common pattern for software architecture separates the internal representation of the information from the display of the information to the user.
Fig. 3. The Model-View-Controller pattern has a clear separation between the display of the information (model) and its internal representation.
In this case, the model comprises the classes such as Terrain. The view is the GUI and the controllers will be the threads that you add to alter the model and the view, such as the simulation engine.
You need to write a concise report detailing and explaining the coding you have done. The report must contain:
11:55pm on 14th September 2020
If you finish your assignment with time to spare, you can attempt one of the following for extra credit:
Order traversal from lowest to highest instead of random order.
Show the depth of water using shades of blue.
|Rough/General Rubric for Marking of Assignment 4|
|Code – conforms to specification, code correctness, style and comments||25|
|Documentation – all aspects required in the assignment brief are covered||20|
|GIT usage log||2|
|Makefile – compile, docs, clean targets||3|
Note: submitted code that does not run will result in a mark of zero. Any plagiarism, academic dishonesty, or falsifying of results reported will get a mark of 0 and be submitted to the university court.
Hi there! Click one of our representatives below and we will get back to you as soon as possible.