alonso 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
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.
- alonso/algorithm.py +47 -28
- alonso/app.py +1 -1
- alonso/batch.py +1 -1
- alonso/merge.py +4 -5
- alonso/partition.py +4 -4
- alonso/test.py +1 -1
- {alonso-0.0.1.dist-info → alonso-0.0.2.dist-info}/METADATA +1 -1
- alonso-0.0.2.dist-info/RECORD +17 -0
- alonso-0.0.1.dist-info/RECORD +0 -17
- {alonso-0.0.1.dist-info → alonso-0.0.2.dist-info}/WHEEL +0 -0
- {alonso-0.0.1.dist-info → alonso-0.0.2.dist-info}/entry_points.txt +0 -0
- {alonso-0.0.1.dist-info → alonso-0.0.2.dist-info}/licenses/LICENSE +0 -0
- {alonso-0.0.1.dist-info → alonso-0.0.2.dist-info}/top_level.txt +0 -0
alonso/algorithm.py
CHANGED
@@ -5,6 +5,7 @@ import itertools
|
|
5
5
|
from . import utils
|
6
6
|
|
7
7
|
import networkx as nx
|
8
|
+
import mendive.algorithm as algo
|
8
9
|
from . import partition
|
9
10
|
from . import stable
|
10
11
|
from . import merge
|
@@ -41,34 +42,52 @@ def find_vertex_cover(graph):
|
|
41
42
|
if working_graph.number_of_nodes() == 0:
|
42
43
|
return set()
|
43
44
|
|
44
|
-
#
|
45
|
-
# This
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
45
|
+
# Structural analysis: detect presence of claw subgraphs (K_{1,3})
|
46
|
+
# This determines which algorithmic approach to use
|
47
|
+
claw = algo.find_claw_coordinates(working_graph, first_claw=True)
|
48
|
+
|
49
|
+
if claw is None:
|
50
|
+
# CASE 1: Claw-free graph - use polynomial-time exact algorithm
|
51
|
+
# Apply Faenza-Oriolo-Stauffer algorithm for weighted stable set on claw-free graphs
|
52
|
+
# The maximum weighted stable set's complement gives us the minimum vertex cover
|
53
|
+
E = working_graph.edges()
|
54
|
+
approximate_vertex_cover = stable.minimum_vertex_cover_claw_free(E)
|
55
|
+
|
56
|
+
else:
|
57
|
+
# CASE 2: Graph contains claws - use divide-and-conquer approach
|
58
|
+
|
59
|
+
# Step 1: Edge partitioning using enhanced Burr-Erdős-Lovász technique
|
60
|
+
# Partition edges E = E1 ∪ E2 such that both induced subgraphs G[E1] and G[E2] are claw-free
|
61
|
+
# Complexity: O(m * (m * Δ * C + C^2)), where m is edges, Δ is maximum degree, C is number of claws
|
62
|
+
E1, E2 = partition.partition_edges_claw_free(working_graph)
|
63
|
+
|
64
|
+
# Step 2: Solve subproblems optimally on claw-free partitions
|
65
|
+
# Each partition can be solved exactly using polynomial-time algorithms
|
66
|
+
vertex_cover_1 = stable.minimum_vertex_cover_claw_free(E1) # O(n^3) for subgraph G[E1]
|
67
|
+
vertex_cover_2 = stable.minimum_vertex_cover_claw_free(E2) # O(n^3) for subgraph G[E2]
|
68
|
+
|
69
|
+
# Step 3: Intelligent merging with 1.42-approximation guarantee
|
70
|
+
# Time complexity: O(|V| × log |V|)
|
71
|
+
approximate_vertex_cover = merge.merge_vertex_covers(
|
72
|
+
working_graph, vertex_cover_1, vertex_cover_2
|
73
|
+
)
|
74
|
+
|
75
|
+
# Step 4: Handle residual uncovered edges through recursion
|
76
|
+
# Construct residual graph containing edges missed by current vertex cover
|
77
|
+
residual_graph = nx.Graph()
|
78
|
+
for u, v in working_graph.edges():
|
79
|
+
# Edge (u,v) is uncovered if neither endpoint is in our current cover
|
80
|
+
if u not in approximate_vertex_cover and v not in approximate_vertex_cover:
|
81
|
+
residual_graph.add_edge(u, v)
|
82
|
+
|
83
|
+
# Recursive call to handle remaining uncovered structure
|
84
|
+
# This ensures completeness: every edge in the original graph is covered
|
85
|
+
residual_vertex_cover = find_vertex_cover(residual_graph)
|
86
|
+
|
87
|
+
# Combine solutions: union of main cover and residual cover
|
88
|
+
approximate_vertex_cover = approximate_vertex_cover.union(residual_vertex_cover)
|
89
|
+
|
90
|
+
return approximate_vertex_cover
|
72
91
|
|
73
92
|
def find_vertex_cover_brute_force(graph):
|
74
93
|
"""
|
alonso/app.py
CHANGED
@@ -82,7 +82,7 @@ def main():
|
|
82
82
|
helper.add_argument('-c', '--count', action='store_true', help='calculate the size of the vertex cover')
|
83
83
|
helper.add_argument('-v', '--verbose', action='store_true', help='anable verbose output')
|
84
84
|
helper.add_argument('-l', '--log', action='store_true', help='enable file logging')
|
85
|
-
helper.add_argument('--version', action='version', version='%(prog)s 0.0.
|
85
|
+
helper.add_argument('--version', action='version', version='%(prog)s 0.0.2')
|
86
86
|
|
87
87
|
# Initialize the parameters
|
88
88
|
args = helper.parse_args()
|
alonso/batch.py
CHANGED
@@ -36,7 +36,7 @@ def main():
|
|
36
36
|
helper.add_argument('-c', '--count', action='store_true', help='calculate the size of the vertex cover')
|
37
37
|
helper.add_argument('-v', '--verbose', action='store_true', help='anable verbose output')
|
38
38
|
helper.add_argument('-l', '--log', action='store_true', help='enable file logging')
|
39
|
-
helper.add_argument('--version', action='version', version='%(prog)s 0.0.
|
39
|
+
helper.add_argument('--version', action='version', version='%(prog)s 0.0.2')
|
40
40
|
|
41
41
|
|
42
42
|
# Initialize the parameters
|
alonso/merge.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
def merge_vertex_covers(
|
1
|
+
def merge_vertex_covers(G, vertex_cover_1, vertex_cover_2):
|
2
2
|
"""
|
3
3
|
Merge two vertex covers from edge partitions to get minimum vertex cover of G.
|
4
4
|
|
5
5
|
Args:
|
6
6
|
G: Graph represented as adjacency list/set of edges
|
7
|
-
E1, E2: Two partitions of edges E
|
8
7
|
vertex_cover_1: Vertex cover for subgraph induced by E1
|
9
8
|
vertex_cover_2: Vertex cover for subgraph induced by E2
|
10
9
|
|
@@ -12,15 +11,15 @@ def merge_vertex_covers(E1, E2, vertex_cover_1, vertex_cover_2):
|
|
12
11
|
Merged vertex cover for the entire graph G
|
13
12
|
"""
|
14
13
|
# All edges in the graph
|
15
|
-
all_edges =
|
14
|
+
all_edges = G.edges()
|
16
15
|
|
17
16
|
# Initialize merge process
|
18
17
|
merged_cover = set()
|
19
18
|
covered_edges = set()
|
20
19
|
|
21
20
|
# Convert vertex covers to lists for merge-sort-like processing
|
22
|
-
candidates_1 = list(vertex_cover_1)
|
23
|
-
candidates_2 = list(vertex_cover_2)
|
21
|
+
candidates_1 = sorted(list(vertex_cover_1), key=lambda x: G.degree(x), reverse=True)
|
22
|
+
candidates_2 = sorted(list(vertex_cover_2), key=lambda x: G.degree(x), reverse=True)
|
24
23
|
|
25
24
|
i, j = 0, 0
|
26
25
|
|
alonso/partition.py
CHANGED
@@ -2,7 +2,7 @@ import networkx as nx
|
|
2
2
|
from typing import Tuple, Set, List
|
3
3
|
from collections import defaultdict
|
4
4
|
import itertools
|
5
|
-
import mendive.algorithm as
|
5
|
+
import mendive.algorithm as algo
|
6
6
|
|
7
7
|
class BurrErdosLovaszPartitioner:
|
8
8
|
"""
|
@@ -64,7 +64,7 @@ class BurrErdosLovaszPartitioner:
|
|
64
64
|
G = nx.Graph()
|
65
65
|
G.add_edges_from(edge_set)
|
66
66
|
|
67
|
-
claw =
|
67
|
+
claw = algo.find_claw_coordinates(G, first_claw=True)
|
68
68
|
if claw is None:
|
69
69
|
return True
|
70
70
|
else:
|
@@ -83,7 +83,7 @@ class BurrErdosLovaszPartitioner:
|
|
83
83
|
k_star_count = 0
|
84
84
|
|
85
85
|
if self.k == 3:
|
86
|
-
all_claws =
|
86
|
+
all_claws = algo.find_claw_coordinates(G, first_claw=False)
|
87
87
|
if all_claws is not None:
|
88
88
|
k_star_count = len(all_claws)
|
89
89
|
else:
|
@@ -161,7 +161,7 @@ class BurrErdosLovaszPartitioner:
|
|
161
161
|
k_stars = []
|
162
162
|
|
163
163
|
if self.k == 3:
|
164
|
-
all_claws =
|
164
|
+
all_claws = algo.find_claw_coordinates(G, first_claw=False)
|
165
165
|
if all_claws is not None:
|
166
166
|
for subset in all_claws:
|
167
167
|
subgraph = G.subgraph(subset)
|
alonso/test.py
CHANGED
@@ -34,7 +34,7 @@ def main():
|
|
34
34
|
helper.add_argument('-w', '--write', action='store_true', help='write the generated random matrix to a file in the current directory')
|
35
35
|
helper.add_argument('-v', '--verbose', action='store_true', help='anable verbose output')
|
36
36
|
helper.add_argument('-l', '--log', action='store_true', help='enable file logging')
|
37
|
-
helper.add_argument('--version', action='version', version='%(prog)s 0.0.
|
37
|
+
helper.add_argument('--version', action='version', version='%(prog)s 0.0.2')
|
38
38
|
|
39
39
|
# Initialize the parameters
|
40
40
|
args = helper.parse_args()
|
@@ -0,0 +1,17 @@
|
|
1
|
+
alonso/__init__.py,sha256=vbC0ysStExEptYRA3SZVoBGFT7ysEDRPnZ9k9NqGMXI,188
|
2
|
+
alonso/algorithm.py,sha256=hJDruQQJxxlvmjJU_pue3A4R2ZEMC4rOXz45O0w3pM4,5534
|
3
|
+
alonso/app.py,sha256=NxYA4Lfh1xw37XpUunwKYoa5ECQTrHcpKjsMMwA_UG8,4320
|
4
|
+
alonso/applogger.py,sha256=fQBo51-TboX1DBqfSxX2P2eKJ5CcyiCq_IVlJTHjxAE,2624
|
5
|
+
alonso/batch.py,sha256=iqtaxKH2ARcLZsV_i6CpwvxPGYHY3vk0dBJiafuMEkU,2305
|
6
|
+
alonso/merge.py,sha256=dWhF9t_2bFp4HT1NCzjhrSlhm8CkJQ4pwBHOhHSkezQ,4257
|
7
|
+
alonso/parser.py,sha256=Ib4TnWdkQb6A6FA3HHEjZDBb7uD0v9Gabwewqfu4XpQ,2549
|
8
|
+
alonso/partition.py,sha256=a4JHiFsZ9MgFWWFLCvmh-k6EbDrMfJbXR_3Tb_IaPrQ,8511
|
9
|
+
alonso/stable.py,sha256=IwINwjd3F7dfoISXlWsNWRkVJzItEojgMyNwzMM7nYc,6577
|
10
|
+
alonso/test.py,sha256=UpeegxqezBU2-3zEMpwWTN9K27uBLroXyJpgeqfGBlo,5472
|
11
|
+
alonso/utils.py,sha256=RmctLB8oDtjf0wKcKFaRvXiRgmtegqfbB1HFFzlpsvE,7674
|
12
|
+
alonso-0.0.2.dist-info/licenses/LICENSE,sha256=nUDh1nfa7rfEv1HocpoqPu0JaFnZKpIVh9eM0MgozpM,1067
|
13
|
+
alonso-0.0.2.dist-info/METADATA,sha256=UxqElz-fH1bKVbUu4tRbQl4lv02Pkw1_2CqaEsr1p1E,9396
|
14
|
+
alonso-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
15
|
+
alonso-0.0.2.dist-info/entry_points.txt,sha256=JSod2CWtklhiaOFW3masqrgqhXIpVRsbIiprSmS1P7g,98
|
16
|
+
alonso-0.0.2.dist-info/top_level.txt,sha256=rOo7SlpYGdic6g55rHDus2d5N2t74H9qamX4yi6z5vw,7
|
17
|
+
alonso-0.0.2.dist-info/RECORD,,
|
alonso-0.0.1.dist-info/RECORD
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
alonso/__init__.py,sha256=vbC0ysStExEptYRA3SZVoBGFT7ysEDRPnZ9k9NqGMXI,188
|
2
|
-
alonso/algorithm.py,sha256=cVsyRQfEPOn-tHdxsTshBro6SjrJ3U0gxUIDROjlTEE,4748
|
3
|
-
alonso/app.py,sha256=0j1-pJgQfyoBwBz3AvwRa4iEW9PjTCD28QyX1rIvlKI,4320
|
4
|
-
alonso/applogger.py,sha256=fQBo51-TboX1DBqfSxX2P2eKJ5CcyiCq_IVlJTHjxAE,2624
|
5
|
-
alonso/batch.py,sha256=BlA4cs_OtmPXh1gmX4fI7Ye10Qtg9pbVgmv1CXW6nFQ,2305
|
6
|
-
alonso/merge.py,sha256=ObWIFqVhXycsjFk7pBqgxw55GrbgCysaGjjo1X58Yds,4209
|
7
|
-
alonso/parser.py,sha256=Ib4TnWdkQb6A6FA3HHEjZDBb7uD0v9Gabwewqfu4XpQ,2549
|
8
|
-
alonso/partition.py,sha256=7RgBCh6daLACnLuVYwvnIwtYARxTByUe_lIjdoDxpII,8515
|
9
|
-
alonso/stable.py,sha256=IwINwjd3F7dfoISXlWsNWRkVJzItEojgMyNwzMM7nYc,6577
|
10
|
-
alonso/test.py,sha256=8-860bd7cJCpx82T0FDbjesmzHxusi-YbhzOHK8mUyA,5472
|
11
|
-
alonso/utils.py,sha256=RmctLB8oDtjf0wKcKFaRvXiRgmtegqfbB1HFFzlpsvE,7674
|
12
|
-
alonso-0.0.1.dist-info/licenses/LICENSE,sha256=nUDh1nfa7rfEv1HocpoqPu0JaFnZKpIVh9eM0MgozpM,1067
|
13
|
-
alonso-0.0.1.dist-info/METADATA,sha256=cikJZVGVFrn2eIQWom1LEoOzx9Clzv1gGIiq_JSByjg,9396
|
14
|
-
alonso-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
15
|
-
alonso-0.0.1.dist-info/entry_points.txt,sha256=JSod2CWtklhiaOFW3masqrgqhXIpVRsbIiprSmS1P7g,98
|
16
|
-
alonso-0.0.1.dist-info/top_level.txt,sha256=rOo7SlpYGdic6g55rHDus2d5N2t74H9qamX4yi6z5vw,7
|
17
|
-
alonso-0.0.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|