• MARS Website
  • Core API
  • SmartOpenHamburg API
  • Model Components API
  • Common API
Show / Hide Table of Contents
  • Mars.Common
    • GeoHash
    • GeoHashDecoder
    • GeohashDecodeResult
    • GeoHashEncoder
    • GeoHashPrecision
    • Hyperrectangle
    • InputHashHelper
    • PositionHelper
  • Mars.Common.Collections
    • BinaryArrayHeap<T>
    • DoubleBits
    • FibonacciHeap<T, TKey>
    • FibonacciHeapDoubleKey<T>
    • FibonacciHeapNode<T, TKey>
    • FibonacciHeapNodeDoubleKey<T>
    • HeapNode
    • IntervalSize
    • K2DTree<T>
    • K2dTreeNode<T>
    • KdTree
    • KdTree<T>
    • KdTreeBase<TNode>
    • KdTreeNode
    • KdTreeNode<T>
    • KdTreeNodeBase<TNode>
    • KdTreeNodeCollection<TNode>
    • KdTreeNodeList<T>
    • Key
    • Node<T>
    • NodeBase<T>
    • NodeDataContainer<T>
    • NodeDistance<TNode>
    • QuadTree<T>
    • Root<T>
    • TreeDataContainer<T>
  • Mars.Common.Collections.CritBit
    • ICritBitTree<TValue>
  • Mars.Common.Collections.Graph
    • EdgeData
    • GraphData
    • GraphSerializer
    • ISpatialGraph
    • KeyContainer
    • NodeData
    • SpatialGraph
    • SpatialGraphHelper
  • Mars.Common.Collections.Graph.Algorithms
    • AStar
    • CompressedPathDatabase
    • ContractionSearch
    • DepthLimitedTraversal
  • Mars.Common.Collections.Graph.Helper
    • INodeFinder
    • KdTreeNodeFinder
    • RunLengthEncoder
  • Mars.Common.Collections.KNNGraph
    • DefaultRandomGenerator
    • DistanceUtils
    • EventSources
    • EventSources.GraphBuildEventSource
    • EventSources.GraphSearchEventSource
    • IProgressReporter
    • IProvideRandomValues
    • KnnGraph<TItem, TDistance>
    • KnnGraph<TItem, TDistance>.KnnSearchResult
    • KnnGraph<TItem, TDistance>.Parameters
    • Node
    • ReverseComparer<T>
    • ReverseComparerExtensions
    • SelectionKind
    • TravelingCosts<TItem, TDistance>
  • Mars.Common.Compat
    • FormatDecoderAttribute
    • FormatEncoderAttribute
    • FormatHandlerAttribute
    • IntegerAttribute
    • NegativeIntegerAttribute
    • NonnegativeIntegerAttribute
    • NonpositiveIntegerAttribute
    • PositiveIntegerAttribute
  • Mars.Common.Data
    • DomainDataImporter
  • Mars.Common.Data.Providers
    • AscDataProvider
    • GeoJsonFeatureCollectionConverter
    • GeoJsonFeatureConverter
    • GeoJsonHelper
    • GeometryDataProvider
    • GraphMlProvider
    • HttpDataProvider
    • IDataProvider<TInput>
    • JsonFileDataProvider
    • JsonTextDataProvider
    • XmlFileDataProvider
    • XmlTextDataProvider
  • Mars.Common.Exceptions
    • DimensionMismatchException
    • ParseException
  • Mars.Common.IO
    • ExtensionMethods
    • FileClientUtils
    • FileKeys
    • HttpClientUtils
    • ObjectSerialize
    • Serializer
    • SerializerCompression
    • SparseFormat
    • SparseReader
    • SparseWriter
  • Mars.Common.IO.Attributes
    • SerializationBinderAttribute
    • SurrogateSelectorAttribute
  • Mars.Common.IO.Console
    • ChildProgressBar
    • IProgressBar
    • ProgressBar
    • ProgressBarBase
    • ProgressBarHeight
    • ProgressBarOptions
    • ProgressBarSimple
  • Mars.Common.IO.Csv
    • CsvAnalyzer
    • CsvReader
    • CsvReader.RecordEnumerator
    • CsvWriter
    • MissingFieldAction
    • ParseErrorAction
    • ValueTrimmingOptions
  • Mars.Common.IO.Events
    • ParseErrorEventArgs
  • Mars.Common.IO.Exceptions
    • MalformedCsvException
    • MissingFieldCsvException
  • Mars.Common.IO.Mapped
    • Context
    • DefaultArrayFactory
    • Extensions
    • IArrayFactory
    • ISerializableToStream
    • MappedAccessor<T>
    • MemoryMap
    • MemoryMap.CreateAccessorFunc<T>
    • MemoryMap.ReadFromDelegate<T>
    • MemoryMap.WriteToDelegate<T>
    • MemoryMapDelegates
    • MemoryMapDelegates.CreateAccessorFunc<T>
    • MemoryMapStream
  • Mars.Common.IO.Mapped.Accessors
    • MappedAccessorByte
    • MappedAccessorDouble
    • MappedAccessorInt16
    • MappedAccessorInt32
    • MappedAccessorInt64
    • MappedAccessorSingle
    • MappedAccessorUInt16
    • MappedAccessorUInt32
    • MappedAccessorUInt64
    • MappedAccessorVariable<T>
  • Mars.Common.IO.Mapped.Arrays
    • Array<T>
    • ArrayBase<T>
    • ArrayProfile
    • MappedArray<TMapped, T>
    • MappedArray<TMapped, T>.MapFrom
    • MappedArray<TMapped, T>.MapTo
    • MemoryArray<T>
    • VariableArray<T>
  • Mars.Common.IO.Mapped.Collections
    • MemoryBackedDictionary<TKey, TValue>
    • MemoryBackedList<T>
  • Mars.Common.IO.Mapped.Indexes
    • Index<T>
  • Mars.Common.IO.Mapped.Streams
    • CappedStream
  • Mars.Common.Socket
    • ByteOrder
    • CloseEventArgs
    • CloseStatusCode
    • CompressionMethod
    • ErrorEventArgs
    • Ext
    • MessageEventArgs
    • WebSocket
    • WebSocketException
    • WebSocketState
  • Mars.Common.Socket.Server
    • IWebSocketSession
    • WebHeaderCollection
    • WebSocketBehavior
    • WebSocketContext
    • WebSocketServer
    • WebSocketServiceHost
    • WebSocketServiceManager
    • WebSocketSessionManager
  • Mars.Numerics
    • Classes
    • Combinatorics
    • Constants
    • Distance
    • Elementwise
    • Jagged
    • MathematicsException
    • MathHelper
    • Matrix
    • MatrixOrder
    • MatrixType
    • Norm
    • Sort
    • Sorting
    • Sparse
    • Sparse<T>
    • Tools
    • Vector
    • VectorHelper
    • VectorType
  • Mars.Numerics.Comparers
    • ArrayComparer<T>
    • ComparerDirection
    • CustomComparer<T>
    • ElementComparer
    • ElementComparer<T>
    • GeneralComparer
    • StableComparer<T>
  • Mars.Numerics.Distances
    • Angular
    • Chebyshev
    • Cosine
    • Dirac<T>
    • Euclidean
    • Hamming
    • Hamming<T>
    • Haversine
    • Jaccard
    • Jaccard<T>
    • Kulczynski
    • Levenshtein
    • Levenshtein<T>
    • Manhattan
    • Matching
    • Minkowski
    • SquareEuclidean
    • Vincenty
    • Vincenty.Ellipsoid
  • Mars.Numerics.Distances.Base
    • IDistance<T>
    • IDistance<TFirst, TSecond>
    • IMetric<T>
    • ISimilarity<T, TU>
    • ISimilarity<T>
  • Mars.Numerics.Exceptions
    • DimensionMismatchException
    • NonPositiveDefiniteMatrixException
    • SingularMatrixException
  • Mars.Numerics.Formats
    • DefaultMatrixFormatProvider
    • IMatrixFormatProvider
    • MatrixFormatProviderBase
    • MatrixFormatter
    • OctaveMatrixFormatProvider
  • Mars.Numerics.Ranges
    • ByteRange
    • DoubleRange
    • FloatRange
    • IntRange
    • IRange<T>
  • Mars.Numerics.Statistics
    • ConstValueDistribution<T>
    • Distribution<T>
    • FastGaussianDistributionD
    • FastGaussianDistributionF
    • IDistribution
    • UniformDiscreteDistribution
    • UniformDistributionD
    • UniformDistributionF
  • Mars.Numerics.Statistics.Base
    • BinarySearch
    • DistributionBase
    • ISampleableDistribution<TObservations>
    • IUnivariateDistribution
    • IUnivariateDistribution<TObservation>
    • UnivariateDiscreteDistribution

