PHP Program
SJF(Shortest Job First) Scheduling
And
Gantt Chart
<?php
$count=1;
$count2=0;
$count3=0;
$flag=0;
$ATT=0;
$AWT=0;
$hold=0;
$hold2=0;
if(isset($_POST["submit"]))
{
$count=$_POST['count'];
}
if(isset($_POST["solve"]))
{
for($x=1;$x<=$count;$x++)
{
$count=$_POST['count'];
$job[$x][0]=$x;
$sort[$x]=$x;
$job[$x][1]=$_POST['bt'.$x];
$job[$x][2]=0;
$flag=1;
}
}
?>
<form method="post">
Number of Jobs:<input type="text" name="count" id="count" placeholder="count" value="<?php echo $count; ?>"><br><br>
<input type="submit" id="submit" placeholder="submit" name="submit" value="Submit">
<br>
<input type="submit" name="solve" id="solve" placeholder="solve" value="Solve">
<br>
<br>
<?php
if($flag==1)
{
for($x=1;$x<=$count;$x++)
{
for($y=1;$y<=$count;$y++)
{
if($job[$y+1][1]<$job[$y][1] && $y<$count)
{
$temp2=$job[$y][1];
$job[$y][1]=$job[$y+1][1];
$job[$y+1][1]=$temp2;
$temp1=$job[$y][0];
$job[$y][0]=$job[$y+1][0];
$job[$y+1][0]=$temp1;
}
$temp1=0;
$temp2=0;
}
}
for($x=1;$x<=$count;$x++)
{
if($count2<$job[$x][2])
{
$count2=$job[$x][2];
}
$hold=$count2+$job[$x][1];
for($y=$count2;$y<$hold;$y++)
{
$count2++;
}
$job[$x][3]=$count2;
$job[$x][4]=$job[$x][3]-$job[$x][2];
$job[$sort[$x]][5]=$job[$x][4]-$job[$x][1];
$ATT=$ATT+$job[$x][4];
$AWT=$AWT+$job[$x][5];
}
$ATT=$ATT/$count;
$AWT=$AWT/$count;
$job[0][3]=0;
for($x=1;$x<=$count;$x++)
{
?>
Job:<?php echo $job[$x][0]; ?> :
<?php
for($y=1;$y<=$job[$x][3];$y++)
{
if($job[$x][2]>$job[$x-1][3])
{
$hold2=$job[$x][2];
}
else
{
$hold2=$job[$x-1][3];
}
if(($y>$hold2 AND $x!=1) OR $x==1)
{
?>
<font style="background-color:#62<?php echo $x;?>4<?php echo $x;?>5" color="#62<?php echo $x;?>4<?php echo $x;?>5" > <?php echo $x;?> </font>
<?php } else { ?>
<font style="background-color:#FFFFFF" color="#FFFFFF"><?php echo $x;?></font>
<?php
}
}
?>
<br>
<?php
}
?>
<br>
<br>
Average Turnaround Time: <?php echo $ATT; ?> <br>
Average Waiting Time: <?php echo $AWT; ?> <br>
<table border="1">
<tr>
<th>JobID</th>
<th>Burst Time</th>
<th>Arrival Time</th>
<th>Finish Time</th>
<th>Turnaround Time</th>
<th>Waiting Time</th>
</tr>
<?php
for($x=1;$x<=$count;$x++)
{
?>
<tr>
<th><?php echo $job[$x][0]; ?></th>
<th><?php echo $job[$x][1]; ?></th>
<th><?php echo $job[$x][2]; ?></th>
<th><?php echo $job[$x][3]; ?></th>
<th><?php echo $job[$x][4]; ?></th>
<th><?php echo $job[$x][5]; ?></th>
</tr>
<?php }} else { ?>
<table border="1">
<tr>
<th>JobID</th>
<th>Burst Time</th>
</tr>
<?php
for($x=1;$x<=$count;$x++)
{
?>
<tr>
<th><?php echo $x ?></th>
<th><input type="text" id="bt<?php echo $x; ?>" name="bt<?php echo $x; ?>" placeholder="bt<?php echo $x; ?>"></th>
</tr>
<?php }} ?>
</table>
</form>
No comments:
Post a Comment