peersim.graph
Class GraphIO

java.lang.Object
  extended by peersim.graph.GraphIO

public class GraphIO
extends java.lang.Object

Implements static methods to load and write graphs.


Method Summary
static Graph readNewscastGraph(java.lang.String file, int direction)
          Read a graph in newscast graph format.
static void writeChaco(Graph g, java.io.PrintStream out)
          Saves the given graph to the given stream in Chaco format.
static void writeDOT(Graph g, java.io.PrintStream out)
          Saves the given graph to the given stream in DOT format.
static void writeEdgeList(Graph g, java.io.PrintStream out)
          Prints graph in edge list format.
static void writeGML(Graph g, java.io.PrintStream out)
          Saves the given graph to the given stream in GML format.
static void writeNeighborList(Graph g, java.io.PrintStream out)
          Prints graph in neighbor list format.
static void writeNetmeter(Graph g, java.io.PrintStream out)
          Saves the given graph to the given stream to be read by NETMETER.
static void writeUCINET_DL(Graph g, java.io.PrintStream out)
          Saves the given graph to the given stream in UCINET DL nodelist format.
static void writeUCINET_DLMatrix(Graph g, java.io.PrintStream out)
          Saves the given graph to the given stream in UCINET DL matrix format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeEdgeList

public static void writeEdgeList(Graph g,
                                 java.io.PrintStream out)
Prints graph in edge list format. Each line contains exactly two node IDs separated by whitespace.


writeNeighborList

public static void writeNeighborList(Graph g,
                                     java.io.PrintStream out)
Prints graph in neighbor list format. Each line starts with the id of a node followed by the ids of its neighbors separated by space.


writeDOT

public static void writeDOT(Graph g,
                            java.io.PrintStream out)
Saves the given graph to the given stream in DOT format. Good for the graphviz package.


writeGML

public static void writeGML(Graph g,
                            java.io.PrintStream out)
Saves the given graph to the given stream in GML format.


writeNetmeter

public static void writeNetmeter(Graph g,
                                 java.io.PrintStream out)
Saves the given graph to the given stream to be read by NETMETER. It should be ok also for Pajek.


writeUCINET_DL

public static void writeUCINET_DL(Graph g,
                                  java.io.PrintStream out)
Saves the given graph to the given stream in UCINET DL nodelist format.


writeUCINET_DLMatrix

public static void writeUCINET_DLMatrix(Graph g,
                                        java.io.PrintStream out)
Saves the given graph to the given stream in UCINET DL matrix format.


writeChaco

public static void writeChaco(Graph g,
                              java.io.PrintStream out)
Saves the given graph to the given stream in Chaco format. We need to output the number of edges so they have to be counted first which might not be very efficient. Note that this format is designed for undirected graphs only.


readNewscastGraph

public static Graph readNewscastGraph(java.lang.String file,
                                      int direction)
                               throws java.io.IOException
Read a graph in newscast graph format. The format depends on mode, the parameter. The file begins with the three byte latin 1 coded "NCG" string followed by the int MODE which is the given parameter. The formats are the following as a function of mode:

Parameters:
file - Filename to read
direction - If 0, the original directionality is preserved, if 1, than each edge is reversed, if 2 then directionality is dropped and the returned graph will be undirected.
Throws:
java.io.IOException