Пример #1
0
        public void CheckPropogation(string fileName1, string fileName2)
        {
            List <Observation> observationsList = MOCreator.ReadObsModelFiles(fileName1, fileName2);

            if (observationsList == null || observationsList.Count == 0)
            {
                return;
            }
            Stopwatch   stopwtch = new Stopwatch();
            Observation obs      = observationsList[1];

            stopwtch.Start();
            obs.TheModel.SetValue(obs.InputValues);
            stopwtch.Stop();
            TimeSpan time1 = stopwtch.Elapsed;

            stopwtch.Restart();
            obs.SetWiresToCorrectValue();
            stopwtch.Stop();
            TimeSpan     time2 = stopwtch.Elapsed;
            StreamWriter sw    = new StreamWriter(obs.TheModel.Id + "proptime.txt");

            sw.Write(time1 + " " + time2);
            sw.Close();
        }
Пример #2
0
        private DiagnosisSet abstractDiagGrounding(Observation observation, DiagnosisSet abstractDiag)
        {
            int          count = 0;
            Observation  obs;
            DiagnosisSet diagnoses = new DiagnosisSet();
            Dictionary <int, DiagnosisSet> coneDiagDic = new Dictionary <int, DiagnosisSet>();
            List <List <Gate> >            tempDiag    = new List <List <Gate> >();
            List <List <Gate> >            temp        = new List <List <Gate> >();

            foreach (Diagnosis diag in abstractDiag.Diagnoses)
            {
                List <Gate> openList = diag.TheDiagnosis;
                // observation.TheModel.SetValue(observation.InputValues);
                observation.SetWiresToCorrectValue();
                if (openList.Count == 0)
                {
                    continue;
                }
                foreach (Cone c in openList)
                {
                    if (coneDiagDic.ContainsKey(c.Id))
                    {
                        continue;
                    }
                    count++;
                    bool[] obIn  = new bool[c.cone.Input.Count];
                    bool[] obOut = new bool[1];
                    for (int i = 0; i < obIn.Length; i++)
                    {
                        obIn[i] = c.cone.Input[i].Value;
                    }
                    obOut[0]     = !c.Output.Value;
                    obs          = new Observation(observation.Id + count, obIn, obOut);
                    obs.TheModel = c.cone;
                    coneDiagDic.Add(c.Id, searchAlgorithm.FindDiagnoses(obs));
                    c.Output.Value = obOut[0];
                }
                foreach (Cone c in openList) //X
                {
                    if (coneDiagDic[c.Id] == null || coneDiagDic[c.Id].Diagnoses.Count == 0)
                    {
                        continue;
                    }
                    if (tempDiag.Count == 0)
                    {
                        foreach (Diagnosis d in coneDiagDic[c.Id].Diagnoses)
                        {
                            tempDiag.Add(new List <Gate>(d.TheDiagnosis));
                        }
                        continue;
                    }
                    if (coneDiagDic[c.Id].Diagnoses.Count == 1)
                    {
                        for (int i = 0; i < tempDiag.Count; i++)
                        {
                            tempDiag[i].AddRange(new List <Gate>(coneDiagDic[c.Id].Diagnoses.First().TheDiagnosis));
                        }
                        continue;
                    }
                    temp.AddRange(tempDiag);
                    tempDiag.Clear();
                    foreach (Diagnosis d in coneDiagDic[c.Id].Diagnoses)
                    {
                        List <Gate> listD = d.TheDiagnosis;
                        foreach (List <Gate> listTemp in temp)
                        {
                            List <Gate> listTempD = new List <Gate>(listTemp);
                            listTempD.AddRange(new List <Gate>(listD));
                            tempDiag.Add(new List <Gate>(listTempD));
                            listTempD.Clear();
                        }
                    }
                    temp.Clear();
                }
                foreach (List <Gate> list in tempDiag)
                {
                    diagnoses.AddDiagnosis(new Diagnosis(list));
                }
                tempDiag.Clear();
            }
            return(diagnoses);
        }