void global_settings_io::import_settings(const std::string& file_path)
{
  YAML::Node node;
  try
  {
    node = YAML::LoadFile(file_path);
    settings_file_name_ = file_path;
  }
  catch(YAML::Exception& e)
  {
    LOG(logger::error, std::string("Failed to load global settings file from \"") + file_path + "\".\n\tError: " + e.what());
    return;
  }
  check_input_validity(node);
  settings_.set_results_dir(node[gsc::results_dir].as<std::string>());
  settings_.set_generation_dir(node[gsc::generation_dir].as<std::string>());
  settings_.set_excitation_file_name(node[gsc::excitation_file_name].as<std::string>());
  settings_.set_relaxation_file_name(node[gsc::relaxation_file_name].as<std::string>());
  settings_.set_trajectory_file_name(node[gsc::trajectory_file_name].as<std::string>());
  settings_.set_eigens_file_name(node[gsc::eigens_file_name].as<std::string>());
  settings_.set_nodes_file_name(node[gsc::nodes_file_name].as<std::string>());
  settings_.set_dump_data(node[gsc::dump_data].as<bool>());
  settings_.set_dump_step(node[gsc::dump_step].as<std::size_t>());
  settings_.set_relaxation_time_limit(node[gsc::relaxation_time_limit].as<std::size_t>());
  stabilization_spec spec(node[gsc::ss::self][gsc::ss::epsilon].as<double>(), node[gsc::ss::self][gsc::ss::step_count].as<std::size_t>());
  settings_.set_stabilization_spec(spec);
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {

	int validity_code = check_input_validity(argc, argv);

	if (validity_code) {

		print_usage(argv[0]);
		return validity_code;

	}

	download_instance* thz = new_instance(argc, argv);
	int ret_code = run_instance(thz);

	tear_down_instance(thz);

	return ret_code;

}
Exemplo n.º 3
0
main(){
    get_input();
    check_input_validity();
    printf("LCM = %d", LCM(n, m));
    getch();
}
Exemplo n.º 4
0
void test_union(std::string const& caseid, G1 const& g1, G2 const& g2,
                int expected_count, int expected_hole_count,
                int expected_point_count, double expected_area,
                ut_settings const& settings)
{
    typedef typename bg::coordinate_type<G1>::type coordinate_type;
    boost::ignore_unused<coordinate_type>();
    boost::ignore_unused(expected_point_count);

    // Declare output (vector of rings or multi_polygon)
    typedef typename setop_output_type<OutputType>::type result_type;
    result_type clip;

#if defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS)
    std::cout << "*** UNION " << caseid << std::endl;
#endif

#if defined(BOOST_GEOMETRY_TEST_CHECK_VALID_INPUT)
    check_input_validity(caseid, 0, g1);
    check_input_validity(caseid, 1, g2);
#endif

    bg::union_(g1, g2, clip);

    typename bg::default_area_result<OutputType>::type area = 0;
    std::size_t n = 0;
    std::size_t holes = 0;
    for (typename result_type::iterator it = clip.begin();
            it != clip.end(); ++it)
    {
        area += bg::area(*it);
        holes += bg::num_interior_rings(*it);
        n += bg::num_points(*it, true);

        if (settings.test_validity)
        {
            // Check validity (currently on separate clips only)
            // std::cout << bg::dsv(*it) << std::endl;
            std::string message;
            bool const valid = bg::is_valid(*it, message);
            BOOST_CHECK_MESSAGE(valid,
                                "union: " << caseid << " not valid " << message);
        }
    }


#if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
    {
        // Test inserter functionality
        // Test if inserter returns output-iterator (using Boost.Range copy)
        result_type inserted, array_with_one_empty_geometry;
        array_with_one_empty_geometry.push_back(OutputType());
        boost::copy(array_with_one_empty_geometry, bg::detail::union_::union_insert<OutputType>(g1, g2, std::back_inserter(inserted)));

        typename bg::default_area_result<OutputType>::type area_inserted = 0;
        int index = 0;
        for (typename result_type::iterator it = inserted.begin();
                it != inserted.end();
                ++it, ++index)
        {
            // Skip the empty polygon created above to avoid the empty_input_exception
            if (! bg::is_empty(*it))
            {
                area_inserted += bg::area(*it);
            }
        }
        BOOST_CHECK_EQUAL(boost::size(clip), boost::size(inserted) - 1);
        BOOST_CHECK_CLOSE(area_inserted, expected_area, settings.percentage);
    }
#endif



#if defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS)
    std::cout << "*** case: " << caseid
              << " area: " << area
              << " points: " << n
              << " polygons: " << boost::size(clip)
              << " holes: " << holes
              << std::endl;
#endif

    BOOST_CHECK_MESSAGE(expected_count < 0 || int(clip.size()) == expected_count,
                        "union: " << caseid
                        << " #clips expected: " << expected_count
                        << " detected: " << clip.size()
                        << " type: " << (type_for_assert_message<G1, G2>())
                       );

    BOOST_CHECK_MESSAGE(expected_hole_count < 0 || int(holes) == expected_hole_count,
                        "union: " << caseid
                        << " #holes expected: " << expected_hole_count
                        << " detected: " << holes
                        << " type: " << (type_for_assert_message<G1, G2>())
                       );

#if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
    BOOST_CHECK_MESSAGE(expected_point_count < 0 || std::abs(int(n) - expected_point_count) < 3,
                        "union: " << caseid
                        << " #points expected: " << expected_point_count
                        << " detected: " << n
                        << " type: " << (type_for_assert_message<G1, G2>())
                       );
#endif

    BOOST_CHECK_CLOSE(area, expected_area, settings.percentage);

#if defined(TEST_WITH_SVG)
    {
        bool const ccw =
            bg::point_order<G1>::value == bg::counterclockwise
            || bg::point_order<G2>::value == bg::counterclockwise;
        bool const open =
            bg::closure<G1>::value == bg::open
            || bg::closure<G2>::value == bg::open;

        std::ostringstream filename;
        filename << "union_"
                 << caseid << "_"
                 << string_from_type<coordinate_type>::name()
                 << (ccw ? "_ccw" : "")
                 << (open ? "_open" : "")
#if defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
                 << "_no_rob"
#endif
                 << ".svg";

        std::ofstream svg(filename.str().c_str());

        bg::svg_mapper
        <
        typename bg::point_type<G2>::type
        > mapper(svg, 500, 500);
        mapper.add(g1);
        mapper.add(g2);

        mapper.map(g1, "fill-opacity:0.5;fill:rgb(153,204,0);"
                   "stroke:rgb(153,204,0);stroke-width:3");
        mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);"
                   "stroke:rgb(51,51,153);stroke-width:3");
        //mapper.map(g1, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");
        //mapper.map(g2, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");

        for (typename result_type::const_iterator it = clip.begin();
                it != clip.end(); ++it)
        {
            mapper.map(*it, "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);"
                       "stroke:rgb(255,0,255);stroke-width:8");
            //mapper.map(*it, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5");
        }
    }