Class Combinatorics

Static class for combinatorics functions.
Inheritance
System.Object
Combinatorics
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Numerics
Assembly: Mars.Numerics.dll
Syntax
public static class Combinatorics

Methods

| Improve this Doc View Source

Combinations<T>(T[], Boolean)

Enumerates all possible value combinations for a given array.
Declaration
public static IEnumerable<T[]> Combinations<T>(this T[] values, bool inPlace = false)
Parameters
Type Name Description
T[] values The array whose combinations need to be generated.
System.Boolean inPlace If set to true, the different generated combinations will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.
Returns
Type Description
System.Collections.Generic.IEnumerable<T[]>
Type Parameters
Name Description
T
| Improve this Doc View Source

Combinations<T>(T[], Int32, Boolean)

Enumerates all possible value combinations for a given array.
Declaration
public static IEnumerable<T[]> Combinations<T>(this T[] values, int k, bool inPlace = false)
Parameters
Type Name Description
T[] values The array whose combinations need to be generated.
System.Int32 k The length of the combinations to be generated.
System.Boolean inPlace If set to true, the different generated combinations will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.
Returns
Type Description
System.Collections.Generic.IEnumerable<T[]>
Type Parameters
Name Description
T
| Improve this Doc View Source

Permutations<T>(T[], Boolean)

