//CHECKS IF THIS ROW IS A SUBSET OF THE GIVEN MAIN public bool isPartOfRow(TruthtableRow main) { if (main.arguments.Count != this.arguments.Count) { throw new Exception("Rows cannot be compared!"); } bool isPart = true; if (main.RowValue != this.RowValue) { return(false); } for (int i = 0; i < main.Arguments.Count; i++) { if (main.Arguments[i].Argument == this.arguments[i].Argument) //same argument { if (main.Arguments[i].Value != '*') //main arg is 1 or 0, thus this arg should be the same as main arg { if (main.Arguments[i].Value != this.arguments[i].Value) { isPart = false; break; } } } else { throw new Exception("Rows cannot be compared!"); } } return(isPart); }
public override bool GetAnswer(TruthtableRow row) { bool leftAnswer = con1.GetAnswer(row); bool rightAnswer = con2.GetAnswer(row); if (leftAnswer || rightAnswer) { return(true); } return(false); }
//CREATE TRUTHTABLE ROWS WITH ROW VALUES private void createTruthtableRows() { if (argumentsChar != null) { if (argumentsChar.Count > 0) { //calculting row true/false swap time (when to print true and when to print false) List <int> rowLenght = new List <int>(); for (int i = argumentsChar.Count - 1; i >= 0; i--) { rowLenght.Add((int)Math.Pow(2, i)); } //creating all rows TruthtableRow tempRow; TruthtableRowArgument tempArg; TruthtableRowArgument[] args = new TruthtableRowArgument[argumentsChar.Count]; for (int i = rowLenght[0] * 2 - 1; i >= 0; i--) //going to next row { for (int j = 0; j < argumentsChar.Count; j++) //creating one row { int cal = i / rowLenght[j]; if (cal % 2 == 0) { tempArg = new TruthtableRowArgument(argumentsChar[j], '1'); } else { tempArg = new TruthtableRowArgument(argumentsChar[j], '0'); } args[j] = tempArg; } tempRow = new TruthtableRow(args.ToList()); rows.Add(tempRow); } } else //Only 1 and/or 0 arguments { rows.Add(new TruthtableRow(new List <TruthtableRowArgument>())); } } else { throw new NullReferenceException(); } }
//CREATE SIMPLE TABLE WITH ROW VALUES public List <TruthtableRow> GetSimpleTable() { if (argumentsChar.Count == 0) //only 0 and/or 1 arguments { List <TruthtableRow> tempList = new List <TruthtableRow>(); TruthtableRow tempRow = new TruthtableRow(new List <TruthtableRowArgument>()); bool rowValue = conHolder.GetTruthtableRowAnswer(tempRow); if (rowValue) { tempRow.RowValue = '1'; } else { tempRow.RowValue = '0'; } tempList.Add(tempRow); return(tempList); } return(getSimpleTableRec(new List <TruthtableRowArgument>(), 0)); }
public override bool GetAnswer(TruthtableRow row) { if (argument == '1') { return(true); } else if (argument == '0') { return(false); } else if (row.GetValueForArgument(argument) == '1') { return(true); } else if (row.GetValueForArgument(argument) == '0') { return(false); } else { throw new Exception("Encountered invalid symbol value for argument " + argument); } }
public abstract bool GetAnswer(TruthtableRow row);
//GET TRUTHTABLE ROW VALUE public bool GetTruthtableRowAnswer(TruthtableRow row) { return(startConnective.GetAnswer(row)); }
//public override Connective Copy() //{ // throw new NotImplementedException(); //} public override bool GetAnswer(TruthtableRow row) { throw new NotImplementedException(); }
private static List <TruthtableRow> getSubrowsOfMainRowRec(TruthtableRow main, int argIndex) { if (argIndex == main.Arguments.Count) { return(new List <TruthtableRow>() { main }); } List <TruthtableRow> subsets = new List <TruthtableRow>(); if (main.Arguments[argIndex].Value == '*') { //copy Main and adjust it List <TruthtableRowArgument> newMainArguments = new List <TruthtableRowArgument>(); for (int i = 0; i < main.Arguments.Count; i++) //copy arguments, but change current argument (on index) { if (i == argIndex) { newMainArguments.Add(new TruthtableRowArgument(main.Arguments[i].Argument, '1')); } else { newMainArguments.Add(main.Arguments[i]); } } TruthtableRow newMain = new TruthtableRow(newMainArguments); newMain.RowValue = main.RowValue; //get subRows if current arg == '1' foreach (TruthtableRow r in getSubrowsOfMainRowRec(newMain, argIndex + 1)) { subsets.Add(r); } TruthtableRowArgument[] newMainArguments2 = new TruthtableRowArgument[newMainArguments.Count]; newMainArguments.CopyTo(newMainArguments2); newMainArguments2[argIndex] = new TruthtableRowArgument(main.Arguments[argIndex].Argument, '0'); TruthtableRow newMain2 = new TruthtableRow(newMainArguments2.ToList()); newMain2.RowValue = main.RowValue; //get subRows if current arg == '0' foreach (TruthtableRow r in getSubrowsOfMainRowRec(newMain2, argIndex + 1)) { subsets.Add(r); } } else if (main.Arguments[argIndex].Value == '1') { foreach (TruthtableRow r in getSubrowsOfMainRowRec(main, argIndex + 1)) { subsets.Add(r); } } else if (main.Arguments[argIndex].Value == '0') { foreach (TruthtableRow r in getSubrowsOfMainRowRec(main, argIndex + 1)) { subsets.Add(r); } } else { throw new Exception("Unknown char"); } return(subsets); }
//GIVE SIMPLE TRUTHTABLEROW (WITH * ARGUMENT VALUES) AND GET ALL NON SIMPLE TRUTHTABLE ROWS RETURNED (NO * ARGUMENT VALUES) public static List <TruthtableRow> GetSubrowsOfMainRow(TruthtableRow main) { return(getSubrowsOfMainRowRec(main, 0)); }