Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Number.prototype.round = function (places) {
- return +(Math.round(this + "e+" + places) + "e-" + places);
- }
- // Condiciones iniciales
- var ac1 = 0
- var ac2 = 0
- var sto1 = 0
- var sto2 = 0
- var ste1 = 0
- var ste2 = 0
- var sta1 = 0
- var sta2 = 0
- var t = 0
- var tpll = 0
- var cq1 = 0
- var cq2 = 0
- var carr1 = 0
- var carr2 = 0
- var tc1 = 0
- var tc2 = 0
- var cll1 = 0
- var cll2 = 0
- var tf = 100
- var count = 1
- function imprimirVector() {
- console.log(`T = ${t}, TC1 = ${tc1}, TC2 = ${tc2}, CLL1 = ${cll1}, CLL2 = ${cll2}, STA1 = ${sta1}, STA2 = ${sta2}, STE1 = ${ste1}, STE2 = ${ste2}, STO1 = ${sto1}, STO2 = ${sto2}`)
- console.log(`TPLL = ${tpll}`)
- }
- class ArrepentidoError extends Error { }
- function getIa() {
- const unIa = (3 + Math.random() * (15 - 3)).round(0);
- console.log(`IA generado = ${unIa}`)
- return unIa
- }
- function getTa() {
- const unTa = (5 + Math.random() * (50 - 5)).round(0);
- console.log(`TA generado = ${unTa}`)
- return unTa
- }
- function llegada1() {
- console.log("Llegó a cola 1")
- cll1++
- const ta = getTa();
- if (tc1 > t) {//estaba ocupado
- ste1 = ste1 + tc1 - t
- tc1 = tc1 + ta
- } else {//estaba libre
- sto1 = sto1 + t - tc1
- tc1 = t + ta
- }
- sta1 = sta1 + ta
- }
- function llegada2() {
- console.log("Llegó a cola 2")
- cll2++
- const ta = getTa();
- if (tc2 > t) {//estaba ocupado
- ste2 = ste2 + tc2 - t
- tc2 = tc2 + ta
- } else {//estaba libre
- sto2 = sto2 + t - tc2
- tc2 = t + ta
- }
- sta2 = sta2 + ta
- }
- function arr1() {
- if (tc1 - t <= 10) {
- // se queda
- } else {
- if (t <= 25) {
- if (Math.random() <= 0.5) {//se queda
- if (tc1 - t >= 20) {
- cq1++
- }
- } else {
- carr1++
- throw new ArrepentidoError('Se arrepintió en cola 1 :(')
- }
- } else {
- carr1++
- throw new ArrepentidoError('Se arrepintió en cola 1 :(')
- }
- }
- }
- function arr2() {
- if (tc2 - t <= 10) {
- // se queda
- } else {
- if (t <= 25) {
- if (Math.random() <= 0.5) {//se queda
- if (tc2 - t >= 20) {
- cq2++
- }
- } else {
- carr2++
- throw new ArrepentidoError('Se arrepintió en cola 2 :(')
- }
- } else {
- carr2++
- throw new ArrepentidoError('Se arrepintió en cola 2 :(')
- }
- }
- }
- function desempate() {
- if (ac1 < 3) { // va a cola 1
- ac1++
- ac2 = 0
- arr1()
- llegada1()
- } else {
- if (ac2 < 4) {// va a cola 2
- ac2++
- arr2()
- llegada2()
- } else { // va a cola 1
- ac1 = 1
- ac2 = 0
- arr1()
- llegada1()
- }
- }
- }
- imprimirVector()
- console.log('')
- while (t <= tf) {
- debugger
- t = tpll
- console.log(`- Evento llegada a las T = ${t}`)
- const ia = getIa()
- tpll = t + ia
- try {
- if (tc1 <= tc2) {
- if (tc1 == tc2) {
- desempate()
- } else {//cola 1
- arr1()
- llegada1()
- }
- } else {
- arr2()
- llegada2()
- }
- } catch (err) {
- if (err instanceof ArrepentidoError) {
- console.log(err.message)
- } else {
- throw err
- }
- }
- imprimirVector()
- console.log('')
- }
- console.log('Resultados:')
- console.log(`PPS1 = ${(sta1 + ste1) / cll1}`)
- console.log(`PPS2 = ${(sta2 + ste2) / cll2}`)
- console.log(`PEC1 = ${ste1 / cll1}`)
- console.log(`PEC2 = ${ste2 / cll2}`)
- console.log(`PTO1 = ${sto1 / tc1 * 100} %`)
- console.log(`PTO2 = ${sto2 / tc2 * 100} %`)
- console.log(`PQ1 = ${cq1 / cll1 * 100} %`)
- console.log(`PQ2 = ${cq2 / cll2 * 100} %`)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement