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.
Your task is to implement a function allocate(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(m n n).
No dictionaries, third party libraries or sets are allowed. Time complexity must be adhered to. Few sample tcs are below:
result = allocate([[0,1,0],[1,1,1],[0,0,1],[0,1,1],[1,0,1],[0,1,0],[0,1,1],[1,1,1],[1,1,1],[1,1,0]],[[2,2,5]],26,28)
assert result is not None
result = allocate([[1,0,0],[1,1,0],[0,0,1],[1,1,1],[1,0,0],[1,1,1],[0,0,0],[0,1,1],[0,1,1],[1,1,0],[1,0,0],[0,0,0],[0,1,0],[1,1,1],[1,0,1],[1,0,1],[0,1,1],[1,0,1],[1,1,1],[1,1,1]],[[6,8,1]],0,27)
assert result is not None
result = allocate([[1,1,0],[1,1,1],[1,1,0],[0,1,1],[1,1,1],[0,1,0],[1,1,1],[0,0,1],[0,0,1],[1,1,0],[0,1,1],[1,1,0],[0,1,0],[1,0,0]],[[4,4,1]],2,27)
assert result is not 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)
assert result is None
result = allocate([[0,0,1],[0,1,1],[0,1,1],[1,0,1],[1,1,1]],[[2,2,1]],30,30)
assert result is not None
result = allocate([[0,0,1],[0,1,0],[1,0,0],[1,1,0],[1,0,0],[1,0,1],[1,1,1],[0,1,0],[0,1,0],[1,1,1],[1,0,1],[0,0,1],[0,1,1]],[[1,4,5]],11,28)
assert result is not None
result = allocate([[1,1,1],[1,0,0],[0,1,1],[0,0,1],[0,0,1],[0,0,1],[1,1,1],[1,1,1],[1,1,1],[0,1,0],[1,1,1],[1,1,0],[0,1,1],[1,0,1],[1,1,1]],[[1,1,8]],14,21)
assert result is not None
result = allocate([[1,0,0],[0,1,0],[0,0,1],[1,1,1],[1,1,1]],[[1,3,1]],9,30)
assert result is not None
assert allocate([[0,0,0]],[[0,0,0]],0,30)==[[[[0,0,0],[0,0,0],[0,0,0],[0,0,0],

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

Step: 3

blur-text-image

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Describe how language emerges.

Answered: 1 week ago