在PHP中创建有向图

时间:2017-01-31 06:16:51

标签: php mysql matrix directed-graph

我正在尝试在php中实现一个简单的代码,我必须从sql数据库创建一个有向图。我只需要以有向图的形式表示E-R图连接。有人能帮我吗? 这是我的初学者代码。此代码尚未运行。建议即兴创作 这段代码基本上是试图创建一个示例图。

<?php
require_once 'Structures/Graph.php';`

$directedGraph =& new Structures_Graph(true);
$nonDirectedGraph =& new Structures_Graph(false);

require_once 'Structures/Graph/Node.php';

$nodeOne =& new Structures_Graph_Node();
$nodeTwo =& new Structures_Graph_Node();
$nodeThree =& new Structures_Graph_Node();
$directedGraph->addNode();
$directedGraph->addNode();
$directedGraph->addNode();

$nodeOne->connectTo($nodeTwo);
$nodeOne->connectTo($nodeThree);

$nodeOne->setData("Node One's Data is a String");
$nodeTwo->setData(1976);
$nodeThree->setData('Some other string');

print("NodeTwo's Data is an integer: " . $nodeTwo->getData());

$nodeOne->setMetadata('example key', "Node One's Sample Metadata");
print("Metadata stored under key 'example key' in node one: " . $nodeOne->getMetadata('example key'));
$nodeOne->unsetMetadata('example key');

// Nodes are able to calculate their indegree and outdegree
print("NodeOne's inDegree: " . $nodeOne->inDegree());
print("NodeOne's outDegree: " . $nodeOne->outDegree());

// and naturally, nodes can report on their arcs
$arcs = $nodeOne->getNeighbours();
for ($i=0;$i<sizeof($arcs);$i++) {
    print("NodeOne has an arc to " . $arcs[$i]->getData());
}
?>
.

0 个答案:

没有答案