当前位置: 首页>>代码示例>>C#>>正文


C# SortedSet.Last方法代码示例

本文整理汇总了C#中SortedSet.Last方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Last方法的具体用法?C# SortedSet.Last怎么用?C# SortedSet.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedSet的用法示例。


在下文中一共展示了SortedSet.Last方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SelectParent

 private static Chromosome SelectParent(SortedSet<Chromosome> tournament, double sumFitness, Random random)
 {
     UniformDistribution uniform = new UniformDistribution(Interval.FromEndpoints(0, 1));
     double randomNumber = uniform.GetRandomValue(random);
     double sumLength = 0;
     foreach (var chromosome in tournament)
     {
         sumLength += chromosome.Fitness / sumFitness;
         if (randomNumber < sumLength)
             return chromosome;
     }
     return tournament.Last();
 }
开发者ID:MislavMandaric,项目名称:genetic-neural-network,代码行数:13,代码来源:Selection.cs

示例2: Main

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[][] field = new int[N][];
        bool[][] used = new bool[N][];

        field = ReadInputData(field);
        used = FillUsedCells(field, used);

        SortedSet<long> specialValues = new SortedSet<long>();
        for (int col = 0; col < field[0].Length; col++)
        {
            long specialValue = GetSpecialValues(field, col, used);
            specialValues.Add(specialValue);
        }

        Console.WriteLine(specialValues.Last());
    }
开发者ID:VictorGeorgiev,项目名称:Telerik-Software-Academy,代码行数:18,代码来源:SpecialValue.cs

示例3: Apply

        public IEnumerable<Violation> Apply(TestCase testCase)
        {
            if (!testCase.TestMethod.DeclaringType.Module.HasSymbols)
                yield break; //TODO: decide what to do here!

            var assertingMethods = testCase.GetCalledAssertingMethods();

            // Note: The Mono compiler appears to emit multiple sequence points with the same start line,
            // i.e. there are multiple instructions with sequence points that refer to the same line.
            // Therefore, let's store line numbers and associate line numbers with asserting calls.

            var sequencePointsStartLines = new SortedSet<int>();
            var assertingSequencePointsStartLines = new SortedSet<int>();

            var tm = testCase.TestMethod;
            foreach (var ins in tm.Body.Instructions)
            {
                var sp = ins.SequencePoint;
                if (sp != null && IsSignificantSequencePoint(ins, sp))
                {
                    sequencePointsStartLines.Add(sp.StartLine);
                }
                if (sequencePointsStartLines.Count > 0 && IsAssertCall(ins, assertingMethods))
                {
                    // As sequence point, use the last one added, which isn't necessarily sp,
                    // since the asserting instruction may lack sequence point.
                    var lastSpLineNumber = sequencePointsStartLines.Last();
                    assertingSequencePointsStartLines.Add(lastSpLineNumber);
                }
            }

            if (assertingSequencePointsStartLines.Count == 0)
                yield break; // this rule doesn't apply
            // If the X asserting sps are the X last ones, then it's ok!
            if (sequencePointsStartLines.EndsWith(assertingSequencePointsStartLines))
                yield break;
            yield return new Violation(this, testCase);
        }
开发者ID:provegard,项目名称:testness,代码行数:38,代码来源:AssertDistributionRule.cs

示例4: More_specific_type_goes_first_three_classes

		public void More_specific_type_goes_first_three_classes()
		{
			var set1 = new SortedSet<Type>(comparer) { typeof(JohnChild), typeof(JohnParent), typeof(JohnGrandparent) };
			var set2 = new SortedSet<Type>(comparer) { typeof(JohnChild), typeof(JohnGrandparent), typeof(JohnParent) };
			var set3 = new SortedSet<Type>(comparer) { typeof(JohnParent), typeof(JohnChild), typeof(JohnGrandparent) };
			var set4 = new SortedSet<Type>(comparer) { typeof(JohnParent), typeof(JohnGrandparent), typeof(JohnChild) };
			var set5 = new SortedSet<Type>(comparer) { typeof(JohnGrandparent), typeof(JohnParent), typeof(JohnChild) };
			var set6 = new SortedSet<Type>(comparer) { typeof(JohnGrandparent), typeof(JohnChild), typeof(JohnParent) };

			Assert.AreEqual(typeof(JohnChild), set1.First());
			Assert.AreEqual(typeof(JohnChild), set2.First());
			Assert.AreEqual(typeof(JohnChild), set3.First());
			Assert.AreEqual(typeof(JohnChild), set4.First());
			Assert.AreEqual(typeof(JohnChild), set5.First());
			Assert.AreEqual(typeof(JohnChild), set6.First());

			Assert.AreEqual(typeof(JohnGrandparent), set1.Last());
			Assert.AreEqual(typeof(JohnGrandparent), set2.Last());
			Assert.AreEqual(typeof(JohnGrandparent), set3.Last());
			Assert.AreEqual(typeof(JohnGrandparent), set4.Last());
			Assert.AreEqual(typeof(JohnGrandparent), set5.Last());
			Assert.AreEqual(typeof(JohnGrandparent), set6.Last());
		}
