experiment.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from pypdevs.simulator import Simulator
  2. import random
  3. # Import the model we experiment with
  4. from system import QueueSystem
  5. # Configuration:
  6. # 1) number of customers to simulate
  7. num = 500
  8. # 2) average time between two customers
  9. time = 30.0
  10. # 3) average size of customer
  11. size = 20.0
  12. # 4) efficiency of processors (products/second)
  13. speed = 0.5
  14. # 5) maximum number of processors used
  15. max_processors = 10
  16. # End of configuration
  17. # Store all results for output to file
  18. values = []
  19. # Loop over different configurations
  20. for i in range(1, max_processors):
  21. # Make sure each of them simulates exactly the same workload
  22. random.seed(1)
  23. # Set up the system
  24. procs = [speed] * i
  25. m = QueueSystem(mu=1.0/time, size=size, num=num, procs=procs)
  26. # PythonPDEVS specific setup and configuration
  27. sim = Simulator(m)
  28. sim.setClassicDEVS()
  29. sim.simulate()
  30. # Gather information for output
  31. evt_list = m.collector.state.events
  32. values.append([e.queueing_time for e in evt_list])
  33. # Write data to file
  34. with open('output.csv', 'w') as f:
  35. for i in range(num):
  36. f.write("%s" % i)
  37. for j in range(len(values)):
  38. f.write(", %5f" % (values[j][i]))
  39. f.write("\n")