예제 #1
0
        public void HS(string fileName1, string fileName2)
        {
            List <Observation> observationsList = MOCreator.ReadObsModelFiles(fileName1, fileName2);

            if (observationsList == null || observationsList.Count == 0)
            {
                return;
            }
            FlipFunction       flip     = new FlipFunction();
            TimeSpan           x        = new TimeSpan(0, 5, 0);
            IterativeDeepening salgo    = new IterativeDeepening(flip, x);
            ConesAlgorithm     algo     = new ConesAlgorithm(salgo);
            Stopwatch          stopwtch = new Stopwatch();
            CSVExport          myExport = new CSVExport();

            salgo.agenda = DiagnosesSearcher.Agenda.helthState;
            foreach (Observation obs in observationsList)
            {
                stopwtch.Start();
                DiagnosisSet diagnoses = algo.FindDiagnoses(obs);
                stopwtch.Stop();
                if (diagnoses != null)
                {
                    myExport.AddRow();
                    myExport["System"]      = obs.TheModel.Id;
                    myExport["Observation"] = obs.Id;
                    myExport["# diagnoses"] = diagnoses.Count;
                    myExport["Runtime"]     = stopwtch.Elapsed;
                }
                stopwtch.Reset();
            }
            myExport.ExportToFile(observationsList.First().TheModel.Id + "HS.csv");
        }
예제 #2
0
        private void writeResultsFile(string mergedFileName)
        {
            if (ResultsRows == null || ResultsRows.Count == 0)
            {
                return;
            }
            CSVExport myExport = new CSVExport();

            foreach (ResultsRow row in ResultsRows)
            {
                myExport.AddRow();
                myExport["System"]             = row.System;
                myExport["Algorithm"]          = row.Algorithm;
                myExport["Bound"]              = row.Bound;
                myExport["Objective Function"] = row.ObjectiveFunction;
                myExport["Overhead"]           = row.Overhead;
                myExport["Observation"]        = row.Observation;
                myExport["# Diagnoses"]        = row.NumberOfDiagnoses;
                myExport["Runtime(ms)"]        = row.Runtime;
                myExport["# Iterations"]       = row.NumberOfIterations;
                myExport["Cost"] = row.Cost;
                myExport["# Fixed Components"]            = row.NumberOfFixedComponents;
                myExport["# Expanded In First Iteration"] = row.ExpandedInFirstIteraion;
                myExport["Found Opt"]           = row.FoundOpt;
                myExport["First Action Chosen"] = row.FirstActionChosen;
                myExport["WC First Action"]     = row.WCfirstAction;
            }
            myExport.ExportToFile(mergedFileName + ".csv");
        }
예제 #3
0
 public BatchPlanner()
 {
     totalStopWatch        = new Stopwatch();
     iteraionDetailsFilled = false;
     Timeout       = new TimeSpan(0, 5, 0);
     myExport      = new CSVExport();
     DiagCropLimit = 100;
     Bound         = -1;
     currentDepth  = 0;
 }
예제 #4
0
        public void CheckMinCard(string fileName1, string fileName2)
        {
            List <Observation> observationsList = MOCreator.ReadObsModelFiles(fileName1, fileName2);

            if (observationsList == null || observationsList.Count == 0)
            {
                return;
            }
            FlipFunction       flip     = new FlipFunction();
            TimeSpan           x        = new TimeSpan(0, 5, 0);
            IterativeDeepening salgo    = new IterativeDeepening(flip, x);
            ConesAlgorithm     algo     = new ConesAlgorithm(salgo);
            CSVExport          myExport = new CSVExport();

            foreach (Observation obs in observationsList)
            {
                algo.CheckMinCard(obs, myExport);
            }
            myExport.ExportToFile(observationsList.First().TheModel.Id + "MinCard.csv");
        }
