/** * Create a new node inside a graph * @param SimpleGraph $oGraph * @param string $sId The unique identifier of this node inside the graph * @param number $x Horizontal position * @param number $y Vertical position */ public function __construct(SimpleGraph $oGraph, $sId, $x = 0, $y = 0) { parent::__construct($oGraph, $sId); $this->x = $x; $this->y = $y; $this->bFiltered = false; }
public function testGraphNode() { $node1 = new GraphNode('Miles'); $this->assertEquals('Miles', $node1->getData()); $node1->setData('Coltrane'); $this->assertEquals('Coltrane', $node1->getData()); $connectedNodes = $node1->getConnectedNodes(); $this->assertTrue(is_array($connectedNodes)); $this->assertTrue(empty($connectedNodes)); $node2 = new GraphNode('Mingus'); $node3 = new GraphNode('Monk'); $node1->addNode($node2); $node1->addNode($node3); $connectedNodes = $node1->getConnectedNodes(); $this->assertTrue(is_array($connectedNodes)); $this->assertEquals(array($node2, $node3), $connectedNodes); }
public function __construct(SimpleGraph $oGraph, GraphNode $oSourceNode, GraphNode $oSinkNode) { $sId = $oSourceNode->GetId() . '-to-' . $oSinkNode->GetId(); parent::__construct($oGraph, $sId, $oSourceNode, $oSinkNode); }
/** * Verify that some non-looping paths from $a to $b pass * through at least one node where $nodePredicate is true. * * @param GraphNode $a * @param GraphNode $b */ private function checkSomePathsWithoutBackEdges(GraphNode $a, GraphNode $b) { if (call_user_func($this->nodePredicate, $a->getAstNode()) && ($this->inclusive || $a !== $this->start && $a !== $this->end)) { return true; } if ($a === $b) { return false; } foreach ($a->getOutEdges() as $e) { if ($e->getAttribute(self::ATTR_STATUS) === self::STATUS_BACK_EDGE) { continue; } if ($e->getAttribute(self::ATTR_STATUS) === self::STATUS_VISITED_EDGE) { continue; } $e->setAttribute(self::ATTR_STATUS, self::STATUS_VISITED_EDGE); if (!call_user_func($this->edgePredicate, $e)) { continue; } $next = $e->getDest(); if ($this->checkSomePathsWithoutBackEdges($next, $b)) { return true; } } return false; }
/** * Fill a lib's node object. * * @param GraphCommons\Graph\Entity\GraphNode $node * @param array|object $g * @return GraphCommons\Graph\Entity\GraphNode */ public final function fillNode(GraphNode $node, $n) : GraphNode { // force input being an object $n = Util::toObject($n); if (isset($n->id)) { $node->setId($n->id)->setName($n->name)->setDescription($n->description); // add suspected (nullable) properties if (isset($n->image)) { $node->setImage($n->image); } if (isset($n->created_at)) { $node->setCreatedAt($n->created_at); } if (isset($n->updated_at)) { $node->setUpdatedAt($n->updated_at); } if (isset($n->properties)) { $node->setProperties($n->properties); } if (isset($n->hubs, $n->users, $n->graphs, $n->graphs_count)) { $node->setHubs((array) $n->hubs)->setUsers((array) $n->users)->setGraphs((array) $n->graphs)->setGraphsCount($n->graphs_count); } // add node type as GraphCommons\Graph\Entity\NodeType $nodeType = new GraphNodeType(); if (isset($n->nodetype)) { $nodeType->setId($n->nodetype->id)->setName($n->nodetype->name)->setColor($n->nodetype->color); $node->setTypeId($n->nodetype->id); } elseif (isset($n->type, $n->type_id)) { $nodeType->setId($n->type_id)->setName($n->type); $node->setTypeId($n->type_id); } $node->setType($nodeType); } return $node; }
/** * Removes the given node but preserves the connectivity of the graph * all "source" nodes are connected to all "sink" nodes * @param GraphNode $oNode * @throws SimpleGraphException */ public function FilterNode(GraphNode $oNode) { if (!array_key_exists($oNode->GetId(), $this->aNodes)) { throw new SimpleGraphException('Cannot filter the node (id=' . $oNode->GetId() . ') from the graph. The node was not found in the graph.'); } $aSourceNodes = array(); $aSinkNodes = array(); foreach ($oNode->GetOutgoingEdges() as $oEdge) { $sSinkId = $oEdge->GetSinkNode()->GetId(); $aSinkNodes[$sSinkId] = $oEdge->GetSinkNode(); $this->_RemoveEdge($oEdge); } foreach ($oNode->GetIncomingEdges() as $oEdge) { $sSourceId = $oEdge->GetSourceNode()->GetId(); $aSourceNodes[$sSourceId] = $oEdge->GetSourceNode(); $this->_RemoveEdge($oEdge); } unset($this->aNodes[$oNode->GetId()]); foreach ($aSourceNodes as $sSourceId => $oSourceNode) { foreach ($aSinkNodes as $sSinkId => $oSinkNode) { $oEdge = new RelationEdge($this, $oSourceNode, $oSinkNode); } } }
public function __construct($data, array $connectedNodes = null) { parent::__construct($data, $connectedNodes); $this->reset(); }
public function __construct(array $values = []) { parent::__construct($values['namespace'], $values['tag'], $values); }