### Console Output for WeightedDirectedGraph Example Source: https://github.com/simphotonics/directed_graph/blob/main/README.md The console output generated by running the Dart example for WeightedDirectedGraph. It shows the initial graph structure, the graph after sorting edges by weight, and the results of finding the lightest, heaviest, and shortest paths. ```console $ dart example/bin/weighted_graph_example.dart Weighted Graph: { 'a': {'b': 1, 'h': 7, 'c': 2, 'e': 40, 'g': 7}, 'b': {'h': 6}, 'c': {'h': 5, 'g': 4}, 'd': {'e': 1, 'f': 2}, 'e': {'g': 2}, 'f': {'i': 3}, 'g': {}, 'h': {}, 'i': {'l': 3, 'k': 2}, 'k': {'g': 4, 'f': 5}, 'l': {'l': 0}, } Neighbouring vertices sorted by weight { 'a': {'b': 1, 'c': 2, 'h': 7, 'g': 7, 'e': 40}, 'b': {'h': 6}, 'c': {'g': 4, 'h': 5}, 'd': {'e': 1, 'f': 2}, 'e': {'g': 2}, 'f': {'i': 3}, 'g': {}, 'h': {}, 'i': {'k': 2, 'l': 3}, 'k': {'g': 4, 'f': 5}, 'l': {'l': 0}, } Lightest path a -> g [a, c, g] weight: 6 Heaviest path a -> g [a, e, g] weigth: 42 Shortest path a -> g [a, g] weight: 7 ``` -------------------------------- ### DirectedGraph Example Source: https://github.com/simphotonics/directed_graph/blob/main/README.md Demonstrates the construction and usage of the DirectedGraph class in Dart. It includes examples of adding edges, checking acyclicity, finding strongly connected components, calculating shortest paths, and more. The graph vertices are of type String and can be sorted using custom comparators. ```Dart import 'package:directed_graph/directed_graph.dart'; // To run this program navigate to // the folder 'directed_graph/example' // in your terminal and type: // // # dart bin/directed_graph_example.dart // // followed by enter. void main() { int comparator(String s1, String s2) => s1.compareTo(s2); int inverseComparator(String s1, String s2) => -comparator(s1, s2); // Constructing a graph from vertices. final graph = DirectedGraph( { 'a': {'b', 'h', 'c', 'e'}, 'b': {'h'}, 'c': {'h', 'g'}, 'd': {'e', 'f'}, 'e': {'g'}, 'f': {'i'}, 'i': {'l'}, 'k': {'g', 'f'} }, // Custom comparators can be specified here: // comparator: comparator, ); print('Example Directed Graph...'); print('graph.toString():'); print(graph); print('\nIs Acylic:'); print(graph.isAcyclic); print('\nStrongly connected components:'); print(graph.stronglyConnectedComponents); print('\nShortestPath(d, l):'); print(graph.shortestPath('d', 'l')); print('\nInDegree(C):'); print(graph.inDegree('c')); print('\nOutDegree(C)'); print(graph.outDegree('c')); print('\nVertices sorted in lexicographical order:'); print(graph.sortedVertices); print('\nVertices sorted in inverse lexicographical order:'); graph.comparator = inverseComparator; print(graph.sortedVertices); graph.comparator = comparator; print('\nInDegreeMap:'); print(graph.inDegreeMap); print('\nSorted Topological Ordering:'); print(graph.sortedTopologicalOrdering); print('\nTopological Ordering:'); print(graph.topologicalOrdering); print('\nLocal Sources:'); print(graph.localSources); // Add edge to render the graph cyclic graph.addEdges('i', {'k'}); graph.addEdges('l', {'l'}); graph.addEdges('i', {'d'}); print('\nCycle:'); print(graph.cycle); print('\nShortest Paths:'); print(graph.shortestPaths('a')); print('\nEdge exists: a->b'); print(graph.edgeExists('a', 'b')); } ``` -------------------------------- ### Run Benchmark Report Source: https://github.com/simphotonics/directed_graph/blob/main/benchmark/README.md Command to execute the benchmark runner and generate a report for the directed_graph package. ```console $ pub run benchmark_runner report ``` -------------------------------- ### WeightedDirectedGraph Construction and Pathfinding Source: https://github.com/simphotonics/directed_graph/blob/main/README.md Demonstrates how to create a WeightedDirectedGraph, sort its edges by weight, and find the lightest, heaviest, and shortest paths between specified vertices. The graph is initialized with string vertices and integer weights, using a custom comparator and summation function. ```dart import 'package:directed_graph/directed_graph.dart'; void main(List args) { int comparator( String s1, String s2, ) { return s1.compareTo(s2); } final a = 'a'; final b = 'b'; final c = 'c'; final d = 'd'; final e = 'e'; final f = 'f'; final g = 'g'; final h = 'h'; final i = 'i'; final k = 'k'; final l = 'l'; int sum(int left, int right) => left + right; var graph = WeightedDirectedGraph( { a: {b: 1, h: 7, c: 2, e: 40, g:7}, b: {h: 6}, c: {h: 5, g: 4}, d: {e: 1, f: 2}, e: {g: 2}, f: {i: 3}, i: {l: 3, k: 2}, k: {g: 4, f: 5}, l: {l: 0} }, summation: sum, zero: 0, comparator: comparator, ); print('Weighted Graph:'); print(graph); print('\nNeighbouring vertices sorted by weight:'); print(graph..sortEdgesByWeight()); final lightestPath = graph.lightestPath(a, g); print('\nLightest path a -> g'); print('$lightestPath weight: ${graph.weightAlong(lightestPath)}'); final heaviestPath = graph.heaviestPath(a, g); print('\nHeaviest path a -> g'); print('$heaviestPath weigth: ${graph.weightAlong(heaviestPath)}'); final shortestPath = graph.shortestPath(a, g); print('\nShortest path a -> g'); print('$shortestPath weight: ${graph.weightAlong(shortestPath)}'); } ``` -------------------------------- ### DirectedGraph Class Usage Source: https://github.com/simphotonics/directed_graph/blob/main/example/README.md Demonstrates how to create a numerical representation of a directed graph using the DirectedGraph class. ```Dart import 'package:directed_graph/directed_graph.dart'; void main() { // Example usage of DirectedGraph var graph = DirectedGraph(); graph.addNode(1); graph.addNode(2); graph.addNode(3); graph.addEdge(1, 2); graph.addEdge(2, 3); print('Graph created successfully.'); } ``` -------------------------------- ### WeightedDirectedGraph Shortest Path Source: https://github.com/simphotonics/directed_graph/blob/main/example/README.md Demonstrates creating a WeightedDirectedGraph object and finding the shortest, lightest, and heaviest paths between two vertices. ```Dart import 'package:directed_graph/directed_graph.dart'; void main() { // Example usage of WeightedDirectedGraph var weightedGraph = WeightedDirectedGraph(); weightedGraph.addNode('A'); weightedGraph.addNode('B'); weightedGraph.addNode('C'); weightedGraph.addEdge('A', 'B', weight: 5); weightedGraph.addEdge('B', 'C', weight: 3); weightedGraph.addEdge('A', 'C', weight: 10); var shortestPath = weightedGraph.shortestPath('A', 'C'); print('Shortest path: $shortestPath'); } ``` -------------------------------- ### Directed Graph Concepts and Terminology Source: https://github.com/simphotonics/directed_graph/blob/main/README.md Explains fundamental graph theory concepts such as vertices, edges, in-degree, out-degree, sources, paths, cycles, walks, DAGs, and topological ordering. It also clarifies the package's definition of an edge, allowing for self-loops. ```dart /* * Directed Graph Concepts: * * Vertex: An element within a graph. * Edge: A connection between two vertices. In a directed graph, edges have a direction (from one vertex to another). * In-degree: The number of edges pointing *to* a vertex. * Out-degree: The number of edges pointing *from* a vertex. * Source: A vertex with an in-degree of zero. * Path: An ordered sequence of connected vertices where inner vertices are distinct. * Cycle: A path where the first and last vertices are the same. * Walk: An ordered sequence of connected vertices, which may revisit vertices. * DAG (Directed Acyclic Graph): A directed graph that contains no cycles. * Topological Ordering: A linear ordering of vertices such that for every directed edge (u, v), vertex u comes before vertex v in the ordering. * * Note: This package allows self-loops (edges connecting a vertex to itself). */ ``` -------------------------------- ### GraphCrawler Class Usage Source: https://github.com/simphotonics/directed_graph/blob/main/example/README.md Demonstrates the usage of the GraphCrawler class for traversing directed graphs. ```Dart import 'package:directed_graph/directed_graph.dart'; void main() { // Example usage of GraphCrawler var graph = DirectedGraph(); graph.addNode(1); graph.addNode(2); graph.addNode(3); graph.addEdge(1, 2); graph.addEdge(2, 3); var crawler = GraphCrawler(graph); var reachableNodes = crawler.reachableNodes(1); print('Nodes reachable from 1: $reachableNodes'); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.