Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. if (ringGraphics.roadway[ii].modified == false)
  2. {
  3.  
  4. // if the cell is one of the two at the turning point....
  5.  
  6. if ((ii == 0 || ii == ringGraphics.numberCells/2) && ringGraphics.roadway[ii].turningDecision == 0) {
  7.  
  8. // decide if the vehicle is going to turn or not
  9.  
  10. // if (Math.random() > percentTurn)
  11. // ringGraphics.roadway[ii].turningDecision = 1;
  12. // else
  13. // ringGraphics.roadway[ii].turningDecision = 2;
  14.  
  15. if (Math.random() > adaptiveness)
  16. {
  17. if (Math.random() > percentTurn)
  18. ringGraphics.roadway[ii].turningDecision = 1;
  19. else
  20. ringGraphics.roadway[ii].turningDecision = 2;
  21. }
  22. else
  23. {
  24. if (ii == 0)
  25. {
  26. if (ringGraphics.currentVehicles1 >= ringGraphics.currentVehicles2)
  27. {
  28. if (Math.random() > percentTurn)
  29. ringGraphics.roadway[ii].turningDecision = 1;
  30. else
  31. ringGraphics.roadway[ii].turningDecision = 2;
  32. }
  33. else
  34. ringGraphics.roadway[ii].turningDecision = 1;
  35. }
  36. else
  37. {
  38. if (ringGraphics.currentVehicles2 >= ringGraphics.currentVehicles1)
  39. {
  40. if (Math.random() > percentTurn)
  41. ringGraphics.roadway[ii].turningDecision = 1;
  42. else
  43. ringGraphics.roadway[ii].turningDecision = 2;
  44. }
  45. else
  46. ringGraphics.roadway[ii].turningDecision = 1;
  47. }
  48.  
  49. }
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. // logic for if the manual turning button is pushed
  59.  
  60. if (ii == 0 && turnLeftToRight == true)
  61. ringGraphics.roadway[ii].turningDecision = 2;
  62. if (ii == ringGraphics.numberCells/2 && turnRightToLeft == true)
  63. ringGraphics.roadway[ii].turningDecision = 2;
  64.  
  65. // decide what the destination cell is, depending on if the vehicle is turning or not
  66.  
  67. if (ringGraphics.roadway[ii].turningDecision < 2)
  68. next = ringGraphics.roadway[ii].nextCell;
  69. else
  70. next = ringGraphics.roadway[ii].turningCell1;
  71.  
  72. // if the cell is occupied, then add this to the time of vehicles in the system
  73.  
  74. if (ringGraphics.roadway[ii].occupied == true) {
  75. vehTimeTraveled++;
  76. if (ii < ringGraphics.numberCells/2)
  77. vehTimeTraveled1++;
  78. else
  79. vehTimeTraveled2++;
  80. }
  81.  
  82.  
  83. // move the vehicle if it can and add this movement to the total movement of vehicles in the system
  84.  
  85. if (ringGraphics.roadway[ii].occupied == true && ringGraphics.roadway[next].timeEmpty >= minEmptyTime-1 &&
  86. (ringGraphics.roadway[ii].cycle == 0 || ((ringGraphics.tt+ringGraphics.roadway[ii].offset) % ringGraphics.roadway[ii].cycle < ringGraphics.roadway[ii].green )))
  87. {
  88. ringGraphics.roadway[next].occupied = true;
  89. ringGraphics.roadway[next].timeEmpty = 0;
  90. ringGraphics.roadway[next].modified = true;
  91. ringGraphics.roadway[next].turningDecision = 0;
  92. ringGraphics.roadway[ii].turningDecision = 0;
  93. ringGraphics.roadway[ii].occupied = false;
  94. ringGraphics.roadway[ii].timeEmpty = 1;
  95. ringGraphics.roadway[ii].modified = true;
  96. vehDistTraveled++;
  97. if (ii < ringGraphics.numberCells/2)
  98. vehDistTraveled1++;
  99. else
  100. vehDistTraveled2++;
  101. }
  102.  
  103. // if the vehicles change rings, then change the count of vehicles on each ring
  104.  
  105. if (next == ringGraphics.roadway[ii].turningCell1 && ii == 0 && ringGraphics.roadway[ii].turningDecision == 0) {
  106. ringGraphics.currentVehicles1--;
  107. ringGraphics.currentVehicles2++;
  108. turnLeftToRight = false;
  109. }
  110. if (next == ringGraphics.roadway[ii].turningCell1 && ii == ringGraphics.numberCells/2 && ringGraphics.roadway[ii].turningDecision == 0) {
  111. ringGraphics.currentVehicles1++;
  112. ringGraphics.currentVehicles2--;
  113. turnRightToLeft = false;
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement