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 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
- # Partition edges into two subsets (E1, E2) using the Burr-Erdős-Lovász (1976) algorithm
45
- # This step divides the graph into two claw-free subgraphs
46
- # Complexity: O(m * (m * Δ * C + C^2)), where m is edges, Δ is maximum degree, C is number of claws
47
- E1, E2 = partition.partition_edges_claw_free(working_graph)
48
-
49
- # Compute minimum vertex cover for E1 using the Faenza, Oriolo & Stauffer (2011) algorithm
50
- # This finds the maximum weighted stable set in the claw-free graph E1, whose complement is the vertex cover
51
- # Complexity: O(n^3), where n is the number of nodes in the subgraph induced by E1
52
- vertex_cover_1 = stable.minimum_vertex_cover_claw_free(E1)
53
-
54
- # Compute minimum vertex cover for E2 using the same Faenza, Oriolo & Stauffer (2011) algorithm
55
- # Complexity: O(n^3) for the subgraph induced by E2
56
- vertex_cover_2 = stable.minimum_vertex_cover_claw_free(E2)
57
-
58
- # Merge the two vertex covers from E1 and E2 to approximate the minimum vertex cover of the original graph
59
- approximate_vertex_cover = merge.merge_vertex_covers(E1, E2, vertex_cover_1, vertex_cover_2)
60
-
61
- # Create a residual graph containing edges not covered by the current vertex cover
62
- residual_graph = nx.Graph()
63
- for u, v in working_graph.edges():
64
- if u not in approximate_vertex_cover and v not in approximate_vertex_cover:
65
- residual_graph.add_edge(u, v) # Add edge if neither endpoint is in the cover
66
-
67
- # Recursively find vertex cover for the residual graph to handle uncovered edges
68
- residual_vertex_cover = find_vertex_cover(residual_graph)
69
-
70
- # Combine the approximate vertex cover with the residual cover to ensure all edges are covered
71
- return approximate_vertex_cover.union(residual_vertex_cover)
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.1')
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.1')
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(E1, E2, vertex_cover_1, vertex_cover_2):
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 = E1.union(E2)
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 claws
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 = claws.find_claw_coordinates(G, first_claw=True)
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 = claws.find_claw_coordinates(G, first_claw=False)
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 = claws.find_claw_coordinates(G, first_claw=False)
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.1')
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alonso
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Compute an Approximate Vertex Cover for undirected graph encoded in DIMACS format.
5
5
  Home-page: https://github.com/frankvegadelgado/alonso
6
6
  Author: Frank Vega
@@ -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,,
@@ -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