Ejemplo n.º 1
0
/**
 * Loads the region type from a YAML file.
 * @param node YAML node.
 */
void RuleRegion::load(const YAML::Node &node)
{
	_type = node["type"].as<std::string>(_type);
	_cost = node["cost"].as<int>(_cost);
	std::vector< std::vector<double> > areas;
	areas = node["areas"].as< std::vector< std::vector<double> > >(areas);
	for (size_t i = 0; i != areas.size(); ++i)
	{
		_lonMin.push_back(areas[i][0] * M_PI / 180);
		_lonMax.push_back(areas[i][1] * M_PI / 180);
		_latMin.push_back(areas[i][2] * M_PI / 180);
		_latMax.push_back(areas[i][3] * M_PI / 180);
	}
	if (const YAML::Node &cities = node["cities"])
	{
		for (YAML::const_iterator i = cities.begin(); i != cities.end(); ++i)
		{
			City *rule = new City("", 0.0, 0.0);
			rule->load(*i);
			_cities.push_back(rule);
		}
	}
	if (const YAML::Node &weights = node["missionWeights"])
	{
		_missionWeights.load(weights);
	}
	_regionWeight = node["regionWeight"].as<unsigned>(_regionWeight);
	_missionZones = node["missionZones"].as< std::vector<MissionZone> >(_missionZones);
	_missionRegion = node["missionRegion"].as<std::string>(_missionRegion);
}
Ejemplo n.º 2
0
/**
 * Loads the region type from a YAML file.
 * @param node YAML node.
 */
void RuleRegion::load(const YAML::Node &node)
{
	_type = node["type"].as<std::string>(_type);
	_cost = node["cost"].as<int>(_cost);
	std::vector< std::vector<double> > areas;
	areas = node["areas"].as< std::vector< std::vector<double> > >(areas);
	for (size_t i = 0; i != areas.size(); ++i)
	{
		_lonMin.push_back(areas[i][0] * M_PI / 180.0);
		_lonMax.push_back(areas[i][1] * M_PI / 180.0);
		_latMin.push_back(areas[i][2] * M_PI / 180.0);
		_latMax.push_back(areas[i][3] * M_PI / 180.0);
	}
	_missionZones = node["missionZones"].as< std::vector<MissionZone> >(_missionZones);
	if (const YAML::Node &cities = node["cities"])
	{
		for (YAML::const_iterator i = cities.begin(); i != cities.end(); ++i)
		{
			// if a city has been added, make sure that it has a zone 3 associated with it, if not, create one for it.
			if (_missionZones.size() >= CITY_MISSION_ZONE)
			{
				MissionArea ma;
				ma.lonMin = ma.lonMax = (*i)["lon"].as<double>(0.0);
				ma.latMin = ma.latMax = (*i)["lat"].as<double>(0.0);
				if (std::find(_missionZones.at(CITY_MISSION_ZONE).areas.begin(),
					_missionZones.at(CITY_MISSION_ZONE).areas.end(),
					ma)	== _missionZones.at(CITY_MISSION_ZONE).areas.end())
				{
					_missionZones.at(CITY_MISSION_ZONE).areas.push_back(ma);
				}
			}

			City *rule = new City("", 0.0, 0.0);
			rule->load(*i);
			_cities.push_back(rule);
		}
		// make sure all the zone 3s line up with cities in this region
		// only applicable if there ARE cities in this region.
		for (std::vector<MissionArea>::iterator i = _missionZones.at(CITY_MISSION_ZONE).areas.begin(); i != _missionZones.at(CITY_MISSION_ZONE).areas.end();)
		{
			bool matching = false;
			for (std::vector<City*>::iterator j = _cities.begin(); j != _cities.end() && !matching; ++j)
			{
				matching = (AreSame((*j)->getLatitude(), ((*i).latMin * M_PI / 180.0)) &&
							AreSame((*j)->getLongitude(), ((*i).lonMin * M_PI / 180.0)) &&
							AreSame((*i).latMax, (*i).latMin) &&
							AreSame((*i).lonMax, (*i).lonMin));
			}
			if (matching)
			{
				++i;
			}
			else
			{
				i = _missionZones.at(CITY_MISSION_ZONE).areas.erase(i);
			}
		}
	}
	if (const YAML::Node &weights = node["missionWeights"])
	{
		_missionWeights.load(weights);
	}
	_regionWeight = node["regionWeight"].as<size_t>(_regionWeight);
	_missionRegion = node["missionRegion"].as<std::string>(_missionRegion);
}