机修复模拟?

时间:2013-01-20 18:14:59

标签: c++ algorithm simulation

问题陈述:

 A system is composed of 1, 2, or 3 machines and a repairman responsible for
 maintaining these machines. Normally, the machines are running and producing 
 a product. At random points in time, the machines fail and are fixed by the
 repairman. If a second or third machine fails while the repairman is busy
 fixing the first machine, these machines will wait on the services of the 
 repairman in a first come, first served order. When repair on a machine is 
 complete, the machine will begin running again and producing a product.
 The repairman will then repair the next machine waiting. When all machines
 are running, the repairman becomes idle.

 simulate this system for a fixed period of time and calculate the fraction
 of time the machines are busy (utilization) and the fraction of time
 the repairman is busy (utilization).

现在,输入是50运行时间和50修复时间,然后给出周期 计算它的利用率和要模拟的机器数量 对于每个测试用例。

示例输入:

7.0  4.5 13.0 10.5  3.0 12.0 ....
9.5  2.5  4.5 12.0  5.7  1.5 ....
20.0 1
20.0 3
0.0 0

示例输出:

       No of     Utilization
Case Machines Machine Repairman

 1       1       .525   .475
 2       3       .558   .775

案例2说明:

enter image description here

Machine Utilization   = ((7+3)+(4.5+6)+(13))/(3*20) = .558
Repairman Utilization =                   (15.5)/20 = .775

我的方法:

1)将机器加载到最小堆(称为runHeap)并给出每个堆    他们是一个运行时间,所以下一个给运行时间将是一个新的    从输入中的50个运行时间开始,

2)计算runHeap中最小提醒运行时间之间的最短时间    ,提醒维修队列头部的维修时间或提醒    时间来完成模拟,并称之为#34; toGo"。

3)通过toGo减去runHeap中所有机器的所有提醒运行时间,    通过toGo

减去repairQueue头部的提醒修复时间

4)所有提醒运行时间== 0的机器,将其推入repairQueue,    修复队列的头部如果提醒修复时间== 0将其推入    runHeap,

5)添加到当前时间

6)如果当前时间<1。模拟时间转到第2步,否则返回利用率。

现在,问题是一个好方法还是可以找出更好的方法?

0 个答案:

没有答案