Enumerates all possible value permutations for a given array.
Declaration
public static IEnumerable<T[]> Permutations<T>(T[] values, bool inPlace = false)
Parameters
Type Name Description
T[] values The array whose permutations need to be generated
System.Boolean inPlace If set to true, the different generated permutations will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.
Returns
Type Description
System.Collections.Generic.IEnumerable<T[]>
Type Parameters
Name Description
T
| Improve this Doc View Source

Sequences(Int32, Boolean)

Provides a way to enumerate all possible ordered permutations with repetitions allowed (i.e. a truth table), without using many memory allocations.
Declaration
public static IEnumerable<int[]> Sequences(int length, bool inPlace = false)
Parameters
Type Name Description
System.Int32 length The length of the sequence to generate.
System.Boolean inPlace If set to true, the different generated sequences will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Int32[]>
Examples

Suppose we would like to generate the same sequences shown in the TruthTable(Int32, Int32)example, however, without explicitly storing all possible combinations in an array. In order to iterate over all possible combinations efficiently, we can use:

int length = 3;  // The number of variables; or number 
             // of columns in the generated table.

foreach (int[] row in Combinatorics.Sequences(length))
{
// The following sequences will be generated in order:
//
//   new int[] { 0, 0, 0 },
//   new int[] { 0, 0, 1 },
//   new int[] { 0, 1, 0 },
//   new int[] { 0, 1, 1 },
//   new int[] { 1, 0, 0 },
//   new int[] { 1, 0, 1 },
//   new int[] { 1, 1, 0 },
//   new int[] { 1, 1, 1 },
}
| Improve this Doc View Source

Sequences(Int32, Int32, Boolean)

Provides a way to enumerate all possible ordered permutations with repetitions allowed (i.e. a truth table), without using many memory allocations.
Declaration
public static IEnumerable<int[]> Sequences(int symbols, int length, bool inPlace = false)
Parameters
Type Name Description
System.Int32 symbols The number of symbols.
System.Int32 length The length of the sequence to generate.
System.Boolean inPlace If set to true, the different generated sequences will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Int32[]>
Examples

Suppose we would like to generate the same sequences shown in the TruthTable(Int32, Int32)example, however, without explicitly storing all possible combinations in an array. In order to iterate over all possible combinations efficiently, we can use:

int symbols = 2; // Binary variables: either 0 or 1
int length = 3;  // The number of variables; or number 
             // of columns in the generated table.

foreach (int[] row in Combinatorics.Sequences(symbols, length))
{
// The following sequences will be generated in order:
//
//   new int[] { 0, 0, 0 },
//   new int[] { 0, 0, 1 },
//   new int[] { 0, 1, 0 },
//   new int[] { 0, 1, 1 },
//   new int[] { 1, 0, 0 },
//   new int[] { 1, 0, 1 },
//   new int[] { 1, 1, 0 },
//   new int[] { 1, 1, 1 },
}
| Improve this Doc View Source

Sequences(Int32[], Boolean, Boolean)

Provides a way to enumerate all possible ordered permutations with repetitions allowed (i.e. a truth table), without using many memory allocations.
Declaration
public static IEnumerable<int[]> Sequences(this int[] symbols, bool inPlace = false, bool firstColumnChangesFaster = false)
Parameters
Type Name Description
System.Int32[] symbols The number of symbols for each variable.
System.Boolean inPlace If set to true, the different generated permutations will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.
System.Boolean firstColumnChangesFaster If set to true, the first elements in the sequences will change faster than last ones. This changes the order in which the sequences are presented, but no their content.
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Int32[]>
Examples

Suppose we would like to generate the same sequences shown in the TruthTable(Int32, Int32)example, however, without explicitly storing all possible combinations in an array. In order to iterate over all possible combinations efficiently, we can use:

