Drone Production

Description :

. Problem Statement
There are N different models of drones manufactured at a drone manufacturing unit of the Air
Force. Each drone must go through 2 major phases: ‘manufacturing’ and ‘flight testing’.
Obviously, ‘manufacturing’ must happen before ‘flight testing’. The time for ‘manufacturing’ and
‘flight testing’ (pmi and fti
for i
th drone) for every drone may be different. If we have only 1 unit for
‘manufacturing’ and 1 unit for ‘flight testing’, how should we produce N drones in a suitable order
such that the total production time is minimized and the drones are ready to deploy at the
earliest?
Requirements:

  1. Write an efficient algorithm to select the drone ‘manufacturing’ and ‘flight testing’ in such
    a way that total production time is minimized.

Sample Input:
For example, if there are 6 different drones in total and time for each drone ‘manufacturing’ and
‘flight testing’ are given as shown
Drone i pmi (minutes) fti (minutes)
1 5 7
2 1 2
3 8 2
4 5 4
5 3 7
6 4 4

Sample Output:
Drones should be produced in the order: 2, 5, 6, 1, 4, 3.
Total production time for all drones is: 28
Idle time of flight testing unit: 2

# Input-Output File Name for I/O operation
inputFileName = 'inputPS3.txt'
outputFileName = 'outputPS3.txt'

# Separator character
delimiter = '/'

# File pointer Opening File in Read Mode
inputFileContent = open(inputFileName, 'r')

# File iterator to read line by line
fileLineItr = iter(inputFileContent.readlines())

# Erase previous output in the output file
open(outputFileName, 'w').close()

input = []


# Function to Sort List by Manufactoring Column in  Ascending then in Descending by Flight Testing time
def sortTheInputList(inputList):
    sorted_list = sorted(inputList, key=lambda x: (x[1], -x[2]))
    #print(sorted_list)
    return sorted_list

# Function to Calculate Time
def getMinimumManufacturingTime(inputList):
    if len(inputList) == 0:
        return
    sortedList = sortTheInputList(inputList)
    currentArrivalTime = 0
    flightTestingFinishTime = 0
    flightTestingIdlTime = 0
    manufacturedOrder = []
    res = 0

# Looping over the Sorted List
    for drones in sortedList:
        manufacturedOrder.append(drones[0])

        currentArrivalTime += drones[1]
        #print("tine =" , current_arrival_time)

        diff = currentArrivalTime - flightTestingFinishTime
        if diff > 0:
            flightTestingIdlTime +=  diff
            flightTestingFinishTime +=diff

        flightTestingFinishTime += drones[2]


        #print("idle time = " , fIdl)
        #print("finish  ====" , flightTesting_finish_time)

        res += flightTestingFinishTime - res

        #print(sorted_list)
        #print("Drones should be produced in the order:" , manufactured_order)
        #print("Total production time for all drones is:",res)
        #print("Idle time of flight testing unit:",fIdl)
    
    try:
        f = open(outputFileName,'a')
        manufacturingOrderStr = ','.join(map(str,manufacturedOrder))
        manufacturingOrderStr = "Drones should be produced in the order: " + manufacturingOrderStr
        productionTimeStr = "Total production time for all drones is: " + str(res)
        idlTime = "Idle time of flight testing unit: " + str(flightTestingIdlTime)
        f.write(manufacturingOrderStr+"\n")
        f.write(productionTimeStr+"\n")
        f.write(idlTime+"\n")
        f.write("\n")
        f.close()
    finally:
        f.close()

# Loop to read , create input data set of drone Manufacturing
while True:
     try:
        fileLine = next(fileLineItr)
        if fileLine in ['\n', '\r\n']:
            getMinimumManufacturingTime(input)
            input.clear()
            continue
        current_row = fileLine.split(delimiter)
        current_row = [int(item.strip()) for item in current_row]
        input.append(current_row)
     except StopIteration:
        getMinimumManufacturingTime(input)
        break


# input = [
#     [1, 5, 7],
#     [2, 1, 2],
#     [3, 8, 2],
#     [4, 5, 10]
# ]
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
error

Enjoy this blog? Please spread the word :)

0
Would love your thoughts, please comment.x
()
x