473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Intersection of Multiple Sets

Hello -

I am working on a scheduling application that has many "rules" for
scheduling people. I throw each person into the set that corresponds
to 2 teams. Then I split this large group (of everybody) into 3 groups
(indicating which day they will work a particular shift).

So I have two disjoint sets: teamA and teamB.
and I have three sets: day1, day2, day3 (not divided by team).
and so on...

This continues for several more steps as I have other rules I must
apply. What I would like to do is find the intersection of these
multiple sets. For example, I want to know who is in Team A *and* is
working on day2 and is working in location1,
TeamA & (day1 & locationA).

I know that there is the set_intersection function that I suppose I
could nest (?), but I could see this making a mess of iterators that
will crash or do something bizarre.

Any suggestions how I can do this?

TIA,
Ryan
Jul 19 '05 #1
1 7763
Ryan R. Rosario wrote in news:cm********************************@4ax.com:
Hello -

I am working on a scheduling application that has many "rules" for
scheduling people. I throw each person into the set that corresponds
to 2 teams. Then I split this large group (of everybody) into 3 groups
(indicating which day they will work a particular shift).

So I have two disjoint sets: teamA and teamB.
and I have three sets: day1, day2, day3 (not divided by team).
and so on...

This continues for several more steps as I have other rules I must
apply. What I would like to do is find the intersection of these
multiple sets. For example, I want to know who is in Team A *and* is
working on day2 and is working in location1,
TeamA & (day1 & locationA).
I'll assume all 3 of the above are std::set< Person >

std::vector< Person > eg( )
{
std::vector< Person > temp, output;

std::set_intersection(
TeamA.begin(), TeamA.end(),
day1.begin(), day1.end(),
std::back_inserter( temp )
);

std::set_intersection(
temp.begin(), temp.end(),
locationA.begin(), locationA.end(),
std::back_inserter( output )
);

return output;
}

You can make this more generic if it helps:

template < typename I1, typename I2, typename I3, typename Out >
Out set_intersect3(
I1 f1, I1 l1, I2 f2, I2 l2, I3 f3, I3 l3, Out out
)
{
typedef typename std::iterator_traits< I1 >::value_type vt;
std::vector< vt > temp;

std::set_intersection(
f1, l1, f2, l2,
std::back_inserter( temp )
);

return std::set_intersection(
temp.begin(), temp.end(), f3, l3, out
);
}

I know that there is the set_intersection function that I suppose I
could nest (?), but I could see this making a mess of iterators that
will crash or do something bizarre.

Don't know how you would "nest" std::set_intersect, But ...

template <typename C1, typename C2>
std::vector< typename C1::value_type >
nest_intersect( C1 const &c1, C2 const &c2 )
{
std::vector< typename C1::value_type > nrv;
std::set_intersect(
c1.begin(), c1.end(), c2.begin(), c2.end(),
std::back)inserter( nrv )
);
return nrv;
}

Now you can do:

std::vector< Person > r =
nest_intersect( TeamA, nest_intersect( day1, locationA ) )
;

Any suggestions how I can do this?


Use a database, its what they're designed for :).

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mickel Grönroos | last post by:
Hi! Are there any standard list methods for getting the intersection and difference of two lists? (The union is easy ("list1.extend(list2)"), unless you want it to contain unique values.) ...
5
by: Antoine Logean | last post by:
Hi, What is the easiest way to get the intersection of two strings in python (a kind a "and" operator) ? ex: string_1 =...
17
by: Gordon Williams | last post by:
Hi, I have to lists that I need to find the common numbers (2nd rounded to nearest integral) and I am wondering if there is a more efficient way of doing it. >>> a= >>> b= >>> ...
7
by: les_ander | last post by:
Hi, I have 2 lists of tuples that look like: E1= and E2=. In this tuple, the ordering does not matter, i.e. (u,v) is the same as (v,u). What I want to do is the following: given 2 list of...
2
by: James Stroud | last post by:
Hello All, I find myself in this situation from time to time: I want to compare two lists of arbitrary objects and (1) find those unique to the first list, (2) find those unique to the second...
3
by: ryu | last post by:
Hi, May I know how to do an intersection of sets using C#? Where the number of sets will only be known during runtime. Many Thanks
3
by: Suresh Jeevanandam | last post by:
I have a list of sets in variable lsets . Now I want to find the intersection of all the sets. r = lsets for s in r: r = r & s Is there any other shorter way?
2
by: mkppk | last post by:
I have kind of strange change I'd like to make to the sets.Set() intersection() method.. Normally, intersection would return items in both s1 and s2 like with something like this: ...
11
by: Prateek | last post by:
I have 3 variable length lists of sets. I need to find the common elements in each list (across sets) really really quickly. Here is some sample code: # Doesn't make sense to union the sets -...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.