예제 #1
0
        public string BuildPDNF()
        {
            if (_truthTable.Count == 1 && _truthTable[0].Key == string.Empty)
            {
                return(null);
            }

            var result = new StringBuilder();

            foreach (var item in _truthTable)
            {
                if (item.Value != 1)
                {
                    continue;
                }
                var listForEvent = new List <string>();
                result.Append('(');

                var i = 0;
                foreach (var let in _listVariables)
                {
                    if (item.Key[i] == '1')
                    {
                        result.Append(@let.Key + " & ");
                        listForEvent.Add(@let.Key.ToString());
                    }
                    else
                    {
                        result.Append("!" + @let.Key + " & ");
                        listForEvent.Add("!" + @let.Key.ToString());
                    }
                    i++;
                }
                result.Remove(result.Length - 3, 3);
                result.Append(") | ");


                var args = new BuildNormalFormEventArgs(listForEvent);
                EventBuildDisjoint?.Invoke(this, args);
            }

            if (result.Length == 0)
            {
                return(null);
            }

            result.Remove(result.Length - 3, 3);

            return(result.ToString());
        }