开发者

Venn diagram as trees

开发者 https://www.devze.com 2023-02-11 22:04 出处:网络
I am faced with the p开发者_运维问答roblem of representing a Venn diagram as a tree structure in order to process the information as XML.

I am faced with the p开发者_运维问答roblem of representing a Venn diagram as a tree structure in order to process the information as XML.

Do anyone have an elegant way for doing this, or maybe some acute observations?

Please note that I am not able to handle individual elements in the sets. Diagrams would be illustrating situations equivalent to "There are 20 students in all, of which 5 do sports, 8 play chess and 3 do both".


From your description my understanding is you are talking about dealing with the aggregate data (count for each set) rather than discrete items. So with that assumption, I would first look at how another code base represents Venn Diagrams (Google Chart API)

The Google chart API represents Venn Diagrams using seven values. I have extracted the descripions below from here: http://code.google.com/apis/chart/image/docs/gallery/venn_charts.html

  • The first three values specify the sizes of three circles: A, B, and C. For a chart with only two circles, specify zero for the third value.
  • The fourth value specifies the size of the intersection of A and B.
  • The fifth value specifies the size of the intersection of A and C. For a chart with only two circles, do not specify a value here.
  • The sixth value specifies the size of the intersection of B and C. For a chart with only two circles, do not specify a value here.
  • The seventh value specifies the size of the common intersection of A, B, and C. For a chart with only two circles, do not specify a value here.

We can apply the same approach to represent your problem domain in XML:

<venn_diagram item_type="Students" item_count="20">
    <set_a name="Play Sports" item_count="5"/>
    <set_b name="Play Chess" item_count="8"/>
    <set_a_and_b name="Play Both" item_count="3"/>
</venn_diagram>

With this information you know enough to draw the diagram.


As others have noted, it's not clear what you need to know, but you have provided some of what you must know. Note that Venn diagrams represent data in a way that is analogous to Disjunctive Normal Form for boolean statements. That is, the universe is the union of non-intersecting sets defined by the intersection between sets and their compliments. For example, with sets A, B, and C you get the following counts (where a single quotation means 'compliment'):

A B C
A B C'
A B'C
A B'C'
A'B C
A'B C'
A'B'C
A'B'C'

You may notice that these are binary values over the set names.. So, basically, if you have a Venn diagram between N sets, you need to know 2^n counts. From that, you can reconstruct all the information you desire. (e.g. 'A' is the set of ABC union ABC' union AB'C union AB'C')

From there, representation as an XML file is just an exercise -- you need to know how many sets, their name, and for every nonzero intersection their count and which sets are complimented in the intersection. (You can store more explicitly if you want to, but XML is already very terse.)

Hope this helps -- even if late!

0

精彩评论

暂无评论...
验证码 换一张
取 消