Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package ec2simulation
  2.  
  3. import rand "math/rand"
  4.  
  5. type Simulation struct {
  6. max_instances uint // Maximum number of instances that may be started
  7. clock *Clock // Simulation virtual time, starts at 0 and incremented by Tick()
  8. rand *rand.Rand // Psuedo-random number generator. Seed may be fixed to allow deterministic results
  9. chunks []*Chunk
  10. }
  11.  
  12. func NewSimulation(max_instances uint) *Simulation {
  13. sim := &Simulation{max_instances: max_instances}
  14. sim.clock = NewClock()
  15. sim.rand = rand.New(rand.NewSource(0))
  16.  
  17. return sim
  18. }
  19.  
  20. func (sim *Simulation) Run(duration uint) {
  21. for i := uint(0); i < duration; i++ {
  22. sim.step()
  23. }
  24. }
  25.  
  26. func (sim *Simulation) AddChunks(count uint, duration_mean uint, duration_stddev float64) {
  27. for i := uint(0); i < count; i++ {
  28. // Create chunk with random duration specified by |duration_mean| and |duration_stddev|
  29. duration := uint(rand.NormFloat64() * duration_stddev + float64(duration_mean))
  30. sim.chunks = append(sim.chunks, NewChunk(sim.clock, duration))
  31. }
  32. }
  33.  
  34.  
  35. func (sim *Simulation) step() {
  36. sim.clock.Tick()
  37. }
Add Comment
Please, Sign In to add comment