• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ItemArray类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ItemArray的典型用法代码示例。如果您正苦于以下问题:C# ItemArray类的具体用法?C# ItemArray怎么用?C# ItemArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ItemArray类属于命名空间,在下文中一共展示了ItemArray类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SinglePointCrossoverCrossTest

 public void SinglePointCrossoverCrossTest() {
   var target = new PrivateObject(typeof(SinglePointCrossover));
   ItemArray<IntegerVector> parents;
   TestRandom random = new TestRandom();
   bool exceptionFired;
   // The following test checks if there is an exception when there are more than 2 parents
   random.Reset();
   parents = new ItemArray<IntegerVector>(new IntegerVector[] { new IntegerVector(5), new IntegerVector(6), new IntegerVector(4) });
   exceptionFired = false;
   try {
     IntegerVector actual;
     actual = (IntegerVector)target.Invoke("Cross", random, parents);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
   // The following test checks if there is an exception when there are less than 2 parents
   random.Reset();
   parents = new ItemArray<IntegerVector>(new IntegerVector[] { new IntegerVector(4) });
   exceptionFired = false;
   try {
     IntegerVector actual;
     actual = (IntegerVector)target.Invoke("Cross", random, parents);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:30,代码来源:SinglePointCrossoverTest.cs


示例2: Apply

    public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
      var len = parents[0].Length;

      var child = new LinearLinkage(len);
      var childGroup = new List<HashSet<int>>();
      var currentParent = random.Next(parents.Length);
      var groups = parents.Select(x => x.GetGroups().Select(y => new HashSet<int>(y)).ToList()).ToList();
      bool remaining;
      do {
        var maxGroup = groups[currentParent].Select((v, i) => Tuple.Create(i, v))
          .MaxItems(x => x.Item2.Count)
          .SampleRandom(random).Item1;
        var group = groups[currentParent][maxGroup];
        groups[currentParent].RemoveAt(maxGroup);
        childGroup.Add(group);

        remaining = false;
        for (var p = 0; p < groups.Count; p++) {
          for (var j = 0; j < groups[p].Count; j++) {
            foreach (var elem in group) groups[p][j].Remove(elem);
            if (!remaining && groups[p][j].Count > 0) remaining = true;
          }
        }

        currentParent = (currentParent + 1) % parents.Length;
      } while (remaining);

      child.SetGroups(childGroup);
      return child;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:30,代码来源:GreedyPartitionCrossover.cs


示例3: DiscreteCrossoverApplyTest

 public void DiscreteCrossoverApplyTest() {
   TestRandom random = new TestRandom();
   RealVector parent1, parent2, expected, actual;
   ItemArray<RealVector> parents;
   bool exceptionFired;
   // The following test is not based on published examples
   random.Reset();
   random.IntNumbers = new int[] { 0, 0, 1, 0, 1 };
   parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
   parents = new ItemArray<RealVector>(new RealVector[] { parent1, parent2 });
   expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.8 });
   actual = DiscreteCrossover.Apply(random, parents);
   Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
   // The following test is not based on published examples
   random.Reset();
   random.IntNumbers = new int[] { 0, 0, 1, 0, 1, 0 };
   parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer
   parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
   parents = new ItemArray<RealVector>(new RealVector[] { parent1, parent2 });
   exceptionFired = false;
   try {
     actual = DiscreteCrossover.Apply(random, parents);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:29,代码来源:DiscreteCrossoverTest.cs


示例4: Apply

 public override IOperation Apply() {
   ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
   for (int i = 0; i < SwarmSize; i++) {
     neighbors[i] = new IntArray(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize });
   }
   Neighbors = neighbors;
   return base.Apply();
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:8,代码来源:RingTopologyInitializer.cs


示例5: GetItems

        public IList<Item> GetItems(Critter critter)
        {
            var container = GetContainer (critter, false);
            if (container == null)
                return new List<Item> (0);

            var itemArray = new ItemArray ();
            container.GetItems (0, itemArray);
            return new List<Item> (itemArray);
        }
开发者ID:wladimiiir,项目名称:vault112,代码行数:10,代码来源:ItemHolderData.cs


示例6: Average

 private DoubleArray Average(IRandom random, ItemArray<DoubleArray> parents) {
   int length = parents[0].Length;
   var result = new DoubleArray(length);
   for (int i = 0; i < length; i++) {
     for (int p = 0; p < parents.Length; p++) {
       result[i] += parents[p][i];
     }
     result[i] /= parents.Length;
   }
   return result;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:11,代码来源:StdDevStrategyVectorCrossover.cs


示例7: PutItems

        public void PutItems(Critter critter, IList<Item> items)
        {
            var container = GetContainer (critter, true);
            if (container == null)
                return;

            var itemArray = new ItemArray ();
            itemArray.AddRange (items);

            Global.MoveItems (itemArray, container, 0);
        }
开发者ID:wladimiiir,项目名称:vault112,代码行数:11,代码来源:ItemHolderData.cs


示例8: Apply

    /// <summary>
    /// Performs a discrete crossover operation on multiple parents.
    /// </summary>
    /// <exception cref="ArgumentException">Thrown when the vectors of the parents are of different length.</exception>
    /// <param name="random">A random number generator.</param>
    /// <param name="parents">An array containing the parents that should be crossed.</param>
    /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    public static RealVector Apply(IRandom random, ItemArray<RealVector> parents) {
      int length = parents[0].Length;

      for (int i = 0; i < parents.Length; i++) {
        if (parents[i].Length != length)
          throw new ArgumentException("DiscreteCrossover: The parents' vectors are of different length.", "parents");
      }

      RealVector result = new RealVector(length);
      for (int i = 0; i < length; i++) {
        result[i] = parents[random.Next(parents.Length)][i];
      }

      return result;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:22,代码来源:DiscreteCrossover.cs


示例9: Apply

    /// <summary>
    /// Performs a discrete crossover operation of any number of given parents.
    /// </summary>
    /// <exception cref="ArgumentException">Thrown when the vectors of the parents are of different length or when there are less than 2 parents.</exception>
    /// <param name="random">A random number generator.</param>
    /// <param name="parents">The list of parents for the crossover operation.</param>
    /// <returns>The newly created integer vector, resulting from the crossover operation.</returns>
    public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents) {
      if (parents.Length < 2) throw new ArgumentException("DiscreteCrossover: There are less than two parents to cross.");
      int length = parents[0].Length;

      for (int i = 0; i < parents.Length; i++) {
        if (parents[i].Length != length)
          throw new ArgumentException("DiscreteCrossover: The parents' vectors are of different length.", "parents");
      }

      var result = new IntegerVector(length);
      for (int i = 0; i < length; i++) {
        result[i] = parents[random.Next(parents.Length)][i];
      }

      return result;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:23,代码来源:DiscreteCrossover.cs


示例10: Apply

 public override IOperation Apply() {
   ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
   for (int i = 0; i < SwarmSize; i++) {
     var numbers = Enumerable.Range(0, SwarmSize).ToList();
     numbers.RemoveAt(i);
     var selectedNumbers = new List<int>(NrOfConnections);
     for (int j = 0; j < NrOfConnections && numbers.Count > 0; j++) {
       int index = Random.Next(numbers.Count);
       selectedNumbers.Add(numbers[index]);
       numbers.RemoveAt(index);
     }
     neighbors[i] = new IntArray(selectedNumbers.ToArray());
   }
   Neighbors = neighbors;
   return base.Apply();
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:16,代码来源:RandomTopologyInitializer.cs


示例11: InstrumentedApply

    public override IOperation InstrumentedApply() {
      ItemArray<IVRPEncoding> parents = new ItemArray<IVRPEncoding>(ParentsParameter.ActualValue.Length);
      for (int i = 0; i < ParentsParameter.ActualValue.Length; i++) {
        IVRPEncoding solution = ParentsParameter.ActualValue[i];

        if (!(solution is PrinsEncoding)) {
          parents[i] = PrinsEncoding.ConvertFrom(solution, ProblemInstance);
        } else {
          parents[i] = solution;
        }
      }
      ParentsParameter.ActualValue = parents;

      ChildParameter.ActualValue =
        Crossover(RandomParameter.ActualValue, parents[0] as PrinsEncoding, parents[1] as PrinsEncoding);

      return base.InstrumentedApply();
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:18,代码来源:PrinsCrossover.cs


示例12: Apply

    public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
      var len = parents[0].Length;
      var child = new LinearLinkage(len);
      var remaining = new SortedSet<int>(Enumerable.Range(0, len));
      do {
        var groups = parents.Select(x => x.GetGroupForward(remaining.Min).Where(y => remaining.Contains(y)).ToList()).ToList();
        var max = groups.Select((v, idx) => Tuple.Create(idx, v.Count)).MaxItems(x => x.Item2).SampleRandom(random).Item1;
        var i = groups[max][0];
        for (var k = 1; k < groups[max].Count; k++) {
          child[i] = groups[max][k];
          remaining.Remove(i);
          i = child[i];
        }
        child[i] = i;
        remaining.Remove(i);
      } while (remaining.Count > 0);

      return child;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:19,代码来源:LowestIndexMaxCrossover.cs


示例13: Apply

    /// <summary>
    /// Performs the average crossover (intermediate recombination) on a list of parents.
    /// </summary>
    /// <exception cref="ArgumentException">Thrown when there is just one parent or when the parent vectors are of different length.</exception>
    /// <remarks>
    /// There can be more than two parents.
    /// </remarks>
    /// <param name="random">The random number generator.</param>
    /// <param name="parents">The list of parents.</param>
    /// <returns>The child vector (average) of the parents.</returns>
    public static RealVector Apply(IRandom random, ItemArray<RealVector> parents) {
      int length = parents[0].Length, parentsCount = parents.Length;
      if (parents.Length < 2) throw new ArgumentException("AverageCrossover: The number of parents is less than 2.", "parents");
      RealVector result = new RealVector(length);
      try {
        double avg;
        for (int i = 0; i < length; i++) {
          avg = 0;
          for (int j = 0; j < parentsCount; j++)
            avg += parents[j][i];
          result[i] = avg / (double)parentsCount;
        }
      }
      catch (IndexOutOfRangeException) {
        throw new ArgumentException("AverageCrossover: The parents' vectors are of different length.", "parents");
      }

      return result;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:29,代码来源:AverageCrossover.cs


示例14: Apply

    public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) {
      var len = parents[0].Length;
      var p = random.Next(parents.Length);
      var child = new LinearLinkage(len);
      var remaining = new SortedSet<int>(Enumerable.Range(0, len));
      do {
        var i = remaining.Min;
        foreach (var g in parents[p].GetGroupForward(i)) {
          if (!remaining.Contains(g)) continue;
          child[i] = g;
          i = g;
          remaining.Remove(g);
        }
        child[i] = i;
        remaining.Remove(i);

        p = (p + 1) % parents.Length;
      } while (remaining.Count > 0);

      return child;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:21,代码来源:LowestIndexFirstCrossover.cs


示例15: ShowMatrixOnConsole

 public static string ShowMatrixOnConsole(ItemArray matrix)
 {
     string x = string.Empty;
     for (int row = Globals.Rows - 1; row >= 0; row--)
     {
         for (int column = 0; column < Globals.Columns; column++)
         {
             if (matrix[row, column] != null)
             {
                 x += matrix[row, column].Value + "|";
             }
             else
             {
                 x += "X" + "|";
             }
         }
         x += Environment.NewLine;
     }
     Debug.Log(x);
     return x;
 }
开发者ID:dgkanatsios,项目名称:2048,代码行数:21,代码来源:Utilities.cs


示例16: Initialize

    public void Initialize()
    {
        if (matrix != null)
            for (int row = 0; row < Globals.Rows; row++)
                for (int column = 0; column < Globals.Columns; column++)
                {
                    if (matrix[row, column] != null && matrix[row, column].GO != null)
                        Destroy(matrix[row, column].GO);
                }

        matrix = new ItemArray();



        //InitArrayWithPremadeData();
        CreateNewItem();
        CreateNewItem();

        score = 0;
        UpdateScore(0);

        gameState = GameState.Playing;
    }
开发者ID:dgkanatsios,项目名称:2048,代码行数:23,代码来源:GameManager.cs


示例17: Analyze

    protected override void Analyze(ItemArray<DoubleArray> qualities, ResultCollection results) {
      ItemArray<IntValue> ranks = RankParameter.ActualValue;

      bool populationLevel = RankParameter.Depth == 1;

      int objectives = qualities[0].Length;
      int frontSize = ranks.Count(x => x.Value == 0);
      ItemArray<IScope> paretoArchive = null;
      if (populationLevel) paretoArchive = new ItemArray<IScope>(frontSize);

      DoubleMatrix front = new DoubleMatrix(frontSize, objectives);
      int counter = 0;
      for (int i = 0; i < ranks.Length; i++) {
        if (ranks[i].Value == 0) {
          for (int k = 0; k < objectives; k++)
            front[counter, k] = qualities[i][k];
          if (populationLevel) {
            paretoArchive[counter] = (IScope)ExecutionContext.Scope.SubScopes[i].Clone();
          }
          counter++;
        }
      }

      front.RowNames = GetRowNames(front);
      front.ColumnNames = GetColumnNames(front);

      if (results.ContainsKey("Pareto Front"))
        results["Pareto Front"].Value = front;
      else results.Add(new Result("Pareto Front", front));

      if (populationLevel) {
        if (results.ContainsKey("Pareto Archive"))
          results["Pareto Archive"].Value = paretoArchive;
        else results.Add(new Result("Pareto Archive", paretoArchive));
      }
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:36,代码来源:RankBasedParetoFrontAnalyzer.cs


示例18: Apply

    /// <summary>
    /// Performs an average crossover of the two given parent integer vectors.
    /// The average is rounded and mapped to the nearest valid value (e.g. if step size is > 1)
    /// </summary>
    /// <param name="random">A random number generator.</param>
    /// <param name="parents">The parents for crossover.</param>
    /// <param name="bounds">The bounds matrix that contains for each dimension one row with minimum (inclusive), maximum (exclusive), and step size columns.
    /// If the number of rows is smaller than the number of dimensions the matrix is cycled.</param>
    /// <returns>The newly created integer vector, resulting from the single point crossover.</returns>
    public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents, IntMatrix bounds) {
      int length = parents[0].Length, parentsCount = parents.Length;
      if (parents.Length < 2) throw new ArgumentException("RoundedAverageCrossover: The number of parents is less than 2.", "parents");
      if (bounds == null || bounds.Rows < 1 || bounds.Columns < 2) throw new ArgumentException("AverageCrossover: Invalid bounds specified.", "bounds");

      var result = new IntegerVector(length);
      try {
        double avg;
        for (int i = 0; i < length; i++) {
          avg = 0;
          for (int j = 0; j < parentsCount; j++)
            avg += parents[j][i];
          avg /= parentsCount;
          int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
          if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
          max = FloorFeasible(min, max, step, max - 1);
          result[i] = RoundFeasible(min, max, step, avg);
        }
      } catch (IndexOutOfRangeException) {
        throw new ArgumentException("RoundedAverageCrossover: The parents' vectors are of different length.", "parents");
      }

      return result;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:33,代码来源:RoundedAverageCrossover.cs


示例19: Cross

 protected abstract IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents);
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:1,代码来源:IntegerVectorCrossover.cs


示例20: Cross

 /// <summary>
 /// Performs a random convex crossover operation for two given parent real vectors.
 /// </summary>
 /// <exception cref="ArgumentException">Thrown if there are not exactly two parents.</exception>
 /// <param name="random">A random number generator.</param>
 /// <param name="parents">An array containing the two real vectors that should be crossed.</param>
 /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
 protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
   if (parents.Length != 2) throw new ArgumentException("ERROR in RandomConvexCrossover: The number of parents is not equal to 2");
   return Apply(random, parents[0], parents[1]);
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:11,代码来源:RandomConvexCrossover.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ItemClass类代码示例发布时间:2022-05-24
下一篇:
C# Item类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap