Menu

Wednesday, August 3, 2016

FCFS SCHEDULING CODES

PHP Program

FCFS(First Come First Serve) Scheduling 
And
Gantt Chart
PHP Program


<!--
   job[10][0]=id
   job[10][1]=bt
   job[10][2]=at
   job[10][3]=ft
   job[10][4]=tt
   job[10][5]=wt
-->
<?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;
             $job[$x][1]=$_POST['bt'.$x];
             $job[$x][2]=$_POST['at'.$x];
             $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++)
      {
        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[$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>Arrival Time</th>
            <th>Burst Time</th>
        </tr>
        <?php
        for($x=1;$x<=$count;$x++)
        {
        ?>
        <tr>
        <th><?php echo $x ?></th>
        <th><input type="text" id="at<?php echo $x; ?>" name="at<?php echo $x; ?>" placeholder="at<?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>  

2 comments:

  1. hi :) this is very helpful.. but can you pls explain/elaborate each variable that u used ? :) thank you so much..

    ReplyDelete
  2. The Casino Site Review 2021
    The luckyclub.live Casino Site is an online casino operated by Direx N.V. The site is regulated by the Malta Gaming Authority. It offers its players a safe, reputable,

    ReplyDelete