/* Now wrap everything up in a loop, and run it. */ int main(int argc, const char * argv[]) { // for grins, let's bump up the repr_size: repr_size = 100; population_size = 1000; population_type p(population_size, repr_type(repr_size, 0)); // each time through this loop is an "update": for(std::size_t i=0; i<10; ++i) { // let's first print out the mean & max fitness each time through: double sum=0.0; double max_fitness=0.0; for(population_type::iterator j=p.begin(); j!=p.end(); ++j) { double f = all_ones(*j); sum += f; max_fitness = std::max(max_fitness, f); } std::cout << "mean: " << sum/p.size() << " max: " << max_fitness << std::endl; // and now the EA: compete(p); random_selection_with_generic_mutation(p); } return 0; }
int maximalRectangle(vector<vector<char> > &matrix) { int H = matrix.size(), W = H ? matrix[0].size() : 0; int max_rect = 0; for (int i = 0; i < H; ++i) { vector<char> all_ones(W, '1'); for (int j = i; j < H; ++j) { all_ones = And(all_ones, matrix[j]); // Cannot exceed max_rect for this j if ((j - i + 1) * W <= max_rect) continue; int max_run = maxRun(all_ones); // Cannot exceed max_rect for the rest of j for this i if ((H - i) * max_run < max_rect) break; max_rect = max(max_rect, (j - i + 1) * max_run); } } return max_rect; }