public void MinimumNumberOfConfRoomsdoesntwork(List <Interval> meetings)
    {
        IntervalComparer ic = new IntervalComparer();

        meetings.Sort(ic);

        int maxOverlap = 1;

        int overlap = 0;

        for (int i = 0; i < meetings.Count - 1 && overlap + i < meetings.Count - 1; ++i)
        {
            int j = i + 1;

            Interval temp    = meetings[j];
            Interval present = meetings[i];
            overlap = 0;

            while (temp.Start < present.End && j < meetings.Count)
            {
                temp = meetings[j];
                overlap++;
                ++j;

                Console.WriteLine("in overlap");
            }
            if (overlap + 1 > maxOverlap)
            {
                maxOverlap = overlap + 1;
            }
        }
        Console.WriteLine(maxOverlap);
    }
Esempio n. 2
0
        public IList <Interval> Merge(IList <Interval> intervals)
        {
            var comparer = new IntervalComparer();
            var list     = intervals.ToList();

            list.Sort(comparer);

            var      result = new List <Interval>();
            Interval lastInterval;

            foreach (var interval in list)
            {
                lastInterval = result.LastOrDefault();
                if (lastInterval != null && lastInterval.end >= interval.start)
                {
                    if (lastInterval.end < interval.end)
                    {
                        lastInterval.end = interval.end;
                    }
                }
                else
                {
                    result.Add(interval);
                }
            }

            return(result);
        }
    public int MinNumberOfConfRooms(Interval[] intervals)
    {
        int length = intervals.Length;

        IntervalComparer c = new IntervalComparer();

        Array.Sort(intervals, c);

        List <Interval> minHeap = new List <Interval>();

        minHeap.Add(intervals[0]);

        for (int i = 1; i < length; i++)
        {
            minHeap.Sort((a, b) => a.End - b.End);

            if (intervals[i].Start >= minHeap[0].End)
            {
                Interval first = minHeap[0];
                minHeap.Remove(first);
            }
            minHeap.Add(intervals[i]);
        }

        Console.WriteLine("min number of conf rooms: " + minHeap.Count);

        return(minHeap.Count);
    }
