Ejemplo n.º 1
0
	inline void forward(std::istream& input_stream, std::ostream& output_stream)
	{
		std::istreambuf_iterator<char> input_begin(input_stream);
		std::istreambuf_iterator<char> input_end;
		std::ostreambuf_iterator<char> output_it(output_stream);
		std::copy(input_begin, input_end, output_it);
	}
Ejemplo n.º 2
0
int main()
 {
    std::string word;
    std::vector<std::string> WordVector;
    std::vector<std::string> ReversedWordVector;

    //Reverse the initial text file
    std::ifstream input_file("TheReverseWordTest.txt", std::ios_base::binary);
    std::ofstream output_file("TheReverseWordTest_reversed.txt", std::ios_base::binary);
    std::istreambuf_iterator<char> input_begin(input_file);
    std::istreambuf_iterator<char> input_end;
    std::ostreambuf_iterator<char> output_begin(output_file);
    std::vector<char> input_data(input_begin, input_end);
    std::reverse_copy(input_data.begin(), input_data.end(), output_begin);
    input_file.close();
    output_file.close();
    
    //Construct a vector of words
    std::ifstream TestFile("TheReverseWordTest.txt");
    while (TestFile >> word) {
        WordVector.push_back(word);
    }
    TestFile.close();
    
    //Construct a vector of reversed words
    std::ifstream ReversedFile("TheReverseWordTest_reversed.txt");
    while (ReversedFile >> word) {
        ReversedWordVector.push_back(word);
    }
    ReversedFile.close();
    
    // Allocate space for intersection
    std::vector<std::string> IntersectionVector;
    // Sort as required by std::set_intersection
    std::sort(WordVector.begin(), WordVector.end());
    std::sort(ReversedWordVector.begin(), ReversedWordVector.end());
    // Compute the set intersection
    std::set_intersection(WordVector.begin(), WordVector.end(), ReversedWordVector.begin(), ReversedWordVector.end(), std::back_inserter(IntersectionVector));
    
    
  
    std::ofstream myfile;
    myfile.open ("uniquepairs.txt");
    

    
    for (std::string n : IntersectionVector)
        myfile<< n << std::endl;
    
    myfile.close();
    return 0;

}
Ejemplo n.º 3
0
int main(int argc, char ** argv)
{
  if (argc < 3) {
    std::cout << "Usage: " << argv[0] << " <no. of cones> <input filename> [<direction-x> <direction-y>]" << std::endl;
    return 1;
  }

  unsigned int k = atoi(argv[1]);
  if (k<2) {
    std::cout << "The number of cones should be larger than 1!" << std::endl;
    return 1;
  }

  // open the file containing the vertex list
  std::ifstream inf(argv[2]);
  if (!inf) {
    std::cout << "Cannot open file " << argv[2] << "!" << std::endl;
    return 1;
  }

  Direction_2 initial_direction;
  if (argc == 3)
    initial_direction = Direction_2(1, 0);  // default initial_direction
  else if (argc == 5)
    initial_direction = Direction_2(atof(argv[3]), atof(argv[4]));
  else {
    std::cout << "Usage: " << argv[0] << " <no. of cones> <input filename> [<direction-x> <direction-y>]" << std::endl;
    return 1;
  }

  // iterators for reading the vertex list file
  std::istream_iterator<Point_2> input_begin( inf );
  std::istream_iterator<Point_2> input_end;

  // initialize the functor
  CGAL::Construct_theta_graph_2<Kernel, Graph> theta(k, initial_direction);
  // create an adjacency_list object
  Graph g;
  // construct the theta graph on the vertex list
  theta(input_begin, input_end, g);

  // obtain the number of vertices in the constructed graph
  boost::graph_traits<Graph>::vertices_size_type n = boost::num_vertices(g);
  // generate gnuplot files for plotting this graph
  std::string file_prefix = "t" + boost::lexical_cast<std::string>(k) + "n" + boost::lexical_cast<std::string>(n);
  CGAL::gnuplot_output_2(g, file_prefix);

  return 0;
}
Ejemplo n.º 4
0
int main(int argc, char ** argv)
{

  if (argc != 3) {
    std::cout << "Usage: " << argv[0] << " <no. of cones> <input filename>" << std::endl;
    return 1;
  }
  unsigned int k = atoi(argv[1]);
  if (k<2) {
    std::cout << "The number of cones should be larger than 1!" << std::endl;
    return 1;
  }
  // open the file containing the vertex list
  std::ifstream inf(argv[2]);
  if (!inf) {
    std::cout << "Cannot open file " << argv[1] << "!" << std::endl;
    return 1;
  }

  // iterators for reading the vertex list file
  std::istream_iterator< Point_2 > input_begin( inf );
  std::istream_iterator< Point_2 > input_end;

  // initialize the functor
  // If the initial direction is omitted, the x-axis will be used
  CGAL::Construct_theta_graph_2<Kernel, Graph> theta(k);
  // create an adjacency_list object
  Graph g;
  // construct the theta graph on the vertex list
  theta(input_begin, input_end, g);

  // select a source vertex for dijkstra's algorithm
  boost::graph_traits<Graph>::vertex_descriptor v0;
  v0 = vertex(0, g);
  std::cout << "The source vertex is: " << g[v0] << std::endl;

  std::cout << "The index of source vertex is: " << v0 << std::endl;

  // calculating edge length in Euclidean distance and store them in the edge property
  boost::graph_traits<Graph>::edge_iterator ei, ei_end;
  for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
    boost::graph_traits<Graph>::edge_descriptor e = *ei;
    boost::graph_traits<Graph>::vertex_descriptor  u = source(e, g);
    boost::graph_traits<Graph>::vertex_descriptor  v = target(e, g);
    const Point_2& pu = g[u];
    const Point_2& pv = g[v];

    double dist = CGAL::sqrt( CGAL::to_double(CGAL::squared_distance(pu,pv)) );
    g[e].euclidean_length = dist;
    std::cout << "Edge (" << g[u] << ", " << g[v] << "): " << dist << std::endl;
  }

  // calculating the distances from v0 to other vertices
  boost::graph_traits<Graph>::vertices_size_type n = num_vertices(g);
  // vector for storing the results
  std::vector<double> distances(n);
  // Calling the Dijkstra's algorithm implementation from boost.
  boost::dijkstra_shortest_paths(g,
                                 v0,
                                 boost::weight_map(get(&Edge_property::euclidean_length, g)).
                                 distance_map(CGAL::make_property_map(distances)) );

  std::cout << "distances are:" << std::endl;
  for (unsigned int i=0; i < n; ++i) {
    std::cout << "distances[" << i << "] = " << distances[i] << ", (x,y)=" << g[vertex(i, g)];
    std::cout << " at Vertex " << i << std::endl;
  }

  return 0;
}