Satsuma
a delicious .NET graph library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
Public Member Functions | Properties | List of all members
Satsuma.IO.GraphML.GraphMLFormat Class Reference

Loads and saves graphs stored in GraphML format. More...

Public Member Functions

 GraphMLFormat ()
 
void Load (XDocument doc)
 Loads from an XML document. More...
 
void Load (XmlReader xml)
 Loads from an XML reader. More...
 
void Load (TextReader reader)
 Loads from a reader. More...
 
void Load (string filename)
 Loads from a file. More...
 
void RegisterPropertyLoader (Func< XElement, GraphMLProperty > loader)
 Registers a new GraphML property loader. More...
 
void Save (TextWriter writer)
 Saves to a writer. More...
 
void Save (string filename)
 Saves to a file. More...
 

Properties

IGraph Graph [get, set]
 The graph itself. More...
 
IList< GraphMLPropertyProperties [get, set]
 The properties (special data for nodes, arcs and the graph itself). More...
 

Detailed Description

Loads and saves graphs stored in GraphML format.

See the GraphML website for information on the GraphML format.

Example (loading a graph and some special values for objects):

using GraphML = Satsuma.IO.GraphML;
// [...]
GraphML.GraphMLFormat f = new GraphML.GraphMLFormat();
f.Load(@"c:\my_little_graph.graphml");
// retrieve the loaded graph
var g = f.Graph;
// retrieve the property defining the appearance of the nodes
GraphML.NodeGraphicsProperty ngProp = (GraphML.NodeGraphicsProperty)
f.Properties.FirstOrDefault(x => x is GraphML.NodeGraphicsProperty);
foreach (var node in g.Nodes())
{
GraphML.NodeGraphics ng = null;
if (ngProp != null) ngProp.TryGetValue(node, out ng);
Console.Write("Node "+node+": ");
if (ng == null) Console.WriteLine("no position defined");
else Console.WriteLine(string.Format("X={0};Y={1}", ng.X, ng.Y));
}
// retrieve some user-defined property defining weights for arcs
GraphML.StandardProperty<double> weights = (GraphML.StandardProperty<double>)
f.Properties.FirstOrDefault(x => x.Name == "weight" &&
(x.Domain == GraphML.PropertyDomain.All || x.Domain == GraphML.PropertyDomain.Arc) &&
x is GraphML.StandardProperty<double>);
foreach (var arc in g.Arcs())
{
double weight = 0;
bool hasWeight = (weights != null && weights.TryGetValue(arc, out weight));
Console.WriteLine("Arc "+arc+": weight is "+(hasWeight ? weight.ToString() : "undefined"));
}

Example (saving a complete bipartite graph without any bells and whistles):

GraphML.GraphMLFormat f = new GraphML.GraphMLFormat();
f.Graph = new CompleteBipartiteGraph(3, 5, Directedness.Undirected);
f.Save(@"c:\my_little_graph.graphml");

For examples on saving extra values for nodes, arcs or the graph itself; see the descendants of GraphMLProperty, such as StandardProperty<T> and NodeGraphicsProperty.

Definition at line 514 of file IO.GraphML.cs.

Constructor & Destructor Documentation

Satsuma.IO.GraphML.GraphMLFormat.GraphMLFormat ( )

Definition at line 533 of file IO.GraphML.cs.

Member Function Documentation

void Satsuma.IO.GraphML.GraphMLFormat.Load ( XDocument  doc)

Loads from an XML document.

Definition at line 573 of file IO.GraphML.cs.

void Satsuma.IO.GraphML.GraphMLFormat.Load ( XmlReader  xml)

Loads from an XML reader.

Definition at line 628 of file IO.GraphML.cs.

void Satsuma.IO.GraphML.GraphMLFormat.Load ( TextReader  reader)

Loads from a reader.

Parameters
readerA reader on the input file, e.g. a StreamReader.

Definition at line 636 of file IO.GraphML.cs.

void Satsuma.IO.GraphML.GraphMLFormat.Load ( string  filename)

Loads from a file.

Definition at line 643 of file IO.GraphML.cs.

void Satsuma.IO.GraphML.GraphMLFormat.RegisterPropertyLoader ( Func< XElement, GraphMLProperty loader)

Registers a new GraphML property loader.

By default, recognition of StandardProperty<T> and NodeGraphicsProperty is supported when loading. You can define your own property classes by calling this method to add a loader.

The loader chain is used to make properties from <key> elements.

Parameters
loaderMust take an XElement (the key) as argument, and return a property with the parameters defined by the key element. Must throw ArgumentException if the element could not be recognized as a definition of the property class supported by the loader.

Definition at line 557 of file IO.GraphML.cs.

void Satsuma.IO.GraphML.GraphMLFormat.Save ( TextWriter  writer)

Saves to a writer.

Parameters
writerA writer on the output file, e.g. a StreamWriter.

Definition at line 708 of file IO.GraphML.cs.

void Satsuma.IO.GraphML.GraphMLFormat.Save ( string  filename)

Saves to a file.

Definition at line 715 of file IO.GraphML.cs.

Property Documentation

IGraph Satsuma.IO.GraphML.GraphMLFormat.Graph
getset

The graph itself.

  • When loading: Must be an IBuildableGraph to accomodate the loaded graph, or null. If null, will be replaced with a new CustomGraph instance.
  • When saving: Can be an arbitrary graph (not null).

Definition at line 527 of file IO.GraphML.cs.

IList<GraphMLProperty> Satsuma.IO.GraphML.GraphMLFormat.Properties
getset

The properties (special data for nodes, arcs and the graph itself).

Definition at line 529 of file IO.GraphML.cs.


The documentation for this class was generated from the following file: