Topic: PHP Help

I'm in MSc IT  and I'm doing project on timetable scheduling using genetic algorithm as my final year project. I have developed the code for it but the problem is timetable is not getting displayed. Please help. Urgent

this is the action.php file in which genetic algorithm is there which should generate the timetable but this code only generates days and subjects in the timetable is not generated.I have also attached the html file first run the tableform.htm and give inputs as no of hours of lecture:6,max lecture per week:8,max lec per day:3 and num of generation:2

<?php
//Declaration
      $TotalRooms=2;
      $Generation=0;
      //$lec = array();
    //$Rooms = array();
        list() = $Rooms ;
        $LengthOfPool=$TotalRooms*4;
        $DaysInWeek=6;
        $count=0;
        $lec1=array();
        list()=$lec1;
                
               $get_noofhoursperday=$_POST['noofhoursperday'];
               $get_maxlectperweek=$_POST['maxlectperweek'];
               $get_maxlectperday=$_POST['maxlectperday'];
               $get_genno=$_POST['genno'];
           
            echo "NO Of Hours Per Day : ".$get_noofhoursperday."<br>";
            echo "Max Lec Per Week : ".$get_maxlectperweek."<br>";
            echo "Max Lec PerDay : ".$get_maxlectperday."<br>";
            echo " Number Of Gen : ".$get_genno."<br>";
   
             //$p=preg_match('','');
             //$p=re.compile(r'\n');
            //$p=re.split(r'\n','');
               //$p= eval('r',\n');
            //file opening
            $subject = "subjects.txt";
             $f = fopen($subject, 'r');
        while (!feof($f))
        {
          //echo "asdsd<br>";
          //$sub=$p.preg_replace( '','','');
           //$sub=$p.preg_replace('','','');
          //$sub=p.sub('',a);
          $sub = fgets($f);
          $lec1[$count]=$sub;
        //$TotalLectures=count($lec1);
        $count=$count+1;
        //exit();
        }

    /* echo "<pre>";
           pr3int_r($lec1);
    echo "</pre>"; */

  Prints(1,2);
   
function Prints ($Room1,$Room2)
{
    $R=array();
    array_push($R,$Room1);
    //$R.($Room1);
    array_push($R,$Room2);
   // $R.($Room2);
            foreach( $R as $eachroom )
              {
                 echo (" ");
                 echo (" ");
                 $i= 9;
                 echo " ";
                 echo "<br>";
                 echo ("Div No : ".$eachroom)."<br>";
                
echo ("---------------------------------------------------------------------------------------------------------------------------------------");

echo ("<br />");
           
echo (" Time '\t\t\t\t\t\t\t\t\t' Mon '\t\t\t\t\t' Tue '\t\t\t\t\t' Wed '\t\t\t\t\t\t' Thu '\t\t\t\t\t' Fri '\t\t\t\t\t'  Sat '\t\t\t\t\t' ");
echo ("<br />");
echo ("--------------------------------------------------------------------------------------------------------------------------------------");
               

  for($h=1;$h<=$get_noofhoursperday;$h++)
              {
           
                if ($i==12)
                {
                   echo ("Lunch Break");
                   echo ("<br />");
                   echo(" ");
                
                    
                  $i=1;
                 //echo ($i,$i+1);
                    echo "$i $i+1 ";

                      
                }
                $i=$i+1;
                       for($d=1; $d<=$DaysInWeek;$d++)
                        {
                         if ($eachroom[$d][$h]==0)
                          echo(" ");
                           for($l=0;$l<=$lec1;$l++)
                           {
                             if ($l[1]==$eachroom[$d][$h])
                                echo ($l[0]);
                            }
            }
        }
    }
}
   
function  CreatePool($Rooms,$LengthOfPool)
           {
           for ($no=1;$no<=$LengthOfPool;$no++)
            {
              // Original  $room=[[0]* $get_noofhoursperday for($i=1; $i<=$DaysInWeek;$i++)];
      
               for($i=1; $i<=$DaysInWeek;$i++)
                $room[]= ($get_noofhoursperday*$i);
        
                $a=array();
                 foreach($a as $b)
                  $room=$get_noofhoursperday*$b;
                   $Rooms.append($room);
                    foreach($room as $Rooms)   
                 {
                     for($d=1;$d<=$DaysInweek;$d++)
                     {
                       for($h=1;$h<= $get_noofhoursperday;$h++)
                        $room[$d][$h]=rand(1,$TotalLectures);
                }         
          }
      }
    return $Rooms;
}


                       function BreedNew($Rooms)
                         {
                         // $room=[[0]*$HoursInDay for( $i=1;$i<=$DaysInWeek;$i++)];
                          for( $i=1;$i<=$DaysInWeek;$i++)
                            $room[]= ($HoursInDay*$i);
                           
                           
                              for($d=1;$d<=$DaysInWeek;$d++)
                              {
                             for( $h=1; $h<= $get_noofhoursperday;$h++)
                              {
                               $room[$d][$h]=rand(1,$TotalLectures);
                                $Rooms.append($room);
                       }
               }
       }


                         function FitnessOfRoom($Rooms)
                          {
                           global $Generation;
                            $Generation=$Generation+1;
                             echo( "Generation no = " +strval($Generation));
                               foreach($room as $Rooms)
                                {
                                 $RoomFit=100;
                                    for($d=1;$d<=$DaysInWeek;$d++)
                                      {       
                                       for($h=1;$h<=$get_noofhoursperday;$h++)
                                        {   
                                          if ($room[$d].count($room[$d][$h])>$get_maxlectperday)
                                             {
                                              $RoomFit=$RoomFit-5;
                                                break;
                                              }
                                              if($RoomFit!=100)
                                               {
                                               $Rooms.remove($room);
                                                BreedNew($Rooms);
                                            }
                                 }
                         }
               }
       return $Rooms;

           }


                     function CrossOver($Roooms)
                       {
                         global $Generation;
                           $Generation=$Generation+1;
                            //echo ("Generation no = " +str($Generation));
                               echo ("Generation no = " +strval($Generation));
                                  $CRate=(int)(count($Rooms)/2);
                                      // in php count is used   $CRate=(int)(count($Rooms)/2);
                                   $Cpoint=(int)($DaysInWeek/2 );
                                    $MRate=10;
   
                                 for($i=0;$i<=$CRate;$i++)
                                  {
                                   $a=rand(0,count($Rooms)-1);
                                   $b=rand(0,count($Rooms)-1);
                                  while( $a==$b)
                                     {
                                      $b=rand(0,count($Rooms)-1);
                                      $father=$Rooms[$a];
                                       $mother=$Rooms[$b];
                                        $child=array();
                                         $Rooms.remove($father);
                                         $Rooms.remove($mother);
                                          $child.extend($father[$Cpoint]);
                                          $child.extend($mother[$Cpoint]);
                                           $Rooms.append($child);

                                        while(count($Rooms<$LengthOfPool))
                                           {
                                             BreedNew($Rooms);
                                                if(rand(1,200)>$MRate)
                                                  Mutate();
                                            }   
                                    }
                            }
                }

   
                          function Mutate()
                           {
                             global $Rooms;
                               $randroom=rand(0,count($Rooms)-1);
                               $randday=rand(0,$DaysInWeek-1);
                                $randhour=rand(0, $get_noofhoursperday-1);
                                 $Rooms[$randroom][$randday][$randhour]=rand(1,$TotalLectures);
                          }
   
                         function  LecturesPerDayAndWeek($Room1,$Room2)
                           {
                           $R=array();
                            $R.append($Room1);
                             $R.append($Room2);
                              for($i=1;$i<=count($R);$i++)     
                              {   
                               for($val=1;$val<=$TotalLectures+1;$i++)
                                 {
                                 $WeekOccured=0;
                                 for($d=1;$d<=$DaysInWeek;$d++)
                                  {
                                   $occurred=0;
               
                                   for($h=1; $h<=$HoursInDay;$h++)
                                    {              
                                    if ($Rooms[$i][$d][$h]==$val)
                                     {
                                      $occurred=$occurred+1;
                                     $WeekOccured=$WeekOccured+1;
                                     if( $occurred >$get_maxlectperday)
                                     return true;
                                  }
                              if ($WeekOccured >$get_maxlectperweek)
                               return true;
                                 
                           }
                      }       
                 }               
             } 
                
  return false;
  }

                      function ClashOfRooms($Rooms)
                        {
                         for($i=1; $i<=count($Rooms)-1;$i++)
                          {
                           $p=$i+1;
                           while ($p!=count($Rooms))
                            {
                             $clash=false;
                              for($d=1;$d<=$DaysInWeek;$i++)
                              {           
                               for($h=1;$h<=$HoursInDay;$h++)
                                {
                                   if ($Rooms[$i][$d][$h]==$Rooms[$p][$d][$h])
                                 $clash=true;
                                  break;
                                  if ($clash==true)
                                     break;
                                    if ($clash==false)
                                     {
                                        if (LecturesPerDayAndWeek($Rooms[$i][$p])==0)
                                         echo $Rooms[$i],$Rooms[$p];
                                          return false;
                                     }
                                 }
                     $p=$p+1;
             CrossOver($Rooms);
             }
        }
    }
   return true;

  }

                      function Fitness($Rooms)
                       {
                        $Rooms=FitnessOfRoom($Rooms);
                          if(ClashOfRooms($Rooms)==0)
                           return false;
                             else
                             return true;
                             $Rooms=CreatePool($Rooms,$LengthOfPool);
                             $RET=true;
                              while($RET==true)
                              {
                              if(Fitness($Rooms)==0)
                               $RET=false;
                                echo(" ");
                                 echo(" ");
      
                        }
              }
?>

Last edited by jyotisi (June 10, 2011 01:46)

Thumbs up

Re: PHP Help

In recent years, online shopping has become popular; however, it still caters to the middle and upper class. In order to shop online, one must be able to have access to a computer, a bank account and a debit card. Shopping has evolved with the growth of technology. According to research found in the Journal of Electronic Commerce, if one focuses on the demographic characteristics of the in-home shopper, in general, the higher the level of education, income, and occupation of the head of the household, the more favourable the perception of non-store shopping., Enrique.(2005) The Impact of Internet User Shopping Patterns and Demographics on Consumer Mobile Buying Behaviour.
9L0-403 exam
NS0-154 exam
JN0-101 exam
1Z0-536 exam
220-702 exam
1Y0-A05 exam
HP0-S25 exam
1Y0-A24 exam

Thumbs up

Re: PHP Help

It is no question that you select to or any man or lady would really want to very own a hermes shop of the own. A hermes online is simply one belonging to some individual of the most favored and considered patterns through the process earth today.

Thumbs up