开发者ID:thefringeninja,项目名称:Castle.Windsor,代码行数:23,代码来源:TypeComparerTestCase.cs

示例5: PrintDetailedChanges

    /// <summary>
    /// Print a list of source changes, along with the success state for other builds of this node.
    /// </summary>
    /// <param name="History">History for this node</param>
    static void PrintDetailedChanges(NodeHistory History, int CurrentCL)
    {
        DateTime StartTime = DateTime.UtcNow;

        // Find all the changelists that we're interested in
        SortedSet<int> BuildChanges = new SortedSet<int>();
        BuildChanges.UnionWith(History.AllStarted.Where(x => x >= History.LastSucceeded));
        BuildChanges.Add(CurrentCL);

        // Find all the changelists that we're interested in
        List<P4Connection.ChangeRecord> ChangeRecords = GetSourceChangeRecords(BuildChanges.First(), BuildChanges.Last());

        // Print all the changes in the set
        int LastCL = BuildChanges.First();
        foreach(int BuildCL in BuildChanges)
        {
            // Show all the changes in this range
            foreach(P4Connection.ChangeRecord Record in ChangeRecords.Where(x => x.CL > LastCL && x.CL <= BuildCL))
            {
                string[] Lines = Record.Summary.Split(new char[]{ '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                Log("             {0} {1} {2}", Record.CL, Record.UserEmail, (Lines.Length > 0)? Lines[0] : "");
            }

            // Show the status of this build
            string BuildStatus;
            if(BuildCL == CurrentCL)
            {
                BuildStatus = "this sync";
            }
            else if (History.AllSucceeded.Contains(BuildCL))
            {
                BuildStatus = "built";
            }
            else if (History.AllFailed.Contains(BuildCL))
            {
                BuildStatus = "FAILED";
            }
            else
            {
                BuildStatus = "running";
            }
            Log(" {0} {1} {2}", (BuildCL == CurrentCL)? ">>>>" : "    ", BuildCL, BuildStatus.ToString());

            // Update the last CL now that we've output this one
            LastCL = BuildCL;
        }

        Log("Took {0:0.0}s to get P4 history", (DateTime.UtcNow - StartTime).TotalSeconds);
    }
开发者ID:colwalder,项目名称:unrealengine,代码行数:53,代码来源:GUBP.cs

示例6: ClusterColorSpace

        //Cluster the final clusters into color space
        public void ClusterColorSpace()
        {
            double maxDist = 20*20;
            int minRegions = 5;

            SortedSet<int> activeClusterIds = new SortedSet<int>(rootIds);
            String logFile = "colorlog.txt";
            StreamWriter log = File.AppendText(logFile);
            log.WriteLine("\n\tCluster ColorSpace Run " + DateTime.Now.ToString());
            log.Flush();

            //the smaller id comes first in the dictionary for pairwise distances
            PriorityQueue<Tuple<int, int>, double> pq = new PriorityQueue<Tuple<int, int>, double>();

            int counter = activeClusterIds.Last()+1;

            int[] ids = activeClusterIds.ToArray<int>();

            //Calculate the initial distances
            for (int i = 0; i < ids.Count(); i++)
            {
                for (int j = i+1; j < ids.Count(); j++)
                {
                    //log.WriteLine(ids[i] + ", " + ids[j] + " dist " + -1 * clusters[ids[i]].lab.SqDist(clusters[ids[j]].lab));
                    //log.Flush();

                    //pq.Enqueue(new Tuple<int, int>(ids[i], ids[j]), -1 * clusters[ids[i]].lab.SqDist(clusters[ids[j]].lab));
                    PixelCluster a = clusters[ids[i]];
                    PixelCluster b = clusters[ids[j]];

                    double newDist = a.lab.SqDist(b.lab);

                    //Add in Ward's variance  (variation in Color Segmentation using Region Merging)
                    //http://www.mathworks.com/help/toolbox/stats/linkage.html
                    //newDist = newDist * Math.Sqrt(2 * a.count * b.count / (a.count + b.count));

                    pq.Enqueue(new Tuple<int, int>(ids[i], ids[j]), -1 * newDist);
                }
            }

            Stopwatch timer = new Stopwatch();
            timer.Start();

            while (activeClusterIds.Count > minRegions)
            {

                //Find the pair with the smallest distance
                KeyValuePair<Tuple<int, int>, double> result = BestPair(pq, activeClusterIds);
                Tuple<int, int> pair = result.Key;
                double bestDist = -1 * result.Value;

                Console.WriteLine("num clusters: " + activeClusterIds.Count());

                if (bestDist > maxDist)
                    break;

                PixelCluster a = clusters[pair.Item1];
                PixelCluster b = clusters[pair.Item2];

                //Create a new cluster with unique id, we don't care about the neighbors
                PixelCluster merged = new PixelCluster();
                merged.id = counter++;
                merged.lab = (a.lab * a.count + b.lab * b.count) / (a.count + b.count);
                merged.count = a.count + b.count;
                merged.children = new int[] { a.id, b.id };
                merged.parentId = merged.id;
                a.parentId = merged.id;
                b.parentId = merged.id;
                clusters.Add(merged.id, merged);

                //Update the active cluster set
                activeClusterIds.Remove(a.id);
                activeClusterIds.Remove(b.id);
                activeClusterIds.Add(merged.id);

                double totalCount = a.count + b.count;

                //Update the distances, based on old distances
                foreach (int i in activeClusterIds)
                {
                    if (i == merged.id)
                        continue;

                    //TODO: Ward's method with minimum variance
                    //For now, just use the dist between the centroids
                    PixelCluster c = clusters[i];
                    double newDist = merged.lab.SqDist(c.lab);

                    //Add in Ward's variance  (variation in Color Segmentation using Region Merging)
                    //http://www.mathworks.com/help/toolbox/stats/linkage.html
                    //newDist = newDist * Math.Sqrt(2*a.count * b.count / (a.count + b.count));

                    if (c.id < merged.id)
                        pq.Enqueue(new Tuple<int, int>(c.id, merged.id), -1 * newDist);
                    else
                        pq.Enqueue(new Tuple<int, int>(merged.id, c.id), -1 * newDist);

                }

//.........这里部分代码省略.........
开发者ID:dritchie,项目名称:SceneColorMaterial,代码行数:101,代码来源:Clustering.cs

示例7: ToEndOfMultiLineComment

        /// <summary>
        /// Goes to the end of the multi-line comment sub part.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <param name="position">The current zero-based character position within <paramref name="input"/>.</param>
        /// <param name="splits">A set of indices of characters before which the input string will be split.</param>
        /// <returns>The new state.</returns>
        State ToEndOfMultiLineComment(string input, ref int position, SortedSet<int> splits)
        {
            int next = input.IndexOf("*/", position);
            if (next < 0)
                throw new ScriptException(string.Format("End of comment started at index {0} not found.", splits.Last()));
            position = next + 2;
            splits.Add(position);

            return State.Normal;
        }
开发者ID:Konctantin,项目名称:SharpAssembler,代码行数:17,代码来源:ScriptTokenizer.cs

示例8: ToEndOfLiteral

        /// <summary>
        /// Goes to the end of the string sub part.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <param name="position">The current zero-based character position within <paramref name="input"/>.</param>
        /// <param name="splits">A set of indices of characters before which the input string will be split.</param>
        /// <param name="literalDelimiter">Thw character that ends the literal.</param>
        /// <returns>The new state.</returns>
        State ToEndOfLiteral(string input, ref int position, SortedSet<int> splits, char literalDelimiter)
        {
            int next = input.IndexOf(literalDelimiter, position);
            if (next < 0)
                throw new ScriptException(string.Format("End of literal ({1}...{1}) started at index {0} not found.", splits.Last(), literalDelimiter));
            position = next + 1;
            splits.Add(position);

            return State.Normal;
        }
开发者ID:Konctantin,项目名称:SharpAssembler,代码行数:18,代码来源:ScriptTokenizer.cs

示例9: FlushFieldNums

        /// <summary>
        /// Returns a sorted array containing unique field numbers </summary>
        private int[] FlushFieldNums()
        {
            SortedSet<int> fieldNums = new SortedSet<int>();
            foreach (DocData dd in PendingDocs)
            {
                foreach (FieldData fd in dd.Fields)
                {
                    fieldNums.Add(fd.FieldNum);
                }
            }

            int numDistinctFields = fieldNums.Count;
            Debug.Assert(numDistinctFields > 0);
            int bitsRequired = PackedInts.BitsRequired(fieldNums.Last());
            int token = (Math.Min(numDistinctFields - 1, 0x07) << 5) | bitsRequired;
            VectorsStream.WriteByte((byte)(sbyte)token);
            if (numDistinctFields - 1 >= 0x07)
            {
                VectorsStream.WriteVInt(numDistinctFields - 1 - 0x07);
            }
            PackedInts.Writer writer = PackedInts.GetWriterNoHeader(VectorsStream, PackedInts.Format.PACKED, fieldNums.Count, bitsRequired, 1);
            foreach (int fieldNum in fieldNums)
            {
                writer.Add(fieldNum);
            }
            writer.Finish();

            int[] fns = new int[fieldNums.Count];
            int i = 0;
            foreach (int key in fieldNums)
            {
                fns[i++] = key;
            }
            return fns;
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:37,代码来源:CompressingTermVectorsWriter.cs


注:本文中的SortedSet.Last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。