foreach (int[] row in Combinatorics.Sequences(new[] { 2, 2 }))
{
// The following sequences will be generated in order:
//
//   new int[] { 0, 0, 0 },
//   new int[] { 0, 0, 1 },
//   new int[] { 0, 1, 0 },
//   new int[] { 0, 1, 1 },
//   new int[] { 1, 0, 0 },
//   new int[] { 1, 0, 1 },
//   new int[] { 1, 1, 0 },
//   new int[] { 1, 1, 1 },
}
| Improve this Doc View Source

Subsets<T>(IEnumerable<T>, Boolean)

Generates all possibles subsets of the given set.
Declaration
public static IEnumerable<SortedSet<T>> Subsets<T>(this IEnumerable<T> set, bool inPlace = false)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> set
System.Boolean inPlace
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Collections.Generic.SortedSet<T>>
Type Parameters
Name Description
T
| Improve this Doc View Source

Subsets<T>(IEnumerable<T>, Int32, Boolean)

Generates all possibles subsets of size k of the given set.
Declaration
public static IEnumerable<SortedSet<T>> Subsets<T>(this IEnumerable<T> set, int k, bool inPlace = false)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> set
System.Int32 k
System.Boolean inPlace
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Collections.Generic.SortedSet<T>>
Type Parameters
Name Description
T
| Improve this Doc View Source

TruthTable(Int32, Int32)

Generates all possible ordered permutations with repetitions allowed (a truth table).
Declaration
public static int[][] TruthTable(int symbols, int length)
Parameters
Type Name Description
System.Int32 symbols The number of symbols.
System.Int32 length The length of the sequence to generate.
Returns
Type Description
System.Int32[][]
Examples

Suppose we would like to generate a truth table for a binary problem. In this case, we are only interested in two symbols: 0 and 1. Let's then generate the table for three binary values

int symbols = 2; // Binary variables: either 0 or 1
int length = 3;  // The number of variables; or number 
             // of columns in the generated table.

// Generate the table using Combinatorics.TruthTable(2,3)
int[][] table = Combinatorics.TruthTable(symbols, length);

// The generated table will be:
{
new int[] { 0, 0, 0 },
new int[] { 0, 0, 1 },
new int[] { 0, 1, 0 },
new int[] { 0, 1, 1 },
new int[] { 1, 0, 0 },
new int[] { 1, 0, 1 },
new int[] { 1, 1, 0 },
new int[] { 1, 1, 1 },
};
See Also
Sequences(Int32, Int32, Boolean)
| Improve this Doc View Source

TruthTable(Int32)

Generates all possible two symbol ordered permutations with repetitions allowed (a truth table).
Declaration
public static int[][] TruthTable(int length)
Parameters
Type Name Description
System.Int32 length The length of the sequence to generate.
Returns
Type Description
System.Int32[][]
Examples

Suppose we would like to generate a truth table for a binary problem. In this case, we are only interested in two symbols: 0 and 1. Let's then generate the table for three binary values

int length = 3;  // The number of variables; or number 
             // of columns in the generated table.

// Generate the table using Combinatorics.TruthTable(3)
int[][] table = Combinatorics.TruthTable(length);

// The generated table will be:
{
new int[] { 0, 0, 0 },
new int[] { 0, 0, 1 },
new int[] { 0, 1, 0 },
new int[] { 0, 1, 1 },
new int[] { 1, 0, 0 },
new int[] { 1, 0, 1 },
new int[] { 1, 1, 0 },
new int[] { 1, 1, 1 },
};
| Improve this Doc View Source

TruthTable(Int32[])

Generates all possible ordered permutations with repetitions allowed (a truth table).
Declaration
public static int[][] TruthTable(this int[] symbols)
Parameters
Type Name Description
System.Int32[] symbols The number of symbols for each variable.
Returns
Type Description
System.Int32[][]
Examples

Suppose we would like to generate a truth table (i.e. all possible combinations of a set of discrete symbols) for variables that contain different numbers symbols. Let's say, for example, that the first variable may contain symbols 0 and 1, the second could contain either 0, 1, or 2, and the last one again could contain only 0 and 1. Thus we can generate the truth table in the following way:

// Number of symbols for each variable
int[] symbols = { 2, 3, 2 };

// Generate the truth table for the given symbols
int[][] table = Combinatorics.TruthTable(symbols);

// The generated table will be:
{
new int[] { 0, 0, 0 },
new int[] { 0, 0, 1 },
new int[] { 0, 1, 0 },
new int[] { 0, 1, 1 },
new int[] { 0, 2, 0 },
new int[] { 0, 2, 1 },
new int[] { 1, 0, 0 },
new int[] { 1, 0, 1 },
new int[] { 1, 1, 0 },
new int[] { 1, 1, 1 },
new int[] { 1, 2, 0 },
new int[] { 1, 2, 1 },
};
See Also
Sequences(Int32, Int32, Boolean)
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © MARS GROUP. HAW Hamburg