Optimal Service Order Problem - Algorithm Design and Analysis Experiment 3

1 question

Optimal service order problem: There are n customers waiting for a service at the same time. The service time required by customer i is ti, 1≤i≤n. There are s places where this service can be provided. How should the service sequence of n customers be arranged so that the average waiting time reaches the minimum? The average waiting time is the sum of the waiting time of n customers divided by n.

2 problem analysis

Greedy strategy: Since the service time of each customer i is ti, in order to minimize the sum of the waiting time for service, customers with the smallest value of ti should be arranged as much as possible for service.

3 Problem Modeling

Problem modeling: Assuming that the time of the original problem is T, an optimal service series is already known, and the optimal solution is min={t(1), t(2),...,t(n)} (where t( i) is the service time required by the i-th customer), then the waiting time required by each customer is:
T(1)=t(1);
T(2)=t(1)+t(2);
 … 
T(n)=t(1)+t(2)+...+t(n);
then, the total waiting time is the optimal solution 
Tmin=n*t(1)+(n-1)*t (2)+(n-2) t(3)...+(n+1-i) t(i)+...+2 t(n-1)+1 t(n)

4 Algorithm description

Enter the list of waiting time required by users
Arrange the waiting time from small to large
Use the mathematical formula Tmin=n*t(1)+(n-1)*t(2)+(n-2) t(3)…+ (n+1-i) t(i)+…+2 t(n-1)+1 t(n) to calculate the result

5 algorithm source code

list = []
i=1
a=1
while a!=0:
    a = int(input())
    list.append(a)
list.pop()
list.sort()
n=len(list)
sum=0
for i in(list):
    b = n*int(i)
    sum = sum+b
    n-=1
print(sum/len(list))

6. Test data
12 23 67 34 61
7. Results of program operation (requirement: screenshots to illustrate the results of algorithm operation)
insert image description here
For more university coursework experiments and training, please pay attention to the official account: Timewood
Reply to related keywords
. looking for advice

Guess you like

Origin blog.csdn.net/qq_43374681/article/details/122381878