You can make a mask representing what users are in each group: for example, for G1, that would be 10001, for G2, that would be 10101, and so on. Then combine these masks using regular bitwise operations.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
If these are actual formulas:
Groups of Groups
GG1 - (G1 && G2) || G3
GG2 - (G2 || G3) && (G1 && G4)
GG3 - (G1 && (G2 || G3)) || G5 then
GG1 = G3
GG2 = 0
GG3 = G5Now I want to be able to determine all the users that satisfy the conditions for GG1, GG2 and GG3. So based on the above examples, we have:
Users in GG1: U1, U2, U5
Users in GG2: U5
Users in GG3: U1, U4, U5
How can I algorithmically determine this? AND the user with the GGroup. If != 0, user is in the group.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
That makes no sense. :sad:
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
no reason to be sad! i'm terrible at explaining things. i would be the worst teacher in the world.. hehe..
anyway maybe this will help, if you put the GG rules into words.
So first I said GG1 = (G1 AND G2) OR G3. sorry for making it so formula-ish even though its not really one.
in words: the users in GG1 are those that are either BOTH in G1 and G2 OR just in G3.
so if U1 is in (G1,G2) and U2 is in (G3), both U1 and U2 would be part of GG1. hope i am making sense now
Ok that still don't make any sense.
Ok let's keep it simple. Let's say you have some variables G1,G2,G3...GN.
These variables (GN) can take two forms, 0 or 1 true or false.
So essentially you are saying:
Giving various boolean formulas:
(G1 && G2) || G3
(G2 || G3) && (G1 && G4)
(G1 && (G2 || G3)) || G5
Determine the final result, i.e it would each expression be either be true or false?
And you want a way to code the expressions dynamically (like say at the command line) rather than having to list a whole bunch of if / and conditions?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
ah.. so the variables (G1..Gn) as you said are more than just true/false. they are bit masks.. so the masks are:
G1: 0001
G2: 0010
G3: 0100
G4: 1000
and then given a user's mask (ie 0110, which states that the user is in G2 and G3 by ANDing against the G2 and G3 bit masks), then yes, i want to determine the final result (true/false) of the expressions. and by dynamically, i mean these expressions are not hard coded anywhere. they are stored somewhere of course, but not in the actual code. given a user's mask and the expression i should be able to call some function which will return true or false.
I'm still struggling to understand, maybe it's just me, but yourfirst example is throwing me of.
Anyway, regardless of GN being just 0 or 1 or a string of zeros and ones, the idea should still be the same.
What you have to do is create an equation parser to handle any type expression. So that your program can handle it rather than just hard coded expressions.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
oh well, sorry for the confusion. thanks for the help though.
So do you know how to write an equation parser?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
I'm still struggling to understand, maybe it's just me, but your first example is throwing me of.
Look at it this way: (G1 && G2) || G3
You are looking for students in
1) Math-202 (G3) --OR--
2) CompSci-101 (G1) AND Economics-101 (G2)
Using language syntax makes the statement backwards. Use logic syntax like you did later with(G1 AND G2) OR G3. This takes it out ot the boolean syntax -- at least for me.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
WaltP, if group X is assigned the user mask 1000101, that means that user 1, 3, and 7 are members of group X.
Suppose group X has users 1,3,7, group Y has users 2,4,7, and group Z has users 3, 5. Then the user masks for X, Y, and Z are 1000101, 1001010, and 0010100, respectively.
Suppose group GGK consists of people who are either in X and Y, or are in group Z. Describing GGK the way you have been, you'd say (X && Y) || Z.
Then compute (X & Y) | Z (where these bitwise operators are taken from C and other languages). Well, the value X & Y contains all the users in groups X and Y: X & Y equals 1000000, after all. Then (X&Y)|Z equals 1010100. So users 7, 5, and 3 are members of the group GGK.
If you had a group and wanted to implement a way of combining groups and then to test arbitrary users to see if they're in the group, the strategy for implementation would depend on the programming language you're using. It would be easier in functional programming languages.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
i had thought about this implementation, and i didnt think it was feasible. keeping the group's user masks updated and current involves too much work. every time a user is added/deleted for example, i would have to go through and change each and every group-user mask.. right?
Nah, his example at least makes sense. What's so hard about updating the group's user masks.
Group X = 100100
User 2 decides to join Group X.
Group X = 100110
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
That's not bad at all. You'd have to store user 3's membership information for each of the 1000 groups anyway, and you'd have to delete that anyway, so this is a linear multiple of the amount of work you'd have to do.
And if by 1000 groups you're including compound groups, then don't store the masks for every user for compound groups; just calculate them user-by-user whenever you need to know all the users that are members.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176