예제 #5
0
        public void CheckMinCard(Observation observation, CSVExport myExport)
        {
            if (searchAlgorithm == null || observation == null || observation.TheModel == null || observation.TheModel.Components == null || observation.TheModel.Components.Count == 0)
            {
                return; //throw
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            DiagnosisSet diagnoses;
            DiagnosisSet abstractDiag;

            searchAlgorithm.agenda = DiagnosesSearcher.Agenda.minCard;
            abstractDiag           = findAbstractDiag(observation);
            string foundMC;

            if (searchAlgorithm.FoundMinCard)
            {
                foundMC = "yes";
            }
            else
            {
                foundMC = "No";
            }
            TimeSpan firstMC     = searchAlgorithm.FirstMinCard;
            TimeSpan absDiagtime = stopwatch.Elapsed;

            diagnoses = abstractDiagGrounding(observation, abstractDiag);
            stopwatch.Stop();
            TimeSpan alltime = stopwatch.Elapsed;

            myExport.AddRow();
            myExport["System"]                  = observation.TheModel.Id;
            myExport["Observation"]             = observation.Id;
            myExport["All MC found?"]           = foundMC;
            myExport["# abstract diagnoses"]    = abstractDiag.Count;
            myExport["# diagnoses"]             = diagnoses.Count;
            myExport["runtime until 1st found"] = firstMC;
            myExport["runtime abstract"]        = absDiagtime;
            myExport["runtime all"]             = alltime;
        }
예제 #6
0
        public void CalcProbabilityMass(string fileModel, string fileObs)
        {
            createNewDiagnoser();
            ConesAlgorithm         conesAlgo        = (ConesAlgorithm)Diagnoser;
            List <Observation>     observationsList = parser.ReadObsModelFiles(fileModel, fileObs);
            CSVExport              myExport         = new CSVExport();
            SystemModel            model            = observationsList[0].TheModel;
            Dictionary <int, Gate> compDic          = model.CreateCompDic();
            string diagnosesFilesPath   = "diagnoses/";
            string tldiagnosesFilesPath = "tldiagnoses/";

            model.createCones();
            Dictionary <int, Cone> conesDic = new Dictionary <int, Cone>();

            foreach (Cone c in model.Cones)
            {
                if (!conesDic.ContainsKey(c.Id))
                {
                    conesDic.Add(c.Id, c);
                }
            }
            foreach (Observation obs in observationsList)
            {
                string       diagFileName     = diagnosesFilesPath + model.Id + "_" + obs.Id + "_Diag.txt";
                DiagnosisSet allDiagnoses     = parser.ReadDiagnosisFile(diagFileName, compDic);
                string       tldFileName      = tldiagnosesFilesPath + model.Id + "_iscas85_" + obs.Id + ".tld"; //!!! txt?
                DiagnosisSet tlDiagnoses      = parser.ReadTLDiagnosisFile(tldFileName, conesDic);
                DiagnosisSet minCardDiagnoses = conesAlgo.AbstractDiagGrounding(obs, tlDiagnoses);
                myExport.AddRow();
                myExport["Observation"]                    = obs.Id;
                myExport["# all diagnoses"]                = allDiagnoses.Count;
                myExport["all diagnoses probability"]      = allDiagnoses.SetProbability;
                myExport["# min card diagnoses"]           = minCardDiagnoses.Count;
                myExport["min card diagnoses probability"] = minCardDiagnoses.SetProbability;
            }
            myExport.ExportToFile(model.Id + "_probabilityMass.csv");
        }
예제 #7
0
        public void BatchRepair(string diagPath, string fileModel, string fileObs, string fileReal, BatchPlanner planner, double overhead, bool minCard, int maxNumOfDiag) //do it more generic
        {
            bool findDiagnoses = false;                                                                                                                                    //

            List <Observation>            observationsList = parser.ReadObsModelFiles(fileModel, fileObs);
            Dictionary <int, List <int> > obsReal          = parser.ReadRealObsFiles(fileReal);

            if (observationsList == null || observationsList.Count == 0 || obsReal == null || obsReal.Count == 0)
            {
                return;
            }
            createNewDiagnoser();
            SystemModel            model   = observationsList[0].TheModel;
            Dictionary <int, Gate> compDic = model.CreateCompDic();
            Stopwatch stopwatch            = new Stopwatch();
            CSVExport myExport             = new CSVExport();

            foreach (Observation obs in observationsList)
            {
                if (!obsReal.ContainsKey(obs.Id))
                {
                    continue;
                }
                List <int> realComp      = new List <int>(obsReal[obs.Id]);
                int        counter       = 0;
                double     cost          = 0;
                int        numberOfFixed = 0;
                stopwatch.Start();
                DiagnosisSet diagnoses = null;

                if (findDiagnoses) //
                {
                    diagnoses = Diagnoser.FindDiagnoses(obs);
                }
                else
                {
                    if (minCard)
                    {
                        string diagFileName = diagPath + model.Id + "_iscas85_" + obs.Id + ".all";
                        diagnoses = parser.ReadGroundedDiagnosesFile(diagFileName, compDic);
                    }
                    else
                    {
                        string diagFileName = diagPath + model.Id + "_" + obs.Id + "_Diag.txt";
                        diagnoses = parser.ReadDiagnosisFile(diagFileName, compDic);
                    }
                }
                if (diagnoses.Count == 1)
                {
                    continue;
                }
                if (maxNumOfDiag > 0 && diagnoses.Count > maxNumOfDiag)
                {
                    continue;
                }
                SystemState state = new SystemState(new List <Comp>(model.Components));
                state.Diagnoses = diagnoses;

                while (realComp.Count != 0)
                {
                    if (state.Diagnoses != null && state.Diagnoses.Count != 0)
                    {
                        RepairAction repairAction = planner.Plan(state);
                        if (repairAction != null)
                        {
                            counter++;
                            cost += overhead;
                            state.SetNextState(repairAction);
                            foreach (Gate gate in repairAction.R)
                            {
                                cost += gate.Cost;
                                numberOfFixed++;
                                if (realComp.Contains(gate.Id))
                                {
                                    realComp.Remove(gate.Id);
                                }
                            }
                            obs.TheModel.SetValue(obs.InputValues);
                            if (realComp.Count == 0)//the system is fixed
                            {
                                planner.ExportIterationDetails(model.Id, obs.Id, counter, true);
                                break;
                            }
                            else
                            {
                                planner.ExportIterationDetails(model.Id, obs.Id, counter, false);
                            }
                            foreach (int gid in realComp)
                            {
                                Gate g;
                                if (compDic.TryGetValue(gid, out g))
                                {
                                    gateFunc.Operate(g);
                                }
                            }
                            obs.OutputValues = model.GetValue();
                            DiagnosisSet newDiagnoses = new DiagnosisSet();
                            foreach (Diagnosis diag in state.Diagnoses.Diagnoses)
                            {
                                if (Diagnoser.IsConsistent(obs, diag))
                                {
                                    newDiagnoses.AddDiagnosis(diag);
                                }
                            }
                            state.Diagnoses = newDiagnoses;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                stopwatch.Stop();
                if (realComp.Count > 0)
                {
                    continue;
                }

                TimeSpan time = stopwatch.Elapsed;
                stopwatch.Reset();
                myExport.AddRow();
                myExport["System"]    = model.Id;
                myExport["Algorithm"] = planner.Algorithm();
                if (planner.Bounded)
                {
                    myExport["Bound"] = planner.Bound;
                }
                else
                {
                    myExport["Bound"] = "No Bound";
                }
                myExport["Objective Function"] = planner.ObjectiveFunction();
                myExport["Overhead"]           = overhead;
                myExport["Observation"]        = obs.Id;
                myExport["# Diagnoses"]        = diagnoses.Count;
                myExport["Runtime"]            = time;
                myExport["# Iterations"]       = counter;
                myExport["Cost"] = cost;
                myExport["# Fixed Components"] = numberOfFixed;
            }
            string fileName = model.Id + "_" + planner.Type() + "_o=" + overhead;

            if (maxNumOfDiag > 0)
            {
                fileName += "_MaxDiag" + maxNumOfDiag;
            }
            myExport.ExportToFile(fileName + ".csv");
            planner.CreateIterationDetailsFile(fileName + "_IterationDetails");
        }
예제 #8
0
 public virtual void CreateIterationDetailsFile(string fileName)
 {
     myExport.ExportToFile(fileName + ".csv");
     myExport = new CSVExport();
 }