由于您已用 标记了问题algorithm
,并且您在编程站点(而不是数学或统计站点)中提问,因此我将从编程的角度来处理这个问题。
模型:
// creates a new ticket for a given service; arrival time and length are only known
// for generated tickets
class Ticket(int arrival, int length, Service s)
// an abstract distribution (parameters are distribution-dependent)
class Distribution(...)
int generate() // generates integer with this distribution
// a service, with a distributions of time-to-finish and time-between-arrivals
// (both set experimentally from historical data).
class Service(Distribution lengths, Distribution arrivals)
// simulated ticket: length from lengths.generate(),
// arrival from t + arrivals.generate();
Ticket createFuture(int t)
// same as above, but arrival = t+0
Ticket createNow(int t)
// a desk, offers one or more services
class Desk()
void addService(Service s) // allows this desk to attend this service
void removeService(Service s)
bool isCompatible(Service s) // is this desk compatible with this service?
void attend(Ticket t) // marks a desk as attending a service
bool isFree() // returns true if the desk is not attending anyone
// returns a finished ticket, if any. After this, isFree() will return true
Ticket finished()
// a policy which assigns tickets to desks. Implement your current one (probably "FIFO")
class Policy()
// returns a suitable desk for that ticket, or null if none is posible/desired
Desk assign(Ticket t, Ticket[] pending, Desk[] deks)
// a live queue of tickets, dispatched using policy p t
class Queue(int startTime, Policy p, Service[] ss, Desk[] ds)
void push(Ticket t) // adds a new real ticket to the queue
// estimates wait-times for new arrivals to all services at time 't'
Map<Service, int> forecast(int t)
void tick() // advances time for this queue
Queue clone(); // deep-clones the queue (including time, policy, desks, and services)
用法:
- 定义您的服务并为它们的到来建模。
- 创建办公桌并为其分配服务。
- 定义你当前的策略,用它创建一个队列。队列将开始为空。
- 随着时间的推移,调用 tick() (并且,如果有票进来,使用 createNow() 来 push() 他们)
- 根据需要调用estimate()
执行:
tick() 将遍历所有桌子以查看哪些已完成(),并根据当前策略将票分配给桌子。通过多次调用 tick() 直到队列为空,可以确定每种服务类型的确切关闭时间——但这会破坏队列,并且只能在当前队列的 clone() 上完成.
Forecast() 将克隆() 队列 N 次,并且对于每个克隆的队列,在添加模拟票证(使用 createFuture() 生成)的同时将时间提前 'now-t' 次。您应该将 createFuture 的时间链接如下:
// create 3 future tickets for service s
Ticket t1 = s.createFuture(now);
Ticket t2 = s.createFuture(t1.arrival);
Ticket t3 = s.createFuture(t2.arrival);
//...
只有在模拟时间达到模拟到达时间后,模拟票才会被推入实际队列。一旦模拟时间达到“now+t”,将确定实际服务延迟并在所有 N 次模拟中取平均值,以产生概率预测。