Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const random = require('random');
- class Storage {
- constructor(a)
- {
- this.work = false;
- this.next = a;
- }
- }
- class Operator {
- constructor(a, b)
- {
- this.work = false;
- this.a = a;
- this.b = b;
- }
- next()
- {
- return Math.round((Math.random() * (this.b - this.a + 1)) + this.a);
- }
- }
- class Generator {
- constructor(a, b)
- {
- this.a = a;
- this.b = b;
- }
- next()
- {
- return Math.round((Math.random() * (this.b - this.a + 1)) + this.a);
- }
- }
- class System {
- constructor()
- {
- this.dt = 0.001;
- this.count = 0;
- this.queue1 = [];
- this.queue2 = [];
- this.st1 = new Storage(15);
- this.st2 = new Storage(30);
- this.op1 = new Operator(15, 25);
- this.op2 = new Operator(30, 50);
- this.op3 = new Operator(20, 60);
- this.generator = new Generator(8, 12);
- }
- eventModelling()
- {
- let aim = 300;
- let genTime = this.generator.next();
- let op1Time = genTime + 0.1;
- let op2Time = genTime + 0.1;
- let op3Time = genTime + 0.1;
- let st1Time = genTime + 0.1;
- let st2Time = genTime + 0.1;
- let amount = 0;
- let broken = 0;
- while (this.count < aim)
- {
- if (!this.op1.work)
- op1Time = 99999;
- if (!this.op2.work)
- op2Time = 99999;
- if (!this.op3.work)
- op3Time = 99999;
- if (!this.st1.work)
- st1Time = 99999;
- if (!this.st2.work)
- st2Time = 99999;
- if (op1Time == Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime) && this.op1.work)
- {
- this.queue1.push(1);
- st1Time = op1Time;
- this.op1.work = false;
- }
- if (op2Time == Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime) && this.op2.work)
- {
- this.queue1.push(1);
- st1Time = op2Time;
- this.op2.work = false;
- }
- if (op3Time == Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime) && this.op3.work)
- {
- this.queue2.push(1);
- st2Time = op3Time;
- this.op3.work = false;
- }
- if (amount != 300)
- {
- if (genTime == Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime))
- {
- amount++;
- if (this.op1.work)
- {
- if (this.op2.work)
- {
- if (this.op3.work)
- broken++;
- else
- {
- this.op3.work = true;
- op3Time = genTime + this.op3.next();
- }
- }
- else
- {
- this.op2.work = true;
- op2Time = genTime + this.op2.next();
- }
- }
- else
- {
- this.op1.work = true;
- op1Time = genTime + this.op1.next();
- }
- genTime += this.generator.next();
- }
- }
- else
- genTime = 99999;
- if(st1Time == Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime) && this.queue1.length > 0)
- {
- if (this.st1.work)
- {
- this.count++;
- this.st1.work = false;
- this.queue1.pop();
- if (this.count == aim)
- {
- console.log("Количество отказов: ", broken,"\nКоличество поступивших заявок: ", amount, "\nКоличество обработанных заявок: ", this.count, "\nВремя работы: ", Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime), "\nВероятность отказа: ", (broken/amount)*100, "%");
- break;
- }
- }
- if (this.queue1.length > 0)
- {
- if (!this.st1.work)
- {
- st1Time = st1Time + this.st1.next;
- this.st1.work = true;
- }
- }
- }
- if(st2Time == Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime) && this.queue2.length > 0)
- {
- if (this.st2.work)
- {
- this.count++;
- this.st2.work = false;
- this.queue2.pop();
- if (this.count == aim)
- {
- console.log("Количество отказов: ", broken,"\nКоличество поступивших заявок: ", amount, "\nКоличество обработанных заявок: ", this.count, "\nВремя работы: ", Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime), "\nВероятность отказа: ", (broken/amount)*100, "%");
- break;
- }
- }
- if (this.queue2.length > 0)
- {
- if (!this.st2.work)
- {
- st2Time = st2Time + this.st2.next;
- this.st2.work = true;
- }
- }
- }
- if (amount == 300 && this.queue1.length == 0 && this.queue2.length == 0 && !this.op1.work && !this.op2.work && !this.op3.work)
- {
- console.log("Количество отказов: ", broken,"\nКоличество поступивших заявок: ", amount, "\nКоличество обработанных заявок: ", this.count, "\nВремя работы: ", Math.min(op1Time, op2Time, op3Time, st1Time, st2Time, genTime), "\nВероятность отказа: ", (broken/amount)*100, "%");
- break;
- }
- }
- }
- }
- function calculate()
- {
- let system = new System;
- system.eventModelling();
- }
- calculate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement