static void Main(string[] args) { Tag[] input = new Tag[] { new Tag('a', 0, 1), new Tag('b', 0, 1), new Tag('c', 0, 2), new Tag('d', 1, 1), new Tag('e', 1, 2), new Tag('f', 1, 2), new Tag('g', 2, 2) }; List<List<Tag>> result = new List<List<Tag>>(); List<Tag> validSequence = null; GetLongestNonOverlappingIntervals(input, 0, result, ref validSequence); foreach( var output in result) { foreach(var output1 in output) { Console.WriteLine(output1.Name); } Console.WriteLine(); } }
static void GetLongestNonOverlappingIntervals(Tag[] input, int iter, List<List<Tag>> result, ref List<Tag> validSequence) { if (iter == input.Length) { result.Add(validSequence); validSequence = null; return; } else { for (int i = iter; i < input.Length; i++) { if (validSequence == null) { validSequence = new List<Tag>(); validSequence.Add(input[i]); } else { int start = input[i].Begin; int end = input[i].End; foreach (var tag in validSequence.ToList<Tag>()) { //Check if there is overlap if (start >= tag.Begin && end <= tag.End) { //there is an overlap } else if (start > tag.End) { //add this to the list of valid sequences validSequence.Add(input[i]); } } } GetLongestNonOverlappingIntervals(input, i + 1, result, ref validSequence); } } }
/// <summary> /// Deprecated Method for adding a new object to the Tag EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTag(Tag tag) { base.AddObject("Tag", tag); }
/// <summary> /// Create a new Tag object. /// </summary> /// <param name="tagID">Initial value of the TagID property.</param> public static Tag CreateTag(global::System.Int32 tagID) { Tag tag = new Tag(); tag.TagID = tagID; return tag; }