lanl-ansi / GraphicalModelLearning.jl

Algorithms for Learning Graphical Models
https://lanl-ansi.github.io/GraphicalModelLearning.jl/stable/
Other
23 stars 10 forks source link

Code for Generating Permutations #11

Closed ccoffrin closed 6 years ago

ccoffrin commented 6 years ago

I think this does the right thing. One question is when generalizing to higher dimensions, are (1,1,2) and (1,2,1) symmetric? Also maybe the logic of the asymmetric flag is revered...

permutations(items, order::Int; asymmetric::Bool = false) = sort(permutations([], items, order, asymmetric))

function permutations(partical_perm::Array{Any,1}, items, order::Int, asymmetric::Bool)
    if order == 0
        return [tuple(partical_perm...)]
    else
        perms = []
        for item in items
            if !asymmetric && length(partical_perm) > 0 
                if partical_perm[end] < item
                    continue
                end
            end
            perm = permutations(vcat([item], partical_perm), items, order-1, asymmetric)
            append!(perms, perm)
        end
        return perms
    end
end
ccoffrin commented 6 years ago

closed in #14