private DiagnosisSet findAbstractDiag(Observation observation) { DiagnosisSet abstractDiag; if (observation.TheModel.cones.Count == 0) { observation.TheModel.createCones(); } List <Cone> cones = observation.TheModel.cones; SystemModel toTest = new SystemModel(observation.TheModel.Id, observation.TheModel.Input, observation.TheModel.Output); foreach (Cone c in cones) { toTest.AddComponent(c); } Observation obs = new Observation(observation.Id, observation.InputValues, observation.OutputValues); obs.TheModel = toTest; abstractDiag = searchAlgorithm.FindDiagnoses(obs); return(abstractDiag); }
public List<Observation> ReadObsModelFiles(string fileModel, string fileObs) //path? { //reading model file List<Observation> observationsList = new List<Observation>(); // if (observationsList.Count > 0) // observationsList.Clear(); FileStream fs = new FileStream(fileModel, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fs); string model_allText = reader.ReadToEnd(); fs.Close(); reader.Close(); fs = null; reader = null; char[] delrow = new char[2]; delrow[0] = '\n'; delrow[1] = '\r'; List<string> rows = model_allText.Split(delrow, StringSplitOptions.RemoveEmptyEntries).ToList(); if(rows==null || rows.Count<4) return null; // throw //build Model SystemModel theModel; string modelID = rows[0].Substring(0, rows[0].Length - 1); List<Wire> inputs = new List<Wire>(); List<Wire> outputs = new List<Wire>(); List<Wire> internalWires = new List<Wire>(); Dictionary<Wire.WireType, Dictionary<int, Wire>> wiresDictionary = new Dictionary<Wire.WireType, Dictionary<int, Wire>>(); wiresDictionary.Add(Wire.WireType.i, new Dictionary<int, Wire>()); wiresDictionary.Add(Wire.WireType.o, new Dictionary<int, Wire>()); wiresDictionary.Add(Wire.WireType.z, new Dictionary<int, Wire>()); //model id // if (!Int32.TryParse(rows[0].Substring(0, rows[0].Length - 1), out modelID)) // return; //throw char[] del = new char[6]; del[0]='.'; del[1]=','; del[2]='['; del[3]=']'; del[4]='('; del[5]=')'; //Wire.WiresDictionary = new Dictionary<string, Wire>(); //input & output string[] inputArr = rows[1].Split(del, StringSplitOptions.RemoveEmptyEntries); string[] outputArr = rows[2].Split(del, StringSplitOptions.RemoveEmptyEntries); for (int i=0; i < inputArr.Length; i++) { //need to check if the Value is Valid? 2<=len<=3, starts with i/o/z, end with a number //need to check if theres as similar wire exist string wireName = inputArr[i]; int wid; if(Int32.TryParse(wireName.Substring(1),out wid)) { if (wireName.StartsWith("i")) { Wire w = new Wire(wid, Wire.WireType.i); inputs.Add(w); wiresDictionary[Wire.WireType.i].Add(wid, w); } } //else -- } for (int j = 0; j < outputArr.Length; j++) { string wireName = outputArr[j]; int wid; if (Int32.TryParse(wireName.Substring(1), out wid)) { if (wireName.StartsWith("o")) { Wire w = new Wire(wid, Wire.WireType.o); outputs.Add(w); wiresDictionary[Wire.WireType.o].Add(wid, w); } } } theModel = new SystemModel(modelID, inputs, outputs); //creating components for (int i = 3; i < rows.Count; i++) { if (!String.IsNullOrEmpty(rows[i])) theModel.AddComponent(CreateComponent(rows[i].Split(del, StringSplitOptions.RemoveEmptyEntries),theModel,wiresDictionary)); } //sort model theModel.SortComponents(); //reading observation fila delrow = new char[1]; delrow[0] = '.'; del = new char[7]; del[0] = '\r'; del[1] = ','; del[2] = '['; del[3] = ']'; del[4] = '('; del[5] = ')'; del[6] = '\n'; rows = null; fs = new FileStream(fileObs, FileMode.Open, FileAccess.Read); reader = new StreamReader(fs); string ob_allText = reader.ReadToEnd(); rows = ob_allText.Split(delrow, StringSplitOptions.RemoveEmptyEntries).ToList(); fs.Close(); reader.Close(); fs = null; reader = null; if (rows == null || rows.Count == 0) return null; // throw //build observation // List<Observation> obList = new List<Observation>(); for (int i = 0; i < rows.Count; i++) { string[] obArr = rows[i].Split(del, StringSplitOptions.RemoveEmptyEntries); if (obArr == null || obArr.Length == 0&& i!=rows.Count-1) return null; //throw if (obArr.Length == 2 + inputs.Count + outputs.Count) { if (!obArr[0].Equals(modelID)) return null; //throw Observation toAdd = CreateObservation(obArr); if (toAdd != null) { toAdd.TheModel = theModel; //try catch observationsList.Add(toAdd); } } //else return/throw? } return observationsList; }