diff --git a/core/relationgraph.class.inc.php b/core/relationgraph.class.inc.php index e13d98867..9f3802c57 100644 --- a/core/relationgraph.class.inc.php +++ b/core/relationgraph.class.inc.php @@ -145,10 +145,10 @@ class RelationRedundancyNode extends GraphNode */ class RelationEdge extends GraphEdge { - public function __construct(SimpleGraph $oGraph, GraphNode $oSourceNode, GraphNode $oSinkNode) + public function __construct(SimpleGraph $oGraph, GraphNode $oSourceNode, GraphNode $oSinkNode, $bMustBeUnique = false) { $sId = $oSourceNode->GetId().'-to-'.$oSinkNode->GetId(); - parent::__construct($oGraph, $sId, $oSourceNode, $oSinkNode); + parent::__construct($oGraph, $sId, $oSourceNode, $oSinkNode, $bMustBeUnique); } } @@ -426,7 +426,7 @@ class RelationGraph extends SimpleGraph if (!$oRedundancyNode) { // Direct link (otherwise handled by ComputeRedundancy) - $oEdge = new RelationEdge($this, $oSourceNode, $oSinkNode); + new RelationEdge($this, $oSourceNode, $oSinkNode); } // Recurse $this->AddRelatedObjects($sRelCode, $bDown, $oRelatedNode, $iMaxDepth - 1, $bEnableRedundancy); diff --git a/core/simplegraph.class.inc.php b/core/simplegraph.class.inc.php index 8a5ea1a31..f817cd73a 100644 --- a/core/simplegraph.class.inc.php +++ b/core/simplegraph.class.inc.php @@ -234,22 +234,24 @@ class GraphEdge extends GraphElement { protected $oSourceNode; protected $oSinkNode; - + /** * Create a new directed edge inside the given graph * @param SimpleGraph $oGraph * @param string $sId The unique identifier of this edge in the graph * @param GraphNode $oSourceNode * @param GraphNode $oSinkNode + * @param bool $bMustBeUnique + * @throws SimpleGraphException */ - public function __construct(SimpleGraph $oGraph, $sId, GraphNode $oSourceNode, GraphNode $oSinkNode) + public function __construct(SimpleGraph $oGraph, $sId, GraphNode $oSourceNode, GraphNode $oSinkNode, $bMustBeUnique = false) { parent::__construct($sId); $this->oSourceNode = $oSourceNode; $this->oSinkNode = $oSinkNode; - $oGraph->_AddEdge($this); + $oGraph->_AddEdge($this, $bMustBeUnique); } - + /** * Get the "source" node for this edge * @return GraphNode @@ -403,11 +405,22 @@ class SimpleGraph /** * INTERNAL USE ONLY * @param GraphEdge $oEdge + * @param bool $bMustBeUnique * @throws SimpleGraphException */ - public function _AddEdge(GraphEdge $oEdge) + public function _AddEdge(GraphEdge $oEdge, $bMustBeUnique = false) { - if (array_key_exists($oEdge->GetId(), $this->aEdges)) throw new SimpleGraphException('Cannot add edge (id='.$oEdge->GetId().') to the graph. An edge with the same id already exists in the graph.'); + if (array_key_exists($oEdge->GetId(), $this->aEdges)) + { + if ($bMustBeUnique) + { + throw new SimpleGraphException('Cannot add edge (id=' . $oEdge->GetId() . ') to the graph. An edge with the same id already exists in the graph.'); + } + else + { + return; + } + } $this->aEdges[$oEdge->GetId()] = $oEdge; $oEdge->GetSourceNode()->_AddOutgoingEdge($oEdge); @@ -692,7 +705,7 @@ EOF } /** - * Merge back to subgraphs into one + * Merge back two subgraphs into one * @param SimpleGraph $oGraph */ public function Merge(SimpleGraph $oGraph)