1 | package tuffy.ground.partition; |
2 | |
3 | import tuffy.infer.MRF; |
4 | import tuffy.util.UIMan; |
5 | |
6 | /** |
7 | * A partition is a subgraph of an MRF component. |
8 | */ |
9 | public class Partition implements Comparable<Partition>{ |
10 | public int id; // ID of this partition |
11 | public int numAtoms = 0; |
12 | public int numIncidentClauses = 0; |
13 | public double ramSize = 0; |
14 | |
15 | public Component parentComponent = null; |
16 | |
17 | public MRF mrf = null; |
18 | |
19 | |
20 | public int compareTo(Partition c){ |
21 | double d = c.size() - size(); |
22 | return (int)(Math.signum(d)); |
23 | } |
24 | |
25 | /** |
26 | * Get the estimated RAM size of this partition. |
27 | */ |
28 | public double size(){ |
29 | return ramSize; |
30 | } |
31 | |
32 | /** |
33 | * Discard all data structures to facilitate GC. (Does it really work?) |
34 | */ |
35 | public void discard() { |
36 | if(mrf != null) mrf.discard(); |
37 | mrf = null; |
38 | } |
39 | |
40 | |
41 | /** |
42 | * Show basic stats about this partition. |
43 | */ |
44 | public void showStats(){ |
45 | String s = "[Partition #" + id + "]" + |
46 | "\tRAM = " + ramSize + |
47 | "\t#atoms = " + numAtoms + |
48 | "\t#incident_clauses = " + numIncidentClauses; |
49 | if(mrf != null){ |
50 | s += "\t#core_atoms = " + mrf.getCoreAtoms().size(); |
51 | s += "\t#core_clauses = " + mrf.clauses.size(); |
52 | } |
53 | UIMan.println(s); |
54 | } |
55 | |
56 | } |