// To read the parameter.config files for a type of network with different modularity public static void read_parameters(String configFile,GlobValues glob) { string[] allLines; ArrayList list = new ArrayList(); using (StreamReader sr = File.OpenText(configFile)) { string s = String.Empty; while ((s = sr.ReadLine()) != null) { allLines = s.Split(new[] {"="}, StringSplitOptions.None); list.Add(allLines[1]); } glob.nodes = Int32.Parse(list[0].ToString()); glob.edges = Int32.Parse(list[1].ToString()); glob.clusters = Int32.Parse(list[2].ToString()); glob.modularityMinValue = Double.Parse(list[3].ToString()); glob.modularityMaxValue = Double.Parse(list[4].ToString()); glob.numberOfGraphs = Int32.Parse(list[5].ToString()); glob.couplingStrength = Double.Parse(list[6].ToString()); glob.couplingProb = Double.Parse(list[7].ToString()); glob.runningTime = Double.Parse(list[8].ToString()); runTime = glob.runningTime; } }
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); } } } }