Skip to content

Commit

Permalink
fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Patel committed Dec 2, 2020
1 parent a8fe840 commit 5f3b7ad
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions screens/fcfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -331,4 +344,4 @@ export default class Fcfs extends InputTable {
);
}
}
}
}

0 comments on commit 5f3b7ad

Please sign in to comment.