Skip to content
Select theme

Optimal Departure Time and Walking Speed for the Cafeteria

The source download includes only this article, without shared templates or dependencies. To compile it, clone the notes repository and follow its setup instructions.

1. Problem

Students may only use the cafeteria floor assigned to their grade. Choose a departure time 𝑡 and average speed 𝑣 to minimize the sum of walking and queueing time, food quality loss, and a penalty for walking too fast.

The model makes the following assumptions:

  • Arrival times for students in this grade follow a shifted lognormal distribution;
  • The cafeteria’s maximum service rate is constant;
  • Food neither runs out nor is replenished during service;
  • Food quality decreases continuously and linearly with the cumulative number of people served;
  • The queue is first-come, first-served, and no one leaves before being served.

2. Arrivals and Queueing

Let 𝑐 be the earliest possible arrival time, and let 𝑁 be the total number of students in this grade dining on this floor. The cumulative distribution function of arrival times is

𝐹(𝑎)={0𝑎𝑐Φ(ln(𝑎𝑐)𝑚𝜎)𝑎>𝑐.

The corresponding density is

𝑓(𝑎)=1(𝑎𝑐)𝜎2𝜋exp((ln(𝑎𝑐)𝑚)22𝜎2),𝑎>𝑐.

Thus, the expected number of arrivals by time 𝑎 is 𝑁𝐹(𝑎). The maximum density is

𝑓max=exp(𝑚+𝜎22)𝜎2𝜋.

Let the constant service rate be 𝜇. If 𝑁𝑓max𝜇, no queue forms. Otherwise, the queue begins to form at time

𝑢=𝑐+exp(𝑚𝜎2𝜎2ln(𝑁𝑓max𝜇)).

The time 𝑒>𝑢 at which the queue clears is the nontrivial solution of

𝑁(𝐹(𝑒)𝐹(𝑢))=𝜇(𝑒𝑢)

This equation generally has no elementary closed-form solution, but it can be solved using one-dimensional bisection. The queueing time for an arrival at time 𝑎 is

𝑤(𝑎)={0𝑎𝑢𝑁𝜇(𝐹(𝑎)𝐹(𝑢))(𝑎𝑢)𝑢<𝑎𝑎<𝑒0𝑎𝑒.

3. Food Quality

Normalize the initial food quality to 1. Suppose that quality has decreased by a total of 𝜂 after all 𝑁 people have been served. The quality after serving 𝑛 people is then

𝑆(𝑛)=1𝜂𝑛𝑁.

Under the first-come, first-served approximation, someone arriving at time 𝑎 has approximately 𝑁𝐹(𝑎) people ahead of them, so their food quality loss is

1𝑆(𝑁𝐹(𝑎))=𝜂𝐹(𝑎).

4. Relative Weights

The original penalty function is

𝐽(𝑡,𝑣)=𝛼(𝑑𝑣+𝑤(𝑡+𝑑𝑣))+𝛽𝜂𝐹(𝑡+𝑑𝑣)+𝛾((𝑣𝑣𝑐)+𝑣𝑐)2.

Multiplying 𝛼,𝛽,𝛾 by the same positive constant does not change the optimum. Thus, when 𝛼>0, it suffices to consider two relative weights:

𝑟𝐵=𝛽𝛼,𝑟𝑉=𝛾𝛼.

After dividing the objective function by 𝛼, the function used in the computation is

𝐽rel(𝑡,𝑣)=𝑑𝑣+𝑤(𝑡+𝑑𝑣)+𝑟𝐵𝜂𝐹(𝑡+𝑑𝑣)+𝑟𝑉((𝑣𝑣𝑐)+𝑣𝑐)2.

This eliminates redundant entries in the three-dimensional table of weights. The configuration file fixes the time weight at 1 and lists the desired values of 𝑟𝐵 and 𝑟𝑉 separately for tabulation.

5. Solution

Set the arrival time to 𝑎=𝑡+𝑑𝑣, and define

𝐻(𝑎)=𝑤(𝑎)+𝑟𝐵𝜂𝐹(𝑎),𝐶(𝑣)=𝑑𝑣+𝑟𝑉((𝑣𝑣𝑐)+𝑣𝑐)2.

Then 𝐽rel(𝑡,𝑣)=𝐻(𝑎)+𝐶(𝑣). Within the interval 𝑢<𝑎<𝑒 during which the queue exists,

𝐻(𝑎)=(𝑁𝜇+𝑟𝐵𝜂)𝑓(𝑎)1.

Interior stationary points satisfy

𝑓(𝑎)=1𝑁𝜇+𝑟𝐵𝜂.

To find the optimal arrival time, it suffices to compare the endpoints of the allowed interval, the queue clearance time 𝑒, and any stationary points lying in (𝑢,𝑒).

When 𝑣>𝑣𝑐 and 𝑟𝑉>0, the optimal speed satisfies

2𝑟𝑉(𝑣)2(𝑣𝑣𝑐)=𝑑𝑣𝑐2.

This cubic equation has a unique solution for 𝑣>𝑣𝑐; clamp that solution to the allowed speed interval. If 𝑟𝑉=0, choose the maximum allowed speed. The final output is

(𝑡,𝑣)=(𝑎𝑑𝑣,𝑣).

6. Parameters

ParameterMeaning
𝑁Total number of students in this grade dining on this floor
𝑐Earliest possible arrival time at the cafeteria
𝑚Mean of ln(𝑎𝑐)
𝜎Standard deviation of ln(𝑎𝑐)
𝜇Number of people served per minute while a queue exists
𝑑Actual travel distance from the departure point to the cafeteria floor assigned to this grade
𝑣𝑐Comfortable walking speed
𝜂Total proportional decrease in quality from the first customer to the last
𝑟𝐵Weight of the food quality penalty relative to the time penalty
𝑟𝑉Weight of the speed penalty relative to the time penalty

The first eight quantities are obtained through observation or measurement; 𝑟𝐵,𝑟𝑉 are freely chosen personal preferences. The two arrays in params.example.toml specify the combinations of relative weights to evaluate.

7. Example Weight Table

The table below is populated automatically from results.example.csv, which is generated by the Rust program. Rows correspond to 𝑟𝐵 and columns to 𝑟𝑉; each cell lists the optimal departure time followed by the optimal speed (meters per minute).

𝑟𝐵\𝑟𝑉01248
012:23:13
160.0
12:23:13
160.0
12:22:30
136.1
12:21:45
117.6
12:21:01
104.0
0.512:23:13
160.0
12:23:13
160.0
12:22:30
136.1
12:21:45
117.6
12:21:01
104.0
112:23:13
160.0
12:23:13
160.0
12:22:30
136.1
12:21:45
117.6
12:21:01
104.0
212:01:56
160.0
12:01:56
160.0
12:01:13
136.1
12:00:28
117.6
11:59:45
104.0
512:01:56
160.0
12:01:56
160.0
12:01:13
136.1
12:00:28
117.6
11:59:45
104.0
View Typst source
#import "../../typ/shared.typ": *
#import "@preview/noteworthy:0.4.0": *
#import "/themes/site/notes.typ": *

#show: tylenotes.with(
  title: "Optimal Departure Time and Walking Speed for the Cafeteria",
  date: "2026-09-01",
  tags: ("model"),
  summary: "Balancing departure time and walking speed for a cafeteria visit: jointly minimizing queueing time, food quality loss, and penalties for excessive speed.",
)

= Problem

Students may only use the cafeteria floor assigned to their grade. Choose a departure time $t$ and average speed $v$ to minimize the sum of walking and queueing time, food quality loss, and a penalty for walking too fast.

The model makes the following assumptions:

- Arrival times for students in this grade follow a shifted lognormal distribution;
- The cafeteria's maximum service rate is constant;
- Food neither runs out nor is replenished during service;
- Food quality decreases continuously and linearly with the cumulative number of people served;
- The queue is first-come, first-served, and no one leaves before being served.

= Arrivals and Queueing

Let $c$ be the earliest possible arrival time, and let $N$ be the total number of students in this grade dining on this floor. The cumulative distribution function of arrival times is

$ F(a) = cases(
  0, & a <= c,
  Phi((ln(a-c)-m)/sigma), & a > c,
). $

The corresponding density is

$ f(a) = 1/((a-c) sigma sqrt(2 pi))
  exp(-((ln(a-c)-m)^2)/(2 sigma^2)), quad a > c. $

Thus, the expected number of arrivals by time $a$ is $N F(a)$. The maximum density is

$ f_max = exp(-m + sigma^2/2)/(sigma sqrt(2 pi)). $

Let the constant service rate be $mu$. If $N f_max <= mu$, no queue forms. Otherwise, the queue begins to form at time

$ u = c + exp(m-sigma^2-sigma sqrt(2 ln((N f_max)/mu))). $

The time $e>u$ at which the queue clears is the nontrivial solution of

$ N(F(e)-F(u)) = mu(e-u) $

This equation generally has no elementary closed-form solution, but it can be solved using one-dimensional bisection. The queueing time for an arrival at time $a$ is

$ w(a) = cases(
  0, & a <= u,
  N/mu (F(a)-F(u))-(a-u), & u < a and a < e,
  0, & a >= e,
). $

= Food Quality

Normalize the initial food quality to $1$. Suppose that quality has decreased by a total of $eta$ after all $N$ people have been served. The quality after serving $n$ people is then

$ S(n) = 1-eta n/N. $

Under the first-come, first-served approximation, someone arriving at time $a$ has approximately $N F(a)$ people ahead of them, so their food quality loss is

$ 1-S(N F(a)) = eta F(a). $

= Relative Weights

The original penalty function is

$ J(t,v)
= alpha (d/v + w(t+d/v))
+ beta eta F(t+d/v)
+ gamma ((v-v_c)_+/v_c)^2. $

Multiplying $alpha,beta,gamma$ by the same positive constant does not change the optimum. Thus, when $alpha>0$, it suffices to consider two relative weights:

$ r_B = beta/alpha, quad r_V = gamma/alpha. $

After dividing the objective function by $alpha$, the function used in the computation is

$ J_"rel"(t,v)
= d/v + w(t+d/v)
+ r_B eta F(t+d/v)
+ r_V ((v-v_c)_+/v_c)^2. $

This eliminates redundant entries in the three-dimensional table of weights. The configuration file fixes the time weight at $1$ and lists the desired values of $r_B$ and $r_V$ separately for tabulation.

= Solution

Set the arrival time to $a=t+d/v$, and define

$ H(a)=w(a)+r_B eta F(a), $

$ C(v)=d/v+r_V ((v-v_c)_+/v_c)^2. $

Then $J_"rel"(t,v)=H(a)+C(v)$. Within the interval $u<a<e$ during which the queue exists,

$ H'(a) = (N/mu + r_B eta) f(a)-1. $

Interior stationary points satisfy

$ f(a) = 1/(N/mu+r_B eta). $

To find the optimal arrival time, it suffices to compare the endpoints of the allowed interval, the queue clearance time $e$, and any stationary points lying in $(u,e)$.

When $v>v_c$ and $r_V>0$, the optimal speed satisfies

$ 2 r_V (v^*)^2(v^*-v_c) = d v_c^2. $

This cubic equation has a unique solution for $v>v_c$; clamp that solution to the allowed speed interval. If $r_V=0$, choose the maximum allowed speed. The final output is

$ (t^*,v^*) = (a^*-d/v^*, v^*). $

= Parameters

#table(
  columns: (auto, 1fr),
  table.header([Parameter], [Meaning]),
  [$N$], [Total number of students in this grade dining on this floor],
  [$c$], [Earliest possible arrival time at the cafeteria],
  [$m$], [Mean of $ln(a-c)$],
  [$sigma$], [Standard deviation of $ln(a-c)$],
  [$mu$], [Number of people served per minute while a queue exists],
  [$d$], [Actual travel distance from the departure point to the cafeteria floor assigned to this grade],
  [$v_c$], [Comfortable walking speed],
  [$eta$], [Total proportional decrease in quality from the first customer to the last],
  [$r_B$], [Weight of the food quality penalty relative to the time penalty],
  [$r_V$], [Weight of the speed penalty relative to the time penalty],
)

The first eight quantities are obtained through observation or measurement; $r_B,r_V$ are freely chosen personal preferences. The two arrays in `params.example.toml` specify the combinations of relative weights to evaluate.

= Example Weight Table

The table below is populated automatically from `results.example.csv`, which is generated by the Rust program. Rows correspond to $r_B$ and columns to $r_V$; each cell lists the optimal departure time followed by the optimal speed (meters per minute).

#let results = csv("results.example.csv", row-type: dictionary)
#let config = toml("params.example.toml")
#let quality-values = config.at("sweep").at("quality_over_time")
#let speed-values = config.at("sweep").at("speed_over_time")
#let cells = ()
#for (i, quality) in quality-values.enumerate() {
  cells.push([#quality])
  for (j, speed-weight) in speed-values.enumerate() {
    let row = results.at(i * speed-values.len() + j)
    cells.push([
      #(row.at("departure_clock")) \
      #(row.at("speed_display"))
    ])
  }
}

#table(
  columns: 1 + speed-values.len(),
  align: center,
  table.header(
    [$r_B backslash r_V$],
    ..speed-values.map(value => [#value]),
  ),
  ..cells,
)

Notes © zzj · Content: CC BY-SA 4.0 · Code: MIT · Built with Astro + Starlight