/// <summary> /// A DFS to find paths that return only original propositions from the test file /// </summary> /// <param name="value"></param> /// <returns></returns> public List <int> Chain(Proposition value) { List <int> result = new List <int>(); List <Proposition> temp; // Singualr Proposition if (value.Single) { if (IsOriginal(value)) { result = new List <int>(); result.Add(value.getA()); return(result); } else if ((temp = FindReferal(value)).Count != 0) { foreach (Proposition Refered in temp) { result = Chain(Refered); if (result.Count != 0) { result.Add(Refered.getB()); } } } else { return(new List <int>()); } } // Implication Proposition else if (value.Operation == Operations.Implication) { if (value.IsAref()) { result = Chain(value.getARef()); } else if (IsOriginal(value.getA())) { result = new List <int>(); result.Add(value.getA()); return(result); } else if ((temp = FindReferal(value.getA())).Count != 0) { foreach (Proposition Refered in temp) { result = Chain(Refered); if (result.Count != 0) { result.Add(Refered.getB()); } } return(result); } else { return(new List <int>()); } } // And Proposition else if (value.Operation == Operations.Conjunction) { List <int> MiniListA = new List <int>(); List <int> MiniListB = new List <int>(); // Find A referals // if a ref if (value.IsAref()) { MiniListA = Chain(value.getARef()); } // If A is a Singular Original else if (IsOriginal(value.getA())) { MiniListA = new List <int>(); MiniListA.Add(value.getA()); } // Else find referals of A else if ((temp = FindReferal(value.getA())).Count != 0) { foreach (Proposition Refered in temp) { MiniListA = Chain(Refered); if (MiniListA.Count() != 0) { MiniListA.Add(value.getA()); } } } // If no referals else { return(new List <int>()); } // Find B referals // If b ref if (value.IsBref()) { MiniListB = Chain(value.getBRef()); } // If B is a Singular Original else if (IsOriginal(value.getB())) { MiniListB = new List <int>(); MiniListB.Add(value.getB()); } // else find referals else if ((temp = FindReferal(value.getB())).Count != 0) { foreach (Proposition Refered in temp) { MiniListB = Chain(Refered); if (MiniListB.Count() != 0) { MiniListB.Add(value.getB()); } } } // If no referals else { return(new List <int>()); } // If nether null then add together and return if ((MiniListA.Count() == 0) || (MiniListB.Count() == 0)) { return(new List <int>()); } result = new List <int>(); result.AddRange(MiniListA); result.AddRange(MiniListB); return(result); } // OR Proposition else if (value.Operation == Operations.Disjunction) { List <int> MiniListA = new List <int>(); List <int> MiniListB = new List <int>(); // Find referals of A // If A ref if (value.IsAref()) { MiniListA = Chain(value.getARef()); } // If A is a Singular Original else if (IsOriginal(value.getA())) { MiniListA = new List <int>(); MiniListA.Add(value.getA()); } // Else find referals else if ((temp = FindReferal(value.getA())).Count != 0) { foreach (Proposition Refered in temp) { MiniListA = Chain(Refered); if (MiniListA.Count() != 0) { MiniListA.Add(value.getA()); } } } //Find referals of B // If B ref if (MiniListA.Count() == 0) { if (value.IsBref()) { MiniListB = Chain(value.getBRef()); } // If B is a Singular Original else if (IsOriginal(value.getB())) { MiniListB = new List <int>(); MiniListB.Add(value.getB()); } // Else find referals else if ((temp = FindReferal(value.getB())).Count != 0) { foreach (Proposition Refered in temp) { MiniListB = Chain(Refered); if (MiniListB.Count() != 0) { MiniListB.Add(value.getB()); } } } } // If both empty, return empty if (MiniListA.Count == 0 && MiniListB.Count == 0) { return(new List <int>()); } //else add together and return result = new List <int>(); result.AddRange(MiniListA); result.AddRange(MiniListB); return(result); } // Finally return the result return(result); }