PHP Program
Round Robin Scheduling
And
Gantt Chart
<?php
$count=1;
$qt=1;
$count2=0;
$count3=0;
$flag=0;
$ATT=0;
$AWT=0;
$hold=0;
$hold2=0;
$timer=0;
$ctr=0;
if(isset($_POST["submit"]))
{
$count=$_POST['count'];
$qt=$_POST['qt'];
}
if(isset($_POST["solve"]))
{
$qt=$_POST['qt'];
$count=$_POST['count'];
for($x=1;$x<=$count;$x++)
{
$job[$x][0]=$x;
$job[$x][1]=$_POST['bt'.$x];
$job[$x][2]=0;
$job[$x][4]=0;
$holder[$x][2]=0;
$job[$x][1]=$job[$x][1];
$ctr=
$btc[$x]=$job[$x][1];
$sort[$x]=$job[$x][1];
$flag=1;
}
}
?>
<form method="post">
Number of Jobs:<input type="text" name="count" id="count" placeholder="count" value="<?php echo $count; ?>"><br><br>
Quantum Time:<input type="text" name="qt" id="qt" placeholder="qt" value="<?php echo $qt; ?>"><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)
{
$sort[$count+1]=$sort[$count] ;
for($x=1;$x<=$count;$x++)
{
for($y=1;$y<=$count;$y++)
{
if($sort[$y+1]<$sort[$y] && $y<$count)
{
$temp2=$sort[$y];
$sort[$y]=$sort[$y+1];
$sort[$y+1]=$temp2;
}
$temp1=0;
$temp2=0;
}
}
$sort[$count]=ceil($sort[$count]/$qt);
for($z=1;$z<=$sort[$count];$z++)
{
for($x=1;$x<=$count;$x++)
{
$qtc=$qt;
if($btc[$x]<=0)
{
}
else
{
if($qt>$btc[$x])
{
$qtc=$btc[$x];
}
$holder[$x][1]=$timer;
$recat[$x][$z]=$timer;
$recat[$x][$z+1]=0;
$timer=$timer+$qtc;
$btc[$x]=$btc[$x]-$qtc;
$job[$x][4]=$job[$x][4]+($holder[$x][1]-$holder[$x][2]);
$holder[$x][2]=$timer;
$recft[$x][$z]=$timer;
$recft[$x][$z+1]=0;
}
}
}
for($x=1;$x<=$count;$x++)
{
$job[$x][5]=$job[$x][4]-$job[$x][1];
$ATT=$ATT+$job[$x][4];
$AWT=$AWT+$job[$x][5];
}
$ATT=$ATT/$count;
$AWT=$AWT/$count;
for($x=1;$x<=$count;$x++)
{
$z=1;
?>
Job:<?php echo $job[$x][0]; ?> :
<?php
for($y=0;$y<=$timer;$y++)
{
if($recat[$x][$z]<$y AND $recft[$x][$z]>=$y){
?>
<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
} elseif($recft[$x][$z]<$y AND $recft[$x][$z]!=0) {
$z++;
?>
<font style="background-color:#FFFFFF" color="#FFFFFF"><?php echo $x;?></font>
<?php
} else {
?>
<font style="background-color:#FFFFFF" color="#FFFFFF"><?php echo $x;?></font>
<?php
}
}
echo "<br>";
}
?>
<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>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][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