-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiag_network.h
199 lines (153 loc) · 5.82 KB
/
diag_network.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#ifndef DSL_DIAG_NETWORK_H
#define DSL_DIAG_NETWORK_H
// {{SMILE_PUBLIC_HEADER}}
#include "extradefinition.h"
#include <vector>
#include <algorithm>
class DSL_network;
class DSL_fastEntropyAssessor;
#define DSL_DIAG_DEFAULT (DSL_DIAG_INDEPENDENCE | DSL_DIAG_PURSUE_ATLEAST_ONE_COMB)
///////////////////////////////
// class DIAG_network
///////////////////////////////
struct DIAG_faultyState
{
int node;
int state;
//operators added by Denver 11-12-03 to allow sorting in STL:
DIAG_faultyState& operator=(const DIAG_faultyState& rhs)
{
if (this == &rhs) return (*this);
node = rhs.node; state=rhs.state;
return (*this);
}
bool operator<(const DIAG_faultyState& rhs) const
{
if (node == rhs.node)
return (state<rhs.state);
return (node<rhs.node);
}
bool operator==(const DIAG_faultyState& rhs) const
{
return (node==rhs.node && state==rhs.state);
}
};
struct DIAG_testInfo
{
int test;
double entropy;
double cost;
double strength;
};
struct DIAG_faultInfo
{
int nodeHandle;
int nodeState;
int faultHandle;
double posterior;
bool operator<(const DIAG_faultInfo& rhs) const
{
return (posterior>rhs.posterior);
}
};
class DIAG_network
{
public:
DIAG_network(void);
DIAG_network(const DIAG_network &other);
~DIAG_network();
int LinkToNetwork(DSL_network *thisNet);
DSL_network &GetNetwork(void) { return *theNet; }
void UpdateFaultBeliefs();
// loads [fileName] and collects network information. It
// is assumed that the model will not change after this
// method is called (i.e., we are in the troubleshooting
// phase, as opposed to the model-building phase).
int LoadModel(char *fileName);
// clears everything and leaves the network as
// if [LoadModel] has just been called...
int RestartDiagnosis(void);
// computes VOI for all the unperformed tests.
int ComputeTestStrengths(int flags = DSL_DIAG_DEFAULT);
bool IsDSepEnabled() const { return dsepEnabled; }
void EnableDSep(bool enable) { dsepEnabled = enable; }
bool AreQuickTestsEnabled() const { return quickTestsEnabled; }
void EnableQuickTests(bool enable) { quickTestsEnabled = enable; }
// returns the array of unperformed tests
DSL_intArray &GetUnperformedTests(void) { return unperformedTests; }
// returns the array of tests statistics. This array is paired with the
// one returned by [GetUnperformedTests]
std::vector<DIAG_testInfo> &GetTestStatistics(void) {return testStatistics; }
// returns the array of faults
const std::vector<DIAG_faultyState> &GetFaults(void) const { return faults; }
//
void CalculateRankedFaults(std::vector<DIAG_faultInfo> &here, double lower, double upper);
void CalculateRankedFaults(std::vector<DIAG_faultInfo> &here, bool ignoreEvidence = false);
// sets the ratio in [theNet] as a user-defined property
void SetEntropyCostRatio(double ratio, double maxRatio, DSL_network *onThisNet);
double GetEntropyCostRatio();
double GetMaxEntropyCostRatio();
// unloads the network, leaving everything as it was
// before [LoadModel] was called
int ClearModel(void);
int InstantiateObservation(int thisNode, int toThisOutcome);
int ReleaseObservation(int thisNode);
// sets [faultHandle] as the pursued fault
int SetPursuedFault(int faultHandle);
int GetPursuedFault(void);
// nescessary functions for working with int_Array
int SetPursuedFaults(const DSL_intArray & faultHandles);
int AddPursuedFault(int faultHandle);
int DeletePursuedFault(int faultHandle);
const DSL_intArray & GetPursuedFaults(void) { return pursuedFaults;}
// traverses the network and set to their default state all those
// nodes flagged as 'set to default'
void SetDefaultStates(void);
// returns the handle of the most likely fault (assummes
// the [theNet] is solved already). To solve the DSL_network
// you should call GetNetwork()->UpdateBeliefs();
int FindMostLikelyFault(void);
// helper function that should not be here but that it is so
// the bridge can be more easily implemented. I suggest this function
// is moved to some other level above here. Dani 29/8/2000
// This function will return [here] a list of handles according
// to the parameters. These handles could be observation handles (node
// handles in SMILE) or target handles (fault handles in DIAG_network)
// NOTE: it does NOT clear [here] before adding the new elements
int GetHandles(
DSL_extraDefinition::troubleType ofThisType,
bool getAll,
bool ranked,
bool mandatory,
bool setToDefault,
std::vector<int> &here);
public:
// BUT NOT NEEDED FOR THE BRIDGE/API
// traverses the network to find and store targets and unperformed tests
int CollectNetworkInfo(void);
// returns true if all mandatories are instantiated...
bool MandatoriesInstantiated(void);
// returns the handle of the fault [faultNode,faultState]
int FindFault(int faultNode, int faultState);
// set the network and recollect the network info
// this function avoid compilation but allows us to use diag info
void SetNetwork(DSL_network *thisNet);
private:
void operator=(const DIAG_network&); // never implemented
void CompileModel();
int Solve();
int SolveMultiple(int flags);
double GetFromProperty(const char *propertyName, double defaultValue);
void DoCalcRankedFaults(std::vector<DIAG_faultInfo> &here, double lower, double upper, bool openSet );
DSL_network *theNet;
DSL_fastEntropyAssessor *theAssessor;
// contains all ranked observations not observed yet
DSL_intArray unperformedTests;
// test results (paired with [unperformedTests])
std::vector<DIAG_testInfo> testStatistics;
std::vector<DIAG_faultyState> faults;
DSL_intArray pursuedFaults; // indexes in [faults]
bool dsepEnabled;
bool quickTestsEnabled;
};
#endif