1
2
3
4 package unbbayes.prs.bn;
5
6 import java.util.ResourceBundle;
7
8 import unbbayes.prs.Graph;
9 import unbbayes.util.extension.bn.inference.IInferenceAlgorithm;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class JunctionTreeAlgorithm implements IInferenceAlgorithm {
23
24 private ProbabilisticNetwork net;
25
26
27
28 private static ResourceBundle utilResource = unbbayes.util.ResourceController.newInstance().getBundle(
29 unbbayes.util.resources.UtilResources.class.getName());
30
31
32
33 protected static ResourceBundle resource = unbbayes.util.ResourceController.newInstance().getBundle(
34 unbbayes.prs.bn.resources.BnResources.class.getName());
35
36
37
38
39
40 public JunctionTreeAlgorithm() {
41 super();
42 }
43
44
45
46
47 public String getDescription() {
48 return this.utilResource.getString("junctionTreeAlgorithmDescription");
49 }
50
51
52
53
54 public String getName() {
55 return this.utilResource.getString("junctionTreeAlgorithmName");
56 }
57
58
59
60
61 public void run() throws IllegalStateException {
62 if (this.getNet() == null
63 || this.getNet().getNodes().size() == 0) {
64 throw new IllegalStateException(resource.getString("EmptyNetException"));
65 }
66 try {
67
68 this.getNet().compile();
69 } catch (Exception e) {
70 throw new IllegalStateException(e);
71 }
72 }
73
74
75
76
77
78
79
80 public void setNetwork(Graph g) throws IllegalArgumentException {
81 this.setNet((ProbabilisticNetwork)g);
82 }
83
84
85
86
87
88 public Graph getNetwork() {
89 return this.getNet();
90 }
91
92
93
94
95 public ProbabilisticNetwork getNet() {
96 return net;
97 }
98
99
100
101
102 public void setNet(ProbabilisticNetwork net) {
103 this.net = net;
104 }
105
106
107
108
109
110 public void reset() {
111 try {
112 this.getNet().initialize();
113 } catch (Exception e) {
114 throw new IllegalStateException(e);
115 }
116 }
117
118
119
120
121 public void propagate() {
122 try {
123 this.getNet().updateEvidences();
124 } catch (Exception e) {
125 throw new RuntimeException(e);
126 }
127 }
128
129
130
131 }