Ejemplo n.º 1
0
 public SimpleSpreading(Network n, NetworkColorizer colorizer = null)
 {
     _network       = n;
     _colorizer     = colorizer;
     _infected      = new List <Vertex>();
     _infectionTime = new Dictionary <Vertex, long>();
 }
Ejemplo n.º 2
0
        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 ...");
        }
Ejemplo n.º 3
0
        public SIRSpreading(Network n, NetworkColorizer colorizer = null)
        {
            _network   = n;
            _colorizer = colorizer;

            _active     = new List <Vertex>();
            _infected   = new List <Vertex>();
            _infections = new Dictionary <Vertex, bool>();
        }
Ejemplo n.º 4
0
 public CEFPlayer(string cefFile, Network n, NetworkColorizer c = null)
 {
     filename  = cefFile;
     network   = n;
     colorizer = c;
     if (cefFile == null || !System.IO.File.Exists(cefFile))
     {
         Logger.AddMessage(LogEntryType.Error, "Given cef-File does not exist.");
     }
 }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            // Basic arg checking
            if (args.Length != 2 || !System.IO.File.Exists(args[0]) || !System.IO.File.Exists(args[1]))
            {
                Console.WriteLine("Usage: CuttleFishPlayer [cxf-File] [cef-File]");
                return;
            }

            // Used to color the network
            NetworkColorizer colorizer = new NetworkColorizer();

            colorizer.DefaultBackgroundColor = Color.White;
            colorizer.DefaultVertexColor     = Color.Black;
            colorizer.DefaultEdgeColor       = Color.Black;

            // Load network from cuttlefish CXF-File
            Network n = Network.LoadFromCXF(args[0]);

            Logger.AddMessage(LogEntryType.AppMsg, string.Format("Initial network: {0} Nodes, {1} Edges", n.VertexCount, n.EdgeCount));

            // Start the visualizer with Fruchterman-Reingold layout
            NetworkVisualizer.Start(n, new RandomLayout(), colorizer);

            // Compute layout and save initial frame
            NetworkVisualizer.Layout.DoLayout();
            NetworkVisualizer.SaveCurrentImage("frame_0000.bmp");

            // Load network evolution from cuttlefish cef file
            NETGen.Dynamics.CEF.CEFPlayer player = new NETGen.Dynamics.CEF.CEFPlayer(args[1], n, colorizer);

            // On each evolution step, recompute layout and save current image
            player.OnStep += new DiscreteDynamics.StepHandler(delegate(long time) {
                NetworkVisualizer.Layout.DoLayout();
                NetworkVisualizer.SaveCurrentImage(string.Format("frame_{0000}.bmp", time));
                Logger.AddMessage(LogEntryType.AppMsg, string.Format("Time {0000}: {1} Nodes, {2} Edges", time, n.VertexCount, n.EdgeCount));
            });

            // Ready, set, go ...
            Logger.AddMessage(LogEntryType.AppMsg, "Press enter to step through network evolution ...");
            Console.ReadLine();
            player.Run();

            Network.SaveToGraphML("mono_network.graphml", n);
        }
