void AlgorithmConfig::init(ParseBlock& block)
{
  // Set the default parameters
  init();

  try {
    if (block.hasProperty("debug")) {
      debug = block("debug").as<bool>();
    }
    if (block.hasProperty("export_solution")) {
      export_solution = block("export_solution").as<bool>();
    }
    if (block.hasProperty("export_catec")) {
      export_catec = block("export_catec").value;
    }
    if (block.hasProperty("export_trajectories")) {
      export_trajectories = block("export_trajectories").as<bool>();
    }
    if (block.hasProperty("solution_filename")) {
      solution_filename = block("solution_filename").value;
    }
    if (block.hasProperty("trajectory_filename")) {
      trajectory_filename = block("trajectory_filename").value;
    }
    if (block.hasProperty("double_geometry")) {
      double_geometry = block("double_geometry").as<std::vector<double> >();
    }
    if (block.hasProperty("geometry_expansion")) {
      geometry_expansion = block("geometry_expansion").as<double>();
    }
  } catch (std::exception &e) {
    std::cerr << "AlgorithmConfig (initializer) --> failed to get the data from block. Content: ";
    std::cerr << e.what() << "\n";
  }
}
void GeneticConfig::init(ParseBlock& block)
{
	Checker *check = getChecker();
	init();
	try {
		block.checkUsing(check);
    resolution::CostConfig::init(block);
		
		

		if (block.hasProperty("initializer_type")) {
			initializer_type = block("initializer_type").value;
		}
		if (block.hasProperty("crossover_type")) {
			crossover_type = block("crossover_type").as<string>();
		}
		if (block.hasProperty("custom_evolution")) {
			custom_evolution = block("custom_evolution").as<bool>();
		}
		
		if (block.hasProperty("mutator_type")) {
			mutator_type = block("mutator_type").as<string>();
		}
		if (block.hasProperty("search_ratio")) {
			search_ratio = block("search_ratio").as<double>();
		}
		
		if (block.hasProperty("max_checks")) {
			max_checks = block("max_checks").as<int>();
		}
		
		if (block.hasProperty("mutation_probability")) {
		  pMutation = block("mutation_probability").as<double>();
		}
		
		if (block.hasProperty("mutation_deviation")) {
		  mutation_dev = block("mutation_deviation").as<double>();
		}
		
		if (block.hasProperty("crossover_probability")) {
		  pCrossover = block("crossover_probability").as<double>();
		}
		
	} catch (std::exception &e) {
		std::cerr << "GeneticConfig::init() --> error while loading data from block\n";
		throw(e);
	}
	delete check;
}
Beispiel #3
0
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;
}
Beispiel #4
0
int main(int argc, char **argv) {
    ArgumentData arg(argc,argv);
    if (argc < 2) {
        cerr << "Use: " << arg.at(0) << "<input_filename>" << endl;
        return 1;
    } else {
      if (arg.isOption("simulation")) {
	UAVFactory fac;
	
	UAV *uav = NULL;
	
	try {
	  ParseBlock block; 
	  block.load(arg.at(1).c_str());
	  uav = fac.create_from_block(block["uav"]);
	} catch (exception &e) {
	  cerr << "main:: Exception while loading data\n";
	}
	
	if (uav != NULL) {
	  cout << uav->toString() << endl;
	  for (int i = 0; i < 100; i++) {
	    uav->actualize();
	  }
	  cout << uav->toString() << endl;
	}
	
	
      } else if (arg.isOption("time-slot")) {
	cout << "Performing time slot testing.\n";
	TimeSlotList list;
	
	double min_dist = 5.0;
	double max_altitude = 250.0;
	try {
	  ParseBlock block; 
	  block.load(arg.at(1).c_str());
	  ParseBlock::Blocks *slots = block.getBlocks("timeslot");
	  
	  if (block.hasProperty("min_dist")) {
	    min_dist = block("min_dist").as<double>();
	  }
	  cout << "Min dist = " << min_dist << endl;
	  
	  if (block.hasProperty("max_altitude")) {
	    max_altitude = block("max_altitude").as<double>();
	  }
	  cout << "Maximum altitude = " << max_altitude << endl;
	  
	  ParseBlock::Blocks::iterator sl = slots->begin();
	  for (;sl != slots->end(); sl++) {
	    TimeSlot s(**sl);
	    cout << "Timeslot loaded: " << s.toString() << endl;
	    list.push_back(s);
	  }
	  
	  
	} catch (exception &e) {
	  cerr << "main:: Exception while loading data\n";
	  exit(1);
	}
	
	
	
	
	// Perform the tests. Check the first with all the other
	TimeSlotList::iterator it = list.begin();
	it++;
	TimeSlot &first = *list.begin();
	cout << "Checking this with all the others. " <<first.toString() << endl;
	for (;it != list.end(); it++) {
	  cout << "With: " << it->toString();
	  if (it->check(first.updraft_id, first.min_time, first.initial_altitude, first.ascending_rate, min_dist, max_altitude, first.uav_id)) {
	    cout << "Passes." << endl;
	  } else {
	   cout << "Fails." << endl; 
	  }
	}
      } else {
	
	URM *urm = NULL;
// 	double sleep_time;
	
	cout << "Performing normal test.\n";
	
	try {
	  ParseBlock data;
	  data.load(arg.at(1).c_str());
    
	  // Get the parameters of URM manager (updrafts, etc.)
	  if (!data.hasBlock("urm")) {
	    cerr << "The data faile has not urm data.\n";
	    exit(1);
	  }
	  urm = new URM(data["urm"]);

// 	  sleep_time = 1.0; // Default sleep time
// 	  if (data.hasProperty("uav_sleep")) {
// 	    sleep_time = data("uav_sleep").as<double>();
// 	  }

	  // Get the UAV data
	  ParseBlock::Blocks *uav_blocks = data.getBlocks("uav");

	  ParseBlock::Blocks::iterator uav_it = uav_blocks->begin();
	  int cont = 0;
// 	  bool error = false;
	  simulator::FlightPlan plan;
	  
	  int n_points = 0;
	  if (arg.isOption("random_wp")) {
	    arg.getOption("random_wp", n_points);
	    
	    for (int i = 0; i < n_points; i++) {
	      functions::RealVector v(2, true);
	      v = v * 1000.0;
	      
	      urm->addWaypoint(v);
	    }
	    
	  }
    
	  for (;uav_it != uav_blocks->end(); uav_it++, cont++) {
	    // Get the UAV parameters
	    UAVFactory fac;
	    UAV *aux = fac.create_from_block(**uav_it);
	    
	    if (!aux) {
	      cerr << "Error while loading UAV " << cont << " data.\n";
	      continue;
	    }
	    
	    aux->id = cont;

	    // Then the planner parameters
      
	    SoaringPlanner *aux_planner = NULL;
      
	    if ((*uav_it)->hasBlock("planner")) {
	      SoaringPlannerFactory fac_planner;
	      aux_planner = fac_planner.createFromBlock( (**uav_it)["planner"] );
	      if (aux_planner != NULL) {
		aux_planner->setURM(urm);
		aux_planner->setUAV(aux);
	      }
	      functions::FormattedTime t0;
	      t0.getTime();
	      if (aux_planner != NULL && aux_planner->execute(plan)) {
		functions::FormattedTime t1;
		t1.getTime();
		cout << "Output flight plan: " << plan.toString() << endl;
		cout << "Expended time: " << t1 - t0 << endl;
		
	      } else {
		cout << "The planner failed.\n";
	      }
	    }
      
	  }
	} catch (exception &e) {
	  cerr << "main:: Exception while loading data\n";
	}
      
	
      }
    }
    
    return 0;
}