Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86066

Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'algorithm': 0.04; 'yet.': 0.04; 'say,': 0.05; 'element': 0.07; '(ie.': 0.09; 'assuming': 0.09; 'calculating': 0.09; 'python': 0.11; 'itself.': 0.14; 'collects': 0.16; 'combinations': 0.16; 'element,': 0.16; 'intersection': 0.16; 'islands': 0.16; 'iteration': 0.16; 'levels,': 0.16; 'loop.': 0.16; 'subject: \n ': 0.16; 'sure.': 0.16; 'thankfully,': 0.16; 'throw': 0.16; 'elements': 0.16; 'index': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'seems': 0.21; 'header:User-Agent:1': 0.23; 'fairly': 0.24; 'second': 0.26; 'least': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'related': 0.29; 'label': 0.30; 'sets': 0.30; "i'm": 0.30; 'large.': 0.31; 'this.': 0.32; 'figure': 0.32; 'becomes': 0.33; 'could': 0.34; "can't": 0.35; 'common': 0.35; 'possible.': 0.35; 'point.': 0.35; 'but': 0.35; 'described': 0.36; 'two': 0.37; 'clear': 0.37; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'easy': 0.60; 'simply': 0.61; 'simple': 0.61; "you're": 0.61; "you've": 0.63; 'show': 0.63; 'refer': 0.63; 'size.': 0.65; 'charset:windows-1252': 0.65; 'between': 0.67; 'received:74.208': 0.68; 'union': 0.69; 'therefore': 0.72; 'lowest': 0.74; 'power': 0.76; 'algorithm,': 0.84; 'common,': 0.84; 'island': 0.84; 'received:74.208.4.194': 0.84; 'sets,': 0.84; 'subject:Sets': 0.84; 'island.': 0.91
Date Sat, 21 Feb 2015 15:18:54 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements
References <Bg5Gw.1344030$No4.494335@fx19.iad>
In-Reply-To <Bg5Gw.1344030$No4.494335@fx19.iad>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:CjZ0P971VuwxngQo7xpWIn1TH0h743zmbr4uJL7wBQA X/BxhrET4PAwtl/M86eOmSJc+2fA6DOWPiGZ2CEd/BF2JLyaWe RtwMQkNzuJhEQMD0FGeXcoNJH14u4GbSxLDlfuEW3VKN0IFUm5 LMFIhW0tx+/rZHG9gj9PRLMDGbP5uPX1QdQ3TCCqM5EQ3Z0KUe t2o7TtBFn5XM3SdyUk1fSL/P3YD1FmHYMiBhRHSZvsZLLFMB4X 1vOvJ/Y2xKzCgbjHwNd0+UauIdJVGxHtDbIYNgKagmdysuw2UG n+4qqFfEbB2ymmT7XWdUgXgwGi88lzxBMzFU2dW5ZTwaZry4VP pb2XpLXNllR28tCNTh6Q=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18983.1424549962.18130.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424549962 news.xs4all.nl 2885 [2001:888:2000:d::a6]:42704
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86066

Show key headers only | View raw


On 02/21/2015 02:46 PM, TommyVee wrote:
> Start off with sets of elements as follows:
>
> 1. A,B,E,F
> 2. G,H,L,P,Q
> 3. C,D,E,F
> 4. E,X,Z
> 5. L,M,R
> 6. O,M,Y
>
> Note that sets 1, 3 and 4 all have the element 'E' in common, therefore
> they are "related" and form the following superset:
>
> A,B,C,D,E,F,X,Z
>
> Likewise, sets 2 and 5 have the element 'L' in common, then set 5 and 6
> have element 'M' in common, therefore they form the following superset:
>
> G,H,L,M,O,P,Q,R,Y
>
> I think you get the point.  As long as sets have at least 1 common
> element, they combine to form a superset.  Also "links" (common
> elements) between sets may go down multiple levels, as described in the
> second case above (2->5->6).  Cycles thankfully, are not possible.
>
> BTW, the number of individual sets (and resultant supersets) will be
> very large.
>
> I don't know where to start with this.

I can't see where you've defined "this" yet.  I think you're trying to 
find all combinations of sets that are "related", and that you're 
assuming some of them won't be.  So perhaps you're trying to build 
"islands" of related sets, and you want each of those islands to be of 
maximal size.

>  I thought about some type of
> recursive algorithm, but I'm not sure.  I could figure out the Python
> implementation easy enough, I'm just stumped on the algorithm itself.
>

Seems like you can have a doubly-nested loop, where your inner loop 
collects all the sets that are related to the one in the outer loop. 
You label each group with an island-number, where the island number is 
simply the lowest number set that's on the island.

It's still not clear what you do with each of those islands, but the 
"superset" you refer to before is simply the OR of everything on the island.

Perhaps you want to show all smaller supersets that are composed of at 
least two sets of an island.  That becomes a fairly simple power-of-two 
iteration of those sets, where you throw out the case where the index is 
a power of two (ie. contains only one set).

As you say, calculating the union or intersection of the various sets in 
python is trivial.

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Algorithm for Creating Supersets of Smaller Sets Based on Common Elements "TommyVee" <xxxxxxxx@xxxxxx.xxx> - 2015-02-21 14:46 -0500
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements Joel Goldstick <joel.goldstick@gmail.com> - 2015-02-21 15:06 -0500
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements Ethan Furman <ethan@stoneleaf.us> - 2015-02-21 12:11 -0800
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements Dave Angel <davea@davea.name> - 2015-02-21 15:18 -0500
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-21 22:40 +0000
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements "TommyVee" <xxxxxxxx@xxxxxx.xxx> - 2015-02-21 19:07 -0500
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-22 15:02 +1100
    Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements wxjmfauth@gmail.com - 2015-02-22 00:15 -0800
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements Peter Pearson <pkpearson@nowhere.invalid> - 2015-02-22 16:49 +0000
  Re: Algorithm for Creating Supersets of Smaller Sets Based on Common Elements duncan smith <buzzard@invalid.invalid> - 2015-02-22 17:02 +0000

csiph-web