Exemplo n.º 1
0
        //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();
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private List <TruthtableRow> getSimpleTableRec(List <TruthtableRowArgument> argList, int argIndex)
        {
            if (argumentsChar.Count <= argIndex)
            {
                return(new List <TruthtableRow>());
            }

            List <TruthtableRow>  acceptedRows = new List <TruthtableRow>(); //Rows to send back
            List <TruthtableRow>  receivedRows;                              //Memory spot for receiving recursive rows
            TruthtableRowArgument temporaryRowArg;
            char result;

            bool divisionSucces; //argList has been enough divided

            //check argument == *
            temporaryRowArg = new TruthtableRowArgument(argumentsChar[argIndex], '*');
            argList.Add(temporaryRowArg);
            result = getSimpleCharResult(argList);
            if (result == '*') //Not yet divided enough for simple table row
            {
                divisionSucces = false;
                receivedRows   = getSimpleTableRec(argList, argIndex + 1);
                foreach (TruthtableRow r in receivedRows)
                {
                    acceptedRows.Add(r);
                }
            }
            else //Divided enough for simple table row
            {
                //Create other arguments
                divisionSucces = true;
                List <TruthtableRowArgument> rowArgs = new List <TruthtableRowArgument>();
                for (int i = 0; i < argumentsChar.Count; i++)
                {
                    if (i < argList.Count)
                    {
                        rowArgs.Add(argList[i]);
                    }
                    else
                    {
                        rowArgs.Add(new TruthtableRowArgument(argumentsChar[i], '*'));
                    }
                }
                //Create row and add it
                acceptedRows.Add(new TruthtableRow(rowArgs, result));
            }
            argList.Remove(temporaryRowArg);

            if (!divisionSucces)
            {
                List <TruthtableRow> trueAndFalseRows = new List <TruthtableRow>();
                List <char>          trueAndFalse     = new List <char>()
                {
                    '0', '1'
                };

                foreach (char value in trueAndFalse) //will check for argument = 0 and argument = 1
                {
                    temporaryRowArg = new TruthtableRowArgument(argumentsChar[argIndex], value);
                    argList.Add(temporaryRowArg);
                    result = getSimpleCharResult(argList);
                    if (result == '*') //Not yet divided enough for simple table row
                    {
                        receivedRows = getSimpleTableRec(argList, argIndex + 1);
                        foreach (TruthtableRow rr in receivedRows)
                        {
                            bool addIt = true;
                            foreach (TruthtableRow ar in acceptedRows)
                            {
                                if (rr.isPartOfRow(ar))
                                {
                                    addIt = false;
                                    break;
                                }
                                //if (ar.RowValue == rr.RowValue)
                                //{
                                //    bool foundDifference = false;
                                //    for (int i = argIndex + 1; i < argumentsChar.Count; i++)
                                //    {
                                //        if (ar.GetValueForArgument(argumentsChar[i]) != '*')
                                //        {
                                //            if (rr.GetValueForArgument(argumentsChar[i]) != ar.GetValueForArgument(argumentsChar[i]))
                                //            {
                                //                //Difference found! Check next AR with RR
                                //                foundDifference = true;
                                //                break;
                                //            }
                                //        }
                                //    }
                                //    if (!foundDifference) //it is the same or part of AR, thus do not add it!
                                //    {
                                //        addIt = false;
                                //        break;
                                //    }
                                //}
                            }
                            if (addIt)
                            {
                                trueAndFalseRows.Add(rr);
                            }
                        }
                    }
                    else //Divided enough for simple table row
                    {
                        //Create other arguments
                        List <TruthtableRowArgument> rowArgs = new List <TruthtableRowArgument>();
                        for (int i = 0; i < argumentsChar.Count; i++)
                        {
                            if (i < argList.Count)
                            {
                                rowArgs.Add(argList[i]);
                            }
                            else
                            {
                                rowArgs.Add(new TruthtableRowArgument(argumentsChar[i], '*'));
                            }
                        }
                        //Create row and add it
                        acceptedRows.Add(new TruthtableRow(rowArgs, result));
                    }
                    argList.Remove(temporaryRowArg);
                }
                foreach (TruthtableRow r in trueAndFalseRows)
                {
                    acceptedRows.Add(r);
                }
            }
            return(acceptedRows);
        }