Building and Running the C# Application
Relevant source files
The following files were used as context for generating this wiki page:The C# code within this repository provides two primary functionalities related to network science. The first is a console application for generating synthetic networks using the Barabasi-Albert preferential attachment model. The second is a Windows Forms GUI application named "Network Analyzer" designed to load network data from a file, compute a variety of statistical metrics, and visualize the results. These tools are intended to support the study of network properties as described in the Barabasi Network Science textbook.
This document outlines the architecture, components, and execution flow of both C# applications, based on an analysis of the source code. It covers the GUI application's entry point, its UI structure, the data processing pipeline for network analysis, and the logic of the separate network generation console application.
Sources: README.md:2-5, Form1.Designer.cs:296, Barabasi.cs:5
Application Entry Point
The primary user-facing application is the "Network Analyzer" GUI. The entry point for this application is the Main method in Program.cs. This method is responsible for initializing the application environment and launching the main form.
// File: Program.cs:16-20
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
This standard Windows Forms startup sequence instantiates and displays Form1, which contains all the UI elements and logic for the network analysis tool.
Sources: Program.cs:15-20
Network Analyzer GUI (Form1)
The Form1 class is the core of the analysis tool, providing both the user interface and the backend logic for processing and visualizing network data.
Sources: Form1.cs, Form1.Designer.cs
UI Layout and Components
The user interface is defined in Form1.Designer.cs and provides controls for data loading, configuration, and visualization.
The following diagram shows the main components of the Form1 user interface.
Sources: Form1.Designer.cs
The key UI components and their functions are summarized below:
| Component ID | Type | Purpose | Source |
|---|---|---|---|
menuStrip1 | MenuStrip | Contains the "File" menu for opening datasets. | Form1.Designer.cs:141 |
openToolStripMenuItem | ToolStripMenuItem | Menu item that triggers the file open dialog. | Form1.Designer.cs:158 |
lblNodes, lblLinks, etc. | Label | Display various calculated network statistics. | Form1.Designer.cs:95-135, Form1.Designer.cs:254, Form1.Designer.cs:260 |
chart1 | Chart | Visualizes the "Degree Correlation" with a power-law regression line. | Form1.Designer.cs:69 |
chart2 | Chart | Visualizes the "Cumulative Degree Distribution" with a power-law regression line. | Form1.Designer.cs:222 |
textBox1 | TextBox | Shows real-time status messages during long calculations. | Form1.Designer.cs:86 |
chkClustering | CheckBox | Toggles the calculation of the average clustering coefficient. | Form1.Designer.cs:214 |
txtCutoff | TextBox | Sets the minimum degree for the power-law fit on the degree distribution. | Form1.Designer.cs:266 |
Core Data Structures
The application uses a set of nested classes defined within Form1.cs to represent the network.
The relationship between these classes is shown below.
Sources: Form1.cs:46-179
Edge: A simple class representing a connection between two nodes,aandb.
Sources: Form1.cs:46-57Node: Represents a single node in the network. Its key properties are detailed in the table below.
Sources: Form1.cs:58-73NodeList: A container for allNodeobjects. It is initialized from a list of edges and is responsible for orchestrating most of the network metric calculations, including degrees, neighbor lists, and clustering coefficients.
Sources: Form1.cs:74-179
Node Class Properties
| Property | Type | Description | Source |
|---|---|---|---|
node_ID | int | Unique identifier for the node. | Form1.cs:64 |
degree | int | The number of connections (edges) the node has. | Form1.cs:65 |
neighbors | List<int> | A list of the node_IDs of connected nodes. | Form1.cs:66 |
clustering | double | The node's local clustering coefficient. | Form1.cs:67 |
neighbors_degree | double | The average degree of the node's neighbors. | Form1.cs:68 |
Data Processing and Analysis Flow
The entire analysis process is initiated when the user selects a file via the "File" -> "Open" menu item, which triggers the openToolStripMenuItem_Click event handler.
The following sequence diagram illustrates the flow of operations from user interaction to final visualization.
Sources: Form1.cs:189-346
The key steps are:
- File Loading: An edgelist file (tab-separated node pairs) is read into a
List<Edge>. - Network Construction: A
NodeListobject is created from the edgelist. Its constructor iterates through the edges to:- Build a unique list of
Nodeobjects. - Populate the
neighborslist and calculate thedegreefor each node. - Calculate the average degree of neighbors (
neighbors_degree) for each node.
- Build a unique list of
- Statistics Display: Basic network properties like node count, link count, and min/max degree are calculated and displayed in the UI labels.
- Degree Correlation: The application calculates the average neighbor degree for each degree
k. These points are plotted onchart1(log-log scale), and a power-law regression is fitted usingMathNet.Numerics.Fit.Powerto find the degree correlation exponent. - Degree Distribution: The cumulative degree distribution
P(k)is calculated. A power-law fit is applied to the tail of this distribution (for degrees greater thantxtCutoff.Text) to estimate the degree exponentgamma. The distribution and the regression line are plotted onchart2(log-log scale).
Sources: Form1.cs:189-346
Network Generation (Barabasi.cs)
Separate from the GUI analyzer, the project includes a console application for generating synthetic networks. This is contained entirely within Barabasi.cs.
Sources: Barabasi.cs
Purpose and Execution Flow
This application generates a network using the Barabasi-Albert model and writes the resulting edgelist to a file. It can also perform edge rewiring to control the network's degree correlation.
The generation process follows these steps:
Sources: Barabasi.cs:7-17, Barabasi.cs:48-64, Barabasi.cs:65-90
The parameters in the Main method are configurable:
| Parameter | Type | Default Value | Description | Source |
|---|---|---|---|---|
nodes | int | 10000 | Total number of nodes to generate in the network. | Barabasi.cs:9 |
degree | int | 3 | Number of edges to add for each new node. | Barabasi.cs:10 |
prob | int | 50 | Percentage of links to rewire in the Associate method. | Barabasi.cs:11 |
sociable | bool | false | Determines rewiring type: true for assortative (positive), false for disassortative. | Barabasi.cs:12 |
The Associate method implements edge rewiring. It randomly selects two edges and, depending on the positive flag, either swaps endpoints to connect nodes of similar degree (assortative mixing) or dissimilar degree (disassortative mixing).
Sources: Barabasi.cs:65-90
Project and Assembly Information
The C# project is configured as an assembly titled "Charts". This information is defined in Properties/AssemblyInfo.cs.
// File: Properties/AssemblyInfo.cs:9
[assembly: AssemblyTitle("Charts")]
[assembly: AssemblyProduct("Charts")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyVersion("1.0.0.0")]
Sources: Properties/AssemblyInfo.cs:9-12, Properties/AssemblyInfo.cs:28-29