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). No dictionaries or sets allowed.
Test cases to pass:
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([[0,0,0],[0,0,1],[1,0,0],[0,0,1],[1,1,1],[0,1,1],[0,0,0],[0,0,0],[1,1,1],[1,1,1]],[[4,5,1],[7,3,3],[5,7,3],[9,2,9],[5,6,9],[5,6,8],[5,6,1],[10,1,2],[9,7,8],[10,7,9]],7,18)
assert result is None
result = allocate([[0,1,0],[0,1,0]],[[6,4,7]],15,27)
assert result is None
result = allocate([[0,1,1],[1,0,1],[0,1,0],[1,1,0],[1,1,1],[0,1,0],[1,0,1],[0,1,0],[1,0,1],[1,0,1],[1,1,1],[0,1,1],[1,0,1],[1,1,1]],[[2,5,5]],17,27)
assert result is not None
result = allocate([[1,1,1],[0,1,1],[1,1,1],[0,1,1],[1,1,1],[0,0,1]],[[1,1,3]],23,30)
assert result is not None
result = allocate([[1,1,1],[0,1,0],[1,1,1],[1,1,0],[1,1,1],[1,0,0],[0,0,1],[1,1,1],[1,1,0],[0,1,0],[1,1,0],[0,0,0],[1,1,0],[1,0,0],[1,0,0],[0,0,1]],[[2,1,4]],0,24)
assert result is not None
result = allocate([[1,0,1],[0,1,1],[1,1,0],[1,1,0],[1,1,1],[0,0,1],[1,0,0],[0,1,1],[1,0,0],[1,1,1],[0,0,1],[0,1,1],[0,1,1]],[[4,6,2]],27,29)
assert result is not 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

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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

2. What are implementation intentions?

Answered: 1 week ago