You are on page 1of 1

Exercise 1

Consider and develop a class Node.

Each node should have the following characteristics:

• Pair of coordinates (𝑥, 𝑦)


• ID (Integer value)

Generate the following nodes and store them in a list.

Node with ID = 1 lies at point (15, 30)


Node with ID = 2 lies at point (-5, -5)
Node with ID = 3 lies at point (1, 5)
Node with ID = 4 lies at point (40, 50)

Then consider and generate a node representing a central location (ID = 0). This central location lies at
point (0,0).
Finally, create a list with the five nodes in ascending order of their Euclidean distance from the central
location.

Exercise 2

Consider the central location and the four nodes of Exercise 1.

Then, create a closed route (trip traveled by a truck) which:


• begins from the central location
• visits every customer once
• returns to the central location
The logic for generating this route should be to visit the nearest (yet unvisited) node from the current
point.
The route should be represented by a list of nodes. For example: [Node 0, Node 2, Node 1, Node 3,
Node 4, Node 0].

Exercise 3

Create a list of 100 persons.

Each person should have the following features:

• ID = 1, …, n
• A random weight between 50 and 100
• A random height between 150, 200

Then, calculate the average weight and height of the population generated.

Finally create a list containing all persons with weight less than the average weight and height less than
the average height.

You might also like