src/cover.cpp
/**
 *	Cross-over constructor. Creates a cover that takes
 * 	some valid maximal (but not necessarily maximum) subset
 *	of the union of two covers.
 */
Cross-over constructor. Creates a cover that takes
some valid maximal (but not necessarily maximum) subset
of the union of two covers.
Cross - over constructor . Creates a cover that takes some valid maximal ( but not necessarily maximum ) subset of the union of two covers .
Cover::Cover(const Cover& a, const Cover& b) {
	fitness_ = 0;
	vector<Slice> united;
	united.insert(united.end(), a.slices_.begin(), a.slices_.end());
	united.insert(united.end(), b.slices_.begin(), b.slices_.end());
	random_shuffle(united.begin(), united.end());
	for (const Slice& u : united) {
		bool collision = false;
        for (Slice &s : slices_) {
        	collision |= s.overlap(u);
        	if (collision) {
        		break;
        	}
        }
        if (!collision) {
            add(u);
        }
	}
}
Cover :: Cover ( const Cover & a , const Cover & b ) { fitness_ = 0 ; vector < Slice > united ; united . insert ( united . end ( ) , a . slices_ . begin ( ) , a . slices_ . end ( ) ) ; united . insert ( united . end ( ) , b . slices_ . begin ( ) , b . slices_ . end ( ) ) ; random_shuffle ( united . begin ( ) , united . end ( ) ) ; for ( const Slice & u : united ) { bool collision = false ; for ( Slice & s : slices_ ) { collision |= s . overlap ( u ) ; if ( collision ) { break ; } } if ( ! collision ) { add ( u ) ; } } }
Cross-over constructor.
Cross - over constructor .
// Concatenate the slices of both parents.  // Randomly shuffle their order. // Loop over the slices, and add them if possible. // If no collision occured, add the // slice to the cover. //cout << a.slices_.size() << " " << b.slices_.size() << " " << slices_.size() << endl;