/**
  * Sorts the specified array of comparable objects
  * from "smallest" to "largest".
  * Calls the abstract <code>sort</code> method to do the actual sort.
  *
  * @param object BasicArray $array The array of objects to be sorted.
  */
 public function sort(BasicArray $array)
 {
     $this->n = $array->getLength();
     $this->array = $array;
     if ($this->n > 0) {
         $this->doSort();
     }
     $this->array = NULL;
 }
 public function __construct()
 {
     parent::__construct();
     $this->setName('DefinitionReader');
     $this->addTest(BasicArray::suite());
     $this->addTest(CssLike\CssLikeSuite::suite());
 }
 /**
  * Constructs a ScalesBalancingProblem
  * for the specified array of weights.
  *
  * @param weight An array of weights.
  */
 public function __construct(BasicArray $weights)
 {
     $this->weights = $weights;
     $this->numberOfWeights = $weights->getLength();
 }
 /**
  * Stores the specified value in this matrix at the specified indices.
  *
  * @param array $indices A set of indices.
  * @param mixed $datum The value to be stored.
  */
 public function offsetSet($indices, $datum)
 {
     if (!$this->offsetExists($indices)) {
         throw new IndexError();
     }
     $i = $indices[0];
     $j = $indices[1];
     $position = $this->findPosition($i, $j);
     if ($position >= 0) {
         $this->array[$position]->setDatum($datum);
     } else {
         if ($this->array->getLength() == $this->numberOfElements) {
             $newArray = new BasicArray(2 * $this->array->getLength());
             for ($k = 0; $k < $this->array->getLength(); ++$k) {
                 $newArray[$k] = $this->array[$k];
             }
             for ($k = $this->array->getLength(); $k < $newArray->getLength(); ++$k) {
                 $newArray[$k] = new SparseMatrixAsVector_Entry();
             }
             $this->array = $newArray;
         }
         $k = $this->numberOfElements;
         while ($k > 0 && ($this->array[$k - 1]->getRow() > $i || $this->array[$k - 1]->getRow() == $i && $this->array[$k - 1]->getColumn() >= $j)) {
             $this->array[$k] = $this->array[$k - 1];
             --$k;
         }
         $this->array[$k] = new SparseMatrixAsVector_Entry($i, $j, $datum);
         ++$this->numberOfElements;
     }
 }
 /**
  * Constructs a ZeroOneKnapsackProblem
  * with the specified weights, profits and capacity.
  *
  * @param object BasicArray $weight
  * The weights of the items to be considered.
  * @param object BasicArray $profit
  * The profits of the items to be considered.
  * @param integer $capacity The total capacity of the knapsack.
  */
 public function __construct(BasicArray $weight, BasicArray $profit, $capacity)
 {
     $this->numberOfItems = $weight->getLength();
     $this->weight = $weight;
     $this->profit = $profit;
     $this->capacity = $capacity;
 }
Exemple #6
0
     */
    public static function main($args)
    {
        printf("BasicArray main program.\n");
        $status = 0;
        $a1 = new BasicArray(3);
        $a1[0] = 2;
        $a1[1] = $a1[0] + 2;
        $a1[2] = $a1[1] + 2;
        printf("a1 = %s\n", str($a1));
        printf("baseIndex = %d\n", $a1->getBaseIndex());
        printf("length = %d\n", $a1->getLength());
        $a2 = new BasicArray(1, 10);
        $a2[10] = 57;
        printf("a2 = %s\n", str($a2));
        printf("baseIndex = %d\n", $a2->getBaseIndex());
        printf("length = %d\n", $a2->getLength());
        $a2->setLength(5);
        printf("a2 = %s\n", str($a2));
        printf("length = %d\n", $a2->getLength());
        $a2->setLength(3);
        printf("a2 = %s\n", str($a2));
        printf("length = %d\n", $a2->getLength());
        $a3 = clone $a2;
        printf("a3 = %s\n", str($a3));
        return $status;
    }
}
if (realpath($argv[0]) == realpath(__FILE__)) {
    exit(BasicArray::main(array_slice($argv, 1)));
}