Table of Contents

Task 2 - CSP - Taxi driving

In a small town, there is an unnamed taxi service that wants to maximize its profit. The service has multiple vehicles at their disposal, and multiple customers to satisfy. One day, an exceptionally large number of customers appeared and the taxi service is overwhelmed. They are quite stubborn and want to satisfy all the customers at once, even if they have to stuff more of them in a single taxi. Suddenly, a clever programmer came up (you) and declared that he can solve the problem.

However, the problem is rather tricky.

The available taxi cars only serve certain destinations, have a limited capacity and what's more, they are of different class. Customers, on the other hand, want to go from their origin to a destination and also belong to a certain class. The customers are rather picky, so they won't get in a taxi of a worse class than theirs (the class 1 is best, hence a customer with a class 2 won't go into a taxi with a class 3 or more). Also, the taxi can serve only a certain number of customers, up to their capacity. What's more, all the customers in a single taxi have to start in the same origin and go to the same destination.

Your program will receive a single JSON input defining the available taxis and the customers. See the following example:

{
	"taxis": [
		{
			"id": "taxi_01",
			"serves": ["A", "B", "C"],
			"class": 1,
			"capacity": 2
		},
		{
			"id": "taxi_02",
			"serves": ["A", "B", "C"],
			"class": 2,
			"capacity": 2
		}
	],
	"customers": [
		{
			"id": "customer_01",
			"origin": "A",
			"destination": "B",
			"class": 1
		},
		{
			"id": "customer_02",
			"origin": "C",
			"destination": "A",
			"class": 3
		}
	]
}

In the example, there are 2 taxis, taxi_01 and taxi_02 (the ids are always unique) with their respective attributes. There are also 2 customers, customer_01 and customer_02. As this is not the first day of the taxi service, they provide you with a method to load this input into a python dictionary.

The program should output a single json with a mapping of customers to taxis. In the example above, there is only one solution:

{"customer_01": "taxi_01", "customer_02": "taxi_02"}

If there are multiple solutions, any single of them is sufficient. If there is no solution, your program should print out an empty json object:

{}

Implementation

Download a package csp_student.zip. It consists of the following files

Submission of your code

You submit on BRUTE - odevzdávací systém. You submit only the `student.py` file.

Evaluation

Your submission will be evaluated on a number of problems and will receive a certain number of points, based on a number of the correctly solved ones (in the time limit). The maximum what your program can receive is 10 points. Some problems are harder than others and require implementation of at least MCV heuristic.

Final score is computed by formula:

score = (correct - 3)/2
where `correct` is a number of correctly solved evaluation instances.

Hints

timeout 10s python student.py samples/hg_01.json

arr_1 = [5,2,3,1,4]
indices = np.argsort(arr_1)
# [3, 1, 2, 4, 0]

arr_2 = ['a', 'b', 'c', 'd', 'e']
arr_2_sorted = [arr_2[i] for i in indices]
# ['d', 'b', 'c', 'e', 'a']

Prosíme vás, jako preferovaný komunikační kanál využívejte fórum. Na fóru máte nejlepší šanci na rychlou odpoveď, která navíc může být relevantní i pro ostatní studenty. Kdybyste přesto potřebovali ohledně této úlohy kontaktovat cvičící přímo, kontaktní osobou je Jaromír Janisch. Zodpovědnost za úlohy je mezi cvičící rozdělena, ne všichni vám budou schopni poradit.