/** * Run an optimization step. */ size_t OptimizationImpl::optimize( Scope& scope, const SingleImplConfig& config) { TypeList to_optimize; single_impls->get_interfaces(to_optimize); for (auto intf : to_optimize) { auto& intf_data = single_impls->get_single_impl_data(intf); TRACE(INTF, 3, "(OPT) %s => %s\n", SHOW(intf), SHOW(intf_data.cls)); if (intf_data.is_escaped()) continue; auto escape = can_optimize(intf, intf_data, config.rename_on_collision); if (escape != EscapeReason::NO_ESCAPE) { single_impls->escape_interface(intf, escape); continue; } do_optimize(intf, intf_data); optimized.insert(intf); } // make a new scope deleting all single impl interfaces Scope new_scope; for (auto cls : scope) { if (optimized.find(cls->get_type()) != optimized.end()) continue; new_scope.push_back(cls); } scope.swap(new_scope); if (must_rewrite_annotations(config)) { rewrite_annotations(scope, config); } return optimized.size(); }
double Optimizer::optimize(unsigned int max_steps) { IMP_OBJECT_LOG; set_has_required_score_states(true); if (!get_model()) { IMP_THROW("Must give the optimizer a model to optimize", base::ValueException); } set_was_used(true); set_is_optimizing_states(true); double ret; IMP_THREADS((ret, max_steps), ret = do_optimize(max_steps););
double Optimizer::optimize(unsigned int max_steps) { IMP_OBJECT_LOG; if (!model_) { IMP_THROW("Must give the optimizer a model to optimize", base::ValueException); } set_was_used(true); set_is_optimizing_states(true); double ret= do_optimize(max_steps); set_is_optimizing_states(false); return ret; }
double Optimizer::optimize(unsigned int max_steps) { IMP_OBJECT_LOG; if (!scoring_function_) { IMP_WARN("No scoring function provided - using Model's implicit " "scoring function (deprecated). Recommend you use a " "ScoringFunction object instead." << std::endl); } set_has_required_score_states(true); set_was_used(true); set_is_optimizing_states(true); double ret; IMP_THREADS((ret, max_steps), { ret = do_optimize(max_steps); });
void do_experiment(swp_t&swp, sind_t&sind, rng_t&rng) { constant_indicator mind( moran_probability(swp.mutantFitness()/swp.residentFitness(), swp.n_individuals())); relative_indicator_t<sind_t, constant_indicator> rind(sind,mind); if (parameters.experiment() == "SWEEP") { IndicatorsDisplayController<swp_t,ParamsClass> ind_display; ind_display.inheritParametersFrom(swp); ind_display.setrecordEvery(0); ind_display.setdisplayEvery(0); ind_display.installIndicator(rind,"fixation/Moran prob"); // // cout << "fixation / Moran probability is " << rind(swp) << endl; // for (double rsr = 0.001; rsr <= 1000; rsr *= 1.1/*1.01*/) // // for (swp.room_switch_rate = 1000; swp.room_switch_rate >= 0.001; // // swp.room_switch_rate /= 1.01) // { double p_switch = rsr / (1 + rsr); // swp.setroom_switch_rate(rsr); // ind_display.update(p_switch,swp); // } for (double mp = 0.01; mp < 1; mp += 0.01) { swp.setlattice_move_probability(mp); ind_display.update(mp,swp); } } else if (parameters.experiment() == "SAMPLE") { cout << "swarming pattern:\n" << canonical(swp); double pfix = sind(swp); cout << "fixation probability: " << pfix << '\n'; cout << "Moran probability: " << mind(swp) << '\n'; } else if (parameters.experiment() == "OPTIMIZE") { cout << "Moran probability: " << mind(swp) << '\n'; do_optimize(swp,sind,swp,rng); } }
static int process_file ( const compress_t *c, lzo_decompress_t decompress, const char *method_name, const char *file_name, lzo_uint l, int t_loops, int c_loops, int d_loops ) { int i; unsigned blocks = 0; unsigned long compressed_len = 0; my_clock_t t_time = 0, c_time = 0, d_time = 0; my_clock_t t_start, c_start, d_start; #ifdef USE_DUMP FILE *dump = NULL; if (opt_dump_compressed_data) dump = fopen(opt_dump_compressed_data,"wb"); #endif /* process the file */ t_start = my_clock(); for (i = 0; i < t_loops; i++) { lzo_uint len, c_len, c_len_max, d_len = 0; lzo_byte *d = data; len = l; c_len = 0; blocks = 0; /* process blocks */ if (len > 0 || opt_try_to_compress_0_bytes) do { int j; int r; const lzo_uint bl = len > opt_block_size ? opt_block_size : len; lzo_uint bl_overwrite = bl; #if defined(__LZO_CHECKER) lzo_byte *dd = NULL; lzo_byte *b1 = NULL; lzo_byte *b2 = NULL; const lzo_uint b1_len = bl + bl / 64 + 16 + 3; #else lzo_byte * const dd = d; lzo_byte * const b1 = block1; lzo_byte * const b2 = block2; const lzo_uint b1_len = sizeof(_block1) - 256; unsigned char random_byte; random_byte = (unsigned char) my_clock(); #endif blocks++; /* may overwrite 3 bytes past the end of the decompressed block */ if (opt_use_asm_fast_decompressor) bl_overwrite += (lzo_uint) sizeof(int) - 1; #if defined(__LZO_CHECKER) /* malloc a block of the exact size to detect any overrun */ dd = malloc(bl_overwrite > 0 ? bl_overwrite : 1); b1 = malloc(b1_len); b2 = dd; if (dd == NULL || b1 == NULL) { perror("malloc"); return EXIT_MEM; } if (bl > 0) memcpy(dd,d,bl); #endif /* compress the block */ c_len = c_len_max = 0; c_start = my_clock(); for (j = r = 0; r == 0 && j < c_loops; j++) { c_len = b1_len; r = do_compress(c,dd,bl,b1,&c_len); if (r == 0 && c_len > c_len_max) c_len_max = c_len; } c_time += my_clock() - c_start; if (r != 0) { printf(" compression failed in block %d (%d) (%lu %lu)\n", blocks, r, (long)c_len, (long)bl); return EXIT_LZO_ERROR; } /* optimize the block */ if (opt_optimize_compressed_data) { d_len = bl; r = do_optimize(c,b1,c_len,b2,&d_len); if (r != 0 || d_len != bl) { printf(" optimization failed in block %d (%d) " "(%lu %lu %lu)\n", blocks, r, (long)c_len, (long)d_len, (long)bl); return EXIT_LZO_ERROR; } } #ifdef USE_DUMP /* dump compressed data to disk */ if (dump) { lzo_fwrite(dump,b1,c_len); fflush(dump); } #endif /* decompress the block and verify */ #if defined(__LZO_CHECKER) lzo_memset(b2,0,bl_overwrite); #else init_mem_checker(b2,_block2,bl_overwrite,random_byte); #endif d_start = my_clock(); for (j = r = 0; r == 0 && j < d_loops; j++) { d_len = bl; r = do_decompress(c,decompress,b1,c_len,b2,&d_len); if (d_len != bl) break; } d_time += my_clock() - d_start; if (r != 0) { printf(" decompression failed in block %d (%d) " "(%lu %lu %lu)\n", blocks, r, (long)c_len, (long)d_len, (long)bl); return EXIT_LZO_ERROR; } if (d_len != bl) { printf(" decompression size error in block %d (%lu %lu %lu)\n", blocks, (long)c_len, (long)d_len, (long)bl); return EXIT_LZO_ERROR; } if (is_compressor(c)) { if (lzo_memcmp(d,b2,bl) != 0) { lzo_uint x = 0; while (x < bl && b2[x] == d[x]) x++; printf(" decompression data error in block %d at offset " "%lu (%lu %lu)\n", blocks, (long)x, (long)c_len, (long)d_len); if (opt_compute_adler32) printf(" checksum: 0x%08lx 0x%08lx\n", (long)adler_in, (long)adler_out); #if 0 printf("Orig: "); r = (x >= 10) ? -10 : 0 - (int) x; for (j = r; j <= 10 && x + j < bl; j++) printf(" %02x", (int)d[x+j]); printf("\nDecomp:"); for (j = r; j <= 10 && x + j < bl; j++) printf(" %02x", (int)b2[x+j]); printf("\n"); #endif return EXIT_LZO_ERROR; } if ((opt_compute_adler32 && adler_in != adler_out) || (opt_compute_crc32 && crc_in != crc_out)) { printf(" checksum error in block %d (%lu %lu)\n", blocks, (long)c_len, (long)d_len); printf(" adler32: 0x%08lx 0x%08lx\n", (long)adler_in, (long)adler_out); printf(" crc32: 0x%08lx 0x%08lx\n", (long)crc_in, (long)crc_out); return EXIT_LZO_ERROR; } } #if defined(__LZO_CHECKER) /* free in reverse order of allocations */ free(b1); free(dd); #else if (check_mem(b2,_block2,bl_overwrite,random_byte) != 0) { printf(" decompression overwrite error in block %d " "(%lu %lu %lu)\n", blocks, (long)c_len, (long)d_len, (long)bl); return EXIT_LZO_ERROR; } #endif d += bl; len -= bl; compressed_len += c_len_max; } while (len > 0); } t_time += my_clock() - t_start; #ifdef USE_DUMP if (dump) fclose(dump); opt_dump_compressed_data = NULL; /* only dump the first file */ #endif print_stats(method_name, file_name, t_loops, c_loops, d_loops, t_time, c_time, d_time, compressed_len, l, blocks); return EXIT_OK; }
void optimize_func(const Index& index, FuncAnalysis ainfo) { Trace::Bump bumper{Trace::hhbbc, kSystemLibBump, is_systemlib_part(*ainfo.ctx.unit)}; do_optimize(index, std::move(ainfo)); }