Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology University

ROBOTICS AND ARTIFICIAL INTELLIGENCE DEPARTMENT

Total Marks: 04

Obtained Marks:

DESIGN AND ANALYSIS OF


ALGORITHMS

Assignment # 02
Last date of Submission: 29 October 2023

Submitted To: Sir Saad Irfan Khan

Student Name: Syed Abdul Moiz Alam

Reg. Number: 21108123

Section: BSAI-4A

DAA BS(AI)-4A SZABIST-ISB


QUESTION 1:
Source Code:

import itertools

# Define the time required for each job for each crane in a 4x4

matrix time_matrix = [

[4, 2, 5, 7],

[8, 3, 10, 8],

[12, 5, 4, 5],

[6, 3, 7, 14]

def calculate_total_time(assignment):

total_time = 0

for i in range(len(assignment)):

total_time +=

time_matrix[i][assignment[i]] return

total_time

# Generate all possible crane-job assignments using

itertools.permutations crane_permutations =

itertools.permutations(range(4))

best_assignment = None

min_total_time = float('inf')

# Iterate through all permutations and find the one with the

DAA BS(AI)-4A SZABIST-ISB


minimum total time for assignment in crane_permutations:

total_time = calculate_total_time(assignment)

if total_time < min_total_time:

min_total_time = total_time

best_assignment = assignment

# Print the best assignment and minimum total time

print("Best Crane-Job Assignment:",

best_assignment) print("Minimum Total Time:",

min_total_time)

Output:

DAA BS(AI)-4A SZABIST-ISB


DAA BS(AI)-4A SZABIST-ISB
DAA BS(AI)-4A SZABIST-ISB

You might also like