my_test_data.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. from entity import *
  2. import random
  3. import numpy as np
  4. from sklearn.mixture import GMM
  5. max_x = 30
  6. max_y = 30
  7. graph_xy = []
  8. for x in range(max_x):
  9. for y in range(max_y):
  10. graph_xy.append((x,y))
  11. random.shuffle(graph_xy)
  12. # def test_orders():
  13. # order_list = [[] for _ in range(144)]
  14. # id = 0
  15. # for t in range(1,145):
  16. # step = 5
  17. # more_1 = random.randint(900,1200)
  18. # more_2 = random.randint(1300,1600)
  19. # less_1 = random.randint(900,1200)
  20. # for i in range(step):
  21. # step_list = []
  22. # if 69 <= t <= 78 or 105 <= t <= 114:
  23. # for i in range(more_1//step):
  24. # to_x = random.randint(0, 29)
  25. # to_y = random.randint(0, 29)
  26. # x = random.randint(0, 29)
  27. # y = random.randint(0, 29)
  28. # order = Order(id, x, y, to_x, to_y, t)
  29. # step_list.append(order)
  30. # id += 1
  31. # for i in range(more_2//step):
  32. # to_x = random.randint(0, 29)
  33. # to_y = random.randint(0, 29)
  34. # x = random.randint(18, 24)
  35. # y = random.randint(18, 24)
  36. # order = Order(id, x, y, to_x, to_y, t)
  37. # step_list.append(order)
  38. # id += 1
  39. # else:
  40. #
  41. # for i in range(less_1//step):
  42. # to_x = random.randint(0, 29)
  43. # to_y = random.randint(0, 29)
  44. # x = random.randint(0, 29)
  45. # y = random.randint(0, 29)
  46. # order = Order(id , x, y, to_x, to_y, t)
  47. # step_list.append(order)
  48. # id += 1
  49. # order_list[t-1].append(step_list)
  50. # save(order_list,"test_orders.pkl")
  51. def test_orders2():
  52. order_list = [[] for _ in range(144)]
  53. id = 0
  54. for t in range(1,145):
  55. more_1 = random.randint(800,900)
  56. # more_2 = random.randint(1300,1600)
  57. less_1 = random.randint(750,850)
  58. if 69 <= t <= 78 or 105 <= t <= 114:
  59. for i in range(more_1):
  60. to_xy = random.choice(graph_xy)
  61. to_x = to_xy[0]
  62. to_y = to_xy[1]
  63. xy = random.choice(graph_xy)
  64. x = xy[0]
  65. y = xy[1]
  66. order = Order(id, x, y, to_x, to_y, t)
  67. order_list[t-1].append(order)
  68. id += 1
  69. # for i in range(more_2):
  70. # to_x = random.randint(0, 29)
  71. # to_y = random.randint(0, 29)
  72. # x = random.randint(18, 24)
  73. # y = random.randint(18, 24)
  74. # order = Order(id, x, y, to_x, to_y, t)
  75. # order_list[t - 1].append(order)
  76. # id += 1
  77. else:
  78. for i in range(less_1):
  79. to_xy = random.choice(graph_xy)
  80. to_x = to_xy[0]
  81. to_y = to_xy[1]
  82. xy = random.choice(graph_xy)
  83. x = xy[0]
  84. y = xy[1]
  85. order = Order(id , x, y, to_x, to_y, t)
  86. order_list[t-1].append(order)
  87. id += 1
  88. # 模拟早晚高峰
  89. gmm = GMM(n_components=2)
  90. gmm.weights_ = np.array([1 / 3, 2 / 3])
  91. gmm.means_ = np.array([[8, 8, 75],
  92. [20, 20, 110]])
  93. gmm.covars_ = np.array([[4, 4, 5],
  94. [4, 4, 5]])
  95. samp = gmm.sample(19100)
  96. # print(samp)
  97. for s in samp:
  98. x = int(round(s[0]))
  99. y = int(round(s[1]))
  100. t = int(round(s[2]))
  101. to_xy = random.choice(graph_xy)
  102. to_x = to_xy[0]
  103. to_y = to_xy[1]
  104. order = Order(id, x, y, to_x, to_y, t)
  105. order_list[t - 1].append(order)
  106. id+=1
  107. n = 0
  108. for o in order_list:
  109. print(n,len(o))
  110. n+=1
  111. new_order_list = [[] for _ in range(144)]
  112. for i in range(len(order_list)):
  113. ol = order_list[i]
  114. step = len(ol)//4
  115. random.shuffle(ol)
  116. start = 0
  117. for _ in range(4):
  118. step_list = ol[start:start+step]
  119. new_order_list[i].append(step_list)
  120. start += step
  121. save(new_order_list,"test_orders05.pkl")
  122. def test_drivers():
  123. drivers_list = []
  124. for i in range(6000):
  125. d_xy = random.choice(graph_xy)
  126. d_x = d_xy[0]
  127. d_y = d_xy[1]
  128. driver = Driver(i, d_x, d_y,time=1)
  129. drivers_list.append(driver)
  130. save(drivers_list, "test_drivers.pkl")
  131. if __name__ == '__main__':
  132. # test_orders()
  133. test_drivers()
  134. test_orders2()
  135. # test_orders2()
  136. # test_drivers2()
  137. pass