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 = 1;
- 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);
- }
- timeModelling()
- {
- let aim = 300;
- let genTime = this.generator.next();
- let op1Time = 0;
- let op2Time = 0;
- let op3Time = 0;
- let st1Time = 0;
- let st2Time = 0;
- let amount = 0;
- let broken = 0;
- let currentTime = 0;
- while (this.count < aim)
- {
- if (currentTime >= op1Time && this.op1.work)
- {
- this.queue1.push(1);
- this.op1.work = false;
- }
- if (currentTime >= op2Time && this.op2.work)
- {
- this.queue1.push(1);
- this.op2.work = false;
- }
- if (currentTime >= op3Time && this.op3.work)
- {
- this.queue2.push(1);
- this.op3.work = false;
- }
- if (amount != 300)
- {
- if (currentTime >= genTime)
- {
- genTime = currentTime + this.generator.next();
- amount++;
- if (this.op1.work)
- {
- if (this.op2.work)
- {
- if (this.op3.work)
- broken++;
- else
- {
- this.op3.work = true;
- op3Time = currentTime + this.op3.next();
- }
- }
- else
- {
- this.op2.work = true;
- op2Time = currentTime + this.op2.next();
- }
- }
- else
- {
- this.op1.work = true;
- op1Time = currentTime + this.op1.next();
- }
- }
- }
- if(currentTime >= st1Time)
- {
- 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Время работы: ", currentTime, "\nВероятность отказа: ", (broken/amount)*100, "%");
- break;
- }
- }
- if (this.queue1.length > 0)
- {
- if (!this.st1.work)
- {
- st1Time = currentTime + this.st1.next;
- this.st1.work = true;
- }
- }
- }
- if(currentTime >= st2Time)
- {
- 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Время работы: ", currentTime, "\nВероятность отказа: ", (broken/amount)*100, "%");
- break;
- }
- }
- if (this.queue2.length > 0)
- {
- if (!this.st2.work)
- {
- st2Time = currentTime + 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Время работы: ", currentTime, "\nВероятность отказа: ", (broken/amount)*100, "%");
- break;
- }
- currentTime += this.dt;
- }
- }
- }
- function calculate()
- {
- let system = new System();
- system.timeModelling();
- }
- calculate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement