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.SimpleGraphFormat Class Reference

Loads and saves graphs which are stored in a very simple format. More...

Public Member Functions

Node[] Load (TextReader reader, Directedness directedness)
 Loads from a reader. More...
 
Node[] Load (string filename, Directedness directedness)
 Loads from a file. More...
 
void Save (TextWriter writer)
 Saves to a writer. More...
 
void Save (string filename)
 Saves to a file. More...
 
 SimpleGraphFormat ()
 

Properties

IList< Dictionary< Arc, string > > Extensions [get, set]
 The extensions (arc functions). More...
 
IGraph Graph [get, set]
 The graph itself. More...
 
int StartIndex [get, set]
 The index where node numbering starts (0 by default). More...
 

Detailed Description

Loads and saves graphs which are stored in a very simple format.

The first line must contain two numbers (the count of nodes and arcs). Each additional line must contain a pair of numbers for each arc (that is, the identifiers of the start and end nodes of the arc).

Optionally, arc functions (extensions) can be defined as excess tokens after the arc definition. Extensions are separated by whitespaces and thus must be nonempty strings containing no whitespaces.

The following example describes a path on 4 nodes, whose arcs each have a name and a cost associated to them. Node numbering starts from 1 here.

4 3
1 2 Arc1 0.2
2 3 Arc2 1.25
3 4 Arc3 0.33

The above example can be processed like this (provided that it is stored in c:\graph.txt):

Node[] nodes = loader.Load(@"c:\graph.txt", Directedness.Directed);
// retrieve the loaded data
IGraph graph = loader.Graph;
Dictionary<Arc, string> arcNames = loader.Extensions[0];
Dictionary<Arc, double> arcCosts =
loader.Extensions[1].ToDictionary(kv => kv.Key, kv => double.Parse(kv.Value, CultureInfo.InvariantCulture));

Definition at line 63 of file IO.cs.

Constructor & Destructor Documentation

Satsuma.IO.SimpleGraphFormat.SimpleGraphFormat ( )

Definition at line 79 of file IO.cs.

Member Function Documentation

Node [] Satsuma.IO.SimpleGraphFormat.Load ( TextReader  reader,
Directedness  directedness 
)

Loads from a reader.

Parameters
readerA reader on the input file, e.g. a StreamReader.
directednessSpecifies the directedness of the graph to be loaded. Possible values:
  • Directedness.Directed: each created arc will be directed.
  • Directedness.Undirected: each created arc will be an edge (i.e. undirected).
Returns
the loaded nodes, by index ascending

Definition at line 90 of file IO.cs.

Node [] Satsuma.IO.SimpleGraphFormat.Load ( string  filename,
Directedness  directedness 
)

Loads from a file.

Definition at line 128 of file IO.cs.

void Satsuma.IO.SimpleGraphFormat.Save ( TextWriter  writer)

Saves to a writer.

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

Definition at line 136 of file IO.cs.

void Satsuma.IO.SimpleGraphFormat.Save ( string  filename)

Saves to a file.

Definition at line 167 of file IO.cs.

Property Documentation

IList<Dictionary<Arc, string> > Satsuma.IO.SimpleGraphFormat.Extensions
getset

The extensions (arc functions).

Warning
All the contained dictionaries must assign values to all the arcs of the graph. Values must be nonempty strings containing no whitespaces. This is not checked when saving.

Definition at line 74 of file IO.cs.

IGraph Satsuma.IO.SimpleGraphFormat.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 69 of file IO.cs.

int Satsuma.IO.SimpleGraphFormat.StartIndex
getset

The index where node numbering starts (0 by default).

Set this parameter to the correct value both before loading and saving.

Definition at line 77 of file IO.cs.


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