public SystemState(List <Comp> components) { if (components != null && components.Count != 0) { HealthState = new HealthStateVector(components); } }
public double FPCost(RepairAction repairAction, HealthStateVector HealthState) { double ans = 0; if (repairAction == null || repairAction.Count == 0 || HealthState == null || HealthState.Count == 0) { return(ans); } foreach (Comp c in repairAction.R) { ans += ((1 - HealthState.GetCompHealthState(c)) * c.Cost); } return(ans); }
private double calcFNCostRegular(RepairAction repairAction, HealthStateVector HealthState) { double FN = 0; double FFP = 0; if (HealthState == null || HealthState.Count == 0) { return(0); } for (int i = 0; i < HealthState.Count; i++) { Comp c = HealthState.Components[i]; double h = HealthState.CurrentHealthState[i]; if (h == 0) { continue; } if (!repairAction.Contains(c)) { FN += (h * Overhead); if (ffpType == FFPType.FFP) { FFP += ((1 - h) * (c.Cost)); } else if (ffpType == FFPType.FFPplusOverhead) { FFP += ((1 - h) * (c.Cost + Overhead)); } } } if (ffpType != FFPType.noFFP) { return(FN + FFP); } return(FN); }
public override DiagnosisSet FindDiagnoses(Observation observation) { if (function == null || observation == null || observation.TheModel == null || observation.TheModel.Components == null || observation.TheModel.Components.Count == 0) { return(null); //throw } //isProperSupersetOf this.observation = observation; DiagnosisSet diagnoses = new DiagnosisSet(); List <Comp> comps = new List <Comp>(observation.TheModel.Components); hSVector = new HealthStateVector(comps); notInDiag = new List <Gate>(); observation.TheModel.SetValue(observation.InputValues); FoundMinCard = false; FirstMinCard = new TimeSpan(); trie = new Trie <string>(); stopwatch.Start(); bool toContinue; foreach (Gate Component in observation.TheModel.Components) { if (closed.Contains(Component.Id)) { if (Component is Cone) { if (((Cone)Component).cone.Components.Count == 0) { continue; } else { toContinue = true; foreach (Gate g in ((Cone)Component).cone.Components) { if (!closed.Contains(g.Id)) { toContinue = false; break; } } if (toContinue) { continue; } } } else { continue; } } function.Operate(Component); if (isDamaged()) { List <Comp> diag = new List <Comp>(); diag.Add(Component); diagnoses.AddDiagnosis(new Diagnosis(diag)); if (diagnoses.Count == 1) { FirstMinCard = stopwatch.Elapsed; } trie.Put(Component.Id + "", Component.Id + ""); } else { notClosed.Add(Component); } Component.SetValue(); } notInDiag.AddRange(notClosed); int depth; toContinue = true; if (agenda == Agenda.HealthState && CheckHSDistance(1, 0.1, diagnoses)) { toContinue = false; } if (diagnoses.Count > 0) { FoundMinCard = true; if (agenda == Agenda.minCard) { toContinue = false; } } for (depth = 2; toContinue && depth <= notClosed.Count; depth++) { if (Stop()) { break; } if (diagnoses.Count > 0) { FoundMinCard = true; if (agenda == Agenda.minCard) { break; } } foreach (Gate g in notClosed) { if (Stop() || !toContinue) { break; } openList.Add(g); trie.Matcher.ResetMatch(); toContinue = deepCheck(depth, diagnoses); openList.Remove(g); } } notClosed.Clear(); openList.Clear(); stopwatch.Stop(); stopwatch.Reset(); return(diagnoses); }