From 5f3b7ad52e1f0170a2a3f7f7995ff12d5f0efb92 Mon Sep 17 00:00:00 2001 From: Vivek Patel Date: Wed, 2 Dec 2020 16:33:27 +0530 Subject: [PATCH] fixed a bug --- screens/fcfs.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/screens/fcfs.js b/screens/fcfs.js index 47bc40c..35a8f90 100644 --- a/screens/fcfs.js +++ b/screens/fcfs.js @@ -172,15 +172,9 @@ export default class Fcfs extends InputTable { this.getIoEnabledAnswer(state); return; } - var tuple = []; + var tuple = [], + tuple_temp = []; var newState = state; - /*var tuple = [ - {pid:1,bt:6,art:2}, - {pid:2,bt:3,art:5}, - {pid:3,bt:8,art:1}, - {pid:4,bt:3,art:0}, - {pid:5,bt:4,art:4}, - ];*/ var n = state.tableData.length; for (let i = 0; i < n; i++) { var tempPid = state.tableData[i][0].substring(1); @@ -190,9 +184,18 @@ export default class Fcfs extends InputTable { bt: parseInt(state.tableData[i][2]), art: parseInt(state.tableData[i][1]), }); + tuple_temp.push({ + pid: tempPid, + bt: parseInt(state.tableData[i][2]), + art: parseInt(state.tableData[i][1]), + }); // console.log(tuple); } - var tuple_temp = tuple; + // var tuple = [ + // { pid: 1, bt: 5, art: 2 }, + // { pid: 2, bt: 1000, art: 3 }, + // { pid: 3, bt: 100, art: 2 }, + // ]; tuple.sort(function (a, b) { if (a.art == b.art) { return a.bt - b.bt; @@ -213,6 +216,7 @@ export default class Fcfs extends InputTable { var que = []; // running queue var state = 0; var flag = 0; + var count = 0; for (var i = 0; i < 10000; i++) { visited[state]++; if (tuple[state].art > i) { @@ -244,6 +248,7 @@ export default class Fcfs extends InputTable { } for (var k = i; k < i + tuple[state].bt; k++) { var smit = []; + count++; for (var y = 0; y < n; y++) { if (tuple[y].art <= k && visited[y] <= 1) { smit.push(tuple[y].pid); @@ -257,6 +262,7 @@ export default class Fcfs extends InputTable { } } } + var cmp_time = []; //completion time for (var i = 0; i < tuple.length; i++) { cmp_time[i] = -1; @@ -265,13 +271,20 @@ export default class Fcfs extends InputTable { if (final_ans[i] === "/") { } else { if (cmp_time[final_ans[i] - 1] == -1) { + console.log("hey " + i + " hry" + final_ans[i]); cmp_time[final_ans[i] - 1] = i + 1; } } } for (var i = 0; i < n; i++) { + //console.log("cm "+cmp_time[i]); + } + for (var i = 0; i < n; i++) { + //console.log(cmp_time[i]+" cm "+tuple_temp[i].art); tat[i] = cmp_time[i] - tuple_temp[i].art; - wt[i] = tat[i] - tuple[i].bt; + //console.log(tat[i]+" tat "+tuple_temp[i].bt); + wt[i] = tat[i] - tuple_temp[i].bt; + console.log(tat[i] + " " + wt[i]); } for (var i = 0; i < n; i++) { total_wt = total_wt + wt[i]; @@ -331,4 +344,4 @@ export default class Fcfs extends InputTable { ); } } -} \ No newline at end of file +}