void SelectBox::setViewSize( CRect& rcSize, bool invalid ) { CControl::setViewSize( rcSize, invalid ); CRect rcScrollbar( size.right-WidthButton, size.bottom, size.right, size.bottom+150 ); scrollbar_->setViewSize( rcScrollbar, invalid ); calcMetrics(); }
std::pair<std::vector<double>, std::vector<double> > & operator()(const std::vector<double> & real_decision_vars, const std::vector<int> & int_decision_vars) { std::string filename = "logWorker" + std::to_string(evaluator_id) + "_EvalNo" + std::to_string(eval_count) + "_" + boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()) + ".log"; boost::filesystem::path debug_log_file_name = save_dir / filename; std::ofstream logging_file; if (is_logging) { logging_file.open(debug_log_file_name.c_str(), std::ios_base::app); if (!logging_file.is_open()) { is_logging = false; std::cout << "attempt to log failed\n"; } } std::vector<double> & obj = objectives_and_constrataints.first; obj[0] = 0; obj[1] = 0; for (int j = 0; j < replicates; ++j) { std::pair<double, double> metric_vals = calcMetrics(worker_dir, real_decision_vars, int_decision_vars, is_logging, logging_file, debug_log_file_name, j); obj[0] += metric_vals.first; obj[1] += metric_vals.second; } obj[0] /= replicates; obj[1] /= replicates; ++eval_count; if (is_logging) logging_file << "\n\n\n FKS: " << obj[0] << "\n Average Clump Diff: " << obj[1] << "\n"; if (is_logging) logging_file.close(); boost::filesystem::remove_all(previous_log_file); previous_log_file = debug_log_file_name; return (objectives_and_constrataints); }
void SelectBox::setList( const SelectBoxList& list, INT32 numVisible ) { list_.clear(); list_ = list; maxVisible_ = min( (INT32)list_.size(), numVisible ); calcMetrics(); if( maxVisible_ < (INT32)list_.size() ) { scrollbar_->setVisible( true ); scrollbar_->setViewSize( rcScrollbar_, false ); scrollbar_->setScrollSize( rcScrollsize_ ); scrollbar_->setWheelInc( 1 / (float)list_.size() ); } else { scrollbar_->setVisible( false ); rcDropdown_.right = size.right; } }
SelectBox::SelectBox( const CRect& rcSize, CControlListener* listener, long tag ) : CControl (rcSize, listener, tag ), scrollbar_( NULL ), state_( 0 ), dropDir_( Dropdown ), font_( kSystemFont ), index_( 0 ), indexSel_( 0 ), indexSaved_( 0 ), maxVisible_( 3 ), scrollOffset_( 0 ) { calcMetrics(); CRect rcScrollbar( size.right-WidthButton, size.bottom, size.right, size.bottom+150 ); scrollbar_ = new CScrollbar( rcScrollbar, this, 0, CScrollbar::kVertical, CRect( 0,0,0,0 )); setWantsFocus( true ); setBackgroundColor( kWhiteCColor ); setFrameColor( kBlackCColor ); setTextColor( kBlackCColor ); setSelectionColor( colOrange ); }
std::pair<std::vector<double>, std::vector<double> > & operator()(const std::vector<double> & real_decision_vars, const std::vector<int> & int_decision_vars, boost::filesystem::path save_path) { if (!boost::filesystem::exists(save_path)) boost::filesystem::create_directory(save_path); std::string filename = "logWorker" + std::to_string(evaluator_id) + "_EvalNo" + std::to_string(eval_count) + "_" + boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()) + ".log"; boost::filesystem::path debug_log_file_name = save_dir / filename; std::ofstream logging_file; if (is_logging) { logging_file.open(debug_log_file_name.c_str(), std::ios_base::app); if (!logging_file.is_open()) { is_logging = false; std::cout << "attempt to log failed\n"; } } boost::filesystem::path objectives_file = save_path / "metrics_for_each_replicate.txt"; std::ofstream objectives_fs(objectives_file.c_str()); std::vector<double> & obj = objectives_and_constrataints.first; obj[0] = 0; obj[1] = 0; for (int j = 0; j < replicates; ++j) { std::pair<double, double> metric_vals = calcMetrics(worker_dir, real_decision_vars, int_decision_vars, is_logging, logging_file, debug_log_file_name, j); double fks = metric_vals.first; double clump = metric_vals.second; objectives_fs << "replicate " << j << " fks: " << fks << " clumpiness: " << clump << "\n"; obj[0] += fks; obj[1] += clump; boost::filesystem::path save_replicate_path = save_path / ("replicate_" + std::to_string(j)); // if (!boost::filesystem::exists(save_replicate_path)) boost::filesystem::create_directory(save_replicate_path); if (boost::filesystem::exists(save_replicate_path)) boost::filesystem::remove_all(save_replicate_path); copyDir(worker_dir, save_replicate_path); boost::filesystem::path output_map = worker_dir / "Log" / "Land_use" / "Land use map_2000-Jan-01 00_00_00.rst"; if (boost::filesystem::exists(output_map)) { boost::filesystem::path png_path = save_path / ("replicate_" + std::to_string(j) + ".png"); blink::raster::gdal_raster<int> out_raster = blink::raster::open_gdal_raster<int>(output_map, GA_ReadOnly); blink::raster::printRaster2PNG(out_raster, colour_mapper, png_path); } } obj[0] /= replicates; obj[1] /= replicates; ++eval_count; if (is_logging) logging_file << "\n\n\n FKS: " << obj[0] << "\n Average Clump Diff: " << obj[1] << "\n"; if (is_logging) logging_file.close(); // boost::filesystem::remove_all(previous_log_file); // previous_log_file = debug_log_file_name; return (objectives_and_constrataints); }