experiment.py 1.2 KB

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