Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 0 additions & 138 deletions src/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Graphp\Graph\Exception\BadMethodCallException;
use Graphp\Graph\Exception\InvalidArgumentException;
use Graphp\Graph\Exception\LogicException;
use Graphp\Graph\Exception\RangeException;
use Graphp\Graph\Set\Vertices;
use Graphp\Graph\Set\VerticesAggregate;

Expand All @@ -19,30 +18,6 @@
*/
abstract class Edge implements VerticesAggregate, AttributeAware
{
/**
* weight of this edge
*
* @var float|int|NULL
* @see self::getWeight()
*/
protected $weight = NULL;

/**
* maximum capacity (maximum flow)
*
* @var float|int|NULL
* @see self::getCapacity()
*/
protected $capacity = NULL;

/**
* flow (capacity currently in use)
*
* @var float|int|NULL
* @see self::getFlow()
*/
protected $flow = NULL;

protected $attributes = array();

/**
Expand Down Expand Up @@ -106,119 +81,6 @@ abstract public function getVertexToFrom(Vertex $startVertex);
*/
abstract public function getVertexFromTo(Vertex $endVertex);

/**
* return weight of edge
*
* @return float|int|NULL numeric weight of edge or NULL=not set
*/
public function getWeight()
{
return $this->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
*
Expand Down
14 changes: 4 additions & 10 deletions src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ public function createVertexClone(Vertex $originalVertex)
if ($this->vertices->hasVertexId($id)) {
throw new RuntimeException('Id of cloned vertex already exists');
}

$newVertex = new Vertex($this, $id);
// TODO: properly set attributes of vertex
$newVertex->getAttributeBag()->setAttributes($originalVertex->getAttributeBag()->getAttributes());
$newVertex->setBalance($originalVertex->getBalance());
$newVertex->setGroup($originalVertex->getGroup());

return $newVertex;
}
Expand All @@ -106,11 +104,10 @@ public function createVertexClone(Vertex $originalVertex)
public function createGraphCloneEdgeless()
{
$graph = new Graph();
$graph->getAttributeBag()->setAttributes($this->getAttributeBag()->getAttributes());
// TODO: set additional graph attributes
$graph->attributes = $this->attributes;

foreach ($this->getVertices() as $originalVertex) {
$graph->createVertexClone($originalVertex);
// $graph->vertices[$vid] = $vertex;
}

return $graph;
Expand Down Expand Up @@ -258,11 +255,8 @@ private function createEdgeCloneInternal(Edge $originalEdge, $ia, $ib)
// create new edge between new a and b
$newEdge = $this->createEdgeUndirected($a, $b);
}
// TODO: copy edge attributes

$newEdge->getAttributeBag()->setAttributes($originalEdge->getAttributeBag()->getAttributes());
$newEdge->setWeight($originalEdge->getWeight());
$newEdge->setFlow($originalEdge->getFlow());
$newEdge->setCapacity($originalEdge->getCapacity());

return $newEdge;
}
Expand Down
58 changes: 0 additions & 58 deletions src/Vertex.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ class Vertex implements EdgesAggregate, AttributeAware
*/
private $graph;

/**
* vertex balance
*
* @var int|float|NULL
* @see Vertex::setBalance()
*/
private $balance;

/**
* group number
*
* @var int
* @see Vertex::setGroup()
*/
private $group = 0;

private $attributes = array();

/**
Expand Down Expand Up @@ -71,48 +55,6 @@ public function getGraph()
return $this->graph;
}

public function getBalance()
{
return $this->balance;
}

public function setBalance($balance)
{
if ($balance !== NULL && !is_float($balance) && !is_int($balance)) {
throw new InvalidArgumentException('Invalid balance given - must be numeric');
}
$this->balance = $balance;

return $this;
}

/**
* set group number of this vertex
*
* @param int $group
* @return Vertex $this (chainable)
* @throws InvalidArgumentException if group is not numeric
*/
public function setGroup($group)
{
if (!is_int($group)) {
throw new InvalidArgumentException('Invalid group number');
}
$this->group = $group;

return $this;
}

/**
* get group number
*
* @return int
*/
public function getGroup()
{
return $this->group;
}

/**
* returns id of this Vertex
*
Expand Down
98 changes: 0 additions & 98 deletions tests/EdgeAttributesTest.php

This file was deleted.

10 changes: 8 additions & 2 deletions tests/GraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function setup()
public function testVertexClone()
{
$graph = new Graph();
$vertex = $graph->createVertex(123)->setBalance(10)->setGroup(4);
$vertex = $graph->createVertex(123);
$vertex->setAttribute('balance', 29);
$vertex->setAttribute('group', 4);

$newgraph = new Graph();
$newvertex = $newgraph->createVertexClone($vertex);
Expand Down Expand Up @@ -56,7 +58,11 @@ public function testGetVertexNonexistant()
public function testGraphClone()
{
$graph = new Graph();
$graph->createVertex(123)->setBalance(10)->setGroup(4);
$graph->setAttribute('title', 'graph');

$vertex = $graph->createVertex(123);
$vertex->setAttribute('balanace', 10);
$vertex->setAttribute('group', 4);

$newgraph = $graph->createGraphClone();

Expand Down
Loading