Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that you are the manager of a security company tasked with assigning security officers ( n ) to a group of companies ( m

Assume that you are the manager of a security company tasked with assigning security officers (n) to a group of companies (m) in a certain month with 30 days numbered D0, D1,..., D29. As- sume that security officers are denoted by SO0, SO1,... SOn1 and the companies are represented by C0,C1,...Cm1. There are three 8-hour shifts per day: S0(midnight-8am), S1(8am-4pm), and S2(4pm-midnight). For each pair company/shift (Cj,Sk), the company Cj has a different number of security officers required for the shift Sk, however, this is constant for each day of the month.
The security officers specify the shifts they are interested in working on, and they have the opportunity to indicate more than one (1) preferred shift. However, they cannot be allocated to more than one (1) shift per day. Further, the shift preference of each security officer should be the same for all the days of the month (and therefore specified only once per security officer).
Your task is to provide a plan for assigning officers to the companies for the coming month according to the requirement of the number of security officers per shift by each company. For each day of the month, and for each shift, each company should be allocated exactly the same number of security officers it requests. There are 2 integer parameters, 0<=min_shifts<=30(minimum number of shifts) and 0<=max_shifts <=30(maximum number of shifts), and the total number of shifts allocated to each security officer in a month should be within these two integer parameters (closed interval).
As long as you comply with the constraints above, you are free to allocate the security officers any way you want.
The input to your function allocate consists of a list of preferred shifts provided by each security officer and the number of security officers requested by the companies for each shift: preferences is a list of lists, where preferences[i][k], is a binary value (0 or 1), indicating whether security officer SOi is interested in working on shift Sk in that month (1 indicates that the officer is interested). officers_per_org is a list of lists, where officers_per_org[j][k] is a non-negative number that specifies how many security officers company Cj needs for shift Sk on each day of that month.
Yourtaskistoimplementafunctionallocate(preferences, officers_per_org, min_shifts, max_shifts) which returns:
None (i.e., Python NoneType), if no allocation satisfying all constraints exists.
Otherwise, it returns a list of lists allocation, where allocation[i][j][d][k] is equal
to 1 if security officer SOi is allocated to work for company Cj during shift Sk on day Dd.
Complexity requirement: The worst-case time complexity of your solution should be O(mnn).
Thank you for your implementation. It passes most test cases except these ones:
result = allocate([[0,1,0],[1,0,1]],[[3,2,1]],8,26)
assert result is None
result = allocate(
[
[1,0,0],
[0,1,0],
[0,0,1],
[0,1,1],
[1,0,1],
[1,0,0],
[1,0,0],
[0,0,0],
],
[[9,1,9]],
7,
20,
)
assert result is None
result = allocate(
[
[1,1,0],
[1,1,0],
[0,1,0],
[0,0,0],
[0,1,0],
[1,0,1],
[0,0,1],
[1,0,1],
[1,1,1],
[1,0,0],
],
[[4,5,10]],
22,
27,
)
result = allocate(
[
[1,0,0],
[0,0,1],
[1,0,0],
[1,1,0],
[0,0,1],
[0,1,1],
[0,0,0],
[1,1,0],
[0,0,0],
[0,0,1],
[0,0,0],
[1,0,1],
[0,1,1],
[1,0,1],
[1,1,1],
[1,0,1],
[1,0,0],
[0,1,0],
[0,1,1],
],
[[4,9,2]],
20,
27,
)
assert result is None
result = allocate(
[[1,0,1],[0,0,1],[0,1,0],[1,0,1],[1,0,0],[0,0,0]],
[[7,7,10]],
28,
28,
)
assert result is None
result = allocate(
[
[0,1,0],
[1,0,0],
[0,1,0],
[1,1,0],
[0,0,1],
[0,1,0],
[0,1,1],
[0,1,0],
[1,1,0],
[1,1,1],
[1,0,0],
[0,1,1],
[1,1,0],
[1,1,0],
[1,0,1],
[1,0,0],
[1,0,1],
[0,1,0],
[1,0,1],
[0,1,1],
],
[[1,3,2],[4,1,1]],
16,
24,
)
assert result is not None
result = allocate(
[
[1,0,1],
[0,1,1],
[0,1,1],
[0,1,1],
[0,1,0],
[0,1,1],
[1,1,0],
[1,0,0],
[0,0,1],
[1,0,1],
[1,1,0],
[1,0,1],
[1,0,0],
[0,1,0],
],
[[2,1,2],[4,3,2]],
30,
30,
)
assert result is not None
result = allocate([[1,1,0],[1,0,1],[1,1,1]],[[10,6,5]],3,25)
assert result is None

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions