I have a multimap defined by
typedef std::pair<int, int> au_pair; //vertices
typedef std::pair<int, int> acq_pair; //ch qlty specified by C
typedef std::multimap<int, acq_pair> au_map;
typedef au_map::iterator It_au;
The no. of simulations depend on the size of the au_map. For eg: if the au_map.size() = 5 I will have C1, C2, C3, C4, C5. and therefore 2^5 = 32 cases.
For example: If the au_map.size()=4, I need to simulate my algorithm for 16 cases.
for(size_t i = 0; i != 16; ++i)
{
for(It_au it = a_map.begin(); it != a_map.end();)
{
acq_pair it1 = it->second;
//case 0:
//C1 = 0, C2 = 0, C3 = 0, C4 = 0
//@Matthieu M 's suggestion http://stackoverflow.com/questions/3110975/c-case-declaration-closed
//bool const c1 = i & 1;
//bool const c2 = i & 2;
//bool const c3 = i & 4;
//bool const c4 = i & 8;
//Update it1.second with corresponding C values
it->second.second = C1;
it++;
it->second.second = C2;
it++;
it->second.second = C3;
it++;
it->second.second = C4;
it++;
}
//simulate algorithm
}
How can I automate this process, where the size of C changes according to the au_map.size()? Thus, I will have C1, C2, C3, C4 when au_map.size() = 4 and C1, C2, C3, C4, C5 when au_map.size() = 5.
Also, what’s preferred a vector with these values or add this to a pair inside multimap? Vector lookup time is lesser than multimap.
Also, if I keep inserting values to a multimap, will the new/updated values be passed to the algorithm?
Like others, I’m not certain I completely understand your question. It looks like all you need is a representation of the binary of each integer from 0 to 2
bits-1 that you can conveniently reference (in the cases you mention,bitsis either 4 or 5, but you want to generalize). If that’s the case, a simpler to manage and access structure will be a vector of bool vectors. That is, rather than using astd::multimap, for general values ofbits, replace thestd::multimapwith astd::vector<std::vector<bool> >… something like:At this point,
c_flags[i]contains a vector of bools representing the binary digits ofiwheretrueandfalsecorrespond to 1 and 0 respectively.You could also use a
std::map<std::vector<bool> >instead of thestd::vector<std::vector<bool> >which may reduce memory requirements (if you don’t need all of the possible binary representations) at the expense of being more expensive computationally. I don’t see why you need to use astd::multimap, but then I don’t have a lot of insight into the specifics of the problem you’re trying to address either.