Skip to content

Commit dd394d4

Browse files
committed
improve readme
1 parent 0559ab5 commit dd394d4

File tree

1 file changed

+146
-96
lines changed

1 file changed

+146
-96
lines changed

README.md

Lines changed: 146 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,151 @@
1-
![Python package](https://github.com/fAndreuzzi/BisPy/workflows/Python%20package/badge.svg?branch=master) <a href='https://coveralls.io/github/fAndreuzzi/BisPy'><img src='https://coveralls.io/repos/github/fAndreuzzi/BisPy/badge.svg' alt='Coverage Status' /></a>
2-
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) <img src='https://img.shields.io/badge/Code%20style-Black-%23000000'/> [![Documentation Status](https://readthedocs.org/projects/bispy-bisimulation-in-python/badge/?version=latest)](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/?badge=latest)
1+
![Python package](https://github.com/fAndreuzzi/BisPy/workflows/Python%20package/badge.svg?branch=master)
2+
<a href='https://coveralls.io/github/fAndreuzzi/BisPy'><img src='https://coveralls.io/repos/github/fAndreuzzi/BisPy/badge.svg' alt='Coverage Status' /></a>
3+
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE)
4+
<img src='https://img.shields.io/badge/Code%20style-Black-%23000000'/>
5+
[![Documentation Status](https://readthedocs.org/projects/bispy-bisimulation-in-python/badge/?version=latest)](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/?badge=latest)
36

47
## Description
5-
**BisPy** is a Python package for the computation of the maximum bisimulation of directed graphs. At the moment it supports the following algorithms:
8+
9+
**BisPy** is a Python package for the computation of the maximum bisimulation
10+
of directed graphs. At the moment it supports the following algorithms:
11+
612
- Paige-Tarjan
713
- Dovier-Piazza-Policriti
814
- Saha
915

10-
An brief introduction to the problem can be found [here](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/?badge=latest#a-brief-introduction-to-bisimulation).
16+
An brief introduction to the problem can be found
17+
[here](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/?badge=latest#a-brief-introduction-to-bisimulation).
1118

1219
## Usage
20+
1321
### Paige-Tarjan, Dovier-Piazza-Policriti
14-
Compute the maximum bisimulation of a graph (represented by an object of type `networkx.DiGraph`):
22+
23+
To compute the maximum bisimulation of a graph, first of all we import
24+
`paige_tarjan` and `dovier_piazza_policriti` from **BisPy**, as well as the
25+
package _NetworkX_, which we use to represent graphs:
26+
1527
```python
16-
> import networkx as nx
17-
> from bispy import paige_tarjan, dovier_piazza_policriti
28+
>>> import networkx as nx
29+
>>> from bispy import paige_tarjan, dovier_piazza_policriti
30+
```
1831

19-
# we create the graph
20-
> graph = networkx.balanced_tree(2,3)
32+
We then create a simple graph:
2133

22-
# Paige-Tarjan's algorithm
23-
> paige_tarjan(graph)
24-
[(7, 8, 9, 10, 11, 12, 13, 14), (3, 4, 5, 6), (1, 2), (0,)]
34+
```python
35+
>>> graph = networkx.balanced_tree(2,3)
36+
```
2537

26-
# and Dovier-Piazza-Policriti's algorithm
27-
> dovier_piazza_policriti(graph)
38+
And we are ready to compute the _maximum bisimulation_ using _Paige-Tarjan_'s
39+
algorithm:
40+
41+
```python
42+
>>> paige_tarjan(graph)
2843
[(7, 8, 9, 10, 11, 12, 13, 14), (3, 4, 5, 6), (1, 2), (0,)]
2944
```
3045

31-
More about the available features (like using a *labeling set*) is discussed in the documentation for [Paige-Tarjan](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/algorithms/paige_tarjan.html)'s and [Dovier-Piazza-Policriti](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/algorithms/dovier_piazza_policriti.html)'s algorithms.
46+
as well as _Dovier-Piazza-Policriti_'s algorithm.
47+
48+
```python
49+
>>> dovier_piazza_policriti(graph)
50+
[(7, 8, 9, 10, 11, 12, 13, 14), (3, 4, 5, 6), (1, 2), (0,)]
51+
52+
```
53+
54+
We may also introduce a _labeling set_ (or _initial partition_):
55+
56+
```python
57+
>>> dovier_piazza_policriti(graph, initial_partition=[(0,7,10), (1,2,3,4,5,6,8,9,11,12,13,14)])
58+
[(7, 10), (8, 9, 11, 12, 13, 14), (3, 4, 5, 6), (1, 2), (0,)]
59+
60+
```
3261

3362
### Saha
34-
The interface for using *Saha*'s algorithm is a little bit different since we do not want to rebuild the *BisPy* representation of the graph from scratch.
63+
64+
The interface to _Saha_'s algorithm is a little bit different since we
65+
do not want to rebuild the **BisPy** representation of the graph from scratch
66+
everytime we add a new edge. We are going to consider the same `graph` object
67+
which we created in the example above:
68+
69+
```python
70+
>>> from bispy import decorate_nx_graph, to_tuple_list, paige_tarjan_qblocks, saha
71+
```
72+
73+
We build the **BisPy** representation of the graph, once and forever:
74+
75+
```python
76+
>>> vertexes, qblocks = decorate_nx_graph(graph)
77+
```
78+
79+
We now need to compute the maximum bisimulation of the graph, since as you can
80+
read from the
81+
[documentation](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/algorithms/saha.html#)
82+
_Saha_'s algorithm needs to receive a maximum bisimulation in order to work.
83+
84+
You may notice that we're using the function `paige_tarjan_qblocks` instead of
85+
`paige_tarjan`. We did so because `paige_tarjan_qblocks` works on graphs in
86+
**BisPy** representation, and returns a partition which is in **BisPy**
87+
representation as well. This allows us to avoid going back and forth from
88+
_NetworkX_ to our representation.
89+
3590
```python
36-
> import networkx as nx
37-
> from bispy import decorate_nx_graph, to_tuple_list, paige_tarjan_qblocks, saha
38-
39-
# we create the graph
40-
> graph = networkx.balanced_tree(2,3)
41-
42-
# we build its BisPy representation
43-
> vertexes, qblocks = decorate_nx_graph(graph)
44-
# compute the maximum bisimulation. `maximum_bisimulation is a list of `_QBlock` objects
45-
> maximum_bisimulation = paige_tarjan_qblocks(qblocks)
46-
47-
# from now on we can update the maximum bisimulation incrementally, everytime
48-
# we add a new edge to the graph
49-
> new_edges_list = random_edges_generator()
50-
> for edge in new_edges_list:
51-
> maximum_bisimulation = saha(maximum_bisimulation, vertexes, edge)
52-
> # print the current maximum bisimulation
53-
> print(to_tuple_list(maximum_bisimulation))
91+
>>> maximum_bisimulation = paige_tarjan_qblocks(qblocks)
5492
```
5593

56-
Note that *Saha*'s algorithm must be applied on a **maximum bisimulation**, otherwise it is going to return wrong results. This is why we called `paige_tarjan_qblocks` (which is just a version of *Paige-Tarjan*'s algorithm which can be applied to the variable `qblocks`) before the call to *Saha*'s algorithm.
94+
We can now use _Saha_'s algorithm to update the maximum bisimulation
95+
incrementally. We assumed to have some method `random_edges_generator` to
96+
generate new edges to be added to the graph:
5797

58-
You can read more about [Saha](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/algorithms/saha.html#)'s algorithm and the module [graph_decorator](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/utilities/graph_decorator.html) on the documentation.
98+
```python
99+
>>> for edge in random_edges_generator():
100+
>>> maximum_bisimulation = saha(maximum_bisimulation, vertexes, edge)
101+
>>> print(to_tuple_list(maximum_bisimulation))
102+
```
59103

60-
## TODO
61-
- [ ] Improve *Saha*'s algorithm performance (at the moment *Saha* is much faster for graph having less than ~1000 nodes, but becomes slow afterwards);
62-
- [ ] *Labeling set* support for *Dovier-Piazza-Policriti*'s algorithm.;
63-
- [ ] Implement performance improvements described on the paper which introduced *Dovier-Piazza-Policriti*'s algorithm;
64-
- [ ] Allow *Saha* to get non-integer graphs as input.
104+
The function `to_tuple_list` converts a list in **BisPy** representation to a
105+
human-readable list of tuples of `int`s, each `int` is the label of a node, and
106+
each tuple represents a block of the current maximum bisimulation.
65107

66108
## Dependencies and installation
109+
67110
**BisPy** requires requires the modules `llist, networkx`. The code is tested
68-
for *Python 3*, while compatibility with *Python 2* is not guaranteed. It can
111+
for _Python 3_, while compatibility with _Python 2_ is not guaranteed. It can
69112
be installed using `pip` or directly from the source code.
70113

71-
### Installing via *pip*
114+
### Installing via _pip_
115+
72116
To install the package:
117+
73118
```bash
74119
> pip install bispy
75120
```
121+
76122
To uninstall the package:
123+
77124
```bash
78125
> pip uninstall bispy
79126
```
80127

81128
### Installing from source
129+
82130
You can clone this repository on your local machine using:
131+
83132
```bash
84133
> git clone https://github.com/fAndreuzzi/BisPy
85134
```
86135

87136
To install the package:
137+
88138
```bash
89139
> cd BisPy
90140
> python setup.py install
91141
```
92142

93143
## Documentation
144+
94145
We used [Sphinx](http://www.sphinx-doc.org/en/stable/) and
95146
[ReadTheDocs](https://readthedocs.org/) for code documentation. You can view
96-
the documentation [here](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/?badge=latest).
147+
the documentation
148+
[here](https://bispy-bisimulation-in-python.readthedocs.io/en/latest/?badge=latest).
97149

98150
To build the HTML version of the docs locally use:
99151

@@ -106,88 +158,86 @@ The generated html can be found in `docs/build/html`.
106158

107159
## Testing
108160

109-
We are using **GitHub actions** for continuous intergration testing. To run tests locally (`pytest` is required) use the following command from the root folder of **BisPy**:
161+
We are using **GitHub actions** for continuous intergration testing. To run
162+
tests locally (`pytest` is required) use the following command from the root
163+
folder of **BisPy**:
110164

111165
```bash
112166
> pytest tests
113167
```
114168

115169
## Authors and acknowledgements
116-
**BisPy** is currently developed and mantained by **Francesco Andreuzzi**.
117-
You can contact me at:
118-
* andreuzzi.francesco at gmail.com
119-
* fandreuz at sissa.it
120170

121-
The project has been developed under the supervision of professor
122-
**Alberto Casagrande** (*University of Trieste*), which was my advisor for
123-
my *bachelor thesis*.
171+
**BisPy** is currently developed and mantained by **Francesco Andreuzzi**. You
172+
can contact me at:
173+
174+
- andreuzzi.francesco at gmail.com
175+
- fandreuz at sissa.it
176+
177+
The project has been developed under the supervision of professor **Alberto
178+
Casagrande** (_University of Trieste_), which was my advisor for my _bachelor
179+
thesis_.
124180

125181
## How to contribute
182+
126183
Contributors are welcome! We are more than happy to receive contributions on
127184
tests, documentation and new features. Our
128185
[Issues](https://github.com/fAndreuzzi/BisPy/issues) section is always full of
129186
things to do.
130187

131188
Here are the guidelines to submit a patch:
132189

133-
1. Start by opening a new [issue](https://github.com/fAndreuzzi/BisPy/issues)
134-
describing the bug you want to fix, or the feature you want to
135-
introduce. This lets us keep track of what is being done at the moment,
136-
and possibly avoid writing different solutions for the same problem.
190+
1. Start by opening a new [issue](https://github.com/fAndreuzzi/BisPy/issues)
191+
describing the bug you want to fix, or the feature you want to introduce.
192+
This lets us keep track of what is being done at the moment, and possibly
193+
avoid writing different solutions for the same problem.
137194

138-
2. Fork the project, and setup a **new** branch to work in (*fix-issue-22*,
139-
for instance). If you do not separate your work in different branches
140-
you may have a bad time when trying to push a pull request to fix
141-
a particular issue.
195+
2. Fork the project, and setup a **new** branch to work in (_fix-issue-22_, for
196+
instance). If you do not separate your work in different branches you may
197+
have a bad time when trying to push a pull request to fix a particular
198+
issue.
142199

143-
3. Run the [**black**](https://github.com/psf/black) formatter before pushing
144-
your code for review.
200+
3. Run the [**black**](https://github.com/psf/black) formatter before pushing
201+
your code for review.
145202

146-
4. Any significant changes should almost always be accompanied by tests. The
147-
project already has good test coverage, so look at some of the existing
148-
tests if you're unsure how to go about it.
203+
4. Any significant changes should almost always be accompanied by tests. The
204+
project already has good test coverage, so look at some of the existing
205+
tests if you're unsure how to go about it.
149206

150-
5. Provide menaningful **commit messages** to help us keeping a good *git*
151-
history.
207+
5. Provide menaningful **commit messages** to help us keeping a good _git_
208+
history.
152209

153-
6. Finally you can submbit your *pull request*!
210+
6. Finally you can submbit your _pull request_!
154211

155212
## References
213+
156214
During the development we constulted the following resources:
157215

158-
- Saha, Diptikalyan. "An incremental bisimulation algorithm."
159-
International Conference on Foundations of Software Technology
160-
and Theoretical Computer Science.
161-
Springer, Berlin, Heidelberg, 2007.
216+
- Saha, Diptikalyan. "An incremental bisimulation algorithm." International
217+
Conference on Foundations of Software Technology and Theoretical Computer
218+
Science. Springer, Berlin, Heidelberg, 2007.
162219
[DOI](https://doi.org/10.1007/978-3-540-77050-3_17)
163-
- Dovier, Agostino, Carla Piazza, and Alberto Policriti.
164-
"A fast bisimulation algorithm." International Conference on
165-
Computer Aided Verification.
220+
- Dovier, Agostino, Carla Piazza, and Alberto Policriti. "A fast bisimulation
221+
algorithm." International Conference on Computer Aided Verification.
166222
Springer, Berlin, Heidelberg, 2001.
167223
[DOI](https://doi.org/10.1007/3-540-44585-4_8)
168-
- Gentilini, Raffaella, Carla Piazza, and Alberto Policriti.
169-
"From bisimulation to simulation: Coarsest partition problems."
170-
Journal of Automated Reasoning 31.1 (2003): 73-103.
171-
[DOI](https://doi.org/10.1023/A:1027328830731)
172-
- Paige, Robert, and Robert E. Tarjan.
173-
"Three partition refinement algorithms."
224+
- Gentilini, Raffaella, Carla Piazza, and Alberto Policriti. "From bisimulation
225+
to simulation: Coarsest partition problems." Journal of Automated Reasoning
226+
31.1 (2003): 73-103. [DOI](https://doi.org/10.1023/A:1027328830731)
227+
- Paige, Robert, and Robert E. Tarjan. "Three partition refinement algorithms."
174228
SIAM Journal on Computing 16.6 (1987): 973-989.
175229
[DOI](https://doi.org/10.1137/0216062)
176-
- Hopcroft, John.
177-
"An n log n algorithm for minimizing states in a finite automaton."
178-
Theory of machines and computations. Academic Press, 1971. 189-196.
179-
- Aczel, Peter.
180-
"Non-well-founded sets." (1988).
181-
- Kanellakis, Paris C., and Scott A. Smolka.
182-
"CCS expressions, finite state processes, and three problems of equivalence."
183-
Information and computation 86.1 (1990): 43-68.
184-
[DOI](https://doi.org/10.1016/0890-5401(90)90025-D)
185-
- Sharir, Micha.
186-
"A strong-connectivity algorithm and its applications in data flow analysis."
187-
Computers & Mathematics with Applications 7.1 (1981): 67-72.
188-
[DOI](https://doi.org/10.1016/0898-1221(81)90008-0)
189-
- Cormen, Thomas H., et al.
190-
Introduction to algorithms. MIT press, 2009.
230+
- Hopcroft, John. "An n log n algorithm for minimizing states in a finite
231+
automaton." Theory of machines and computations. Academic Press, 1971.
232+
189-196.
233+
- Aczel, Peter. "Non-well-founded sets." (1988).
234+
- Kanellakis, Paris C., and Scott A. Smolka. "CCS expressions, finite state
235+
processes, and three problems of equivalence." Information and computation
236+
86.1 (1990): 43-68. [DOI](<https://doi.org/10.1016/0890-5401(90)90025-D>)
237+
- Sharir, Micha. "A strong-connectivity algorithm and its applications in data
238+
flow analysis." Computers & Mathematics with Applications 7.1 (1981): 67-72.
239+
[DOI](<https://doi.org/10.1016/0898-1221(81)90008-0>)
240+
- Cormen, Thomas H., et al. Introduction to algorithms. MIT press, 2009.
191241
(ISBN: 9780262533058)
192242

193243
## License

0 commit comments

Comments
 (0)