#endif
}
void user_settings_io::import_settings(const std::string& file_path)
{
  YAML::Node node;
  try
  {
    node = YAML::LoadFile(file_path);
    settings_file_name_ = file_path;
  }
  catch(YAML::Exception& e)
  {
    const std::string& error = "Failed to load user settings file from \"" + file_path + "\".\n\tError: " + e.what();
    LOG(logger::critical, error);
    throw std::runtime_error(error);
  }

  /// Check input file structure validity
  check_input_validity(node);

  settings_.set_fs(node[usc::fs].as<double>());
  settings_.set_excitation_time(node[usc::excitation_time].as<std::size_t>());
  settings_.set_excitation_time_step(node[usc::excitation_time_step].as<double>());
  YAML::Node spec_node = node[usc::rtss::self];
  relaxation_time_step_spec spec(spec_node[usc::rtss::initial_step].as<double>(), spec_node[usc::rtss::time_delta].as<std::size_t>(), spec_node[usc::rtss::coefficient].as<double>());
  settings_.set_relaxation_time_step_spec(spec);
  settings_.set_simulations_count(node[usc::simulations_count].as<std::size_t>());

  if(node[usc::force_application_nodes])
  {
    const YAML::Node& force_node = node[usc::force_application_nodes];
    std::vector<std::size_t> nodes;
    for(std::size_t i = 0; i < force_node.size(); ++i)
    {
      std::size_t node = force_node[i].as<std::size_t>();
      nodes.push_back(node);
    }
    settings_.set_force_application_nodes(nodes);
  }
  settings_.set_forces_dynamic(node[usc::forces_dynamic].as<bool>());

  if(node[usc::visualization_nodes])
  {
    const YAML::Node& visualization_node = node[usc::visualization_nodes];
    std::vector<std::size_t> nodes;
    for(std::size_t i = 0; i < visualization_node.size(); ++i)
    {
      std::size_t node = visualization_node[i].as<std::size_t>();
      nodes.push_back(node);
    }
    settings_.set_visualization_nodes(nodes);
  }

  if(node[usc::nodes])
  {
    settings_.set_network(read_network_from_yaml(node));
  }
  else
  {
    std::string absolute_path = node[usc::network_file_path].as<std::string>();
    if(!absolute_path.empty())
    {
      if(absolute_path[0] != '/')
      {
        //This is relative path, need to attach current YAML file's directory to path
        absolute_path.insert(0, file_path.substr(0, file_path.find_last_of("/") + 1));
      }
      network_file_name_ = absolute_path;
      import_network_from_external_file(absolute_path);
    }
  }

  if(node[usc::l0])
  {
    double cutoff = node[usc::l0].as<double>();
    settings_.set_cutoff_distance(cutoff);
    network net = settings_.get_network();
    net.set_cutoff_distance(cutoff);
    settings_.set_network(net);
  }

  std::cout << settings_ << std::endl;
}