use Fhaculty\Graph\Graph; use Fhaculty\Graph\Vertex; $graph = new Graph(); $node = $graph->createVertex('myNode'); // Add an attribute to the node $node->setAttribute('color', 'blue');
use Fhaculty\Graph\Graph; use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Edge\Directed; $graph = new Graph(); $node1 = $graph->createVertex('Node 1'); $node2 = $graph->createVertex('Node 2'); // Connect the nodes with a directed edge $edge = $node1->createEdgeTo($node2)->setAttribute('weight', 2.5);In this example, we create a new graph and add two nodes to it. We then create a directed edge connecting the two nodes and set an attribute called "weight" on the edge with a value of 2.5. The package library used in these examples is called "graphp/graph". The library can be installed using Composer and provides a comprehensive set of classes and methods for creating and managing graphs in PHP.