Ejemplo n.º 6
0
        public VisualizerControl() :
            base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            colorizer = new NetworkColorizer();
            this.fileChooserNetworkFile.FileSet    += HandleFileChooserNetworkFilehandleFileSet;
            this.btnComputeLayout.Clicked          += HandleBtnComputeLayouthandleClicked;
            this.btnChoseDefaultNodeColor.ColorSet += HandleBtnChoseDefaultNodeColorhandleColorSet;
            this.btnChoseEdgeColor.ColorSet        += HandleBtnChoseEdgeColorhandleColorSet;
            this.btnSearch.Clicked                 += HandleBtnSearchhandleClicked;
            this.fileChooserExportPDF.FileSet      += HandleFileChooserExportPDFhandleFileSet;
            this.fileChooserExportBitmap.FileSet   += HandleFileChooserExportBitmaphandleFileSet;
            this.fileChooserHighlightNodes.FileSet += HandleFileChooserHighlightNodeshandleFileSet;
            this.btnApplyNodeSize.Clicked          += HandleBtnApplyNodeSizehandleClicked;
            this.btnApplyEdgeWidth.Clicked         += HandleBtnApplyEdgeWidthhandleClicked;
            this.fileChooserCEFFile.FileSet        += HandleFileChooserCEFFilehandleFileSet;
            this.btnRunCEF.Clicked                 += HandlebtnRunCEFhandleClicked;
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("\nUsage: Visualize [network-file] [iterations=50]\n");
                return;
            }

            string network_file = args[0];
            int    iterations   = args.Length >= 2 ? int.Parse(args[1]) : 50;

            // Load the temporal and aggregate network
            Console.Write("Loading temporal network ...");
            TemporalNetwork net = TemporalNetwork.ReadFromFile(network_file);

            Console.WriteLine("done");
            Console.Write("Computing aggregate network ...");
            WeightedNetwork agg = net.AggregateNetwork;

            Console.WriteLine("done");

            // Change the colors
            NetworkColorizer colors = new NetworkColorizer();

            colors.DefaultBackgroundColor = Color.White;
            colors.DefaultVertexColor     = Color.DarkBlue;
            colors.DefaultEdgeColor       = Color.Black;

            Renderer.CurvedEdges = true;

            RenderableTempNet temp_net = new RenderableTempNet(net);

            // Start rendering ...
            Renderer.Start(temp_net, new FRLayout(iterations), colors);


            // Asynchronously compute the layout ...
            Renderer.Layout.DoLayout();

            Application.Run(new VisualizationController(temp_net));
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("\nUsage: Visualize [network-file] [iterations=50]\n");
                return;
            }

            string network_file = args[0];
            int iterations = args.Length >= 2 ? int.Parse(args[1]) : 50;

            // Load the temporal and aggregate network
            Console.Write("Loading temporal network ...");
            TemporalNetwork net = TemporalNetwork.ReadFromFile(network_file);
            Console.WriteLine("done");
            Console.Write("Computing aggregate network ...");
            WeightedNetwork agg = net.AggregateNetwork;
            Console.WriteLine("done");

            // Change the colors
            NetworkColorizer colors = new NetworkColorizer();
            colors.DefaultBackgroundColor = Color.White;
            colors.DefaultVertexColor = Color.DarkBlue;
            colors.DefaultEdgeColor = Color.Black;

            Renderer.CurvedEdges = true;

            RenderableTempNet temp_net = new RenderableTempNet(net);

            // Start rendering ...
            Renderer.Start(temp_net, new FRLayout(iterations), colors);

            // Asynchronously compute the layout ...
            Renderer.Layout.DoLayout();

            Application.Run(new VisualizationController(temp_net));
        }
