Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. Number.prototype.round = function (places) {
  2. return +(Math.round(this + "e+" + places) + "e-" + places);
  3. }
  4.  
  5. // Condiciones iniciales
  6. var ac1 = 0
  7. var ac2 = 0
  8. var sto1 = 0
  9. var sto2 = 0
  10. var ste1 = 0
  11. var ste2 = 0
  12. var sta1 = 0
  13. var sta2 = 0
  14. var t = 0
  15. var tpll = 0
  16. var cq1 = 0
  17. var cq2 = 0
  18. var carr1 = 0
  19. var carr2 = 0
  20. var tc1 = 0
  21. var tc2 = 0
  22. var cll1 = 0
  23. var cll2 = 0
  24.  
  25. var tf = 100
  26. var count = 1
  27.  
  28. function imprimirVector() {
  29. console.log(`T = ${t}, TC1 = ${tc1}, TC2 = ${tc2}, CLL1 = ${cll1}, CLL2 = ${cll2}, STA1 = ${sta1}, STA2 = ${sta2}, STE1 = ${ste1}, STE2 = ${ste2}, STO1 = ${sto1}, STO2 = ${sto2}`)
  30. console.log(`TPLL = ${tpll}`)
  31. }
  32.  
  33. class ArrepentidoError extends Error { }
  34.  
  35. function getIa() {
  36. const unIa = (3 + Math.random() * (15 - 3)).round(0);
  37. console.log(`IA generado = ${unIa}`)
  38. return unIa
  39. }
  40.  
  41. function getTa() {
  42. const unTa = (5 + Math.random() * (50 - 5)).round(0);
  43. console.log(`TA generado = ${unTa}`)
  44. return unTa
  45. }
  46.  
  47. function llegada1() {
  48. console.log("Llegó a cola 1")
  49. cll1++
  50. const ta = getTa();
  51. if (tc1 > t) {//estaba ocupado
  52. ste1 = ste1 + tc1 - t
  53. tc1 = tc1 + ta
  54. } else {//estaba libre
  55. sto1 = sto1 + t - tc1
  56. tc1 = t + ta
  57. }
  58.  
  59. sta1 = sta1 + ta
  60. }
  61.  
  62.  
  63. function llegada2() {
  64. console.log("Llegó a cola 2")
  65. cll2++
  66. const ta = getTa();
  67. if (tc2 > t) {//estaba ocupado
  68. ste2 = ste2 + tc2 - t
  69. tc2 = tc2 + ta
  70. } else {//estaba libre
  71. sto2 = sto2 + t - tc2
  72. tc2 = t + ta
  73. }
  74.  
  75. sta2 = sta2 + ta
  76. }
  77.  
  78.  
  79. function arr1() {
  80. if (tc1 - t <= 10) {
  81. // se queda
  82. } else {
  83. if (t <= 25) {
  84. if (Math.random() <= 0.5) {//se queda
  85. if (tc1 - t >= 20) {
  86. cq1++
  87. }
  88. } else {
  89. carr1++
  90. throw new ArrepentidoError('Se arrepintió en cola 1 :(')
  91. }
  92. } else {
  93. carr1++
  94. throw new ArrepentidoError('Se arrepintió en cola 1 :(')
  95. }
  96. }
  97. }
  98.  
  99.  
  100. function arr2() {
  101. if (tc2 - t <= 10) {
  102. // se queda
  103. } else {
  104. if (t <= 25) {
  105. if (Math.random() <= 0.5) {//se queda
  106. if (tc2 - t >= 20) {
  107. cq2++
  108. }
  109. } else {
  110. carr2++
  111. throw new ArrepentidoError('Se arrepintió en cola 2 :(')
  112. }
  113. } else {
  114. carr2++
  115. throw new ArrepentidoError('Se arrepintió en cola 2 :(')
  116. }
  117. }
  118. }
  119.  
  120. function desempate() {
  121. if (ac1 < 3) { // va a cola 1
  122. ac1++
  123. ac2 = 0
  124. arr1()
  125. llegada1()
  126. } else {
  127. if (ac2 < 4) {// va a cola 2
  128. ac2++
  129. arr2()
  130. llegada2()
  131. } else { // va a cola 1
  132. ac1 = 1
  133. ac2 = 0
  134. arr1()
  135. llegada1()
  136. }
  137. }
  138. }
  139.  
  140. imprimirVector()
  141. console.log('')
  142. while (t <= tf) {
  143. debugger
  144. t = tpll
  145. console.log(`- Evento llegada a las T = ${t}`)
  146. const ia = getIa()
  147. tpll = t + ia
  148. try {
  149. if (tc1 <= tc2) {
  150. if (tc1 == tc2) {
  151. desempate()
  152. } else {//cola 1
  153. arr1()
  154. llegada1()
  155. }
  156. } else {
  157. arr2()
  158. llegada2()
  159. }
  160. } catch (err) {
  161. if (err instanceof ArrepentidoError) {
  162. console.log(err.message)
  163. } else {
  164. throw err
  165. }
  166. }
  167. imprimirVector()
  168. console.log('')
  169. }
  170.  
  171. console.log('Resultados:')
  172. console.log(`PPS1 = ${(sta1 + ste1) / cll1}`)
  173. console.log(`PPS2 = ${(sta2 + ste2) / cll2}`)
  174. console.log(`PEC1 = ${ste1 / cll1}`)
  175. console.log(`PEC2 = ${ste2 / cll2}`)
  176. console.log(`PTO1 = ${sto1 / tc1 * 100} %`)
  177. console.log(`PTO2 = ${sto2 / tc2 * 100} %`)
  178. console.log(`PQ1 = ${cq1 / cll1 * 100} %`)
  179. console.log(`PQ2 = ${cq2 / cll2 * 100} %`)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement