<commit_before># README

DATK is a Distributed Algorithms Toolkit for Python


## Documentation

Visit [amin10.github.com/datk](http://amin10.github.io/datk/) for documentation


## Testing

Run tests by executing the following command in the repo directory

    $ python -m datk.tests.tests

    $ python -m datk.tests.networks_tests


## Usage

### Networks

#### Ring Network


```python
>>> x = Bidirectional_Ring(8)
>>> x.draw()
```

![png](readme/output_3_0.png)

```python
>>> x.state()
```

<samp style='white-space:pre-wrap'>
[('P4', {'n': 8}),
 ('P1', {'n': 8}),
 ('P2', {'n': 8}),
 ('P5', {'n': 8}),
 ('P0', {'n': 8}),
 ('P7', {'n': 8}),
 ('P6', {'n': 8}),
 ('P3', {'n': 8})]
</samp>


#### Line Network

```python
>>> Bidirectional_Line(6).draw()
```

![png](readme/output_6_0.png)


#### Random Line Network

```python
>>> Random_Line_Network(16).draw()
```

![png](readme/output_8_0.png)

```python
>>> Random_Line_Network(16, sparsity=0).draw()
```

![png](readme/output_9_0.png)

```python
>>> Random_Line_Network(16, sparsity=0.5).draw()
```

![png](readme/output_10_0.png)

```python
>>> Random_Line_Network(16, sparsity=float('inf')).draw()
```

![png](readme/output_11_0.png)


### Algorithms

#### A Basic Algorithm: LCR

```python
>>> x = Unidirectional_Ring(5)
```

##### Initial Network State

```python
>>> x.state()
```

<samp style='white-space:pre-wrap'>
[('P2', {'n': 5}),
 ('P4', {'n': 5}),
 ('P1', {'n': 5}),
 ('P0', {'n': 5}),
 ('P3', {'n': 5})]
</samp>


```python
>>> lcr = LCR(x)
```

<samp style='white-space:pre-wrap'>
--------------
Running LCR on
[P2 -> {P4}, P4 -> {P1}, P1 -> {P0}, P0 -> {P3}, P3 -> {P2}]
Round 1
P2.status is non-leader
P1.status is non-leader
P0.status is non-leader
Round 2
P0.status is non-leader
Round 3
P3.status is non-leader
Round 4
P2.status is non-leader
Round 5
P4.status is leader
Algorithm Terminated
Message Complexity: 11
----------------------
</samp>


##### Time Complexity

```python
>>> print lcr.r, "rounds"
```

<samp style='white-space:pre-wrap'>
5 rounds
</samp>

##### Message Complexity

```python
>>> print lcr.message_count, "messages"
```

<samp style='white-space:pre-wrap'>
11 messages
</samp>

##### Final Network State

```python
>>> x.state()
```

<samp style='white-space:pre-wrap'>
[('P2', {'n': 5, 'status': 'non-leader'}),
 ('P4', {'n': 5, 'status': 'leader'}),
 ('P1', {'n': 5, 'status': 'non-leader'}),
 ('P0', {'n': 5, 'status': 'non-leader'}),
 ('P3', {'n': 5, 'status': 'non-leader'})]
</samp><commit_msg>README styling with samp 2<commit_after># README

DATK is a Distributed Algorithms Toolkit for Python


## Documentation

Visit [amin10.github.com/datk](http://amin10.github.io/datk/) for documentation


## Testing

Run tests by executing the following command in the repo directory

    $ python -m datk.tests.tests

    $ python -m datk.tests.networks_tests


## Usage

### Networks

#### Ring Network


```python
>>> x = Bidirectional_Ring(8)
>>> x.draw()
```

![png](readme/output_3_0.png)

```python
>>> x.state()
```

<samp style='white-space:pre-wrap'>
[('P4', {'n': 8}),
 ('P1', {'n': 8}),
 ('P2', {'n': 8}),
 ('P5', {'n': 8}),
 ('P0', {'n': 8}),
 ('P7', {'n': 8}),
 ('P6', {'n': 8}),
 ('P3', {'n': 8})]
</samp>


#### Line Network

```python
>>> Bidirectional_Line(6).draw()
```

![png](readme/output_6_0.png)


#### Random Line Network

```python
>>> Random_Line_Network(16).draw()
```

![png](readme/output_8_0.png)

```python
>>> Random_Line_Network(16, sparsity=0).draw()
```

![png](readme/output_9_0.png)

```python
>>> Random_Line_Network(16, sparsity=0.5).draw()
```

![png](readme/output_10_0.png)

```python
>>> Random_Line_Network(16, sparsity=float('inf')).draw()
```

![png](readme/output_11_0.png)


### Algorithms

#### A Basic Algorithm: LCR

```python
>>> x = Unidirectional_Ring(5)
```

##### Initial Network State

```python
>>> x.state()
```

<samp style='white-space:pre-wrap'>
[('P2', {'n': 5}),
 ('P4', {'n': 5}),
 ('P1', {'n': 5}),
 ('P0', {'n': 5}),
 ('P3', {'n': 5})]
</samp>


```python
>>> lcr = LCR(x)
```

<samp style='white-space:pre-wrap'>
--------------
Running LCR on
[P2 -> {P4}, P4 -> {P1}, P1 -> {P0}, P0 -> {P3}, P3 -> {P2}]
Round 1
P2.status is non-leader
P1.status is non-leader
P0.status is non-leader
Round 2
P0.status is non-leader
Round 3
P3.status is non-leader
Round 4
P2.status is non-leader
Round 5
P4.status is leader
Algorithm Terminated
Message Complexity: 11
----------------------
</samp>


##### Time Complexity

```python
>>> print lcr.r, "rounds"
```

<samp style='white-space:pre-wrap'>
5 rounds
</samp>

##### Message Complexity

```python
>>> print lcr.message_count, "messages"
```

<samp style='white-space:pre-wrap'>
11 messages
</samp>

##### Final Network State

```python
>>> x.state()
```

<div><samp style='white-space:pre-wrap'>
[('P2', {'n': 5, 'status': 'non-leader'}),
 ('P4', {'n': 5, 'status': 'leader'}),
 ('P1', {'n': 5, 'status': 'non-leader'}),
 ('P0', {'n': 5, 'status': 'non-leader'}),
 ('P3', {'n': 5, 'status': 'non-leader'})]
</samp></div>

{'fraction_non_alphanumeric': 0.2705975779233671, 'fraction_numerical': 0.03791939646615049, 'mean_word_length': 4.253388946819603, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '435838', 'n_tokens_mistral': 2187, 'n_tokens_neox': 1982, 'n_words': 473}