static void Main(string[] args) { // Create a random network SimpleNetwork net = SimpleNetwork.ReadFromEdgeList("demo.edges"); // We use a custom coloring NetworkColorizer colors = new NetworkColorizer(); colors.DefaultBackgroundColor = Color.Black; colors.DefaultEdgeColor = Color.WhiteSmoke; colors.DefaultVertexColor = Color.SteelBlue; // Let's use curved edges instead of the default straight ones Renderer.CurvedEdges = true; // Fire up the visualizer window Renderer.Start(net, new NETVisualizer.Layouts.FruchtermanReingold.FRLayout(10), colors); // Trigger the layout Renderer.Layout.DoLayoutAsync(); // The rendering and layouting is done asynchronously in parallel, // so you can modify the network while the visualization and the layout continues Console.Write("Press ANY KEY to add another edge"); Console.ReadKey(); net.AddEdge("a", "b"); net.AddEdge("b", "c"); // Trigger the layout again. Only changed nodes will be relayouted ... Renderer.Layout.DoLayoutAsync(); Console.WriteLine("Waiting for rendering window to be closed ..."); }
/// <summary> /// Reads a directed network from an edge list /// </summary> /// <param name="file">The filename to read the network from</param> /// <param name="sep">The separator charactor used in the file</param> /// <returns>A network</returns> public static SimpleNetwork ReadFromEdgeList(string file, char sep = ' ') { string[] edges = System.IO.File.ReadAllLines(file); SimpleNetwork net = new SimpleNetwork(); foreach (string edge in edges) { string[] nodes = edge.Split(sep); net.AddEdge(nodes[0], nodes[1]); } return net; }
/// <summary> /// Reads a directed network from an edge list /// </summary> /// <param name="file">The filename to read the network from</param> /// <param name="sep">The separator charactor used in the file</param> /// <returns>A network</returns> public static SimpleNetwork ReadFromEdgeList(string file, char sep = ' ') { string[] edges = System.IO.File.ReadAllLines(file); SimpleNetwork net = new SimpleNetwork(); foreach (string edge in edges) { string[] nodes = edge.Split(sep); net.AddEdge(nodes[0], nodes[1]); } return(net); }
/// <summary> /// Generates a simple random network with n nodes and m edges /// </summary> /// <param name="n">The number of nodes</param> /// <param name="m">The number of edges</param> /// <returns>A random network</returns> public static SimpleNetwork CreateRandomNetwork(int n, int m) { Random r = new Random(); SimpleNetwork net = new SimpleNetwork(); for(int i = 0; i<n; i++) net.AddVertex(i.ToString()); for (int j = 0; j < m; j++) { string x = net.GetVertexArray()[r.Next(net.GetVertexCount())]; string y = net.GetVertexArray()[r.Next(net.GetVertexCount())]; net.AddEdge(x, y); } return net; }
/// <summary> /// Generates a simple random network with n nodes and m edges /// </summary> /// <param name="n">The number of nodes</param> /// <param name="m">The number of edges</param> /// <returns>A random network</returns> public static SimpleNetwork CreateRandomNetwork(int n, int m) { Random r = new Random(); SimpleNetwork net = new SimpleNetwork(); for (int i = 0; i < n; i++) { net.AddVertex(i.ToString()); } for (int j = 0; j < m; j++) { string x = net.GetVertexArray()[r.Next(net.GetVertexCount())]; string y = net.GetVertexArray()[r.Next(net.GetVertexCount())]; net.AddEdge(x, y); } return(net); }