### Basic Graph Setup in GraphStream Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Instantiates a new graph with a given ID using the default implementation. This is the simplest way to start a graph. ```Java Graph g = new DefaultGraph("id"); ``` -------------------------------- ### Graph Creation and Manipulation Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md A comprehensive example demonstrating how to create a graph, add nodes and edges, set attributes, iterate over elements, and save/load the graph using GML format. ```java // Create a graph Graph graph = new DefaultGraph("myGraph"); graph.setStrict(true); graph.setAutoCreate(false); // Add nodes Node a = graph.addNode("A"); Node b = graph.addNode("B"); Node c = graph.addNode("C"); // Add edges Edge e1 = graph.addEdge("e1", "A", "B", false); // undirected Edge e2 = graph.addEdge("e2", "B", "C", true); // directed: B → C // Set attributes a.setAttribute("label", "Node A"); a.setAttribute("weight", 10.5); // Iterate over nodes for (Node node : graph) { System.out.println(node.getId()); } // Access elements System.out.println("Nodes: " + graph.getNodeCount()); System.out.println("Edges: " + graph.getEdgeCount()); // Save and load graph.write("mygraph.gml"); Graph loaded = new DefaultGraph("loaded"); loaded.read("mygraph.gml"); ``` -------------------------------- ### Configuration Options Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/COMPLETION_SUMMARY.txt Documentation for various configuration options, including graph constructor parameters, runtime methods, factory setup, file formats, viewer setup, and layout configuration. ```APIDOC ## Configuration ### Description Documentation for various configuration options, including graph constructor parameters (5 overloads), runtime configuration methods, factory setup procedures, file format configuration, viewer setup (UI selection), and layout configuration. Also covers performance tuning guidelines and common configuration patterns. ### Endpoint `configuration.md` ### Features Covered - Graph constructor parameters (5 overloads) - Runtime configuration methods - Factory setup procedures - File format configuration - Viewer setup (UI selection) - Layout configuration - Performance tuning guidelines - Common configuration patterns ``` -------------------------------- ### GraphStream Node and Graph Usage Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md A comprehensive example showing how to create a graph, add nodes and edges, access node properties like degree, set node positions, iterate over neighbors and edges, check connectivity, and set node attributes. ```java Graph graph = new DefaultGraph("network"); // Create nodes Node a = graph.addNode("A"); Node b = graph.addNode("B"); Node c = graph.addNode("C"); Node d = graph.addNode("D"); // Create edges graph.addEdge("e1", "A", "B"); graph.addEdge("e2", "B", "C"); graph.addEdge("e3", "C", "D"); graph.addEdge("e4", "D", "A"); // Access node properties System.out.println("Node A degree: " + a.getDegree()); // 2 // Set position a.setxy(0.0, 0.0); b.setxy(10.0, 0.0); c.setxy(10.0, 10.0); d.setxy(0.0, 10.0); // Access neighbors System.out.println("A's neighbors:"); for (Node neighbor : a.getEachNeighbor()) { System.out.println(" - " + neighbor.getId()); } // Check connectivity if (a.hasEdge(b)) { System.out.println("A and B are connected"); } // Iterate edges System.out.println("Edges from A:"); for (Edge edge : a.getEachEdge()) { System.out.println(" - " + edge.getId()); Node other = a.getNeighborNode(edge); System.out.println(" Connected to: " + other.getId()); } // Set attributes (inherited from Element) a.setAttribute("label", "Node A"); a.setAttribute("weight", 1.5); a.setAttribute("color", "red"); ``` -------------------------------- ### Breadth-First Traversal Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Demonstrates how to use BreadthFirstIterator to traverse a graph starting from a root node, printing each node's ID and its depth. ```java Graph graph = new DefaultGraph("tree"); Node root = graph.addNode("root"); Node a = graph.addNode("a"); Node b = graph.addNode("b"); Node c = graph.addNode("c"); Node d = graph.addNode("d"); graph.addEdge("e1", "root", "a"); graph.addEdge("e2", "root", "b"); graph.addEdge("e3", "a", "c"); graph.addEdge("e4", "b", "d"); BreadthFirstIterator iter = new BreadthFirstIterator(root); while (iter.hasNext()) { Node node = iter.next(); int depth = iter.getDepthOf(node); System.out.println(node.getId() + " (depth: " + depth + ")"); } System.out.println("Max depth: " + iter.getDepthMax()); ``` -------------------------------- ### Depth-First Traversal Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Demonstrates how to use DepthFirstIterator to traverse a graph starting from a root node and retrieve the depth of each visited node. ```java DepthFirstIterator iter = new DepthFirstIterator(root); while (iter.hasNext()) { Node node = iter.next(); int depth = iter.getDepthOf(node); System.out.println(node.getId() + " (depth: " + depth + ")"); } ``` -------------------------------- ### DefaultGraph Usage Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Example of creating a graph instance using the DefaultGraph class, recommended for new code. ```java // Preferred for new code Graph graph = new DefaultGraph("myGraph"); ``` -------------------------------- ### Custom NodeFactory Usage Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Demonstrates how to implement and use a custom NodeFactory to create custom node instances. ```java class MyNode extends AbstractNode { // Custom node implementation } class MyNodeFactory implements NodeFactory { @Override public MyNode newInstance(String id, Graph graph) { return new MyNode(graph, id); } } Graph graph = new DefaultGraph("custom"); graph.setNodeFactory(new MyNodeFactory()); // Now addNode creates MyNode instances MyNode node = graph.addNode("n1"); ``` -------------------------------- ### Full Element Attribute Management Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Demonstrates setting, getting, checking existence, retrieving first available, iterating, and removing attributes on GraphStream nodes and edges. ```java Graph graph = new DefaultGraph("demo"); Node node = graph.addNode("n1"); Edge edge = graph.addEdge("e1", "n1", "n2"); // Set attributes node.setAttribute("label", "Node 1"); node.setAttribute("weight", 5.2); node.setAttribute("color", "red"); node.setAttribute("position", Arrays.asList(10.0, 20.0, 0.0)); edge.setAttribute("weight", 1.5); // Get attributes String label = node.getAttribute("label", String.class); double weight = node.getNumber("weight"); List pos = node.getVector("position"); // Check existence Object value = node.getAttribute("nonexistent"); System.out.println("Exists: " + (value != null)); // Get first available Object name = node.getFirstAttributeOf("label", "name", "id"); // Iterate attributes for (String key : node.getAttributeKeySet()) { System.out.println(key + ": " + node.getAttribute(key)); } // Remove attributes node.removeAttribute("weight"); node.clearAttributes(); ``` -------------------------------- ### Example: Get Opposite Node Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/edge-interface.md Demonstrates how to get the opposite node of an edge using a known endpoint. ```java Edge edge = graph.getEdge("e1"); Node source = edge.getSourceNode(); Node opposite = edge.getOpposite(source); // target node ``` -------------------------------- ### GraphStream Edge Usage Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/edge-interface.md A comprehensive example demonstrating the creation of nodes and edges (directed, undirected, self-loop), accessing endpoints, checking edge properties, and setting/getting attributes. ```java Graph graph = new DefaultGraph("directed"); // Create nodes Node a = graph.addNode("A"); Node b = graph.addNode("B"); Node c = graph.addNode("C"); // Create edges Edge e1 = graph.addEdge("e1", "A", "B", true); // directed A → B Edge e2 = graph.addEdge("e2", "B", "C", false); // undirected B -- C Edge e3 = graph.addEdge("e3", "C", "C", true); // self-loop // Access endpoints System.out.println("e1 source: " + e1.getSourceNode().getId()); // A System.out.println("e1 target: " + e1.getTargetNode().getId()); // B // Get opposite node Node opposite = e1.getOpposite(a); // returns B System.out.println("Opposite of A: " + opposite.getId()); // Check edge type System.out.println("e1 directed: " + e1.isDirected()); // true System.out.println("e2 directed: " + e2.isDirected()); // false System.out.println("e3 self-loop: " + e3.isSelfLoop()); // true // Set attributes (inherited from Element) e1.setAttribute("weight", 2.5); e1.setAttribute("color", "blue"); e1.setAttribute("label", "Relation"); // Get attributes double weight = e1.getNumber("weight"); String label = e1.getLabel("label"); ``` -------------------------------- ### Path Manipulation Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Illustrates creating a Path, adding nodes to it, checking its length and root, iterating through its nodes, and removing the last node. ```java Path path = new Path(nodeA); path.push(nodeB); path.push(nodeC); path.push(nodeD); System.out.println("Path length: " + path.getLength()); // 4 System.out.println("Root: " + path.getRoot().getId()); // A for (int i = 0; i < path.getLength(); i++) { System.out.println(path.getNodeAt(i).getId()); } path.pop(); // Remove D System.out.println("Length after pop: " + path.getLength()); // 3 ``` -------------------------------- ### Initialize Graph with Custom Capacities Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Example of initializing a graph with specific initial capacities for nodes and edges to optimize performance for large graphs. ```java // For a graph with ~10000 nodes Graph large = new DefaultGraph("large", true, false, 10000, 0); // Allocates space for 10000 nodes upfront, avoiding reallocation ``` ```java // For a graph with ~1000 nodes and ~5000 edges Graph graph = new DefaultGraph("graph", true, false, 1000, 5000); ``` -------------------------------- ### MultiGraph Usage Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Demonstrates adding nodes and multiple edges between them using MultiGraph. ```java Graph graph = new MultiGraph("routes"); // Add cities (nodes) graph.addNode("NYC"); graph.addNode("LA"); // Add multiple routes (edges) between same cities graph.addEdge("flight1", "NYC", "LA", true); // Directed flight graph.addEdge("flight2", "NYC", "LA", true); // Another flight graph.addEdge("train", "NYC", "LA", false); // Undirected train ``` -------------------------------- ### enableAutoLayout() Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Starts the automatic layout algorithm thread, enabling dynamic graph arrangement. ```APIDOC ## enableAutoLayout() ### Description Starts the automatic layout algorithm thread, enabling dynamic graph arrangement. ### Method POST ### Endpoint enableAutoLayout ``` -------------------------------- ### FileSource.begin, nextStep, end Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/file-io.md Provides an event-by-event reading mechanism. Use `begin()` to start, `nextStep()` to process individual events, and `end()` to finish. ```APIDOC ## FileSource Event-by-Event Reading ### Description Allows for incremental reading of graph files, processing events one by one. ### Methods #### begin(String filename) ##### Description Begins reading a file. Used with `nextStep()` for event-by-event processing. ##### Method Signature ```java void begin(String filename) throws IOException, GraphParseException ``` #### nextStep() ##### Description Reads the next step/event from the file. ##### Method Signature ```java boolean nextStep() throws IOException, GraphParseException ``` ##### Returns `boolean` - True if more events remain, false if end of file reached #### end() ##### Description Closes the file and finishes reading. ##### Method Signature ```java void end() throws IOException ``` ``` -------------------------------- ### Graph Traversal Algorithms Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Provides examples for performing Breadth-First Search (BFS) and Depth-First Search (DFS) on a graph. ```java // Breadth-first search BreadthFirstIterator bfs = new BreadthFirstIterator(startNode); while (bfs.hasNext()) { Node node = bfs.next(); int depth = bfs.getDepthOf(node); // Process node at given depth } // Depth-first search DepthFirstIterator dfs = new DepthFirstIterator(startNode); while (dfs.hasNext()) { Node node = dfs.next(); // Process node } ``` -------------------------------- ### VerboseSink Usage Example Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Logs all graph events to the console using VerboseSink. Ensure GraphListeners and DefaultGraph are imported. ```java Graph graph = new DefaultGraph("logged"); // Print all events to console VerboseSink sink = new VerboseSink(); graph.addSink(sink); graph.addNode("A"); graph.addEdge("e1", "A", "B"); // Outputs each event to System.out graph.removeSink(sink); ``` -------------------------------- ### Advanced Graph Display with Custom Layout and Interaction Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md This snippet demonstrates advanced viewer setup, including creating a viewer without auto-layout, implementing a custom layout algorithm, running it in the background, and setting up a ViewerPipe for interaction. It includes an event loop for processing viewer events and application logic. ```java Graph graph = new DefaultGraph("advanced"); // Create viewer without auto-layout Viewer viewer = new Viewer(graph, false); // Create a custom layout Layout layout = Layouts.newLayoutAlgorithm(); // Run layout in background LayoutRunner layoutRunner = new LayoutRunner(graph, layout, true, 33); // ~30 FPS layoutRunner.start(); // Create viewer pipe for interaction ViewerPipe pipe = new ViewerPipe(viewer); pipe.addSink(graph); // Event loop boolean running = true; while (running) { pipe.pump(); // Your application logic here Thread.sleep(33); } layoutRunner.release(); ``` -------------------------------- ### Configurable Graph Setup in GraphStream Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Instantiates a new graph with a given ID and custom configuration options. Use this to control strict checking, auto-node creation, and initial capacity. ```Java Graph g = new DefaultGraph("id", strictChecking, // boolean: throw exceptions? autoCreate, // boolean: auto-create missing nodes? initialNodeCapacity, // int: pre-allocate space initialEdgeCapacity); // int: pre-allocate space ``` -------------------------------- ### Enable Auto Layout Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Starts the automatic layout algorithm thread. Use this to enable automatic layout updates for the graph visualization. ```java void enableAutoLayout() ``` -------------------------------- ### Setting and Getting Node Attributes Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Demonstrates how to set and retrieve various types of attributes on a graph node. Supports string, number, and list types. ```java node.setAttribute("label", "Node A"); node.setAttribute("color", "red"); node.setAttribute("position", Arrays.asList(1.0, 2.0, 3.0)); String label = node.getLabel("label"); double number = node.getNumber("size"); List pos = node.getVector("position"); ``` -------------------------------- ### Safe Graph Loading with Fallbacks Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/errors.md A comprehensive example of loading a graph safely in lenient mode, with error handling for file not found and parsing errors, including attempts to read from a backup file and falling back to an empty graph. ```java public Graph loadGraphSafely(String filename) { Graph graph = new DefaultGraph("loaded", false, false); // Lenient try { // Try primary source graph.read(filename); } catch (IOException e) { System.err.println("File not found: " + filename); // Try backup try { graph.read(filename + ".backup"); } catch (IOException e2) { System.err.println("Backup also unavailable"); return null; } } catch (GraphParseException e) { System.err.println("Parse error in file: " + e.getMessage()); // Create empty graph as fallback System.out.println("Using empty graph"); } return graph; } ``` -------------------------------- ### Create and Populate a Graph Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Demonstrates how to initialize a new graph, add nodes and edges, and set attributes for them. ```java Graph graph = new DefaultGraph("myGraph"); Node n1 = graph.addNode("A"); Node n2 = graph.addNode("B"); Edge e = graph.addEdge("e1", n1, n2); n1.setAttribute("label", "First"); e.setAttribute("weight", 2.5); ``` -------------------------------- ### BreadthFirstIterator getDepthOf() Method Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Gets the traversal depth of a specific node that has already been visited. The start node has a depth of 0. ```java int getDepthOf(Node node) ``` -------------------------------- ### Set Java System Properties for GraphStream Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Configure GraphStream behavior by setting Java system properties before library initialization. This example sets the UI backend and headless mode. ```java // Set system properties before using library System.setProperty("org.graphstream.ui", "javafx"); System.setProperty("java.awt.headless", "false"); // For GUI ``` -------------------------------- ### Handling GraphParseException with Fallback Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/errors.md This example shows a robust error handling pattern for graph file parsing. If the primary file fails to parse, it attempts to load a backup file, also handling potential IOExceptions. ```java String filename = "graph.gml"; Graph graph = new DefaultGraph("loaded"); try { graph.read(filename); } catch (GraphParseException e) { System.err.println("Could not parse file: " + filename); System.err.println("Reason: " + e.getMessage()); // Fall back to alternative source try { graph.read(filename + ".backup"); } catch (IOException | GraphParseException e2) { System.err.println("Backup file also failed"); } } catch (IOException e) { System.err.println("Could not read file: " + filename); } ``` -------------------------------- ### Large Graph with Capacity Hints Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Shows how to initialize a DefaultGraph with capacity hints for a large number of nodes and edges, which helps avoid reallocation overhead when adding millions of elements. ```java // For a graph with ~10000 nodes and ~50000 edges Graph graph = new DefaultGraph("large", true, false, 10000, 50000); // ... add millions of elements without reallocation overhead ``` -------------------------------- ### begin(String filename) Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/file-io.md Opens a file for writing, preparing it for incremental writes. This method is typically used in conjunction with flush() and end() for more control over the writing process. ```APIDOC ## begin(String filename) ### Description Opens a file for writing. This method is used to initiate the writing process, often for incremental writes when used with `flush()`. ### Method ```java void begin(String filename) throws IOException ``` ### Parameters #### Path Parameters - **filename** (String) - Yes - Description: The path of the file to open for writing. ``` -------------------------------- ### DepthFirstIterator Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Traverses nodes in a graph in depth-first order. It allows iterating through nodes starting from a specified node and provides methods to get the current depth of a node. ```APIDOC ## DepthFirstIterator `org.graphstream.graph.DepthFirstIterator` — Traverses nodes in depth-first order. ### Signature ```java public class DepthFirstIterator extends DFSIterator ``` **Package:** `org.graphstream.graph` ### Constructor #### DepthFirstIterator(Node start) ```java public DepthFirstIterator(Node start) ``` Creates an iterator starting from the given node. ### Methods Same as BreadthFirstIterator: hasNext(), next(), getDepthOf(), getDepthMax() ### Usage Example ```java DepthFirstIterator iter = new DepthFirstIterator(root); while (iter.hasNext()) { Node node = iter.next(); int depth = iter.getDepthOf(node); System.out.println(node.getId() + " (depth: " + depth + ")"); } ``` ``` -------------------------------- ### BreadthFirstIterator Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Traverses nodes in breadth-first order starting from a given node. Provides methods to check for next nodes, retrieve the next node, and get the depth of visited nodes. ```APIDOC ## BreadthFirstIterator ### Description Traverses nodes in breadth-first order starting from a given node. Provides methods to check for next nodes, retrieve the next node, and get the depth of visited nodes. ### Class Signature ```java public class BreadthFirstIterator extends BFSIterator ``` ### Constructor #### BreadthFirstIterator(Node start) Creates an iterator starting from the given node. | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | start | Node | Yes | — | Starting node for traversal | ### Methods #### hasNext() Returns `true` if more nodes to visit. ```java boolean hasNext() ``` #### next() Returns the next node in BFS order. ```java Node next() ``` #### getDepthOf(Node node) Gets the traversal depth of a visited node. | Parameter | Type | Description | |-----------|------|-------------| | node | Node | A node visited during traversal | **Returns:** `int` — Depth level (0 for start node) ```java int getDepthOf(Node node) ``` #### getDepthMax() Gets the maximum depth reached during traversal. **Returns:** `int` — Maximum depth reached during traversal ```java int getDepthMax() ``` ### Usage Example ```java Graph graph = new DefaultGraph("tree"); Node root = graph.addNode("root"); Node a = graph.addNode("a"); Node b = graph.addNode("b"); Node c = graph.addNode("c"); Node d = graph.addNode("d"); graph.addEdge("e1", "root", "a"); graph.addEdge("e2", "root", "b"); graph.addEdge("e3", "a", "c"); graph.addEdge("e4", "b", "d"); BreadthFirstIterator iter = new BreadthFirstIterator(root); while (iter.hasNext()) { Node node = iter.next(); int depth = iter.getDepthOf(node); System.out.println(node.getId() + " (depth: " + depth + ")"); } System.out.println("Max depth: " + iter.getDepthMax()); ``` ``` -------------------------------- ### Get Attribute Count Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Get the total number of attributes currently set on an element. ```java int getAttributeCount() ``` -------------------------------- ### Configure Production Graph with Capacity Hints Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Configure a production-ready graph with strict checking and capacity hints for nodes and edges. This helps in performance tuning by pre-allocating memory. ```java // Strict checking with capacity hints Graph graph = new DefaultGraph("prod", true, false, 1000, 5000); ``` -------------------------------- ### Create and Start LayoutRunner Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Instantiates a LayoutRunner to execute a layout algorithm in a background thread. Use this when you need to run layout computations asynchronously. The 'releaseLock' parameter controls the update frequency. ```java Layout layout = new SpringBox(false); LayoutRunner runner = new LayoutRunner(graph, layout, true, 0); runner.start(); // Layout runs in background thread // Later, stop the layout runner.release(); ``` -------------------------------- ### Basic Graph Creation and Population Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Demonstrates the basic creation of a DefaultGraph, adding nodes, and then adding edges between them. Shows how to query the node and edge counts. ```java Graph graph = new DefaultGraph("network"); // Add nodes Node n1 = graph.addNode("Node1"); Node n2 = graph.addNode("Node2"); Node n3 = graph.addNode("Node3"); // Add edges graph.addEdge("e1", "Node1", "Node2"); graph.addEdge("e2", "Node2", "Node3"); // Query structure System.out.println("Nodes: " + graph.getNodeCount()); System.out.println("Edges: " + graph.getEdgeCount()); ``` -------------------------------- ### Get Opposite Node of an Edge Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/edge-interface.md Gets the node at the other end of this edge, given one of its endpoints. Returns null if the provided node is not an endpoint. ```java Node getOpposite(Node node) ``` -------------------------------- ### Graph ID Initialization Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Demonstrates how to initialize a graph with a specific ID and verify it. ```java Graph graph = new DefaultGraph("myGraph"); assert graph.getId().equals("myGraph"); ``` -------------------------------- ### Create SingleGraph with Capacity Hints Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Initialize a `SingleGraph` with a given ID, checking behavior, auto-creation settings, and initial capacity hints for nodes and edges. ```java Graph graph = new SingleGraph("myGraph", false, true, 1000, 1000); ``` -------------------------------- ### Basic Graph Creation and Manipulation in Java Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Demonstrates the fundamental steps of creating a graph, adding nodes and edges, setting attributes, saving to a file, and displaying the graph using the GraphStream library. ```java // Create a graph Graph graph = new DefaultGraph("myGraph"); // Add nodes graph.addNode("A"); graph.addNode("B"); graph.addNode("C"); // Add edges graph.addEdge("e1", "A", "B"); graph.addEdge("e2", "B", "C"); // Query structure System.out.println("Nodes: " + graph.getNodeCount()); System.out.println("Edges: " + graph.getEdgeCount()); // Set attributes graph.getNode("A").setAttribute("label", "Node A"); graph.getNode("A").setAttribute("color", "red"); // Save to file graph.write("graph.gml"); // Display Viewer viewer = graph.display(); ``` -------------------------------- ### Select Default and Specific Layout Algorithms Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Instantiate a default layout algorithm or choose from specific implementations like SpringBox or LinLog. The constructor argument for some layouts indicates whether to stabilize. ```java Layout layout = Layouts.newLayoutAlgorithm(); Layout springBox = new SpringBox(false); Layout linLog = new LinLog(false); ``` -------------------------------- ### Get Edge Factory Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves the factory used for creating edge instances. ```java EdgeFactory edgeFactory() ``` -------------------------------- ### Get Node Factory Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves the factory used for creating node instances. ```java NodeFactory nodeFactory() ``` -------------------------------- ### Initialize LinLog Layout Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Instantiates the LinLog layout algorithm, optimized for visualizing weighted graphs. Set stabilize to true to pre-compute stable positions. ```java Layout layout = new LinLog(false); ``` -------------------------------- ### Get Graph Containing the Edge Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/edge-interface.md Retrieves the graph object to which this edge belongs. ```java Graph getGraph() ``` -------------------------------- ### Mark Simulation Step Beginning Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Marks the beginning of a new step in the simulation, used for tracking dynamic graph evolution. ```java void stepBegins(double time) ``` -------------------------------- ### Get Simulation Step Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves the current simulation step, represented as a double timestamp. ```java double getStep() ``` -------------------------------- ### EdgeRejectedException Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/types.md Thrown when an edge cannot be added, for example, if it's a duplicate in a SingleGraph or in strict mode. ```APIDOC ## EdgeRejectedException ### Description Thrown when an edge cannot be added (e.g., duplicate in SingleGraph, strict mode). ### Exception `org.graphstream.graph.EdgeRejectedException` ``` -------------------------------- ### DefaultGraph Construction (Capacity Hints) Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Constructs a DefaultGraph with capacity hints to pre-allocate memory for a specified number of nodes and edges, optimizing performance for large graphs. ```java Graph g = new DefaultGraph("g", true, false, 1000, 2000); // Pre-allocate for ~1000 nodes and ~2000 edges ``` -------------------------------- ### Write Entire Graph using Graph Convenience Method Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/file-io.md This demonstrates a simplified way to write the entire graph to a file using the Graph convenience method. It internally uses a FileSink. ```java Graph graph = new DefaultGraph("myGraph"); // ... populate graph ... try { graph.write("output/graph.gml"); } catch (IOException e) { e.printStackTrace(); } ``` -------------------------------- ### Get List of Neighbor Nodes Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Returns a list of all nodes directly connected to the current node. ```Java List getNeighborNodeList() ``` -------------------------------- ### Get Array Attribute Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves an array of objects by key. Returns null if the attribute is not found. ```java Object[] array = node.getArray("myArray"); ``` -------------------------------- ### Get Element ID Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves the unique identifier of a graph element. This operation is constant time. ```Java String getId() ``` -------------------------------- ### Step Begins Event Callback Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/streams-and-pipes.md This callback is invoked at the beginning of each simulation step for dynamic graphs. It provides the source, timestamp, and the current step number. ```java void stepBegins(String sourceId, long timeId, double step) ``` -------------------------------- ### Initialize SpringBox Layout Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Instantiates the SpringBox force-directed layout algorithm. Set stabilize to true to pre-compute stable positions. ```java Layout layout = new SpringBox(false); ``` -------------------------------- ### BreadthFirstIterator Constructor Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Creates a BreadthFirstIterator starting from a specified node. This is used to initiate a breadth-first traversal. ```java public BreadthFirstIterator(Node start) ``` -------------------------------- ### Layout.getNodeIndex(Node node) Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Gets the internal index assigned to a specific node within the layout algorithm. ```APIDOC ## getNodeIndex(Node node) ### Description Gets the internal index for a node in the layout algorithm. ### Signature ```java int getNodeIndex(Node node) ``` ``` -------------------------------- ### Get String/Char Label Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves a character sequence attribute by key. Use this for string or character-based attributes. ```java CharSequence label = node.getLabel("text"); ``` -------------------------------- ### LayoutRunner.run() Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md The main method executed when the LayoutRunner thread is started. This method is called automatically by the Java runtime. ```APIDOC ## run() ### Description Main thread method (called automatically when thread starts). ``` -------------------------------- ### Configure Small In-Memory Graph Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Use this minimal configuration for testing purposes. It creates a simple in-memory graph. ```java // Minimal configuration, best for testing Graph graph = new DefaultGraph("small"); ``` -------------------------------- ### Get Node Z-coordinate Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieves the Z-coordinate of the node. This method returns a double value representing the coordinate if it has been set. ```java double z() ``` -------------------------------- ### Get Node Y-coordinate Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieves the Y-coordinate of the node. This method returns a double value representing the coordinate if it has been set. ```java double y() ``` -------------------------------- ### Get Node X-coordinate Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieves the X-coordinate of the node. This method returns a double value representing the coordinate if it has been set. ```java double x() ``` -------------------------------- ### Compare Graph Reallocation Performance Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Demonstrates the performance difference between default graph capacities (leading to reallocations) and pre-allocated capacities for adding a large number of nodes. ```java // Bad: Default capacities, many reallocations Graph graph = new DefaultGraph("bad"); for (int i = 0; i < 100000; i++) { graph.addNode("n" + i); // Repeated reallocation } // Good: Pre-allocated capacity Graph graph = new DefaultGraph("good", true, false, 100000, 0); for (int i = 0; i < 100000; i++) { graph.addNode("n" + i); // No reallocation } ``` -------------------------------- ### Change Graph Configuration at Runtime Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Demonstrates how to change strict checking and auto-creation modes on an existing graph instance. ```Java Graph graph = new DefaultGraph("graph"); // Change strict checking graph.setStrict(false); boolean isStrict = graph.isStrict(); // Change auto-creation graph.setAutoCreate(true); boolean isAutoCreate = graph.isAutoCreationEnabled(); ``` -------------------------------- ### Get Element Sinks Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves an iterable of all ElementSink listeners registered to this graph. Use this to inspect or manage element listeners. ```java Iterable elementSinks() ``` -------------------------------- ### Layouts.newLayoutAlgorithm() Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Factory method to create a default layout algorithm, typically the SpringBox layout. ```APIDOC ## newLayoutAlgorithm() ### Description Creates the default layout algorithm (typically SpringBox). ### Returns - **Layout** - A layout implementation ``` -------------------------------- ### Interactive Graph Visualization Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Shows how to create an interactive graph visualization with auto-layout and process viewer events in a loop. ```java Graph graph = new DefaultGraph("interactive"); graph.addNode("A"); graph.addEdge("e1", "A", "B"); Viewer viewer = graph.display(true); // With auto-layout ViewerPipe pipe = new ViewerPipe(viewer); pipe.addSink(graph); while (true) { pipe.pump(); // Process viewer events // Your application logic } ``` -------------------------------- ### Get Attribute Sinks Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves an iterable of all AttributeSink listeners registered to this graph. Use this to inspect or manage attribute listeners. ```java Iterable attributeSinks() ``` -------------------------------- ### File I/O Documentation Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/COMPLETION_SUMMARY.txt Documentation for file input and output operations, supporting multiple formats. ```APIDOC ## File I/O ### Description Documentation for file input and output operations, supporting 8 different formats for graph data persistence. ### Endpoint `api-reference/file-io.md` ### Supported Formats - 8 formats supported. ``` -------------------------------- ### Get Vector Attribute Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves a list of numbers (vector) by key. Ensures the list is not null and contains Number objects. ```java List coords = node.getVector("xyz"); if (coords != null && coords.size() == 3) { double x = coords.get(0).doubleValue(); double y = coords.get(1).doubleValue(); double z = coords.get(2).doubleValue(); } ``` -------------------------------- ### BreadthFirstIterator getDepthMax() Method Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/utilities.md Retrieves the maximum depth reached during the breadth-first traversal. This indicates the furthest level from the start node. ```java int getDepthMax() ``` -------------------------------- ### Get Edge by ID Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieves a specific edge connected to this node using its unique identifier. Returns null if no such edge is found. ```java Edge getEdge(String id) ``` -------------------------------- ### Quick Graph Display with Auto-Layout Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Use this one-liner to quickly display a graph with an automatically managed layout. Ensure a graph object is already created and populated. ```java Graph graph = new DefaultGraph("display"); graph.addNode("A"); graph.addNode("B"); graph.addEdge("e", "A", "B"); // One-liner to display with auto-layout Viewer viewer = graph.display(); ``` -------------------------------- ### Dynamic Graph with Auto-Creation Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Illustrates creating a dynamic graph using DefaultGraph in auto-create mode. Nodes are automatically created when edges are added between non-existent nodes. ```java Graph graph = new DefaultGraph("dynamic", false, true); // Nodes are automatically created Edge e = graph.addEdge("e1", "A", "B"); // Creates A and B if missing System.out.println("Nodes: " + graph.getNodeCount()); // 2 ``` -------------------------------- ### Get Incoming Degree of Node Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Calculates the number of edges entering this node. This includes incoming directed edges and all undirected edges. ```java int getInDegree() ``` -------------------------------- ### Get Outgoing Degree of Node Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Calculates the number of edges leaving this node. This includes outgoing directed edges and all undirected edges. ```java int getOutDegree() ``` -------------------------------- ### Read and Write Graph Data to Files Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Demonstrates reading from and writing to files, including auto-detection of format and explicit format specification. ```java // Read (auto-detects format from extension) Graph graph = new DefaultGraph("loaded"); graph.read("data/graph.gml"); // Write (auto-detects format from extension) graph.write("output/graph.gml"); // Explicit format FileSource source = new FileSourceGML(); source.addSink(graph); source.readAll("graph.gml"); FileSink sink = new FileSinkGML(); sink.writeAll(graph, "output.gml"); ``` -------------------------------- ### Get Target Node of an Edge Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/edge-interface.md Retrieves the target node of an edge. For directed edges, this is the destination. For undirected edges, it's the other endpoint. ```java Node getTargetNode() ``` -------------------------------- ### ViewerPipe Constructor Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Creates a pipe connected to a viewer. This is the initial step to establish communication. ```Java public ViewerPipe(Viewer viewer) ``` -------------------------------- ### Create Default Layout Algorithm Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Creates a default layout algorithm instance, typically SpringBox. This is a convenient factory method for obtaining a standard layout implementation. ```java Layout layout = Layouts.newLayoutAlgorithm(); LayoutRunner runner = new LayoutRunner(graph, layout, true, 0); ``` -------------------------------- ### Get Neighbor Node by Edge Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieves the node at the other end of a given edge connected to the current node. Ensure the edge is connected to this node. ```Java Node getNeighborNode(Edge edge) ``` ```Java Edge edge = node.getEdge(0); Node neighbor = node.getNeighborNode(edge); ``` -------------------------------- ### Handle IOException When Reading Graph File Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/errors.md Demonstrates how to catch and handle IOException when attempting to read a graph file that may not exist or be accessible. ```java Graph graph = new DefaultGraph("test"); try { // File doesn't exist graph.read("/path/that/does/not/exist/graph.gml"); } catch (IOException e) { System.err.println("File not found or cannot be read: " + e.getMessage()); } ``` -------------------------------- ### Get Total Degree of Node Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Calculates the total number of edges connected to this node. For directed graphs, this includes both incoming and outgoing edges. ```java int getDegree() ``` -------------------------------- ### Graph Constructor Signatures Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Shows the different constructor signatures available for SingleGraph, DefaultGraph, and MultiGraph implementations. ```java public SingleGraph(String id) public SingleGraph(String id, boolean strictChecking, boolean autoCreate) public SingleGraph(String id, boolean strictChecking, boolean autoCreate, int initialNodeCapacity, int initialEdgeCapacity) ``` -------------------------------- ### Get Element Index Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves the automatically maintained index of a graph element. The index is used internally and elements are re-indexed upon removal. ```Java int getIndex() ``` -------------------------------- ### Create SingleGraph with ID and Options Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Create a `SingleGraph` specifying the graph ID, whether to enable strict checking, and if nodes should be auto-created. ```java Graph graph = new SingleGraph("myGraph", false, true); ``` -------------------------------- ### Disable and Re-enable Strict Checking Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Use the `setStrict` method to temporarily disable strict checking, for example, during graph loading, and then re-enable it for validation. ```Java Graph graph = new DefaultGraph("graph", true, false); // Disable strict checking for loading graph.setStrict(false); // ... load graph ... // Re-enable for validation graph.setStrict(true); ``` -------------------------------- ### Handling IdAlreadyInUseException Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/errors.md Demonstrates how to catch and handle the IdAlreadyInUseException when adding a node that already exists. It shows options for logging, using the existing node, or failing fast. ```java Graph graph = new DefaultGraph("strict"); // Strict by default Node n1 = graph.addNode("A"); // This throws IdAlreadyInUseException try { graph.addNode("A"); // "A" already exists } catch (IdAlreadyInUseException e) { System.err.println("Node already exists: " + e.getMessage()); } ``` ```java Graph graph = new DefaultGraph("myGraph"); // Strict mode try { Node node = graph.addNode("nodeId"); } catch (IdAlreadyInUseException e) { // Option 1: Log and skip System.err.println("Node already exists, skipping: " + e); // Option 2: Handle gracefully Node existing = graph.getNode("nodeId"); System.out.println("Using existing node: " + existing.getId()); // Option 3: Fail fast throw new RuntimeException("Failed to add unique node", e); } ``` -------------------------------- ### SingleGraph(String id, boolean strictChecking, boolean autoCreate, int initialNodeCapacity, int initialEdgeCapacity) Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-implementations.md Creates an empty graph with specified capacity hints for nodes and edges, offering fine-grained control over initial storage. ```APIDOC ## SingleGraph(String id, boolean strictChecking, boolean autoCreate, int initialNodeCapacity, int initialEdgeCapacity) ### Description Creates an empty graph with specified capacity hints. ### Method Java Constructor ### Parameters #### Path Parameters - **id** (String) - Required - Graph identifier - **strictChecking** (boolean) - Required - Error checking mode - **autoCreate** (boolean) - Required - Auto-create nodes - **initialNodeCapacity** (int) - Required - Initial node storage capacity - **initialEdgeCapacity** (int) - Required - Initial edge storage capacity ### Request Example ```java Graph graph = new SingleGraph("myGraph", false, true, 1000, 5000); ``` ``` -------------------------------- ### ViewerPipe Constructor Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/viewer-and-layout.md Creates a pipe connected to a viewer, enabling communication from the viewer back to the application. ```APIDOC ## ViewerPipe(Viewer viewer) ### Description Creates a pipe connected to a viewer. ### Signature ```java public ViewerPipe(Viewer viewer) ``` ``` -------------------------------- ### Chaining AttributePipes for Event Flow Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/streams-and-pipes.md Demonstrates how to chain multiple AttributePipes to create a pipeline for event propagation from a source graph to a sink graph. ```java // Source -> Pipe1 -> Pipe2 -> Sink Graph source = new DefaultGraph("source"); AttributePipe pipe1 = new AttributePipe(); AttributePipe pipe2 = new AttributePipe(); Graph sink = new DefaultGraph("sink"); source.addSink(pipe1); pipe1.addSink(pipe2); pipe2.addSink(sink); // Events flow through pipeline ``` -------------------------------- ### Get Edge by Index Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieves an edge connected to this node based on its index in the node's edge list. Throws IndexOutOfBoundsException if the index is invalid. ```java Edge getEdge(int index) throws IndexOutOfBoundsException ``` -------------------------------- ### Get Numeric Attribute Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves a numeric attribute by key, attempting to parse string values as doubles. Returns Double.NaN if the attribute is not found or not numeric. ```java double weight = node.getNumber("weight"); if (!Double.isNaN(weight)) { System.out.println("Weight: " + weight); } ``` -------------------------------- ### Get Source Node of an Edge Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/edge-interface.md Retrieves the source node of an edge. For directed edges, this is the origin. For undirected edges, it's one of the two endpoints. ```java Node getSourceNode() ``` -------------------------------- ### Get Attribute by Key Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/element-interface.md Retrieves an attribute value from a graph element using its string key. Returns null if the attribute is not found. This operation has logarithmic complexity. ```Java Object getAttribute(String key) ``` ```Java Node node = graph.getNode("n1"); Object value = node.getAttribute("color"); if (value != null) { System.out.println("Color: " + value); } ``` -------------------------------- ### Configure Layout Parameters Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/configuration.md Set parameters for a chosen layout algorithm, such as stabilization threshold, computation quality, and force magnitude. A LayoutRunner can then be initialized to apply the layout to a graph. ```java Layout layout = new SpringBox(false); layout.setStabilizationLimit(0.95); layout.setQuality(4); layout.setForce(0.5); LayoutRunner runner = new LayoutRunner(graph, layout, true, 33); runner.start(); ``` -------------------------------- ### Element Interface Definition Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/types.md The base interface for all graph components, providing identity and attribute access. Includes methods for getting and setting attributes, and iterating over attribute keys. ```Java public interface Element { // Identity String getId(); int getIndex(); // Attribute access Object getAttribute(String key); T getAttribute(String key, Class clazz); Object getFirstAttributeOf(String... keys); T getFirstAttributeOf(Class clazz, String... keys); // Convenience methods default CharSequence getLabel(String key) { ... } default double getNumber(String key) { ... } default List getVector(String key) { ... } default Object[] getArray(String key) { ... } // Modification void setAttribute(String key, Object value); void removeAttribute(String key); void clearAttributes(); // Iteration Iterable getAttributeKeySet(); int getAttributeCount(); Stream attributeStream(); } ``` -------------------------------- ### Handle File Not Found and Parse Errors Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/README.md Shows how to catch IOExceptions for missing files and GraphParseException for malformed graph data during reading. ```Java try { graph.read("missing.gml"); } catch (IOException e) { System.err.println("File not found"); } catch (GraphParseException e) { System.err.println("Parse error"); } ``` -------------------------------- ### Detailed IOException Handling for Graph File Reading Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/errors.md Provides a more granular approach to handling different types of IOExceptions, such as file not found or permission denied, during graph file reading. ```java String filename = "data/graph.gml"; Graph graph = new DefaultGraph("loaded"); try { graph.read(filename); } catch (IOException e) { if (e.getMessage().contains("No such file")) { System.err.println("File does not exist: " + filename); } else if (e.getMessage().contains("Permission denied")) { System.err.println("Permission denied reading: " + filename); } else { System.err.println("I/O error: " + e.getMessage()); } } catch (GraphParseException e) { System.err.println("File format error: " + e.getMessage()); } ``` -------------------------------- ### Get Node by Integer Index Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves a node by its automatically maintained index. This method is suitable for iterating through nodes when their IDs are not immediately known. It throws an IndexOutOfBoundsException if the index is invalid. ```java for (int i = 0; i < graph.getNodeCount(); i++) { Node node = graph.getNode(i); System.out.println(node.getId()); } ``` -------------------------------- ### getStep() Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/graph-interface.md Retrieves the current simulation step, represented as a double-precision floating-point number. ```APIDOC ## getStep() ### Description Retrieves the current simulation step (timestamp). ### Returns `double` — The current simulation step (timestamp). ``` -------------------------------- ### Get Node Coordinates Source: https://github.com/graphstream/gs-core/blob/dev/_autodocs/api-reference/node-interface.md Retrieve the 2D or 3D coordinates of a node. These methods return the coordinate value if it has been set, otherwise, their behavior might depend on the specific graph implementation. ```APIDOC ## x() ### Description Retrieves the X-coordinate of the node. ### Returns - `double` - The X-coordinate of the node if set. ## y() ### Description Retrieves the Y-coordinate of the node. ### Returns - `double` - The Y-coordinate of the node if set. ## z() ### Description Retrieves the Z-coordinate of the node. ### Returns - `double` - The Z-coordinate of the node if set. ```