public void RunISCASRepairAlgorithm(string filesPath, BatchPlanner planner, double overhead, int maxDiag, string system)
        {
            string    fileModel = filesPath + "systems/" + system + ".txt";
            string    fileObs   = filesPath + "observations/" + system + "_iscas85.obs";
            string    fileReal  = filesPath + "real/" + system + "_minCard_Real.txt";
            string    diagPath  = filesPath + "groundedDiagnoses/";
            Simulator sim       = new Simulator();

            sim.BatchRepair(diagPath, fileModel, fileObs, fileReal, planner, overhead, true, maxDiag);
        }
        public void RunRepairAlgorithmPhysio(string filesPath, BatchPlanner planner, double overhead, int maxDiag)
        {
            PhysiotherapySimulator sim = new PhysiotherapySimulator();

            sim.BatchRepair(filesPath, planner, overhead, maxDiag);
        }
Esempio n. 3
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");
        }