cartesian product...

From: deancoo (s2cuts555_at_yahoo.ca)
Date: 02/28/05


Date: Mon, 28 Feb 2005 11:24:46 GMT

I need to do a Cartesian product, which is inherently expensive. Turns out,
it's too expensive. I've dropped in that portion of my C++ code in hopes
that someone with greater expertise with STL containers and algorithms would
be able to see if there are any significant inefficiencies in what I've
done. Otherwise, I'm going to have to rethink my solution, which I really
would like to avoid. Thanks for any help.

d

    // initialize iterators to vectors
    bc_it_start = board_combinations.begin();
    bc_it_end = board_combinations.end();
    hcmb_it_start = tcart_combinations.begin();
    hcmb_it_end = tcart_combinations.end();

    for (hcmb_it=hcmb_it_start; hcmb_it!=hcmb_it_end; hcmb_it++) {

        for (bc_it=bc_it_start; bc_it!=bc_it_end; bc_it++) {

            // set iterators to containers within outside containers
            cc_it_start = hcmb_it->mycarts.begin();
            cc_it_end = hcmb_it->mycarts.end();
            brd_it_start = bc_it->mycarts.begin();
            brd_it_end = bc_it->mycarts.end();

            copy(cc_it_start, cc_it_end,
back_inserter(current_combination.mycarts));
            copy(brd_it_start, brd_it_end,
back_inserter(current_combination.mycarts));

            cartesian_prod.push_back(current_combination);
            current_combination.mycarts.clear();
        };
    };



Relevant Pages

  • Re: outputting random boolean values
    ... am sorry but I do not yet understand how to avoid this. ... While writing to the buffer during a regeneration, ... while the driver was replacing the old pattern in the buffer with the ... then a portion of old data, and then a portion of new data again. ...
    (comp.lang.labview)
  • Re: OT: CNNs Jack Cafferty on Palin
    ... and they'll have to rethink their strategy. ... Sorry, but this portion of the population (as shown in the video, as ... When Obama wins, he's going to have a tough time dealing with the aftershocks. ...
    (rec.music.classical.recordings)
  • Re: Is this JOIN good ?
    ... Is a.fk the child of c.pk? ... relationships are sufficient to avoid a Cartesian product. ...
    (comp.databases.oracle.server)
  • Re: Validation of text
    ... predefine letter, say 'H', followed by a numeric value of varying length? ... you may want to avoid 'leading' zeros in the numeric ... portion e.g. basic pattern: ...
    (microsoft.public.access.forms)
  • Re: OT: CNNs Jack Cafferty on Palin
    ... and they'll have to rethink their strategy. ... Sorry, but this portion of the population (as shown in the video, as ... Obama, either as candidate or as prez. ...
    (rec.music.classical.recordings)