FastMcsplit 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastmcsplit-0.0.1/MANIFEST.in +8 -0
- fastmcsplit-0.0.1/PKG-INFO +158 -0
- fastmcsplit-0.0.1/README.md +200 -0
- fastmcsplit-0.0.1/args/ParseArgs.hpp +208 -0
- fastmcsplit-0.0.1/docs/testpypi.md +73 -0
- fastmcsplit-0.0.1/header/EdgeAttr.hpp +357 -0
- fastmcsplit-0.0.1/header/Graph.hpp +113 -0
- fastmcsplit-0.0.1/header/GreedySearchMatching.hpp +535 -0
- fastmcsplit-0.0.1/header/Node.hpp +179 -0
- fastmcsplit-0.0.1/header/NodeAttr.hpp +64 -0
- fastmcsplit-0.0.1/header/NodeClasses/NodeClass.hpp +171 -0
- fastmcsplit-0.0.1/header/NodeClasses/NodeClassCompute.hpp +183 -0
- fastmcsplit-0.0.1/header/NodeNeighbor.hpp +106 -0
- fastmcsplit-0.0.1/header/Parser/ParseCSVFile.hpp +795 -0
- fastmcsplit-0.0.1/header/Parser/ParseFile.hpp +61 -0
- fastmcsplit-0.0.1/header/Parser/ParseGFUFile.hpp +381 -0
- fastmcsplit-0.0.1/header/Parser/ParseGRFFile.hpp +385 -0
- fastmcsplit-0.0.1/header/Parser/ParseLADFile.hpp +369 -0
- fastmcsplit-0.0.1/header/Parser/Parser.hpp +44 -0
- fastmcsplit-0.0.1/header/Reductions/R1.hpp +242 -0
- fastmcsplit-0.0.1/header/Reductions/R2.hpp +333 -0
- fastmcsplit-0.0.1/header/Reductions/R3.hpp +175 -0
- fastmcsplit-0.0.1/header/Reductions/R4.hpp +135 -0
- fastmcsplit-0.0.1/header/Reductions/R5.hpp +219 -0
- fastmcsplit-0.0.1/header/Reductions/R6.hpp +161 -0
- fastmcsplit-0.0.1/header/Reductions/R8.hpp +266 -0
- fastmcsplit-0.0.1/header/Reductions/r_utils.hpp +342 -0
- fastmcsplit-0.0.1/header/SearchMatching.hpp +2506 -0
- fastmcsplit-0.0.1/header/define.hpp +43 -0
- fastmcsplit-0.0.1/header/time_utils.hpp +46 -0
- fastmcsplit-0.0.1/header/utils.hpp +114 -0
- fastmcsplit-0.0.1/pyproject.toml +35 -0
- fastmcsplit-0.0.1/python/FastMcsplit.egg-info/PKG-INFO +158 -0
- fastmcsplit-0.0.1/python/FastMcsplit.egg-info/SOURCES.txt +42 -0
- fastmcsplit-0.0.1/python/FastMcsplit.egg-info/dependency_links.txt +1 -0
- fastmcsplit-0.0.1/python/FastMcsplit.egg-info/requires.txt +7 -0
- fastmcsplit-0.0.1/python/FastMcsplit.egg-info/top_level.txt +1 -0
- fastmcsplit-0.0.1/python/README.md +139 -0
- fastmcsplit-0.0.1/python/fastmcsplit/__init__.py +5 -0
- fastmcsplit-0.0.1/python/fastmcsplit/api.py +340 -0
- fastmcsplit-0.0.1/python/native.cpp +297 -0
- fastmcsplit-0.0.1/setup.cfg +4 -0
- fastmcsplit-0.0.1/setup.py +15 -0
- fastmcsplit-0.0.1/tests/test_python_api.py +249 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: FastMcsplit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Native C++ maximum common induced subgraph solver for Python and NetworkX
|
|
5
|
+
Author: Wilfried Agbeto, Camille Coti, Vladimir Reinharz
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: C++
|
|
9
|
+
Classifier: Operating System :: MacOS
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Provides-Extra: networkx
|
|
15
|
+
Requires-Dist: networkx>=3; extra == "networkx"
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
18
|
+
Requires-Dist: networkx>=3; extra == "test"
|
|
19
|
+
|
|
20
|
+
# FastMcsplit
|
|
21
|
+
|
|
22
|
+
CPython bindings for the C++ **FastMcSplit** solver for the Maximum Common
|
|
23
|
+
Induced Subgraph (MCIS) problem. See the [C++ solver documentation][solver] for
|
|
24
|
+
the algorithm, reward strategies, heuristics, and graph format definitions.
|
|
25
|
+
|
|
26
|
+
## Authors
|
|
27
|
+
|
|
28
|
+
Wilfried Agbeto, Camille Coti, and Vladimir Reinharz.
|
|
29
|
+
|
|
30
|
+
## Dependencies
|
|
31
|
+
|
|
32
|
+
- Python 3.10 or later.
|
|
33
|
+
- NetworkX 3 or later (optional): install it separately to use `solve()` or
|
|
34
|
+
`approximate()` with NetworkX graphs. The CSV and file interfaces do not
|
|
35
|
+
require NetworkX.
|
|
36
|
+
|
|
37
|
+
Building from source on Linux or macOS also requires a C++17 compiler.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install FastMcsplit
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## NetworkX interface
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import networkx as nx
|
|
49
|
+
import fastmcsplit
|
|
50
|
+
|
|
51
|
+
pattern = nx.Graph([(0, 1), (1, 2)])
|
|
52
|
+
target = nx.Graph([("a", "b"), ("b", "c"), ("c", "d")])
|
|
53
|
+
|
|
54
|
+
result = fastmcsplit.solve(pattern, target)
|
|
55
|
+
print(result.mapping) # Pattern vertices -> target vertices
|
|
56
|
+
print(result.size, result.optimal) # 3 True
|
|
57
|
+
|
|
58
|
+
approximation = fastmcsplit.approximate(pattern, target)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`Graph`, `DiGraph`, `MultiGraph`, and `MultiDiGraph` are supported. Original
|
|
62
|
+
Python vertex objects are preserved. Labels are ignored unless `node_label_key`
|
|
63
|
+
or `edge_label_key` is supplied; a missing requested attribute raises `ValueError`.
|
|
64
|
+
|
|
65
|
+
`approximate()` runs only the greedy heuristic. For any interface, use
|
|
66
|
+
`method="approximate"` for the same mode. There is no guaranteed approximation
|
|
67
|
+
ratio; see `Result.optimal` below for the meaning of its optimality flag.
|
|
68
|
+
|
|
69
|
+
## CSV interface
|
|
70
|
+
|
|
71
|
+
Pass CSV text or an iterable of lines using the documented [file format][formats].
|
|
72
|
+
IDs in the returned mapping are strings.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import fastmcsplit
|
|
76
|
+
|
|
77
|
+
pattern = ['3', '0,1,B53', '1,2,CWW']
|
|
78
|
+
target = ['4', 'a,b,B53', 'b,c,CWW', 'c,d,CHH']
|
|
79
|
+
|
|
80
|
+
result = fastmcsplit.solve_csv(pattern, target, directed=True)
|
|
81
|
+
print(result.mapping)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Defaults are `directed=True` and `edge_labels=True`; set either to `False` as
|
|
85
|
+
needed. Declare isolated non-numeric IDs explicitly. Missing numeric IDs are
|
|
86
|
+
filled from `0` to `n-1` when all explicit IDs are in that range. Labels cannot
|
|
87
|
+
contain CSV delimiters; NetworkX inputs allow arbitrary Python labels.
|
|
88
|
+
|
|
89
|
+
## File interface
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import fastmcsplit
|
|
93
|
+
|
|
94
|
+
result = fastmcsplit.solve_files("p.txt", "t.txt", format="ulad")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Both files must use the same [supported format][formats]; the default is `csv`.
|
|
98
|
+
LAD/GRF/GFU mappings use integer IDs; CSV mappings use strings.
|
|
99
|
+
|
|
100
|
+
For CLI compatibility, `solve_files(format="csv")` ignores edge labels and
|
|
101
|
+
`ucsv` preserves them; use `solve_csv` for directed labelled CSV.
|
|
102
|
+
For undirected text inputs, reciprocal records are merged: the multiplicity
|
|
103
|
+
of each labelled edge is the maximum count of its two orientations. NetworkX
|
|
104
|
+
edges are used directly.
|
|
105
|
+
|
|
106
|
+
## Search options
|
|
107
|
+
|
|
108
|
+
The same keyword options work with all three interfaces.
|
|
109
|
+
|
|
110
|
+
| Option | Default | Meaning |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `method` | `"exact"` | `"exact"` or `"approximate"`. |
|
|
113
|
+
| `connected` | `False` | Require a connected solution; directed connectivity is weak connectivity. |
|
|
114
|
+
| `greedy` | `False` | Initialize exact search with the greedy heuristic. Always used in approximate mode. |
|
|
115
|
+
| `big_first` | `False` | Try large solution sizes first. Exact mode only. |
|
|
116
|
+
| `reward_strategy` | `None` | Select a reward name/ID below; `None` disables reward bonuses. |
|
|
117
|
+
| `adaptive_rewards` | `False` | Use adaptive rewards as described in the C++ documentation. |
|
|
118
|
+
| `heuristic` | `0` | Vertex ordering, name or ID below. |
|
|
119
|
+
| `disabled_reductions` | `()` | Disable rules, e.g. `("R1", "R4")` or `(1, 4)`. R8 is currently inactive in the Python binding. |
|
|
120
|
+
| `verbose` | `False` | Native diagnostic output to the process stdout. |
|
|
121
|
+
|
|
122
|
+
Reward names: `capacity_diversity` (1), `pair_diversity` (2), `class_count` (3),
|
|
123
|
+
`combined_diversity` (4).
|
|
124
|
+
|
|
125
|
+
Heuristic names: `reward_degree` (0), `reward_pressure` (1),
|
|
126
|
+
`exploration_degree` (2), `exploration_pressure` (3).
|
|
127
|
+
|
|
128
|
+
See the [C++ documentation][solver] for their behavior. Approximate mode skips
|
|
129
|
+
exact-search reductions and reward/adaptation settings; disabling reductions
|
|
130
|
+
can still affect equivalence preprocessing.
|
|
131
|
+
|
|
132
|
+
## Custom label equality
|
|
133
|
+
|
|
134
|
+
Pass `node_label_eq_fn` or `edge_label_eq_fn`, each accepting two labels and
|
|
135
|
+
returning a boolean. For string labels, for example:
|
|
136
|
+
`edge_label_eq_fn=lambda a, b: a.lower() == b.lower()`.
|
|
137
|
+
Comparisons must be reflexive, symmetric, and transitive; invalid equivalence
|
|
138
|
+
classes raise `ValueError`. Without callbacks, Python equality is used and
|
|
139
|
+
labels are not converted to strings.
|
|
140
|
+
|
|
141
|
+
## Result
|
|
142
|
+
|
|
143
|
+
Every interface returns a `Result` containing one mapping:
|
|
144
|
+
|
|
145
|
+
- `mapping`: dictionary from pattern vertices to target vertices.
|
|
146
|
+
- `size`: number of matched vertices.
|
|
147
|
+
- `optimal`: whether optimality was certified. In approximate mode, `False`
|
|
148
|
+
means uncertified; the solution may still be optimal.
|
|
149
|
+
- `upper_bound`: initial cardinality upper bound (not a remaining-search bound).
|
|
150
|
+
- `runtime`: native conversion/preprocessing/search time in seconds; excludes Python conversion.
|
|
151
|
+
- `explored_nodes`: exact-search node count; zero in approximate-only mode.
|
|
152
|
+
- `method`: `"exact"` or `"approximate"`.
|
|
153
|
+
|
|
154
|
+
There is no timeout or cancellation option. Parallel edges are limited to
|
|
155
|
+
255 per direction, or 127 undirected loops per vertex.
|
|
156
|
+
|
|
157
|
+
[solver]: https://gitlab.info.uqam.ca/agbeto.kossi_wilfried/fastmcsplit/-/blob/FastMcSplit/README.md
|
|
158
|
+
[formats]: https://gitlab.info.uqam.ca/agbeto.kossi_wilfried/fastmcsplit/-/blob/FastMcSplit/README.md#file-formats
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# FastMcSplit
|
|
2
|
+
|
|
3
|
+
FastMcSplit is a C++ solver for the **Maximum Common Induced Subgraph (MCIS)** problem, supporting directed and undirected graphs, with or without labels.
|
|
4
|
+
|
|
5
|
+
## Authors
|
|
6
|
+
|
|
7
|
+
Camille Coti, Vladimir Reinharz, and Wilfried Agbeto.
|
|
8
|
+
|
|
9
|
+
## Python library
|
|
10
|
+
|
|
11
|
+
CPython bindings are available in this repository as **FastMcsplit** (import
|
|
12
|
+
`fastmcsplit`), with NetworkX, CSV, and file interfaces, plus an approximation-only
|
|
13
|
+
mode. See the [Python API documentation](python/README.md) and
|
|
14
|
+
[TestPyPI instructions](docs/testpypi.md).
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### Prerequisites
|
|
19
|
+
|
|
20
|
+
- CMake 3.22 or later
|
|
21
|
+
- A C++17 compiler
|
|
22
|
+
|
|
23
|
+
### Build instructions
|
|
24
|
+
|
|
25
|
+
From the source directory:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
|
29
|
+
cmake --build build --parallel
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The executable is generated at `build/bin/Release/FastMcSplit`.
|
|
33
|
+
|
|
34
|
+
To install it:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cmake --install build --prefix "$HOME/.local"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Replace the prefix with your preferred installation directory.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
FastMcSplit [OPTIONS]... PATTERN_FILE TARGET_FILE
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For example, using the included undirected LAD graphs:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
./build/bin/Release/FastMcSplit -F ulad p.txt t.txt
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The program prints the best mapping as `(pattern_vertex, target_vertex)` pairs.
|
|
55
|
+
|
|
56
|
+
| Option | Description |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `-F, --format FORMAT` | Input format: `csv` (default), `ucsv`, `lad`, `ulad`, `grf`, `ugrf`, `elgrf`, `elugrf`, `gfu`, or `ugfu`. |
|
|
59
|
+
| `-W, --without-rules RULES` | All CLI reduction rules are enabled by default. Disable selected rules, for example `-W 'R1\|R4'`. |
|
|
60
|
+
| `-R, --reward_strategy ID` | Select fixed reward strategy 1–4 (see below). By default, no reward bonus is applied. |
|
|
61
|
+
| `-A, --adaptive-reward` | Cycle through reward strategies 1–4 (see below). Disabled by default. |
|
|
62
|
+
| `-h, --heuristic ID` | Select vertex-ordering heuristic 1–3 (see below). The default is 0. |
|
|
63
|
+
| `-C, --connected` | Search for a connected common induced subgraph. Disabled by default. |
|
|
64
|
+
| `-B, --big-first` | Try large solution sizes first. Disabled by default. |
|
|
65
|
+
| `-g, --greedy` | Run the greedy heuristic before the exact search. Disabled by default. |
|
|
66
|
+
| `-v, --verbose` | Print graph statistics, solution size, and timings. Disabled by default. |
|
|
67
|
+
| `-V, --version` | Show version information. |
|
|
68
|
+
| `-H, --help` | Show the complete help. |
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
./build/bin/Release/FastMcSplit -H
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Reward strategies (`-R`)
|
|
75
|
+
|
|
76
|
+
Rewards increase the scores of the last matched pattern and target vertices to guide later search choices. Without `-R` or `-A`, no reward bonus is applied. With `-R` alone, the selected strategy remains fixed.
|
|
77
|
+
|
|
78
|
+
For each active bidomain $C$, let $P_C$ and $T_C$ be its remaining pattern and target vertices. Define:
|
|
79
|
+
|
|
80
|
+
$$
|
|
81
|
+
a_C=\min(|P_C|,|T_C|),\qquad b_C=|P_C|\,|T_C|,
|
|
82
|
+
$$
|
|
83
|
+
|
|
84
|
+
$$
|
|
85
|
+
p_C=\frac{a_C}{\sum_D a_D},\qquad
|
|
86
|
+
r_C=\frac{b_C}{\sum_D b_D},\qquad
|
|
87
|
+
\Delta=U_{\mathrm{previous}}-U,
|
|
88
|
+
$$
|
|
89
|
+
|
|
90
|
+
where $U=\sum_C a_C$ is the remaining-cardinality upper bound. The diversity scores are $D_a=1/\sum_C p_C^2$ and $D_b=1/\sum_C r_C^2$.
|
|
91
|
+
|
|
92
|
+
| Value | Reward | Effect |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `1` | $\Delta+D_a$ | Combines upper-bound reduction with diversity of bidomain matching capacities. |
|
|
95
|
+
| `2` | $\Delta+D_b$ | Combines upper-bound reduction with diversity of candidate-pair counts. |
|
|
96
|
+
| `3` | $\Delta+N$ | Combines upper-bound reduction with the number $N$ of active bidomains. |
|
|
97
|
+
| `4` | $\Delta+D_a+D_b$ | Combines both diversity measures with upper-bound reduction. |
|
|
98
|
+
|
|
99
|
+
The diversity scores are larger when the corresponding quantities are spread more evenly across bidomains.
|
|
100
|
+
|
|
101
|
+
### Adaptive rewards (`-A`)
|
|
102
|
+
|
|
103
|
+
Disabled by default. With `-A`, the solver starts from the strategy supplied by `-R`, or strategy 1 if omitted. It cycles through strategies 1–4 after $\max(1,2\min(n,m))$ uses, where $n$ and $m$ are the graph sizes. Finding a better solution resets the switch counter.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
./build/bin/Release/FastMcSplit -F ulad -A -R 2 p.txt t.txt
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Vertex-ordering heuristics (`-h`)
|
|
110
|
+
|
|
111
|
+
The default is heuristic 0; `-h` accepts 1, 2, or 3. These heuristics apply to sparse, unlabelled target graphs. Dense targets (density greater than 0.5) and labelled instances use dedicated orderings. The solver can also prioritize a remaining vertex equivalent to the last matched pattern vertex before applying these orderings.
|
|
112
|
+
|
|
113
|
+
Otherwise, the solver first considers active bidomains minimizing $\max(|P_C|,|T_C|)$. Within those bidomains, it selects a pattern vertex using the following criteria, in priority order:
|
|
114
|
+
|
|
115
|
+
| Value | Selection criteria |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `0` (default) | Highest accumulated reward score, then highest degree, then smallest vertex ID. |
|
|
118
|
+
| `1` | Highest accumulated reward score, then highest degree, then most neighbours touched by current matches, then largest bidomain index and vertex ID. |
|
|
119
|
+
| `2` | Highest exploration score, then highest degree, then smallest vertex ID. |
|
|
120
|
+
| `3` | Highest exploration score, then highest degree, then most neighbours touched by current matches, then largest bidomain index and vertex ID. |
|
|
121
|
+
|
|
122
|
+
Heuristics 2 and 3 use:
|
|
123
|
+
|
|
124
|
+
$$
|
|
125
|
+
S(u)=g(u)+2\sqrt{\frac{\log(K+2)}{c(u)+1}}-0.1c(u),
|
|
126
|
+
$$
|
|
127
|
+
|
|
128
|
+
where $g(u)$ is the accumulated reward score, $K$ is the total number of recorded pattern-vertex selections, and $c(u)$ is the usage counter for $u$. The square-root term encourages exploration, while the last term penalizes frequent reuse. When a selected vertex improves the best solution, its usage counter is halved.
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
./build/bin/Release/FastMcSplit -F ulad -R 4 -h 2 p.txt t.txt
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## File formats
|
|
135
|
+
|
|
136
|
+
Both input graphs must use the same format. Vertex identifiers start at zero.
|
|
137
|
+
|
|
138
|
+
### CSV
|
|
139
|
+
|
|
140
|
+
The first line gives the number of vertices. Each following record describes an edge (`u,v`) or an isolated vertex (`u`).
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
3
|
|
144
|
+
0,1
|
|
145
|
+
1,2
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Vertex labels use `id;label`, for example `0;a,1;b`. An optional third field gives an edge label, for example `0;a,1;b,x`.
|
|
149
|
+
|
|
150
|
+
Use `-F csv` for directed graphs or `-F ucsv` for undirected graphs. Edge labels are enabled in `ucsv` mode.
|
|
151
|
+
|
|
152
|
+
### LAD
|
|
153
|
+
|
|
154
|
+
The first line gives the number of vertices. Each following line gives the number of successors of a vertex, followed by their identifiers.
|
|
155
|
+
|
|
156
|
+
```text
|
|
157
|
+
3
|
|
158
|
+
2 1 2
|
|
159
|
+
1 0
|
|
160
|
+
1 0
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Use `-F lad` for directed graphs or `-F ulad` for undirected graphs.
|
|
164
|
+
|
|
165
|
+
### GRF
|
|
166
|
+
|
|
167
|
+
The first line gives the number of vertices, followed by one `vertex_id vertex_label` line per vertex. For each vertex, give its number of outgoing edges, followed by one `source target` line per edge.
|
|
168
|
+
|
|
169
|
+
```text
|
|
170
|
+
3
|
|
171
|
+
0 a
|
|
172
|
+
1 b
|
|
173
|
+
2 a
|
|
174
|
+
2
|
|
175
|
+
0 1
|
|
176
|
+
0 2
|
|
177
|
+
1
|
|
178
|
+
1 0
|
|
179
|
+
1
|
|
180
|
+
2 0
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Use `-F grf` for directed graphs or `-F ugrf` for undirected graphs. For edge labels, add a third field to each edge record and use `-F elgrf` or `-F elugrf`.
|
|
184
|
+
|
|
185
|
+
### GFU
|
|
186
|
+
|
|
187
|
+
A GFU file contains the graph name, the number of vertices, one label per vertex, the number of edges, and the edge list.
|
|
188
|
+
|
|
189
|
+
```text
|
|
190
|
+
example
|
|
191
|
+
3
|
|
192
|
+
a
|
|
193
|
+
b
|
|
194
|
+
a
|
|
195
|
+
2
|
|
196
|
+
0 1
|
|
197
|
+
1 2
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
In the current implementation, use `-F gfu` for undirected graphs and `-F ugfu` for directed graphs.
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ParseArgs.hpp
|
|
3
|
+
* @author WILFRIED AGBETO (agbeto.kossi_wilfried@courrier.uqam.ca)
|
|
4
|
+
* @brief Class for retrieving command line arguments
|
|
5
|
+
* @version 0.1
|
|
6
|
+
* @date 2023-08-07
|
|
7
|
+
*
|
|
8
|
+
* @copyright Copyright (c) 2023
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#ifndef PARSE_ARGS_H
|
|
13
|
+
#define PARSE_ARGS_H
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <vector>
|
|
16
|
+
#include <define.hpp>
|
|
17
|
+
#include <iostream>
|
|
18
|
+
#include <sstream>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @class ParseArgs
|
|
22
|
+
* @brief FR: Gestionnaire statique des options de ligne de commande.
|
|
23
|
+
* EN: Static command-line option manager.
|
|
24
|
+
*
|
|
25
|
+
* FR: Cette classe conserve les options parsees dans des champs statiques afin
|
|
26
|
+
* que le reste du programme puisse interroger la configuration courante.
|
|
27
|
+
*
|
|
28
|
+
* EN: This class stores parsed options in static fields so the rest of the
|
|
29
|
+
* program can query the current configuration.
|
|
30
|
+
*/
|
|
31
|
+
class ParseArgs
|
|
32
|
+
{
|
|
33
|
+
private:
|
|
34
|
+
static std::string ALGORITHM;
|
|
35
|
+
static int COMPLETE_GRAPH_FILE;
|
|
36
|
+
static std::string OUT_DIR;
|
|
37
|
+
static int EXACT_ISO;
|
|
38
|
+
static std::string OUT_FILE;
|
|
39
|
+
static std::string OUT_PUT_LINK;
|
|
40
|
+
static int ALL_SOLUTION;
|
|
41
|
+
static int LABELED_EDGE;
|
|
42
|
+
static std::string SOLUTION;
|
|
43
|
+
static std::string FORMAT;
|
|
44
|
+
static int VERBOSE;
|
|
45
|
+
static std::string PATTERN_FILE;
|
|
46
|
+
static std::string TARGET_FILE;
|
|
47
|
+
static int READ_IN_STDIN;
|
|
48
|
+
static int FILTER_NODE;
|
|
49
|
+
static int SORT_GRAPH;
|
|
50
|
+
static bool CONNECTED;
|
|
51
|
+
static bool BIG_FIRST;
|
|
52
|
+
static bool GREEDY;
|
|
53
|
+
static bool ADAPTIVE_REWARD;
|
|
54
|
+
static bool W_REDUCTIONS[8];
|
|
55
|
+
static int REWARD_STRATEGY;
|
|
56
|
+
static int HEURISTIC;
|
|
57
|
+
public:
|
|
58
|
+
ParseArgs();
|
|
59
|
+
~ParseArgs();
|
|
60
|
+
/** FR: Verifie l'existence d'un fichier. EN: Checks whether a file exists. */
|
|
61
|
+
static int checkIfFileExists(const char* filename);
|
|
62
|
+
static void read_interaction_from_file(char *file_name);
|
|
63
|
+
/** FR: Affiche l'aide CLI. EN: Prints CLI help. */
|
|
64
|
+
static void print_help_text();
|
|
65
|
+
/** FR: Affiche la version. EN: Prints version information. */
|
|
66
|
+
static void print_version_text();
|
|
67
|
+
/** FR: Parse les arguments du programme. EN: Parses program arguments. */
|
|
68
|
+
static void fast_args_parse(int argc, char *argv[]);
|
|
69
|
+
static int getCOMPLETE_GRAPH_FILE();
|
|
70
|
+
static int getAll_solution();
|
|
71
|
+
static int getVERBOSE();
|
|
72
|
+
static std::string getPATTERN_FILE();
|
|
73
|
+
static std::string getTARGET_FILE();
|
|
74
|
+
static std::string getFORMAT();
|
|
75
|
+
static std::string getALGORITHM();
|
|
76
|
+
static std::string getSOLUTION();
|
|
77
|
+
static int getFILTER_NODE();
|
|
78
|
+
static int getSortGraph();
|
|
79
|
+
static bool getCONNECTED();
|
|
80
|
+
static bool getBIG_FIRST();
|
|
81
|
+
static bool getGREEDY();
|
|
82
|
+
static bool getADAPTIVE_REWARD();
|
|
83
|
+
static bool DO_REDUCTION(int r_id);
|
|
84
|
+
static int get_REWARD_STRATEGY();
|
|
85
|
+
static int get_HEURISTIC();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
#define HELP_TEXT "\
|
|
89
|
+
Usage: %s [OPTIONS]... PATTERN_FILE TARGET_FILE\n\
|
|
90
|
+
\n\
|
|
91
|
+
FastMcSplit searches for a large/common matching between PATTERN_FILE and TARGET_FILE.\n\
|
|
92
|
+
The two input files must use the same format selected with -F/--format.\n\
|
|
93
|
+
\n\
|
|
94
|
+
Options:\n\
|
|
95
|
+
-F, --format FORMAT\n\
|
|
96
|
+
Input graph format. Default: csv.\n\
|
|
97
|
+
Accepted values:\n\
|
|
98
|
+
csv directed CSV without edge labels\n\
|
|
99
|
+
ucsv undirected CSV\n\
|
|
100
|
+
lad directed LAD format, used by Glasgow tools\n\
|
|
101
|
+
ulad undirected LAD format\n\
|
|
102
|
+
grf directed GRF format, used by VF3\n\
|
|
103
|
+
ugrf undirected GRF format\n\
|
|
104
|
+
elgrf directed GRF with edge labels\n\
|
|
105
|
+
elugrf undirected GRF with edge labels\n\
|
|
106
|
+
gfu GFU/RI format\n\
|
|
107
|
+
ugfu undirected GFU/RI format\n\
|
|
108
|
+
\n\
|
|
109
|
+
-W, --without-rules RULES\n\
|
|
110
|
+
Disable one or more reduction rules. RULES is a '|' separated list.\n\
|
|
111
|
+
Each item must be R1, R2, R3, R4, R5, R6, R7, or R8.\n\
|
|
112
|
+
Example: -W R1|R4 disables reductions 1 and 4.\n\
|
|
113
|
+
Example: -W R8 disables reduction 8.\n\
|
|
114
|
+
\n\
|
|
115
|
+
-R, --reward_strategy ID\n\
|
|
116
|
+
Select the fixed reward strategy used to guide node ordering.\n\
|
|
117
|
+
Accepted values: 1, 2, 3, 4. If absent, no reward bonus is applied.\n\
|
|
118
|
+
Notation used below, for every active class C:\n\
|
|
119
|
+
P = number of remaining pattern nodes in C\n\
|
|
120
|
+
T = number of remaining target nodes in C\n\
|
|
121
|
+
m = min(P,T), prod = P*T, ub = sum(m)\n\
|
|
122
|
+
p_m = m / sum(m), p_prod = prod / sum(prod)\n\
|
|
123
|
+
delta = previous_ub - ub\n\
|
|
124
|
+
The reward is added to p_vgrade/t_vgrade for the last matched pair.\n\
|
|
125
|
+
Rewards are stored as double scores, so fractional bonuses are preserved.\n\
|
|
126
|
+
Strategies 1 and 2 use a Simpson-style entropy/diversity score:\n\
|
|
127
|
+
squared probabilities are used instead of probability*log(probability).\n\
|
|
128
|
+
1: reward = delta + 1 / sum(p_m^2)\n\
|
|
129
|
+
2: reward = delta + 1 / sum(p_prod^2)\n\
|
|
130
|
+
3: reward = delta + number_of_active_classes\n\
|
|
131
|
+
4: reward = delta + 1 / sum(p_m^2) + 1 / sum(p_prod^2)\n\
|
|
132
|
+
Without -A/--adaptive-reward, this strategy is kept for the whole search.\n\
|
|
133
|
+
\n\
|
|
134
|
+
-A, --adaptive-reward\n\
|
|
135
|
+
Enable adaptive reward selection. The solver starts from -R if provided,\n\
|
|
136
|
+
cycles through strategies 1..4 after a fixed number of uses, and resets\n\
|
|
137
|
+
the use counter whenever the current strategy improves the best solution.\n\
|
|
138
|
+
Current switch threshold: 2 * min(|PATTERN_NODES|, |TARGET_NODES|) uses.\n\
|
|
139
|
+
\n\
|
|
140
|
+
-h, --heuristic ID\n\
|
|
141
|
+
Select the pattern-variable ordering heuristic. The solver always first\n\
|
|
142
|
+
chooses the active classes minimizing max(|P_C|, |T_C|); this option only\n\
|
|
143
|
+
changes how a pattern vertex is selected among those candidate classes.\n\
|
|
144
|
+
It is used for sparse, unlabelled target graphs. Dense target graphs\n\
|
|
145
|
+
(density > 0.5) ignore this option and use: smallest pattern degree, then\n\
|
|
146
|
+
smallest neighbor-degree sum. Labelled sparse graphs use their dedicated\n\
|
|
147
|
+
labelled ordering.\n\
|
|
148
|
+
Accepted values are 1, 2, and 3. If -h is omitted, heuristic 0 is used.\n\
|
|
149
|
+
heuristic 0: highest p_vgrade, then highest degree, then smallest id\n\
|
|
150
|
+
heuristic 1: highest p_vgrade, then highest degree, then highest\n\
|
|
151
|
+
matched-neighbor pressure p_deg_m, then largest class/id\n\
|
|
152
|
+
heuristic 2: highest effective score, then highest degree, then\n\
|
|
153
|
+
smallest id\n\
|
|
154
|
+
heuristic 3: highest effective score, then highest degree, then highest\n\
|
|
155
|
+
matched-neighbor pressure p_deg_m, then largest class/id\n\
|
|
156
|
+
effective score = p_vgrade + 2.0*sqrt(log(total_choices+2)/(uses+1))\n\
|
|
157
|
+
- 0.1*uses\n\
|
|
158
|
+
If a selected variable improves the best solution, its use counter is\n\
|
|
159
|
+
halved.\n\
|
|
160
|
+
\n\
|
|
161
|
+
-C, --connected\n\
|
|
162
|
+
Restrict the search to connected expansions after the first matched node.\n\
|
|
163
|
+
\n\
|
|
164
|
+
-B, --big-first\n\
|
|
165
|
+
Search large target solution sizes first. The solver starts from the\n\
|
|
166
|
+
initial upper bound and decreases the goal until the optimum is found.\n\
|
|
167
|
+
\n\
|
|
168
|
+
-g, --greedy\n\
|
|
169
|
+
Run the greedy algorithm before the exact search. The greedy incumbent is\n\
|
|
170
|
+
used as an initial lower bound and may also select the target ordering\n\
|
|
171
|
+
used by the exact solver.\n\
|
|
172
|
+
\n\
|
|
173
|
+
-G, --get-all-solution\n\
|
|
174
|
+
Request all solutions. Note: the current executable primarily reports the\n\
|
|
175
|
+
best solution found; use this flag only with code paths that consume it.\n\
|
|
176
|
+
\n\
|
|
177
|
+
-S, --solution MODE\n\
|
|
178
|
+
Choose solution output mode.\n\
|
|
179
|
+
Accepted values:\n\
|
|
180
|
+
count-solution print the number of solutions, default\n\
|
|
181
|
+
print-solution print solution mappings\n\
|
|
182
|
+
save-solution save solution mappings, if supported by the caller\n\
|
|
183
|
+
\n\
|
|
184
|
+
-f, --filter\n\
|
|
185
|
+
Enable node filtering flag. This is parsed and stored for experimental\n\
|
|
186
|
+
code paths.\n\
|
|
187
|
+
\n\
|
|
188
|
+
-v, --verbose\n\
|
|
189
|
+
Print extra diagnostic information: graph statistics, timings, upper\n\
|
|
190
|
+
bound, incumbent improvements, and adaptive reward switches.\n\
|
|
191
|
+
\n\
|
|
192
|
+
-V, --version\n\
|
|
193
|
+
Show version information and exit.\n\
|
|
194
|
+
\n\
|
|
195
|
+
-H, --help\n\
|
|
196
|
+
Show this help message and exit. Note: uppercase -H is help; lowercase\n\
|
|
197
|
+
-h selects the heuristic.\n\
|
|
198
|
+
\n\
|
|
199
|
+
Examples:\n\
|
|
200
|
+
%s -F lad pattern.lad target.lad\n\
|
|
201
|
+
%s -F grf -g -R 2 -v pattern.grf target.grf\n\
|
|
202
|
+
%s -F csv -A -R 1 -W R2|R5 pattern.csv target.csv\n\
|
|
203
|
+
"
|
|
204
|
+
#define VERSION_TEXT "\
|
|
205
|
+
%s (GNU) %d\n\
|
|
206
|
+
Written by Camille Coti. Vladimir Reinharz and Wilfried Agbeto.\n\
|
|
207
|
+
"
|
|
208
|
+
#endif
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Build and test FastMcsplit on TestPyPI
|
|
2
|
+
|
|
3
|
+
Use a Python 3.10+ environment and a C++17 compiler on Linux or macOS.
|
|
4
|
+
The distribution is `FastMcsplit`, imported as `fastmcsplit`.
|
|
5
|
+
|
|
6
|
+
## Local validation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
python3 -m venv .venv-package
|
|
10
|
+
source .venv-package/bin/activate
|
|
11
|
+
python -m pip install build twine pytest networkx
|
|
12
|
+
python -m pip install -e '.[test]'
|
|
13
|
+
python -m pytest
|
|
14
|
+
python -m build --outdir dist/0.0.1
|
|
15
|
+
python -m twine check dist/0.0.1/*
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The source archive includes the C++ headers; CMake is not required for pip builds.
|
|
19
|
+
The wheel is specific to the build machine's Python ABI and platform. Other
|
|
20
|
+
platforms can build the source distribution. The current release is `0.0.1`.
|
|
21
|
+
Each release has its own output directory so older distributions are not uploaded
|
|
22
|
+
again by a wildcard.
|
|
23
|
+
|
|
24
|
+
## Upload to TestPyPI
|
|
25
|
+
|
|
26
|
+
Create a separate account at https://test.pypi.org/ and a TestPyPI API token.
|
|
27
|
+
Use `__token__` as the username and let Twine prompt for the token. Do not put
|
|
28
|
+
tokens in source files or shell command arguments.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m twine upload --repository testpypi --username __token__ dist/0.0.1/*
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This command targets TestPyPI only. Reusing an uploaded filename/version is not
|
|
35
|
+
allowed; increment `project.version` in `pyproject.toml` and `__version__` in
|
|
36
|
+
`python/fastmcsplit/__init__.py` before rebuilding a new release.
|
|
37
|
+
|
|
38
|
+
## Install back from TestPyPI in a clean environment
|
|
39
|
+
|
|
40
|
+
Install build tools and optional dependencies from PyPI first. Then install
|
|
41
|
+
FastMcsplit from TestPyPI with build isolation disabled, so pip uses those local
|
|
42
|
+
build tools instead of trying to download them from TestPyPI:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python3 -m venv /tmp/fastmcsplit-testpypi
|
|
46
|
+
source /tmp/fastmcsplit-testpypi/bin/activate
|
|
47
|
+
python -m pip install --index-url https://pypi.org/simple/ 'setuptools>=77' wheel networkx
|
|
48
|
+
python -m pip install --index-url https://test.pypi.org/simple/ --no-build-isolation --no-deps FastMcsplit==0.0.1
|
|
49
|
+
python -c 'import fastmcsplit, networkx as nx; r = fastmcsplit.solve(nx.path_graph(3), nx.path_graph(4)); assert r.size == 3 and r.optimal; print(r)'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`--no-deps` skips runtime dependencies; it does not disable the installation of
|
|
53
|
+
build dependencies. `--no-build-isolation` makes pip use the build tools already
|
|
54
|
+
installed above. NetworkX is optional and only needed for the NetworkX interface
|
|
55
|
+
and the example command above. Building from the source archive, as on Linux
|
|
56
|
+
when no matching wheel is published, also requires a C++17 compiler.
|
|
57
|
+
|
|
58
|
+
Follow the official [TestPyPI guide](https://packaging.python.org/en/latest/guides/using-testpypi/).
|
|
59
|
+
|
|
60
|
+
## Publish to PyPI
|
|
61
|
+
|
|
62
|
+
Create an account and API token on https://pypi.org/. PyPI and TestPyPI use
|
|
63
|
+
separate accounts and tokens. Upload the validated archives to the main index:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python -m twine upload --repository pypi --username __token__ dist/0.0.1/*
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Enter the PyPI API token when Twine prompts for it. Once published, install with:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
python -m pip install FastMcsplit==0.0.1
|
|
73
|
+
```
|