Find greedy algorithm with code A company has a set of n rev

Find greedy algorithm with code

A company has a set of n revenue streams and a team of n members. Each stream must be matched to exactly one member and each member charges a commission fee as a percentage of revenue. The company wishes to minimizes the amount of money spent on commission. The n revenue streams have revenues R = r1,r2,...,rn and the n members each charge commission L = l1,l2,...,ln.

Devise a greedy algorithm to compute an optimal solution to the problem.

Solution

r = [10, 5, 10, 20, 25, 22, 18, 7] #revenue values
l = [10, 2, 55, 8, 44, 12, 33, 100] #commision percentages

commisions = [r[i]*l[i]/100.0 for i in range(len(r))] #commission values

commisions_for_rev = {} #initialising a dictionary

#creating a dictionary of commisions with revenue number and values
for i in range(len(commisions)):
    commisions_for_rev[i] = commisions[i]

#sorting the dictionary based on values. This returns a list of tuples
commisions_for_rev = sorted(commisions_for_rev.items(), key=lambda x: x[1])

#print the order of revenue streams to pursue to minimize the commisions payed on revenues
for com in commisions_for_rev:
    print \"r\",com[0],\"   \",

Find greedy algorithm with code A company has a set of n revenue streams and a team of n members. Each stream must be matched to exactly one member and each mem

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site