예제 #1
0
 public void EpidemicSyncTest()
 {
     Network n = new Network();
     Vertex a = n.CreateVertex();
     Vertex b = n.CreateVertex();
     n.CreateEdge(a, b);
     Kuramoto sync = new Kuramoto(n, 2d);
     sync.WriteTimeSeries(null);
     sync.Stop();
 }
예제 #2
0
        static void Main(string[] args)
        {
            GlobValues glob = new GlobValues();
            string configFile, dir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), inputPath, outputPath;
            String[] path = dir.Split(new string[] { "Launch" }, StringSplitOptions.None);
            inputPath = path[0] + "Launch" + Path.DirectorySeparatorChar + "input";
            configFile = inputPath + Path.DirectorySeparatorChar + "config.param.txt";
               // outputPath = path[0] + "Launch" + Path.DirectorySeparatorChar + "output";
            Console.WriteLine("File is : " + configFile);

            Console.WriteLine("Starting the program to generate the network based on modularity..");
            try
            {
                // Read parameters from param.config file

                read_parameters(configFile, glob);
            }
            catch
            {
                Console.WriteLine("Usage: mono Demo.exe [nodes] [edges] [clusters] [resultfile]");
                return;
            }

            // Displays the information

            Console.WriteLine("Given Parameter values");
            Console.WriteLine("\n Nodes: " + glob.nodes + "\n Edges: " + glob.edges + "\n Clusters: " + glob.clusters + "\n Modularity MinValue: " + glob.modularityMinValue + "\n Modularity MaxValue: " + glob.modularityMaxValue);
            Console.WriteLine(" Number of runs: " + glob.numberOfGraphs + "\n Coupling probability value: "+glob.couplingProb*100);

            string sourceNetworkFile = inputPath = path[0] + "Launch" + Path.DirectorySeparatorChar + "Launch" + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + "Debug" + Path.DirectorySeparatorChar + "network.edges";

            string sourceResultFile = inputPath = path[0] + "Launch" + Path.DirectorySeparatorChar + "Launch" + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + "Debug" + Path.DirectorySeparatorChar + "result.dat";

            // For loop to make n number of Networks with the given size and modularity ...
            double modularity = glob.modularityMinValue;

            while (modularity <= glob.modularityMaxValue)
            {
                String outputFile = "Result_M" + modularity;
                outputPath = path[0] + "Launch" + Path.DirectorySeparatorChar + outputFile;
                System.IO.Directory.CreateDirectory(outputPath);

                try
                {

                    for (int n = 1; n <= glob.numberOfGraphs; n++)
                    {
                        network = new ClusterNetwork(glob.nodes, glob.edges, glob.clusters, modularity, true);

                        // Restricting the modularity value upto 1 decimal place
                       // modularity = Math.Round(network.NewmanModularityUndirected, 1);

                        String memberOutputFile = outputPath + Path.DirectorySeparatorChar + "membership.dat";
                        System.IO.StreamWriter sw = System.IO.File.CreateText(memberOutputFile);
                        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, modularity);
                        // To move a file or folder to a new location without renaming it. We rename the files after running the Kuramoto model.

                        string destinationResultFile = outputPath + Path.DirectorySeparatorChar + n + "_res_N" + network.VertexCount + "_E" + network.EdgeCount + "_C" + glob.clusters + "_M" + modularity + "_K" + glob.couplingStrength + ".dat";
                        string destinationNetworkFile = outputPath + Path.DirectorySeparatorChar + n + "_network_N" + network.VertexCount + "_E" + network.EdgeCount + "_C" + glob.clusters + "_M" + modularity + "_K" + glob.couplingStrength + ".edges";

                        System.IO.File.Move(outputPath + Path.DirectorySeparatorChar + "membership.dat", outputPath + Path.DirectorySeparatorChar + n + "_mem_N" + network.VertexCount + "_E" + network.EdgeCount + "_C" + glob.clusters + "_M" + modularity + "_K" + glob.couplingStrength + ".dat");
                        try
                        {
                            Console.WriteLine("Moving the generated files to output directory..");
                            System.IO.File.Move(sourceNetworkFile, destinationNetworkFile);
                        }
                        catch (IOException e)
                        {
                            Console.WriteLine(e.Message);
                        }

                        // Run the Kuramoto model here and store the results in the output directory
                        NetworkColorizer colorizer = new NetworkColorizer();
                        // Distribution of natural frequencies
                        double mean_frequency = 1d;
                        Normal normal = new Normal(mean_frequency, mean_frequency / 5d);

                        sync = new Kuramoto(network,
                                        glob.couplingStrength,
                                        glob.couplingProb,
                                        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 (sourceResultFile != null)
                            sync.WriteTimeSeries(sourceResultFile);

                        // Moving results of kuramoto model into output directory
                        System.IO.File.Move(sourceResultFile, destinationResultFile);

                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e);
                }
                modularity = modularity + 0.1;
            }
            // End line of the program
            Console.WriteLine("Program ended successfully..");
        }
        static void Main(string[] args)
        {
            string configFile, dir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), netFile, NetworkFile, resFile,destResultFile;
            string[] path = dir.Split(new string[] { "Launch" }, StringSplitOptions.None);

            string srcResultFile = path[0] +"Launch" + Path.DirectorySeparatorChar + "Launch" + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + "Debug" + Path.DirectorySeparatorChar + "result.dat";
            configFile = path[0] + Path.DirectorySeparatorChar + "Launch" + Path.DirectorySeparatorChar + "config.param.txt";

            Console.WriteLine("Starting the program to generate the network based on Barbasi Albert Model..");

            GlobValues glob = new GlobValues();
            try
            {
                // Read parameters from param.config file
                read_parameters(configFile, glob);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

               for (int i = 1; i<= glob.numberOfGraphs; i++)
            {
                for (double j = glob.minPower; j <= (glob.maxPower + 0.1); j=j+0.1)
                {
                    // Creating network file
                    netFile = i+ "_BarbasiNetwork_N"+glob.nodes+ "_powerLaw"+j+"_K"+glob.couplingStrength+".edges";
                    NetworkFile =  path[0] + "Launch" + Path.DirectorySeparatorChar + "output" + Path.DirectorySeparatorChar+netFile ;
                    resFile = i + "_res_N" + glob.nodes + "_powerLaw" + j + "_K" + glob.couplingStrength+".dat";
                    destResultFile     =  path[0] + "Launch" + Path.DirectorySeparatorChar + "output" + Path.DirectorySeparatorChar + resFile;
                    try
                        {

                                 // upload the network to run the Kuramoto Model
                                 pop = Network.LoadFromEdgeFile(NetworkFile);

                                // Run the Kuramoto model here and store the results in the output directory
                                NetworkColorizer colorizer = new NetworkColorizer();
                                // Distribution of natural frequencies
                                double mean_frequency = 1d;
                                Normal normal = new Normal(mean_frequency, mean_frequency / 5d);
                                                sync = new Kuramoto(pop,
                                                glob.couplingStrength,
                                                glob.couplingProb,
                                                colorizer,
                                                new Func<Vertex, Vertex[]>(v => { return new Vertex[] { v.RandomNeighbor }; })
                                                );

                                foreach (Vertex v in pop.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 (srcResultFile != null)
                                    sync.WriteTimeSeries(srcResultFile);

                                // Moving results of kuramoto model into output directory
                                System.IO.File.Move(srcResultFile, destResultFile);

                       }
                            catch (Exception e)
                            {
                                Console.WriteLine("Error: " + e);
                            }

               }
             }
        }
예제 #4
0
파일: Demo.cs 프로젝트: schwarzertod/NETGen
    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);
    }