esperanza 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Frank Vega
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,288 @@
1
+ Metadata-Version: 2.4
2
+ Name: esperanza
3
+ Version: 0.0.1
4
+ Summary: Compute the Approximate Independent Set for undirected graph encoded in DIMACS format.
5
+ Home-page: https://github.com/frankvegadelgado/esperanza
6
+ Author: Frank Vega
7
+ Author-email: vega.frank@gmail.com
8
+ License: MIT License
9
+ Project-URL: Source Code, https://github.com/frankvegadelgado/esperanza
10
+ Project-URL: Documentation Research, https://dev.to/frank_vega_987689489099bf/the-esperanza-algorithm-4khe
11
+ Classifier: Topic :: Scientific/Engineering
12
+ Classifier: Topic :: Software Development
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Education
19
+ Classifier: Intended Audience :: Information Technology
20
+ Classifier: Intended Audience :: Science/Research
21
+ Classifier: Natural Language :: English
22
+ Requires-Python: >=3.12
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: hvala>=0.0.7
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: license
33
+ Dynamic: license-file
34
+ Dynamic: project-url
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
38
+
39
+ # Esperanza: Approximate Independent Set Solver
40
+
41
+ ![Erbarme dich, mein Gott (Bach)](docs/greco.jpg)
42
+
43
+ This work builds upon [The Esperanza Algorithm](https://dev.to/frank_vega_987689489099bf/the-esperanza-algorithm-4khe).
44
+
45
+ ---
46
+
47
+ # Maximum Independent Set (MIS) Problem: Overview
48
+
49
+ ## Definition
50
+
51
+ The **Maximum Independent Set (MIS)** problem is a fundamental NP-hard problem in graph theory. Given an undirected graph $G = (V, E)$, an _independent set_ is a subset of vertices $S \subseteq V$ where no two vertices in $S$ are adjacent. The MIS problem seeks the largest such subset $S$.
52
+
53
+ ## Key Properties
54
+
55
+ - **NP-Hardness**: MIS is computationally intractable (no known polynomial-time solution unless $P = NP$).
56
+ - **Equivalent Problems**:
57
+ - MIS is equivalent to finding the largest _clique_ in the complement graph $\overline{G}$.
58
+ - It is also related to the _Minimum Vertex Cover_ problem: $S$ is an MIS iff $V \setminus S$ is a vertex cover.
59
+
60
+ ## Applications
61
+
62
+ 1. **Scheduling**: Assigning non-conflicting tasks (e.g., scheduling exams with no shared students).
63
+ 2. **Network Design**: Selecting non-adjacent nodes for efficient resource allocation.
64
+ 3. **Bioinformatics**: Modeling protein-protein interaction networks.
65
+
66
+ ## Algorithms
67
+
68
+ | Approach | Description | Complexity |
69
+ | ------------------- | ---------------------------------------------------------------------- | ------------------- |
70
+ | Brute-Force | Checks all possible subsets of vertices. | $O(2^n)$ |
71
+ | Greedy Heuristics | Selects vertices with minimal degree iteratively. | $O(n + m)$ (approx) |
72
+ | Dynamic Programming | Used for trees or graphs with bounded treewidth. | $O(3^{tw})$ |
73
+ | Approximation | No PTAS exists; best-known approximation ratio is $O(n / (\log n)^2)$. | NP-Hard |
74
+
75
+ ## Example
76
+
77
+ For a graph with vertices $\\{A, B, C\\}$ and edges $\\{(A,B), (B,C)\\}$:
78
+
79
+ - **Independent Sets**: $\\{A, C\\}$, $\\{A\\}$, $\\{B\\}$, $\\{C\\}$.
80
+ - **MIS**: $\\{A, C\\}$ (size 2).
81
+
82
+ ## Open Challenges
83
+
84
+ - Finding a constant-factor approximation for general graphs.
85
+ - Efficient quantum or parallel algorithms for large-scale graphs.
86
+
87
+ ---
88
+
89
+ ## Problem Statement
90
+
91
+ Input: A Boolean Adjacency Matrix $M$.
92
+
93
+ Answer: Find a Maximum Independent Set.
94
+
95
+ ### Example Instance: 5 x 5 matrix
96
+
97
+ | | c1 | c2 | c3 | c4 | c5 |
98
+ | ------ | --- | --- | --- | --- | --- |
99
+ | **r1** | 0 | 0 | 1 | 0 | 1 |
100
+ | **r2** | 0 | 0 | 0 | 1 | 0 |
101
+ | **r3** | 1 | 0 | 0 | 0 | 1 |
102
+ | **r4** | 0 | 1 | 0 | 0 | 0 |
103
+ | **r5** | 1 | 0 | 1 | 0 | 0 |
104
+
105
+ The input for undirected graph is typically provided in [DIMACS](http://dimacs.rutgers.edu/Challenges) format. In this way, the previous adjacency matrix is represented in a text file using the following string representation:
106
+
107
+ ```
108
+ p edge 5 4
109
+ e 1 3
110
+ e 1 5
111
+ e 2 4
112
+ e 3 5
113
+ ```
114
+
115
+ This represents a 5x5 matrix in DIMACS format such that each edge $(v,w)$ appears exactly once in the input file and is not repeated as $(w,v)$. In this format, every edge appears in the form of
116
+
117
+ ```
118
+ e W V
119
+ ```
120
+
121
+ where the fields W and V specify the endpoints of the edge while the lower-case character `e` signifies that this is an edge descriptor line.
122
+
123
+ _Example Solution:_
124
+
125
+ Independent Set Found `4, 5`: Nodes `4`, and `5` constitute an optimal solution.
126
+
127
+ ---
128
+
129
+ # Compile and Environment
130
+
131
+ ## Prerequisites
132
+
133
+ - Python ≥ 3.12
134
+
135
+ ## Installation
136
+
137
+ ```bash
138
+ pip install esperanza
139
+ ```
140
+
141
+ ## Execution
142
+
143
+ 1. Clone the repository:
144
+
145
+ ```bash
146
+ git clone https://github.com/frankvegadelgado/esperanza.git
147
+ cd esperanza
148
+ ```
149
+
150
+ 2. Run the script:
151
+
152
+ ```bash
153
+ hope -i ./benchmarks/testMatrix1
154
+ ```
155
+
156
+ utilizing the `hope` command provided by Esperanza's Library to execute the Boolean adjacency matrix `esperanza\benchmarks\testMatrix1`. The file `testMatrix1` represents the example described herein. We also support `.xz`, `.lzma`, `.bz2`, and `.bzip2` compressed text files.
157
+
158
+ **Example Output:**
159
+
160
+ ```
161
+ testMatrix1: Independent Set Found 4, 5
162
+ ```
163
+
164
+ This indicates nodes `4, 5` form a Independent Set.
165
+
166
+ ---
167
+
168
+ ## Independent Set Size
169
+
170
+ Use the `-c` flag to count the nodes in the Independent Set:
171
+
172
+ ```bash
173
+ hope -i ./benchmarks/testMatrix2 -c
174
+ ```
175
+
176
+ **Output:**
177
+
178
+ ```
179
+ testMatrix2: Independent Set Size 5
180
+ ```
181
+
182
+ ---
183
+
184
+ # Command Options
185
+
186
+ Display help and options:
187
+
188
+ ```bash
189
+ hope -h
190
+ ```
191
+
192
+ **Output:**
193
+
194
+ ```bash
195
+ usage: hope [-h] -i INPUTFILE [-a] [-b] [-c] [-v] [-l] [--version]
196
+
197
+ Compute the Approximate Independent Set for undirected graph encoded in DIMACS format.
198
+
199
+ options:
200
+ -h, --help show this help message and exit
201
+ -i INPUTFILE, --inputFile INPUTFILE
202
+ input file path
203
+ -a, --approximation enable comparison with a polynomial-time approximation approach within a factor of at most 2
204
+ -b, --bruteForce enable comparison with the exponential-time brute-force approach
205
+ -c, --count calculate the size of the Independent Set
206
+ -v, --verbose anable verbose output
207
+ -l, --log enable file logging
208
+ --version show program's version number and exit
209
+ ```
210
+
211
+ ---
212
+
213
+ # Batch Execution
214
+
215
+ Batch execution allows you to solve multiple graphs within a directory consecutively.
216
+
217
+ To view available command-line options for the `batch_hope` command, use the following in your terminal or command prompt:
218
+
219
+ ```bash
220
+ batch_hope -h
221
+ ```
222
+
223
+ This will display the following help information:
224
+
225
+ ```bash
226
+ usage: batch_hope [-h] -i INPUTDIRECTORY [-a] [-b] [-c] [-v] [-l] [--version]
227
+
228
+ Compute the Approximate Independent Set for all undirected graphs encoded in DIMACS format and stored in a directory.
229
+
230
+ options:
231
+ -h, --help show this help message and exit
232
+ -i INPUTDIRECTORY, --inputDirectory INPUTDIRECTORY
233
+ Input directory path
234
+ -a, --approximation enable comparison with a polynomial-time approximation approach within a factor of at most 2
235
+ -b, --bruteForce enable comparison with the exponential-time brute-force approach
236
+ -c, --count calculate the size of the Independent Set
237
+ -v, --verbose anable verbose output
238
+ -l, --log enable file logging
239
+ --version show program's version number and exit
240
+ ```
241
+
242
+ ---
243
+
244
+ # Testing Application
245
+
246
+ A command-line utility named `test_hope` is provided for evaluating the Algorithm using randomly generated, large sparse matrices. It supports the following options:
247
+
248
+ ```bash
249
+ usage: test_hope [-h] -d DIMENSION [-n NUM_TESTS] [-s SPARSITY] [-a] [-b] [-c] [-w] [-v] [-l] [--version]
250
+
251
+ The Esperanza Testing Application using randomly generated, large sparse matrices.
252
+
253
+ options:
254
+ -h, --help show this help message and exit
255
+ -d DIMENSION, --dimension DIMENSION
256
+ an integer specifying the dimensions of the square matrices
257
+ -n NUM_TESTS, --num_tests NUM_TESTS
258
+ an integer specifying the number of tests to run
259
+ -s SPARSITY, --sparsity SPARSITY
260
+ sparsity of the matrices (0.0 for dense, close to 1.0 for very sparse)
261
+ -a, --approximation enable comparison with a polynomial-time approximation approach within a factor of at most 2
262
+ -b, --bruteForce enable comparison with the exponential-time brute-force approach
263
+ -c, --count calculate the size of the Independent Set
264
+ -w, --write write the generated random matrix to a file in the current directory
265
+ -v, --verbose anable verbose output
266
+ -l, --log enable file logging
267
+ --version show program's version number and exit
268
+ ```
269
+
270
+ ---
271
+
272
+ # Code
273
+
274
+ - Python implementation by **Frank Vega**.
275
+
276
+ ---
277
+
278
+ # Complexity
279
+
280
+ ```diff
281
+ + This algorithm finds near-optimal solutions for MIS in polynomial time, with an approximation ratio below 2. This breakthrough challenges the computational boundaries of P vs. NP providing strong evidence that P = NP.
282
+ ```
283
+
284
+ ---
285
+
286
+ # License
287
+
288
+ - MIT License.
@@ -0,0 +1,250 @@
1
+ # Esperanza: Approximate Independent Set Solver
2
+
3
+ ![Erbarme dich, mein Gott (Bach)](docs/greco.jpg)
4
+
5
+ This work builds upon [The Esperanza Algorithm](https://dev.to/frank_vega_987689489099bf/the-esperanza-algorithm-4khe).
6
+
7
+ ---
8
+
9
+ # Maximum Independent Set (MIS) Problem: Overview
10
+
11
+ ## Definition
12
+
13
+ The **Maximum Independent Set (MIS)** problem is a fundamental NP-hard problem in graph theory. Given an undirected graph $G = (V, E)$, an _independent set_ is a subset of vertices $S \subseteq V$ where no two vertices in $S$ are adjacent. The MIS problem seeks the largest such subset $S$.
14
+
15
+ ## Key Properties
16
+
17
+ - **NP-Hardness**: MIS is computationally intractable (no known polynomial-time solution unless $P = NP$).
18
+ - **Equivalent Problems**:
19
+ - MIS is equivalent to finding the largest _clique_ in the complement graph $\overline{G}$.
20
+ - It is also related to the _Minimum Vertex Cover_ problem: $S$ is an MIS iff $V \setminus S$ is a vertex cover.
21
+
22
+ ## Applications
23
+
24
+ 1. **Scheduling**: Assigning non-conflicting tasks (e.g., scheduling exams with no shared students).
25
+ 2. **Network Design**: Selecting non-adjacent nodes for efficient resource allocation.
26
+ 3. **Bioinformatics**: Modeling protein-protein interaction networks.
27
+
28
+ ## Algorithms
29
+
30
+ | Approach | Description | Complexity |
31
+ | ------------------- | ---------------------------------------------------------------------- | ------------------- |
32
+ | Brute-Force | Checks all possible subsets of vertices. | $O(2^n)$ |
33
+ | Greedy Heuristics | Selects vertices with minimal degree iteratively. | $O(n + m)$ (approx) |
34
+ | Dynamic Programming | Used for trees or graphs with bounded treewidth. | $O(3^{tw})$ |
35
+ | Approximation | No PTAS exists; best-known approximation ratio is $O(n / (\log n)^2)$. | NP-Hard |
36
+
37
+ ## Example
38
+
39
+ For a graph with vertices $\\{A, B, C\\}$ and edges $\\{(A,B), (B,C)\\}$:
40
+
41
+ - **Independent Sets**: $\\{A, C\\}$, $\\{A\\}$, $\\{B\\}$, $\\{C\\}$.
42
+ - **MIS**: $\\{A, C\\}$ (size 2).
43
+
44
+ ## Open Challenges
45
+
46
+ - Finding a constant-factor approximation for general graphs.
47
+ - Efficient quantum or parallel algorithms for large-scale graphs.
48
+
49
+ ---
50
+
51
+ ## Problem Statement
52
+
53
+ Input: A Boolean Adjacency Matrix $M$.
54
+
55
+ Answer: Find a Maximum Independent Set.
56
+
57
+ ### Example Instance: 5 x 5 matrix
58
+
59
+ | | c1 | c2 | c3 | c4 | c5 |
60
+ | ------ | --- | --- | --- | --- | --- |
61
+ | **r1** | 0 | 0 | 1 | 0 | 1 |
62
+ | **r2** | 0 | 0 | 0 | 1 | 0 |
63
+ | **r3** | 1 | 0 | 0 | 0 | 1 |
64
+ | **r4** | 0 | 1 | 0 | 0 | 0 |
65
+ | **r5** | 1 | 0 | 1 | 0 | 0 |
66
+
67
+ The input for undirected graph is typically provided in [DIMACS](http://dimacs.rutgers.edu/Challenges) format. In this way, the previous adjacency matrix is represented in a text file using the following string representation:
68
+
69
+ ```
70
+ p edge 5 4
71
+ e 1 3
72
+ e 1 5
73
+ e 2 4
74
+ e 3 5
75
+ ```
76
+
77
+ This represents a 5x5 matrix in DIMACS format such that each edge $(v,w)$ appears exactly once in the input file and is not repeated as $(w,v)$. In this format, every edge appears in the form of
78
+
79
+ ```
80
+ e W V
81
+ ```
82
+
83
+ where the fields W and V specify the endpoints of the edge while the lower-case character `e` signifies that this is an edge descriptor line.
84
+
85
+ _Example Solution:_
86
+
87
+ Independent Set Found `4, 5`: Nodes `4`, and `5` constitute an optimal solution.
88
+
89
+ ---
90
+
91
+ # Compile and Environment
92
+
93
+ ## Prerequisites
94
+
95
+ - Python ≥ 3.12
96
+
97
+ ## Installation
98
+
99
+ ```bash
100
+ pip install esperanza
101
+ ```
102
+
103
+ ## Execution
104
+
105
+ 1. Clone the repository:
106
+
107
+ ```bash
108
+ git clone https://github.com/frankvegadelgado/esperanza.git
109
+ cd esperanza
110
+ ```
111
+
112
+ 2. Run the script:
113
+
114
+ ```bash
115
+ hope -i ./benchmarks/testMatrix1
116
+ ```
117
+
118
+ utilizing the `hope` command provided by Esperanza's Library to execute the Boolean adjacency matrix `esperanza\benchmarks\testMatrix1`. The file `testMatrix1` represents the example described herein. We also support `.xz`, `.lzma`, `.bz2`, and `.bzip2` compressed text files.
119
+
120
+ **Example Output:**
121
+
122
+ ```
123
+ testMatrix1: Independent Set Found 4, 5
124
+ ```
125
+
126
+ This indicates nodes `4, 5` form a Independent Set.
127
+
128
+ ---
129
+
130
+ ## Independent Set Size
131
+
132
+ Use the `-c` flag to count the nodes in the Independent Set:
133
+
134
+ ```bash
135
+ hope -i ./benchmarks/testMatrix2 -c
136
+ ```
137
+
138
+ **Output:**
139
+
140
+ ```
141
+ testMatrix2: Independent Set Size 5
142
+ ```
143
+
144
+ ---
145
+
146
+ # Command Options
147
+
148
+ Display help and options:
149
+
150
+ ```bash
151
+ hope -h
152
+ ```
153
+
154
+ **Output:**
155
+
156
+ ```bash
157
+ usage: hope [-h] -i INPUTFILE [-a] [-b] [-c] [-v] [-l] [--version]
158
+
159
+ Compute the Approximate Independent Set for undirected graph encoded in DIMACS format.
160
+
161
+ options:
162
+ -h, --help show this help message and exit
163
+ -i INPUTFILE, --inputFile INPUTFILE
164
+ input file path
165
+ -a, --approximation enable comparison with a polynomial-time approximation approach within a factor of at most 2
166
+ -b, --bruteForce enable comparison with the exponential-time brute-force approach
167
+ -c, --count calculate the size of the Independent Set
168
+ -v, --verbose anable verbose output
169
+ -l, --log enable file logging
170
+ --version show program's version number and exit
171
+ ```
172
+
173
+ ---
174
+
175
+ # Batch Execution
176
+
177
+ Batch execution allows you to solve multiple graphs within a directory consecutively.
178
+
179
+ To view available command-line options for the `batch_hope` command, use the following in your terminal or command prompt:
180
+
181
+ ```bash
182
+ batch_hope -h
183
+ ```
184
+
185
+ This will display the following help information:
186
+
187
+ ```bash
188
+ usage: batch_hope [-h] -i INPUTDIRECTORY [-a] [-b] [-c] [-v] [-l] [--version]
189
+
190
+ Compute the Approximate Independent Set for all undirected graphs encoded in DIMACS format and stored in a directory.
191
+
192
+ options:
193
+ -h, --help show this help message and exit
194
+ -i INPUTDIRECTORY, --inputDirectory INPUTDIRECTORY
195
+ Input directory path
196
+ -a, --approximation enable comparison with a polynomial-time approximation approach within a factor of at most 2
197
+ -b, --bruteForce enable comparison with the exponential-time brute-force approach
198
+ -c, --count calculate the size of the Independent Set
199
+ -v, --verbose anable verbose output
200
+ -l, --log enable file logging
201
+ --version show program's version number and exit
202
+ ```
203
+
204
+ ---
205
+
206
+ # Testing Application
207
+
208
+ A command-line utility named `test_hope` is provided for evaluating the Algorithm using randomly generated, large sparse matrices. It supports the following options:
209
+
210
+ ```bash
211
+ usage: test_hope [-h] -d DIMENSION [-n NUM_TESTS] [-s SPARSITY] [-a] [-b] [-c] [-w] [-v] [-l] [--version]
212
+
213
+ The Esperanza Testing Application using randomly generated, large sparse matrices.
214
+
215
+ options:
216
+ -h, --help show this help message and exit
217
+ -d DIMENSION, --dimension DIMENSION
218
+ an integer specifying the dimensions of the square matrices
219
+ -n NUM_TESTS, --num_tests NUM_TESTS
220
+ an integer specifying the number of tests to run
221
+ -s SPARSITY, --sparsity SPARSITY
222
+ sparsity of the matrices (0.0 for dense, close to 1.0 for very sparse)
223
+ -a, --approximation enable comparison with a polynomial-time approximation approach within a factor of at most 2
224
+ -b, --bruteForce enable comparison with the exponential-time brute-force approach
225
+ -c, --count calculate the size of the Independent Set
226
+ -w, --write write the generated random matrix to a file in the current directory
227
+ -v, --verbose anable verbose output
228
+ -l, --log enable file logging
229
+ --version show program's version number and exit
230
+ ```
231
+
232
+ ---
233
+
234
+ # Code
235
+
236
+ - Python implementation by **Frank Vega**.
237
+
238
+ ---
239
+
240
+ # Complexity
241
+
242
+ ```diff
243
+ + This algorithm finds near-optimal solutions for MIS in polynomial time, with an approximation ratio below 2. This breakthrough challenges the computational boundaries of P vs. NP providing strong evidence that P = NP.
244
+ ```
245
+
246
+ ---
247
+
248
+ # License
249
+
250
+ - MIT License.
@@ -0,0 +1,4 @@
1
+ # Esperanza: Approximate Independent Set Solver https://pypi.org/project/esperanza
2
+ # Author: Frank Vega
3
+
4
+ __all__ = ["utils", "algorithm", "parser", "applogger", "test", "app", "batch"]