/** * 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; }
/** * 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 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(); }
/** * 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; }