weight; } /** * set new weight for edge * * @param float|int|NULL $weight new numeric weight of edge or NULL=unset weight * @return self $this (chainable) * @throws InvalidArgumentException if given weight is not numeric */ public function setWeight($weight) { if ($weight !== NULL && !is_float($weight) && !is_int($weight)) { throw new InvalidArgumentException('Invalid weight given - must be numeric or NULL'); } $this->weight = $weight; return $this; } /** * get total capacity of this edge * * @return float|int|NULL numeric capacity or NULL=not set */ public function getCapacity() { return $this->capacity; } /** * get the capacity remaining (total capacity - current flow) * * @return float|int|NULL numeric capacity remaining or NULL=no upper capacity set */ public function getCapacityRemaining() { if ($this->capacity === NULL) { return NULL; } return $this->capacity - $this->flow; } /** * set new total capacity of this edge * * @param float|int|NULL $capacity * @return self $this (chainable) * @throws InvalidArgumentException if $capacity is invalid (not numeric or negative) * @throws RangeException if current flow exceeds new capacity */ public function setCapacity($capacity) { if ($capacity !== NULL) { if (!is_float($capacity) && !is_int($capacity)) { throw new InvalidArgumentException('Invalid capacity given - must be numeric'); } if ($capacity < 0) { throw new InvalidArgumentException('Capacity must not be negative'); } if ($this->flow !== NULL && $this->flow > $capacity) { throw new RangeException('Current flow of ' . $this->flow . ' exceeds new capacity'); } } $this->capacity = $capacity; return $this; } /** * get current flow (capacity currently in use) * * @return float|int|NULL numeric flow or NULL=not set */ public function getFlow() { return $this->flow; } /** * set new total flow (capacity currently in use) * * @param float|int|NULL $flow * @return self $this (chainable) * @throws InvalidArgumentException if $flow is invalid (not numeric or negative) * @throws RangeException if flow exceeds current maximum capacity */ public function setFlow($flow) { if ($flow !== NULL) { if (!is_float($flow) && !is_int($flow)) { throw new InvalidArgumentException('Invalid flow given - must be numeric'); } if ($flow < 0) { throw new InvalidArgumentException('Flow must not be negative'); } if ($this->capacity !== NULL && $flow > $this->capacity) { throw new RangeException('New flow exceeds maximum capacity'); } } $this->flow = $flow; return $this; } /** * get set of all Vertices this edge connects * * @return Vertices */ //abstract public function getVertices(); /** * get graph instance this edge is attached to * * @return Graph * @throws LogicException */ public function getGraph() { foreach ($this->getVertices() as $vertex) { return $vertex->getGraph(); // the following code can only be reached if this edge does not // contain any vertices (invalid state), so ignore its coverage // @codeCoverageIgnoreStart } throw new LogicException('Internal error: should not be reached'); // @codeCoverageIgnoreEnd } /** * destroy edge and remove reference from vertices and graph * * @uses Graph::removeEdge() * @uses Vertex::removeEdge() * @return void */ public function destroy() { $this->getGraph()->removeEdge($this); foreach ($this->getVertices() as $vertex) { $vertex->removeEdge($this); } } /** * create new clone of this edge between adjacent vertices * * @return self new edge * @uses Graph::createEdgeClone() */ public function createEdgeClone() { return $this->getGraph()->createEdgeClone($this); } /** * create new clone of this edge inverted (in opposite direction) between adjacent vertices * * @return self new edge * @uses Graph::createEdgeCloneInverted() */ public function createEdgeCloneInverted() { return $this->getGraph()->createEdgeCloneInverted($this); } /** * do NOT allow cloning of objects * * @throws BadMethodCallException */ private function __clone() { // @codeCoverageIgnoreStart throw new BadMethodCallException(); // @codeCoverageIgnoreEnd } public function getAttribute($name, $default = null) { return isset($this->attributes[$name]) ? $this->attributes[$name] : $default; } public function setAttribute($name, $value) { $this->attributes[$name] = $value; } public function getAttributeBag() { return new AttributeBagReference($this->attributes); } }