powerset

How can I find all 'long' simple acyclic paths in a graph?

删除回忆录丶 提交于 2019-12-11 13:22:27
问题 Let's say we have a fully connected directed graph G . The vertices are [a,b,c] . There are edges in both directions between each vertex. Given a starting vertex a , I would like to traverse the graph in all directions and save the path only when I hit a vertex which is already in the path. So, the function full_paths(a,G) should return: - [{a,b}, {b,c}, {c,d}] - [{a,b}, {b,d}, {d,c}] - [{a,c}, {c,b}, {b,d}] - [{a,c}, {c,d}, {d,b}] - [{a,d}, {d,c}, {c,b}] - [{a,d}, {d,b}, {b,c}] I do not need

How do I generate set partitions of a certain size?

纵然是瞬间 提交于 2019-12-11 05:16:49
问题 I would like to generate partitions for a set in a specific way: I need to filter out all partitions which are not of size N in the process of generating these partitions. The general solution is "Generate all “unique” subsets of a set (not a powerset)". For the set S with the following subsets: [a,b,c] [a,b] [c] [d,e,f] [d,f] [e] and the following 'unique' elements: a, b, c, d, e, f the result of the function/method running with the argument N = 2 should be: [[a,b,c], [d,e,f]] While the

How to get the largest possible column sequence with the least possible row NAs from a huge matrix?

北城余情 提交于 2019-12-10 11:27:22
问题 I want to select columns from a data frame so that the resulting continuous column-sequences are as long as possible, while the number of rows with NAs is as small as possible, because they have to be dropped afterwards. (The reason I want to do this is, that I want to run TraMineR::seqsubm() to automatically get a matrix of transition costs (by transition probability) and later run cluster::agnes() on it. TraMineR::seqsubm() doesn't like NA states and cluster::agnes() with NA states in the

Generate all possible subgraphs of a directed graph keeping the number of vertices

Deadly 提交于 2019-12-10 10:48:36
问题 I have two lists of vertices: V and S . I would like to generate all possible directed graphs from V and S so, that each vertex from V has only one out-edge and exactly one in-edge, and each vertex from S can have any number of in- and out- edges. Each graph in the result should contain exactly all vertices from V and from S . The result can contain both connected and disconnected graphs. First I thought it was a powerset-related problem, but powerset has many other sets that may contain just

Generate powerset lazily

匆匆过客 提交于 2019-12-09 00:50:27
问题 I want to calculate powerset of a set. Because I don't need the whole powerset at a time, it's better to generate it lazily. For example: powerset (set ["a"; "b"; "c"]) = seq { set []; set ["a"]; set ["b"]; set ["c"]; set ["a"; "b"]; set ["a"; "c"]; set ["b"; "c"]; set ["a";"b"; "c"]; } Since the result is a sequence, I prefer it in the above order. How can I do it in an idomatic way in F#? EDIT: This is what I'm going to use (based on BLUEPIXY's answer): let powerset s = let rec loop n l =

Iteratively calculate the power set of a set or vector

被刻印的时光 ゝ 提交于 2019-12-08 09:16:48
问题 While there are plenty of examples on how to generate the actual power set of a set, I can't find anything about iteratively (as in std::iterator ) generating the power set. The reason why I would appreciate such an algorithm is the size of my base set. As the power set of a n-element set has 2^n elements, I would quickly run out of memory when actually computing the set. So, is there any way to create an iterator for the power set of a given set? Is it even possible? If it would be easier,

Parallel power set generation in Erlang?

痴心易碎 提交于 2019-12-08 02:15:44
问题 There is a lot of example implementations of generating a powerset of a set in Java, Python and others, but I still can not understand how the actual algorithm works. What are the steps taken by an algorithm to generate a power set P(S) of a set S? (For example, the power set of {1,2,3,4} is {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.) UPD: I have found this explanation, but still I don't get it. I am trying to understand

efficient powerset algorithm for subsets of minimal length

痞子三分冷 提交于 2019-12-07 12:46:36
问题 i am using the following C# function to get a powerset limited to subsets of a minimal length string[] PowerSet(int min_len, string set) { IEnumerable<IEnumerable<string>> seed = new List<IEnumerable<string>>() { Enumerable.Empty<string>() }; return set.Replace(" ", "") .Split(',') .Aggregate(seed, (a, b) => a.Concat(a.Select(x => x.Concat(new[] { b })))) .Where(subset => subset.Count() >= min_len) .Select(subset => string.Join(",", subset)) .ToArray(); } the problem is that when the original

Prolog powerset predicate [closed]

风流意气都作罢 提交于 2019-12-06 09:29:48
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center . Closed 6 years ago . I wish to define a predicate powerset(X, P) which is true when P is the powerset of X. Should work whether or not P is ground. Alexander Serebrenik Since you use SICStus Prolog you can use the subseq0(+Sequence, ?SubSequence) from library(lists), which "is true when SubSequence is a subsequence of Sequence, but

Parallel power set generation in Erlang?

。_饼干妹妹 提交于 2019-12-06 05:13:46
There is a lot of example implementations of generating a powerset of a set in Java, Python and others, but I still can not understand how the actual algorithm works. What are the steps taken by an algorithm to generate a power set P(S) of a set S? (For example, the power set of {1,2,3,4} is {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.) UPD: I have found this explanation, but still I don't get it. I am trying to understand the algorithm of generating a power set, because I would like to write a parallel implementation of it