Package y25.base

Lays out the framework for working with layered graphs.

See:
          Description

Interface Summary
EdgeMap Provides access to data associated with an edge.
GraphCursor A cursor interface for interating over graphs.
GraphMap Provides access to data associated with a graph.
GraphTools.RealizerFactory An interface for creation of node and edge realizers.
LayerEdgeCursor A cursor interface for iterating over layer edges.
LayerEdgeMap Provides access to data associated with a layer edge.
NodeMap Provides access to data associated with a node.
 

Class Summary
GraphList Specialized list implementation for instances of type Graph.
GraphTools A utility class which provides means to duplicate entire Graphs or Graph2Ds.
GraphTools.GraphDataInfo Stores information about a DataProvider.
LayerEdge A LayerEdge connects two Nodes that may reside inside different Graphs but that are all inside the same LayeredGraph.
LayerEdgeList Specialized list implementation for instances of type LayerEdge.
LayeredGraph The base for the entire y25 package.
 

Package y25.base Description

Lays out the framework for working with layered graphs.

The main class of this package is LayeredGraph.

A layered graph is a kind of meta-graph that is composed of multiple layers, where each layer is represented by a single Graph object. Nodes residing in the same Graph can be connected by creating normal Edges, whereas nodes residing in different graphs (that belong to the same layered graph) can be connected using LayerEdges.

Such a layered graph may be useful in a variety of applications: In a time dependent process, each layer could represent a snapshot of various entities at a given time. Alternatively, a hierarchical structure can be modeled by putting parent nodes in one layer, children of those nodes in another layer and children of the children in yet another layer, etc. These applications imply the need for a possibility to identify a group of nodes or edges belonging to different layers as beeing logically the same. Therefore, each node and each edge can be assigned a user definded ID that starts from 1 and has to be positive. Also, each node can specify the ID of its parent node. If it has no parents, then the parent ID of that node is 0.

All graphs inside the layered graph have either been created by calling one of the createGraph methods of the layered graph or by importing existing graphs into the layered graph via the importGraph methods. Since each graph has a graph listener attached to it, newly created nodes and edges are assigned a new and unique ID automatically.

Creating a Layered Graph

An example will illustrate the concepts described above:
LayeredGraph layeredGraph = new LayeredGraph(); // creates the layered graph object

// Creating Graphs, Nodes, Edges 
Graph graph1 = layeredGraph.createGraph();       // creates a new layer(graph) inside the layered graph and returns the created graph
Node node1 = graph1.createNode();                // creates a new node inside graph1, automatically gets node ID 1
Node node2 = graph1.createNode();                // creates another node inside graph1, automatically gets node ID 2
Edge edge1 = graph1.createEdge(node1, node2);    // creates a new edge inside graph1, automatically gets edge ID 1

Graph graph2 = layeredGraph.createGraph();       // creates another layer(graph) inside the layered graph and returns the created graph
Node node3 = graph2.createNode();                // creates a new node inside graph2, automatically gets node ID 3
Node node4 = graph2.createNode();                // creates another node inside graph2, automatically gets node ID 4
Edge edge2 = graph2.createEdge(node3, node4);    // creates a new edge inside graph2, automatically gets edge ID 2

// Creating LayerEdges
LayerEdge layerEdge1 = layeredGraph.createLayerEdge(node1, node3); // a layer edge between nodes of different layers
LayerEdge layerEdge32= layeredGraph.createLayerEdge(node1, node2); // layer edges inside one layer are allowed !

Working with a LayeredGraph

After the layered graph is created, there are various methods of modifying it. One is changing properties of its elements by using methods of the layered graph object:
layeredGraph.setParentID(node2, layeredGraph.getNodeID(node4));
                                                 // sets the parent ID of node2 to the node ID of node4
layeredGraph.setNodeID(node3, layeredGraph.getNodeID(node1));
                                                 // sets the node ID of node3 to that of node1. node1 and node2 are logically the same
layeredGraph.setEdgeID(edge2, layeredGraph.getEdgeID(edge1));
                                                 // same as above, but with edges
Another very important mechanism is iterating over the elements of a layered graphs and performing work on them:
// Iterate over all graphs inside the layered graph
for (GraphCursor gc = layeredGraph.graphs(); gc.ok(); gc.next()) {
    Graph graph = gc.graph(); // the current graph
    
    // Iterate over all nodes of the current graph
    for (NodeCursor nc = graph.nodes(); nc.ok(); nc.next()) {
        Node node = nc.node(); // the current node
        // ... do some work ...
    }
    
    // Iterate over all edges of the current graph
    for (EdgeCursor ec = graph.edges(); ec.ok(); ec.next()) {
        Edge edge = ec.edge(); // the current edge
        // ... do some work ...
    }
}

// Iterate over all layer edges inside the layered graph
for (LayerEdgeCursor lec = layeredGraph.layerEdges(); lec.ok(); lec.next()) {
    LayerEdge layerEdge = lec.layerEdge();
    // ... do some work ...
}

// Iterate over all layer edges starting from a given node
Node sourceNode;
for (LayerEdgeCursor lec = layeredGraph.outLayerEdges(sourceNode); lec.ok(); lec.next()) {
    LayerEdge layerEdge = lec.layerEdge();
    // ... do some work ...
}

// Iterate over all layer edges terminating in a given node
Node targetNode;
for (LayerEdgeCursor lec = layeredGraph.inLayerEdges(targetNode); lec.ok(); lec.next()) {
    LayerEdge layerEdge = lec.layerEdge();
    // ... do some work ...
}