Example usage for org.apache.commons.math3.util CombinatoricsUtils combinationsIterator

List of usage examples for org.apache.commons.math3.util CombinatoricsUtils combinationsIterator

Introduction

In this page you can find the example usage for org.apache.commons.math3.util CombinatoricsUtils combinationsIterator.

Prototype

public static Iterator<int[]> combinationsIterator(int n, int k) 

Source Link

Document

Returns an iterator whose range is the k-element subsets of {0, ..., n - 1} represented as int[] arrays.

Usage

From source file:com.github.braully.graph.operation.GraphCalcCaratheodoryNumberBinaryStrategy.java

public OperationConvexityGraphResult findCaratheodroySetBruteForce(
        UndirectedSparseGraphTO<Integer, Integer> graph, int currentSize) {
    OperationConvexityGraphResult processedHullSet = null;
    if (graph == null || graph.getVertexCount() <= 0) {
        return processedHullSet;
    }// w  w  w  .j av  a2  s.co m
    Collection vertices = graph.getVertices();
    int veticesCount = vertices.size();
    Iterator<int[]> combinationsIterator = CombinatoricsUtils.combinationsIterator(graph.getVertexCount(),
            currentSize);
    while (combinationsIterator.hasNext()) {
        int[] currentSet = combinationsIterator.next();
        OperationConvexityGraphResult hsp3g = hsp3(graph, currentSet);
        if (hsp3g != null) {
            processedHullSet = hsp3g;
            break;
        }
    }
    return processedHullSet;
}

From source file:com.github.braully.graph.hn.GraphWS.java

public Set<Integer> findHullSetBruteForce(UndirectedSparseGraphTO<Integer, Integer> graph, int currentSetSize) {
    Set<Integer> hullSet = null;
    if (graph == null || graph.getVertexCount() <= 0) {
        return hullSet;
    }/*from   w w  w .  j  a va 2 s.  co m*/
    Collection vertices = graph.getVertices();
    Iterator<int[]> combinationsIterator = CombinatoricsUtils.combinationsIterator(graph.getVertexCount(),
            currentSetSize);
    while (combinationsIterator.hasNext()) {
        int[] currentSet = combinationsIterator.next();
        if (checkIfHullSet(graph, currentSet)) {
            hullSet = new HashSet<>(currentSetSize);
            for (int i : currentSet) {
                hullSet.add(i);
            }
            break;
        }
    }
    return hullSet;
}