示例#1
0
 public SystemState(List <Gate> components)
 {
     if (components != null && components.Count != 0)
     {
         HelthState = new HelthStateVector(components);
     }
 }
        public double WastedCost(List <Gate> repairAction, HelthStateVector helthState)
        {
            double ans = 0;

            if (repairAction == null || repairAction.Count == 0 || helthState == null || helthState.Count == 0)
            {
                return(ans);
            }
            foreach (Gate g in repairAction)
            {
                ans += ((1 - helthState.GetCompHealthState(g)) * g.Cost);
            }
            return(ans);
        }
        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
            }
            this.observation = observation;
            DiagnosisSet diagnoses = new DiagnosisSet();

            hSVector  = new HelthStateVector(observation.TheModel.Components);
            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 <Gate> diag = new List <Gate>();
                    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.helthState && CheckHSDistance(5, 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);
        }