- Timestamp:
- 11/25/14 03:26:00 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks
- Property svn:mergeinfo changed
-
branches/OptimizationNetworks/HeuristicLab.Common/3.3/EnumerableExtensions.cs
r9456 r11576 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 87 87 return result; 88 88 } 89 90 /// <summary> 91 /// Compute the n-ary cartesian product of arbitrarily many sequences: http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx 92 /// </summary> 93 /// <typeparam name="T">The type of the elements inside each sequence</typeparam> 94 /// <param name="sequences">The collection of sequences</param> 95 /// <returns>An enumerable sequence of all the possible combinations of elements</returns> 96 public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences) { 97 IEnumerable<IEnumerable<T>> result = new[] { Enumerable.Empty<T>() }; 98 return sequences.Where(s => s.Any()).Aggregate(result, (current, s) => (from seq in current from item in s select seq.Concat(new[] { item }))); 99 } 89 100 } 90 101 }
Note: See TracChangeset
for help on using the changeset viewer.