title: Problem in sorting non dominated pairs of a set of points
body: <p>I wrote non dominated sorting algorithm in php based on the NSGA II algorithm. The portion of the code is given below</p>
  <pre><code>function fast_non_dominated_sort($values1, $values2)
  {
      
      $S= [];
      for($i=0; $i&lt;sizeof($values1); $i++)
          $S[$i]= [];
  
      $front=[[]];
      $n= [];
      $rank= [];
  
      for($i=0;$i&lt;sizeof($values1); $i++)
      {
          $n[$i]=0;
          $rank[$i]=0;
      }
      
  
      for($p=0;$p&lt;sizeof($values1); $p++)
      {
          $S[$p]=[];
          $n[$p]=0;
          for($q=0;$q&lt;sizeof($values1); $q++)
          {
  
              if(($values1[$p] &gt; $values1[$q] &amp;&amp; $values2[$p] &gt; $values2[$q]) || ($values1[$p] &gt;= $values1[$q] &amp;&amp; $values2[$p] &gt; $values2[$q]) || ($values1[$p] &gt; $values1[$q] and $values2[$p] &gt;= $values2[$q]))                                                                                              
                  if(!in_array($q, $S[$p]))
                      array_push($S[$p], $q);
  
  
              elseif(($values1[$q] &gt; $values1[$p] &amp;&amp; $values2[$q] &gt; $values2[$p]) || ($values1[$q] &gt;= $values1[$p] &amp;&amp; $values2[$q] &gt; $values2[$p]) || ($values1[$q] &gt; $values1[$p] &amp;&amp; $values2[$q] &gt;= $values2[$p]))
                  $n[$p]=$n[$p]+1;
  
          }
  
          if($n[$p]==0)
          {
              $rank[$p]=0;
              if(!in_array($p, $front[0]))
                  array_push($front[0], $p);
          }
  
      }
      
      
      $i=0;
      while($front[$i]!=[])
      {
          $Q=[];
  
          foreach($front[$i] as $p)
          {
              foreach($S[$p] as $q)
              {
                  $n[$q]=$n[$q]-1;
                  if($n[$q]==0)
                  {
                      $rank[$q]=$i+1;
                      if(!in_array($q, $Q))
                          array_push($Q, $q);
                  }   
              }
          }
  
          $i=$i+1;
          array_push($front, $Q);
      }
  
      unset($front[sizeof($front)-1]);
      return $front;
  }
  
  
  $x_values=[190, 180, 165, 160];
  $y_values=[80, 85, 70, 22];
  
  
  $result=fast_non_dominated_sort($x_values, $y_values);
  </code></pre>
  <p>The returned sorted points are [[0,1,2,3]]. However the result should have been [[0,1], [2], [3]]. Can anybody help me find out the bug in this code.</p>
  <p>Any help is appreciated. For further clarifications drop a comment.</p>