allpy
view lib/graph.py @ 117:fd7371f14c6d
lib::graph -- improvement of code and fix of bug in add_node function
author | boris <bnagaev@gmail.com> |
---|---|
date | Sat, 23 Oct 2010 20:59:22 +0400 |
parents | 0ef1a722b738 |
children | dd9fa5a8dc5a |
line source
1 # -*- coding: utf-8 -*-
7 pass
12 """
13 Data:
14 nodes -- set of elements
15 lines -- {line: cost}.
16 line is frozenset([e1, e2])
17 cost is float in (0, 1] or 1 (if all lines are equal)
19 >>> g = Graph(set([1,2,3]), {frozenset([1,2]): 1})
20 >>> g.fast_cliques()
21 Fast algorithm started
22 [frozenset([1, 2]), frozenset([3])]
23 >>> g = Graph(set([1,2,3,4]), {frozenset([1,2]): 0.98, frozenset([1,3]): 0.98,
24 ... frozenset([2,3]): 0.1})
25 >>> g.fast_cliques()
26 Fast algorithm started
27 [frozenset([1, 2, 3]), frozenset([4])]
28 >>> g.bron_kerbosh()
29 Bron and Kerbosh algorithm started
30 [frozenset([1, 2, 3]), frozenset([4])]
31 """
41 @staticmethod
84 break
87 """
88 returns list of cliques
89 clique is frozenset
90 if timeout=-1, it means infinity
91 if timeout has happened, raises TimeoutError
93 lava flow
94 """
114 continue
116 # ?? used ???? ???????????????? ??????????????, ?????????????????????? ???? ?????????? ?????????????????? ???? candidates
117 # (?????? ???? used ???? ?????????????????? ???????? ???? ?? 1 ???? candidates)
123 break
132 continue
134 # ???????????????? ?????????????? v ???? candidates ?? ?????????????????? ???? ?? compsub
138 # ?????????????????? new_candidates ?? new_used, ???????????? ???? candidates ?? used ??????????????, ???? ?????????????????????? ?? v
139 # (???? ????????, ???????????????? ???????????? ?????????????????????? ?? v)
150 # ?????????????? v ???? candidates ?? ???????????????? ?? used
153 # ???????? new_candidates ?? new_used ??????????
155 # compsub ??? ??????????
159 # ?????????? ???????????????????? ???????????????? bron_kerbosh(new_candidates, new_used)
162 # TIMEOUT check start
166 # TIMEOUT check end
175 continue
177 # ?????????????? v ???? compsub
185 """
186 returns list of cliques
187 clique is frozenset
188 """
197 break
200 # drop nodes, while its is possible
205 break
214 # add nodes, while its is possible
223 break
235 """
236 returns length-sorted list of cliques
237 clique is frozenset
239 can change self!
241 try to execute bron_kerbosh
242 if it raises TimeoutError, executes fast_cliques
243 """