void CostConfig::init(ParseBlock& block) { Checker *check = getConfigChecker(); try { resolution::AlgorithmConfig::init(block); // Cost parameters distance_cost = block["cost"]("distance").as<double>(); collision_penalty = block["cost"]("collision_penalty").as<double>(); // Sampling parameters population = block("population").as<int>(); generations = block("generations").as<int>(); if (block.hasProperty("max_time")) { max_time = block("max_time").as<double>(); } else { max_time = -1.0; } waypoint_dimension = block("waypoint_dimension").as<int>(); intermediate_waypoints = block("intermediate_waypoints").as<int>(); if (block.hasProperty("altitude_levels")) { altitude_levels = block("altitude_levels").as<bool>(); } if (block.hasProperty("altitude_step")) { altitude_step = block("altitude_step").as<double>(); } if (block.hasProperty("export_evolution")) { export_evolution = block("export_evolution").as<bool>(); if (export_evolution && block.hasProperty("evolution_filename")) { evolution_file = block("evolution_filename").as<string>(); } else { export_evolution = false; } } if (block.hasProperty("cost_type")) { objective_type = block("cost_type").as<string>(); } if (block.hasProperty("time_exploration")) { time_exploration = block("time_exploration").as<bool>(); } if (block.hasProperty("time_exploration_type")) { time_exploration_type = static_cast<resolution::TimeExplorationTypes>(block("time_exploration_type").as<int>()); } if (block.hasProperty("init_time")) { std::vector<double> v; v = block("init_time").as<std::vector<double> >(); long usec = 0; if (v.size() > 1) { usec = v.at(1); } init_time.setTime(v.at(0), usec); } else { init_time.getTime(); } // Bounds upper_bounds = block["bounds"]("upper").as<std::vector<double> >(); lower_bounds = block["bounds"]("lower").as<std::vector<double> >(); if (block["bounds"].hasProperty("speed_bounds")) { speed_bounds = block["bounds"]("speed").as<std::vector<double> >(); } else { speed_bounds = upper_bounds; } if (block.hasProperty("modify_trajectory")) { modify_trajectory = block("modify_trajectory").as<bool>(); } if (block.hasProperty("min_control_dist")) { min_control_dist = block("min_control_dist").as<double>(); } if (block.hasProperty("best_individual")) { best_individual = block("best_individual").as<string>(); } if (block.hasProperty("initial_solution")) { ParseBlock::Properties *iss = block.getProperties("initial_solution"); ParseBlock::Properties::iterator it = iss->begin(); for (;it != iss->end(); it++) { std::vector <double> v = (*it)->as<std::vector<double> >(); functions::RealVector aux(v); initial_solution.push_back(v); } } if (block.hasProperty("export_all_evolution")) { export_all_evolution = true; } if (block.hasProperty("manoeuvre_selection")) { manoeuvre_selection = block("manoeuvre_selection").as<bool>(); } else { manoeuvre_selection = false; // default value } if (block.hasProperty("min_z")) { min_z = block("min_z").as<double>(); } else { min_z = 0.0; } if (block.hasProperty("max_z")) { max_z = block("max_z").as<double>(); } else { max_z = 2.0; } if (block.hasProperty("max_course")) { max_course = block("max_course").as<double>(); } else { max_course = 1.0; } } catch (std::runtime_error &e) { std::cerr << "CostConfig::init --> Exception while reading data from block. Content: " << e.what()<< "\n"; throw(e); } delete check; }