Background

The police force for the city of Parallelopolis have been hassled about slow response times and require an update of their computer systems to help keep the peace. One of their major challenges is organising which police units should respond to suspects, and which police station suspects should be taken to.

In this assignment, you will be developing an application that simulates police units picking up a police dog, attending crime scenes, picking up suspects, and dropping them off at a police station within the city of Parallelopolis.

Submission

To prepare your solution for submission, first ensure it is working on the lab computers. Provide an Eclipse project with code files that execute straight away. Your code should not depend on any external packages, e.g it needs to compile and execute with the standard JAVA SDK and JRE.

Task one and two should be in two modules that can be run separately for testing purposes. Please have the CSV files be input from and output to the root directory of the project. Include a small text file named Readme.txt with a brief description of your project and how to run it.

Requirements

This application will be split into two main tasks. The first task will provide a simulation of police units picking up suspects and delivering them to the local police station. The second task will require you to visualise this simulation in a GUI windows.

The data input for this simulation will come from two CSV files, "police.csv" and "suspects.csv". Your application will need to load these files in and parse them accordingly. Samples of these files will b available on Canvas, and a more detailed description of their contents is below.

Task A) Simulation

The first task is to implement a simulation of the police units' activity. This needs to be in a self- contained module, so it can be tested easily and separately from the second task. This module will read the "police.csv" and "suspects.csv", run for a set period of time, then output the updated information to "police-output.csv" and "suspects-output.csv". The output files will use the same format as the input file format.

The Simulation has the following elements:

  • City of Parallelopolis: This is represented by a grid with dimensions of O to 100 in both the x and y dimensions.
  • The Police Units: These police units are loaded in through the "police.csV' file. Each police unit has an ID number, an (x,y) location, a current status, a Yes/No field for if it has a police dog and an assigned suspect ID. Police units who haven't been assigned a suspect will have an empty suspect ID.
  • The Suspects: The suspects are loaded in through the "suspects.csV' file. Each suspect has an ID number, an (x,y) location, a current status and an assigned police unit ID. Suspects who haven't yet been assigned a police unit will have an empty police unit ID.
  • The Kennel: This holds a set of police dogs at location (50,50) in the city grid. The Police Stations: There are 4 stations in Parallelopolis at these locations:
    • Downtown - (25,5)
    • Midtown - (80,30)
    • Uptown - (10,90)
    • Lazytown - (70,80)

The position of the Kennel and the Police Stations will remain constant, while the initial positions of Police Units and Suspects will be read in from the data files.

Every second, the police units will update their status and position. Their actions will be determined based on their current status. The explanation for each police unit status is shown below:

  • 'Standby': Check if there are any suspects to pick up. Assign the closest unassigned suspect to this police unit. Change the police unit status to 'Approaching Kennel'. If there are no available suspects, do nothing.
  • 'Approaching Kennel': Move the police unit towards the Kennel by 3 moves (see restrictions). If the police unit reaches the Kennel, change the status to 'At Kennel'
  • 'At Kennel': If the police unit is collecting a police dog, remove one dog from the kennel and assign it to the police unit then change the status to 'Approaching Suspect'. If the police unit is returning a police dog, unassign it from the police unit, return it to the kennel and change status to 'Returning'.
  • 'Approaching Suspect': Move the police unit towards the assigned suspect by 4 moves. If the police unit reaches the suspect, change the status to 'At Scene'
  • 'At Scene': If the police unit has been at the scene for four seconds, change the status to 'Approaching Kennel'. Otherwise do nothing.
  • 'Returning': Move the police unit towards the nearest available station (see restrictions) by 3 moves. If the police unit reaches the station, change the status to 'Standby'

Some of the police unit actions also change the status of their assigned suspect:

  • When a police unit is assigned a suspect, the suspect's status is changed to 'Assigned'
  • When the police unit reaches the suspect, the suspect's status is changed to 'Caught'
  • When the police unit reaches the station, with the caught suspect, the suspect's status is changed to 'Jailed'. The suspect is then unassigned from the police unit.

Restrictions:

  • The closest distance is defined as the Euclidean (straight-line) distance between two points.
  • A move is a one unit change in either the x-coordinate or the y-coordinate. Police units will always move to reduce the distance towards their target (kennel, suspect or station)
  • The number of police units a station can accommodate is defined by the total number of police units divided by four, rounded up. E.g If there are 5 police units, each station can accommodate two police units.
  • The total number of police dogs in the simulation is defined by the total number of suspects in the simulation divided by 2, rounded up. E.g if there are 7 suspects, the total number of police dogs available is 4.
  • The task can be assumed to have a duration of 60 seconds.
  • To simplify the task you can assume that all police units will start in the standby status with no assigned suspects. All suspects will hence then start in the 'Unassigned' status

Tips:

  • Each police unit should have its own thread. These threads need to run independently of all the other police units.
  • Consider which of your implemented data structures need to be thread safe and implement accordingly.
  • This is especially important when assigning unique resources - You don't want two threads thinking they own the same resource!

Task B) GUI Interface

The second task is to implement a GUI that displays the simulation designed in Task A. An example of this GUI is shown below. see image.

The list displays the details of all the police units within the simulation. This will show a real-time display of where every police unit is, along with their status, whether they have a police dog with them and the id of their assigned suspect.

  • The simulation should run inside a background thread to prevent freezing the GUI
  • The GUI components should not be modified from the background thread directly to avoid unpredictable errors.
  • Using SwingWorker and SwingUtilities is recommended to keep this simple
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.