pharo-networks is a powerful complex network library designed to assist researchers, engineers, and data scientists in analyzing and modeling complex systems. Built upon state-of-the-art methodologies and algorithms, pharo-networks offers a comprehensive suite of tools and functionalities for the analysis and simulation of complex networks.
# Complex Networks Library
Welcome to the Complex Networks Library, a comprehensive suite designed to model, analyze, and visualize complex networks using object-oriented paradigms. Built with elegance and flexibility in mind, this library offers a rich set of classes and methods catering to various needs in network science.
## Overview
Networks are everywhere - from social networks that connect people to biological systems connecting various species in an ecosystem. Understanding their structure, dynamics, and intricacies can provide valuable insights into diverse fields such as sociology, biology, physics, and computer science. The Complex Networks Library is developed to be a one-stop solution for researchers, developers, and enthusiasts who are keen to dive deep into the world of networks.
### Key Features:
1. **Versatile Network Components**: The core of the library consists of classes like `NetworkGraph`, `NetworkNode`, `NetworkDirectedEdge`, `NetworkUndirectedEdge`, and `NetworkAttribute`, ensuring a robust representation of nodes, edges, and their attributes.
2. **Algorithms and Analysis**: Whether it's finding the centrality using methods from the `Centrality` class or analyzing matrix representations with the `Matrices` class, the library covers a broad spectrum of graph algorithms and network metrics.
3. **Graph Generation**: Classes like `ConfigurationModel` allow users to create complex network models from given degree sequences, aiding in generating both directed and undirected graphs.
4. **Extensible Design**: With its modular architecture, adding new algorithms, network models, or features becomes a seamless process.
## Getting Started
Dive into the individual classes' documentation to understand their functionalities and see usage examples. Whether you're building a new kind of network model, analyzing existing networks, or simply exploring the fascinating world of graphs, the Complex Networks Library provides the tools you need.
---
# NetworkNode
A class to represent a network node within a graph.
## Instance Variables
- `id`: A unique identifier for the node.
- `adjacentNodes`: A collection of nodes adjacent to this node.
- `adjacentEdges`: A collection of edges adjacent to this node.
- `attributes`: A collection of attributes associated with this node.
## Methods
### Instance Creation
- **`with: anId`**: Creates a new node with the specified identifier `anId`.
### Adding
- **`addAttribute: anAttributeObject`**: Adds an attribute to the node.
### Accessing
- **`adjacentEdges`**: Returns the adjacent edges to this node.
- **`adjacentEdges: aEdgeList`**: Sets the adjacent edges to this node.
- **`adjacentNodes`**: Returns the adjacent nodes to this node.
- **`adjacentNodes: aNodeList`**: Sets the adjacent nodes to this node.
- **`from: sourceNode`**: A placeholder method for derived classes.
- **`from: sourceNode edge: anEdge`**: A placeholder method for derived classes.
- **`id`**: Returns the identifier of the node.
- **`id: anId`**: Sets the identifier of the node.
- **`to: targetNode`**: Adds an adjacent node.
- **`to: targetNode edge: anEdge`**: Adds an adjacent node and edge.
### Initialization
- **`initialize`**: Initializes the instance variables.
### Printing
- **`printOn: stream`**: Prints the node's label and identifier on the given stream.
### Label
- **`label`**: Returns a string representing the label of the node.
## Usage Example
```smalltalk
node := NetworkNode with: 1.
```
---
# NetworkUndirectedEdge
A class to represent an undirected edge in the network.
## Instance Variables
- `model`: A reference to the associated model object.
- `node1`: One of the nodes connected by the edge.
- `node2`: The other node connected by the edge.
- `attributes`: A collection of attributes associated with the edge.
## Methods
### Adding
- **`addAttribute: anAttributeObject`**: Adds an attribute to the edge.
### Accessing
- **`asTuple`**: Returns a tuple containing the connected nodes.
- **`model`**: Returns the associated model object.
- **`model: anObject`**: Sets the associated model object.
- **`node1`**: Returns one of the connected nodes.
- **`node1: anObject`**: Sets one of the connected nodes.
- **`node2`**: Returns the other connected node.
- **`node2: anObject`**: Sets the other connected node.
### Initialization
- **`initialize`**: Initializes the instance variables.
### Printing
- **`printOn: aStream`**: Prints the edge's connected nodes on the given stream.
## Usage Example
```smalltalk
edge := NetworkUndirectedEdge new.
edge node1: node1.
edge node2: node2.
```
---
# NetworkDirectedEdge
This class represents a directed edge in the network, extending from one node (source) to another (target).
## Instance Variables
- `model`: A reference to the associated model object.
- `from`: The source node of the edge.
- `to`: The target node of the edge.
- `attributes`: A collection of attributes associated with the edge.
## Methods
### Adding
- **`addAttribute: anAttributeObject`**: Adds an attribute to the edge.
### Converting
- **`asTuple`**: Returns a tuple containing the source and target nodes.
### Accessing
- **`from`**: Returns the source node of the edge.
- **`from: anObject`**: Sets the source node of the edge.
- **`model`**: Returns the associated model object.
- **`model: anObject`**: Sets the associated model object.
- **`to`**: Returns the target node of the edge.
- **`to: anObject`**: Sets the target node of the edge.
### Initialization
- **`initialize`**: Initializes the instance variables.
### Printing
- **`printOn: aStream`**: Prints the edge's source and target nodes on the given stream.
## Usage Example
```smalltalk
edge := NetworkDirectedEdge new.
edge from: node1.
edge to: node2.
```
---
# NetworkAttribute
A class to represent a node's or edge's attribute within the network.
## Instance Variables
- `model`: A reference to the associated model object.
- `attributeName`: The name of the attribute.
- `attributeValue`: The value of the attribute.
## Methods
### Getter
- **`attributeName`**: Returns the name of the attribute.
- **`attributeValue`**: Returns the value of the attribute.
### Setter
- **`attributeName: aString`**: Sets the name of the attribute.
- **`attributeValue: aString`**: Sets the value of the attribute.
### Initialization
- **`setAttribute: name value: value`**: Initializes the attribute with a given name and value.
## Usage Example
```smalltalk
attribute := NetworkAttribute new.
attribute setAttribute: 'color' value: 'red'.
```
---
# NetworkGraph
A class that represents a network graph, containing methods for building and manipulating the graph.
## Instance Variables
- `nodes`: A collection of nodes in the graph.
- `edges`: A collection of edges in the graph.
- `sortingBlock`: A block used for sorting nodes.
- `directed`: A boolean indicating whether the graph is directed or not.
## Methods
### Testing
- **`isAbstract`**: Returns whether the class is abstract.
### Adding
- **`addDirectedEdge: fromId to: toId`**: Adds a directed edge between nodes with given IDs.
- **`addUndirectedEdge: fromId to: toId`**: Adds an undirected edge between nodes with given IDs.
### Building - Graph
- **`addNodeByID: anId`**: Adds a node with the given ID to the graph.
- **`edges: aCollection from: source to: target`**: Adds edges to the graph from a collection, specifying source and target.
- **`emptyGraph`**: Empties the graph.
- **`nodes: aNodeList`**: Adds nodes from a list to the graph.
- **`rawNodes: aRawNodeList`**: Sets the nodes from a raw node list.
### Accessing
- **`directed`**: Returns whether the graph is directed.
- **`directed: aBoolean`**: Sets whether the graph is directed.
- **`edgeBetween: node1 and: node2`**: Returns the edge between two nodes, if exists.
- **`edgeClass`**: Returns the appropriate edge class based on the graph's directedness.
- **`edges`**: Returns the edges in the graph.
- **`findEdge: aModel`**: Finds an edge by its model.
- **`findNode: anId`**: Finds a node by its ID.
- **`findNode: anId ifAbsent: aBlock`**: Finds a node by its ID, executing a block if absent.
- **`findNode: anId ifFound: aBlock`**: Finds a node by its ID, executing a block if found.
- **`getAttributeWithName: anAttributeName edge: anEdge`**: Gets an attribute by name from an edge.
- **`graph`**: Returns the graph as a collection of nodes and edges.
- **`nodeClass`**: Returns the node class.
- **`nodes`**: Returns the nodes in the graph.
### Configuration
- **`initialize`**: Initializes the instance variables.
## Usage Example
```smalltalk
graph := NetworkGraph new.
graph addNodeByID: 1.
graph addNodeByID: 2.
graph addDirectedEdge: 1 to: 2.
```
---
Network Algorithms
---
# Assortativity
The `Assortativity` class contains methods to measure the assortativity of networks. Assortativity quantifies the similarity of connections in the graph with respect to the node degree. A positive assortativity coefficient indicates that nodes tend to link to other nodes with the same or similar degree, while a negative coefficient indicates nodes tend to link to nodes with differing degrees.
## Methods:
### 1. assortativityCoefficientFor: aGraph
- **Description**: Computes the assortativity coefficient for an undirected graph.
- **Formula**:
$$
r = \frac{4 \times E \times \sum_{ij} e_{ij} - \left(\sum_{i} a_{i} + b_{i}\right)^2}{2 \times E \times \sum_{i} a_{i}^2 + b_{i}^2 - \left(\sum_{i} a_{i} + b_{i}\right)^2}
$$
Where $E$ is the number of edges and $e_{ij}$, $a_{i}$, and $b_{i}$ are derived from the degrees of nodes connected by each edge.
### 2. assortativityCoefficientFor: aGraph useInDegree: useInDegree useOutDegree: useOutDegree
- **Description**: Computes the assortativity coefficient for a directed graph considering in-degrees, out-degrees, or both.
- **Formula**:
$$
r = \frac{\sum_{ij} e_{ij} - \left(\sum_{i} a_{i} + b_{i}\right)^2}{\sum_{i} a_{i}^2 + b_{i}^2 - \left(\sum_{i} a_{i} + b_{i}\