예제 #1
0
        Coverage RemoveSubsets(Coverage groups)
        {
            var not_subsets = new Coverage();

            foreach (var candidate_subset in groups)
            {
                if (!groups.Any(candidate_superset => candidate_subset.IsProperSubsetOf(candidate_superset)))
                {
                    not_subsets.Add(candidate_subset);
                }
            }

            return(not_subsets);
        }
예제 #2
0
        public static string ToSOPExpression(this Coverage coverage)
        {
            var result = new StringBuilder();
            var groups = coverage.OrderBy(g => g.Count).ToList();

            for (int g = 0; g < groups.Count; g++)
            {
                result.Append(groups[g].ToMintermExpression());
                if (g != (groups.Count - 1))
                {
                    result.Append(" + ");
                }
            }

            return(result.ToString());
        }
예제 #3
0
        Coverage MergeGroups(Coverage groups)
        {
            var merged = new Coverage();

            foreach (var g1 in groups)
            {
                foreach (var g2 in groups)
                {
                    // Two groups can only merge if they are adjacent and disjoint
                    if (g1.Intersect(g2).Count() == 0 && AreGroupsAdjacent(g1, g2))
                    {
                        var new_group = new Group(g1.Union(g2));
                        merged.Add(new_group);
                    }
                }
            }

            return(new Coverage(groups.Union(merged)));
        }
예제 #4
0
        public HashSet <Coverage> Minimize()
        {
            var groups = new Coverage();

            // Generate initial groups (of cardinality 1)
            foreach (var one in on_set_binary)
            {
                groups.Add(new Group()
                {
                    one
                });
            }

            // onsider the don't cares as 'ones', but don't consider them essential
            foreach (var dc in dc_set_binary)
            {
                groups.Add(new Group()
                {
                    dc
                });
            }

            Coverage previous_groups = null;

            // Continue merging and optimizing until it's possible
            while (previous_groups == null || !groups.Equals(previous_groups))
            {
                previous_groups = groups; // Save the state before merging and optimizing

                // Merge groups of cardinality 'n' to create groups of double cardinality
                groups = MergeGroups(groups);
                // Clean up groups that are strict subsets of other groups
                groups = RemoveSubsets(groups);
            }

            // Detect essential groups
            groups = MarkEssential(groups);

            // Remove completely redundant groups, that is, groups that cover 'ones' (of the function) already covered by other ESSENTIAL groups
            groups = RemoveRedundant(groups);

            return(GetCoverages(groups));
        }
예제 #5
0
        bool IsValidCoverage(Coverage selected_groups, out Coverage coverage)
        {
            coverage = null;
            var on_set = new SortedSet <string>(on_set_binary);

            foreach (var g in selected_groups)
            {
                on_set.ExceptWith(g);
            }

            // A coverage is valid if and only if it covers all the 'ones' of the function
            if (on_set.Any())
            {
                return(false);
            }
            else
            {
                coverage = new Coverage(selected_groups)
                {
                    Cost = CoverageCost(selected_groups)
                };
                return(true);
            }
        }