///|
/// A fixed population of terminals visits a CPU, disk and parallel delay.
/// One class only; FCFS centers are single exponential servers, not M/M/c.
fn main raise {
  let model : @queue.ClosedNetwork = {
    centers: [@queue.Fcfs(0.05), @queue.Fcfs(0.08), @queue.Delay(0.2)],
    visits: [2.0, 1.0, 1.0],
    think_time: 1.0,
  }
  let curve = model.population_curve(20)
  let selected = model.population_for_throughput(6.0, 20)
  assert_true(selected.throughput >= 6.0)
  assert_true(curve[selected.population - 1].throughput < 6.0)
  for point in curve {
    // The CPU demand 2*0.05 bounds throughput by 10 completions/second.
    assert_true(point.throughput <= 10.0 + 1.0e-10)
    assert_true(point.conservation_residual < 1.0e-8)
    let mut accounted = point.mean_think_population
    for center in point.centers {
      accounted += center.mean_jobs
    }
    assert_true((accounted - point.population.to_double()).abs() < 1.0e-8)
  }
  println("minimal_population=" + selected.to_json().stringify())
  println("population20=" + curve[20].to_json().stringify())
  // Sensitivity: CPU demand halved while visits and think time stay fixed.
  let faster : @queue.ClosedNetwork = {
    centers: [@queue.Fcfs(0.025), @queue.Fcfs(0.08), @queue.Delay(0.2)],
    visits: [2.0, 1.0, 1.0],
    think_time: 1.0,
  }
  assert_true(faster.analyze_population(20).throughput > curve[20].throughput)
  println("faster_CPU=" + faster.analyze_population(20).to_json().stringify())
}