C# Application Architecture
Relevant source files
The following files were used as context for generating this wiki page:The C# portion of this repository consists of two distinct applications: a Windows Forms "Network Analyzer" for analyzing network properties from an edgelist file, and a console application for generating networks using the Barabasi-Albert model. The analyzer computes and visualizes key network metrics like degree distribution, clustering coefficient, and degree correlation. The generator creates synthetic networks with preferential attachment and can perform assortative or disassortative rewiring.
This architecture separates the concerns of network generation and analysis into two self-contained C# projects, Networks and Charts respectively.
Sources: README.md, Form1.cs, Barabasi.cs
Network Analyzer (Charts Project)
The Charts project is a Windows Forms application that provides a graphical user interface for loading network data and analyzing its statistical properties.
Sources: Properties/AssemblyInfo.cs:10, Program.cs:9
Application Entry Point
The application's entry point is the Main method in Program.cs. It initializes and runs Form1, which contains the main UI and logic for the analyzer.
// Program.cs:15-19
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Sources: Program.cs:15-19
UI Layer (Form1)
The user interface is defined in Form1.cs and Form1.Designer.cs. It consists of a main form titled "Network Analyzer" containing controls for file loading, displaying statistics, and plotting charts.
The following diagram illustrates the layout of the main UI components.
Diagram showing the main UI components of the Network Analyzer.
Sources: Form1.Designer.cs
Key UI components and their functions are summarized below:
| Component ID | Type | Description |
|---|---|---|
openToolStripMenuItem | ToolStripMenuItem | Triggers the file open dialog to load an edgelist. |
lblNodes, lblLinks, etc. | Label | Display calculated network statistics. |
chkClustering | CheckBox | Toggles the calculation of the average clustering coefficient. |
txtCutoff | TextBox | Sets the minimum degree for power-law regression on the degree distribution. |
chart1 | Chart | Displays the degree correlation plot. |
chart2 | Chart | Displays the cumulative degree distribution plot. |
textBox1 | TextBox | Shows real-time status updates during long calculations. |
Sources: Form1.Designer.cs:30-248, Form1.cs:205-206, 320-321
Core Data Models
The analysis logic relies on a set of nested classes within Form1.cs to represent the network structure.
Class diagram showing the relationship between Edge, Node, and NodeList within Form1.
Sources: Form1.cs:51-182
Edge: A simple class to represent a link between two nodes,aandb.Node: Represents a single node in the network, storing its ID, degree, list of neighbors, clustering coefficient, and the average degree of its neighbors.NodeList: A container for allNodeobjects. Its constructor is the main driver for building the network representation from an edgelist and calculating node-level properties like degree and neighbor lists. It also contains methods for calculating global network properties like the average clustering coefficient.
Sources: Form1.cs:51-182
Data Processing and Analysis Flow
The entire analysis process is initiated by the user selecting a file via the "Open" menu item. The openToolStripMenuItem_Click event handler orchestrates the file parsing, network construction, metric calculation, and chart rendering.
The following flowchart outlines the sequence of operations:
Flowchart of the network analysis process triggered by opening a file.
Sources: Form1.cs:192-318
The sequence diagram below shows the interaction between the UI and the data model during this process.
Sequence diagram of user interaction and subsequent data processing.
Sources: Form1.cs:192-318
Network Generator (Networks Project)
The Barabasi.cs file defines a separate console application in the Networks namespace. Its purpose is to generate a network using the Barabasi-Albert preferential attachment model and save it as an edgelist file.
Sources: Barabasi.cs:5, README.md:5
Core Classes
The generator uses a simpler data structure compared to the analyzer.
Edge: Identical to the one in the analyzer, representing a link.Edgelist: A collection ofEdgeobjects. Its constructor contains the logic for the Barabasi-Albert model. It also includes methods for network rewiring (Associate) and writing the output to a file (Write).
Sources: Barabasi.cs:22-101
Generation and Rewiring Flow
The Main method in Barabasi.cs controls the generation process.
Flowchart of the network generation and rewiring process in Barabasi.cs.
Sources: Barabasi.cs:7-16, 42-63, 64-92
The Associate method can rewire the network to be either assortative (hubs connect to hubs) or disassortative (hubs connect to low-degree nodes) by swapping endpoints between two randomly chosen edges.
Sources: Barabasi.cs:64-92
Conclusion
The C# application architecture is split into two functional components: a Charts GUI application for detailed network analysis and a Networks console application for synthetic network generation. The analyzer provides a user-friendly way to load real-world network data and compute complex metrics, visualizing them through interactive charts. The generator implements the Barabasi-Albert model, a fundamental algorithm in network science, providing a tool for creating scale-free networks for study. This separation allows each tool to be focused and independent.