Ejemplo n.º 9
0
    static void Main(string[] args)
    {
        try
        {
            // The resultfile is given as command line argument
            //nodes = Int32.Parse(args[0]);
            //edges = Int32.Parse(args[1]);
            //clusters = Int32.Parse(args[2]);
            resultfile = args[3];
        } catch {
            Console.WriteLine("Usage: mono Demo.exe [nodes] [edges] [clusters] [resultfile]");
            return;
        }

        // Create a network of the given size and modularity ...
        network = new ClusterNetwork(nodes, edges, clusters, 0.63d, true);

        System.IO.StreamWriter sw = System.IO.File.CreateText("membership.dat");

        int i = 0;

        foreach (Vertex v in network.Vertices)
        {
            v.Label = (i++).ToString();
            sw.WriteLine(network.GetClusterForNode(v).ToString());
        }
        sw.Close();

        Network.SaveToEdgeFile(network, "network.edges");

        Console.WriteLine("Created network with {0} vertices, {1} edges and modularity {2:0.00}", network.VertexCount, network.EdgeCount, network.NewmanModularityUndirected);

        // Run the real-time visualization
        NetworkColorizer colorizer = new NetworkColorizer();
        //NetworkVisualizer.Start(network, new NETGen.Layouts.FruchtermanReingold.FruchtermanReingoldLayout(15), colorizer);
        //NetworkVisualizer.Layout.DoLayoutAsync();

        // Distribution of natural frequencies
        double mean_frequency = 1d;
        Normal normal         = new Normal(mean_frequency, mean_frequency / 5d);

        sync = new Kuramoto(network,
                            K,
                            colorizer,
                            new Func <Vertex, Vertex[]>(v => { return(new Vertex[] { v.RandomNeighbor }); })
                            );

        foreach (Vertex v in network.Vertices)
        {
            sync.NaturalFrequencies[v] = normal.Sample();
        }


        foreach (int g in network.ClusterIDs)
        {
            pacemaker_mode[g] = false;
        }

        sync.OnStep += new Kuramoto.StepHandler(recordOrder);

        Logger.AddMessage(LogEntryType.AppMsg, "Press enter to start synchronization experiment...");
        Console.ReadLine();


        // Run the simulation
        sync.Run();

        // Write the time series to the resultfile
        if (resultfile != null)
        {
            sync.WriteTimeSeries(resultfile);
        }
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new synchronization experiment
        /// </summary>
        /// <param name='n'>
        /// The network to run the experiment for
        /// </param>
        /// <param name='colorizer'>
        /// Will be used to color vertices and edges as the experiment runs. Can be null or omitted altogether if no visualization is used.
        /// </param>
        /// <param name='selectNeighbor'>
        /// A lambda expression that will be invoked whenever a neighbor is chosen to couple to. If null or not given, an unbiased random neighbor selection will be used.
        /// </param>
        public Kuramoto(Network n, double K, NetworkColorizer colorizer = null, Func <Vertex, Vertex[]> couplingSelector = null) : base(0d, new DenseVector((int)n.VertexCount))
        {
            _network   = n;
            _colorizer = colorizer;

            CouplingStrengths  = new Dictionary <Tuple <Vertex, Vertex>, double>();
            NaturalFrequencies = new ConcurrentDictionary <Vertex, double>();

            foreach (Edge e in _network.Edges)
            {
                Tuple <Vertex, Vertex> t1 = new Tuple <Vertex, Vertex>(e.Source, e.Target);
                Tuple <Vertex, Vertex> t2 = new Tuple <Vertex, Vertex>(e.Target, e.Source);

                if (e.EdgeType == EdgeType.Undirected || e.EdgeType == EdgeType.DirectedAB)
                {
                    CouplingStrengths[t1] = K;
                }

                if (e.EdgeType == EdgeType.Undirected || e.EdgeType == EdgeType.DirectedBA)
                {
                    CouplingStrengths[t2] = K;
                }
            }

            _mapping = new Dictionary <Vertex, int>();

            int i = 0;

            foreach (Vertex v in _network.Vertices)
            {
                NaturalFrequencies[v] = 0.1d;
                _mapping[v]           = i++;
            }

            // if no neighbor selector is given, just couple to all nearest neighbors
            if (couplingSelector == null)
            {
                CouplingSelector = new Func <Vertex, Vertex[]>(v => {
                    return(v.Neigbors.ToArray());
                });
            }
            else
            {
                CouplingSelector = couplingSelector;
            }

            // Initialize phases, colors and average degree
            foreach (Vertex v in _network.Vertices)
            {
                CurrentValues[_mapping[v]] = _network.NextRandomDouble() * Math.PI * 2d;
                if (_colorizer != null)
                {
                    _colorizer[v] = ColorFromPhase(CurrentValues[_mapping[v]]);
                }
                _avgDeg += v.Degree;
            }
            _avgDeg /= (double)_network.VertexCount;

            Logger.AddMessage(LogEntryType.Info, string.Format("Sychchronization module initialized. Initial global order = {0:0.000}", GetOrder(_network.Vertices.ToArray())));

            TimeDelta = Math.PI / 100d;

            OnStep += new StepHandler(recolor);
        }