1 Introduction
The electric power grid is the network infrastructure responsible for the generation and trans- mission of electricity. We have three types of elements in a power grid:
A generator: this is a station that generates electricity. A generator has a power limit that it cannot exceed.
A transmitter: this is a station that transmits electricity. A transmitter can be connected directly to a generator or to another transmitter. A transmitter has a maximum power that can pass through it.
A consumer: this can be a household, a shop, a factory etc. A consumer can only be attached to a transmitter (not directly to a generator), and no element can be attached to it. A consumer has maximum consumption power that it cannot exceed.
For simplicity, we assume that the power grid can be represented as a general (non-binary) tree. The grid contains only one generator located at the root, whereas consumers are located at leaf nodes. See Figure 1 for an example.
We are interested in the following:
Finding how much power is generated, transmitted or consumed by an This is the total power required by the consumers in the corresponding subtree.
Example 1. In the grid shown in Figure 1: Elements 6 and 9 are consuming 0 power, since there are no consumers attached to them. Element 16 consumes 4, Element 8 consumes 10, and Element 4 consumes 19.
Whether there is an overload in the grid. An overload takes place when the power required at an element exceeds its By definition, overloads can only happen at the generator or the transmitters (but not consumers).
Example 2. In the grid shown in Figure 1, the only element that has an overload is Element 4, since it consumes 19, and its limit is 18.
In this programming assignment, we will use general trees to represent a power grid.
id: 3 type: Generator
Power:36
id: 4
type: Transmitter Power:18
id: 5
type: Transmitter Power:18
id: 7
type: Transmitter Power:18
id: 8
type: Transmitter Power:12
id: 6
type: Transmitter Power:12
id: 10 type: Consumer
Power:9
id: 12 type: Consumer
Power:4
id: 16 type: Consumer
Power:4
id: 17 type: Consumer
Power:4
id: 13 type: Consumer
Power:3
id: 11 type: Consumer
Power:3
id: 14 type: Consumer
Power:4
id: 9
type: Transmitter Power:12
The enumeration ElemType is defined as follows:
Using these definitions, write the class PowerGridUtils:
public c l a s s Power Grid Utils {
// Return the IDs of all elements in the power grid pg in pre - order.
public s t a t i c Queue < Integer > collect Preorder ( GT < PGElem > pg);
// Searches the power grid pg for the element with ID id. If found , it is made current and true is returned , otherwise false is returned.
public s t a t i c boolean find ( GT < PGElem > pg , int id);
// Add the generator element gen to the power grid pg. This can only be done if the grid is empty. If successful , the method returns true.
If there is already a generator , or gen is not of type Generator , false is returned.
public s t a t i c boolean add Generator ( GT < PGElem > pg , PGElem gen );
// Attaches pgn to the element id and returns true if successful. Note that a consumer can only be attached to a transmitter , and no element can be be attached to it. The tree must not contain more than one generator located at the root. If id does not exist , or there is already aelement with the same ID as pgn , pgn is not attached , and the method retrurns false.
public s t a t i c boolean attach ( GT < PGElem > pg , PGElem pgn , int id);
// Removes element by ID , all corresponding subtree is removed. If removed , true is returned , false is returned otherwise.
public s t a t i c boolean remove ( GT < PGElem > pg , int id);
// Computes total power that consumed by a element ( and all its subtree
). If id is incorrect , -1 is returned.
public s t a t i c double total Power ( GT < PGElem > pg , int id);
// Checks if the power grid contains an overload. The method returns the ID of the first element preorder that has an overload and -1 if there is no overload.
public s t a t i c int find Overload ( GT < PGElem > pg);
}
4 Deliverable and rules
You must deliver:
Source code submission to Web-CAT. You have to upload the following class in a zipped file:
java
java
Notice that you should not upload the interfaces and classes given to you.
The submission deadline is: 26/11/2019.
You have to read and follow the following rules:
The specification given in the assignment (class and interface names, and method signatures) must not be Any change to the specification results in compilation errors and consequently the mark zero.
All data structures used in this assignment must be implemented by the The use of Java collections or any other data structures library is strictly forbidden.
This assignment is an individual Sharing code with other students will result in harsh penalties.
Posting the code of the assignment or a link to it on public servers, social platforms or any communication media including but not limited to Facebook, Twitter or WhatsApp will result in disciplinary measures against any involved
The submitted software will be evaluated automatically using Web-Cat.
All submitted code will be automatically checked for similarity, and if plagiarism is con- firmed penalties will
You may be selected for discussing your code with an examiner at the discretion of the teaching If the examiner concludes plagiarism has taken place, penalties will apply.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of