Esempio n. 4
0
    /// <summary>
    /// Initializes a new instance of the <see cref="DenseNfa{TState, TSymbol}"/> class.
    /// </summary>
    /// <param name="stateComparer">The state comparer to use.</param>
    /// <param name="symbolIntervalComparer">The symbol interval comparer to use.</param>
    public DenseNfa(IEqualityComparer <TState> stateComparer, IntervalComparer <TSymbol> symbolIntervalComparer)
    {
        var(all, accepting, initial) = ObservableCollection <TState> .StateWithAcceptingAndInitial(() => new HashSet <TState>(stateComparer));

        this.allStates          = all;
        this.initialStates      = initial;
        this.acceptingStates    = accepting;
        this.alphabet           = new(new DenseSet <TSymbol>(symbolIntervalComparer));
        this.transitions        = new(stateComparer, symbolIntervalComparer);
        this.epsilonTransitions = new(stateComparer);

        this.allStates.Removed += (sender, item) =>
        {
            // Remove both ways from transitions
            this.transitions.TransitionMap.Remove(item);
            foreach (var map in this.transitions.TransitionMap.Values)
            {
                foreach (var toSet in map.Values)
                {
                    toSet.Remove(item);
                }
            }
            // Remove both ways from epsilon transitions
            this.epsilonTransitions.EpsilonTransitionMap.Remove(item);
            foreach (var toSet in this.epsilonTransitions.EpsilonTransitionMap.Values)
            {
                toSet.Remove(item);
            }
        };
        this.allStates.Cleared += (sender, eventArgs) =>
        {
            this.transitions.Clear();
            this.epsilonTransitions.Clear();
        };

        this.transitions.Added += (sender, item) =>
        {
            this.alphabet.Add(item.Symbol);
            this.allStates.Add(item.Source);
            this.allStates.Add(item.Destination);
        };

        this.epsilonTransitions.Added += (sender, item) =>
        {
            this.allStates.Add(item.Source);
            this.allStates.Add(item.Destination);
        };

        this.alphabet.Removed += (sender, item) =>
        {
            foreach (var onMap in this.transitions.TransitionMap.Values)
            {
                onMap.Remove(item);
            }
        };
        this.alphabet.Cleared += (sender, eventArgs) => this.transitions.Clear();
    }
        /// <summary>
        /// writes the annotations to the current database file
        /// </summary>
        public void Write(TranscriptCacheData cacheData)
        {
            _blockStream.WriteHeader(_header.Write);

            WriteItems(_writer, cacheData.Genes, x => x.Write(_writer));
            WriteItems(_writer, cacheData.TranscriptRegions, x => x.Write(_writer));
            WriteItems(_writer, cacheData.Mirnas, x => x.Write(_writer));
            WriteItems(_writer, cacheData.PeptideSeqs, x => _writer.WriteOptAscii(x));

            var geneComparer             = new GeneComparer();
            var transcriptRegionComparer = new TranscriptRegionComparer();
            var intervalComparer         = new IntervalComparer();

            var geneIndices             = CreateIndex(cacheData.Genes, geneComparer);
            var transcriptRegionIndices = CreateIndex(cacheData.TranscriptRegions, transcriptRegionComparer);
            var microRnaIndices         = CreateIndex(cacheData.Mirnas, intervalComparer);
            var peptideIndices          = CreateIndex(cacheData.PeptideSeqs, EqualityComparer <string> .Default);

            WriteIntervals(_writer, cacheData.RegulatoryRegionIntervalArrays, x => x.Write(_writer));
            WriteIntervals(_writer, cacheData.TranscriptIntervalArrays, x => x.Write(_writer, geneIndices, transcriptRegionIndices, microRnaIndices, peptideIndices));
        }
        private static (IGene[] Genes, ITranscriptRegion[] TranscriptRegions, IInterval[] Mirnas, string[] PeptideSeqs) GetUniqueData(
            IEnumerable <IntervalArray <ITranscript> > intervalArrays)
        {
            var intervalComparer         = new IntervalComparer();
            var transcriptRegionComparer = new TranscriptRegionComparer();
            var geneComparer             = new GeneComparer();

            var geneSet             = new HashSet <IGene>(geneComparer);
            var transcriptRegionSet = new HashSet <ITranscriptRegion>(transcriptRegionComparer);
            var mirnaSet            = new HashSet <IInterval>(intervalComparer);
            var peptideSet          = new HashSet <string>();

            foreach (var intervalArray in intervalArrays)
            {
                if (intervalArray == null)
                {
                    continue;
                }

                foreach (var interval in intervalArray.Array)
                {
                    var transcript = interval.Value;
                    geneSet.Add(transcript.Gene);
                    AddString(peptideSet, transcript.Translation?.PeptideSeq);
                    AddTranscriptRegions(transcriptRegionSet, transcript.TranscriptRegions);
                    AddIntervals(mirnaSet, transcript.MicroRnas);
                }
            }

            var genes             = GetUniqueGenes(geneSet);
            var transcriptRegions = GetUniqueTranscriptRegions(transcriptRegionSet);
            var mirnas            = GetUniqueIntervals(mirnaSet);
            var peptideSeqs       = GetUniqueStrings(peptideSet);

            return(genes, transcriptRegions, mirnas, peptideSeqs);
        }
Esempio n. 7
0
 public TransitionCollection(IEqualityComparer <TState> stateComparer, IntervalComparer <TSymbol> symbolComparer)
 {
     this.TransitionMap          = new(stateComparer);
     this.StateComparer          = stateComparer;
     this.SymbolIntervalComparer = symbolComparer;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DenseSet{T}"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use.</param>
 public DenseSet(IntervalComparer <T> comparer)
 {
     this.intervals = new(comparer, iv => iv, (o, n) => n);
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DenseMap{TKey, TValue}"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use.</param>
 public DenseMap(IntervalComparer <TKey> comparer)
     : this(comparer, Combiner <TValue> .Default)
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DenseMap{TKey, TValue}"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use.</param>
 /// <param name="combiner">The combiner to use.</param>
 public DenseMap(IntervalComparer <TKey> comparer, ICombiner <TValue> combiner)
 {
     this.Combiner  = combiner;
     this.intervals = new(comparer, kv => kv.Key, (kv, newIv) => new(newIv, kv.Value));
 }