示例#1
0
int main(int argc, char* argv[]) {
  try {
    if (argc != 2) {
      std::cerr << "Usage: client <host>" << std::endl;
      return 1;
    }

    boost::asio::io_service io_service;

    boost::asio::ip::udp::resolver resolver(io_service);
    boost::asio::ip::udp::resolver::query query(
        boost::asio::ip::udp::v4(),
        argv[1],
        "7000");
    boost::asio::ip::udp::endpoint receiver_endpoint = *resolver.resolve(query);

    boost::asio::ip::udp::socket socket(io_service);
    socket.open(boost::asio::ip::udp::v4());

    while (true) {
      std::string str = generate_random_node();
      socket.send_to(boost::asio::buffer(str), receiver_endpoint);
      //std::this_thread::sleep_for(std::chrono::milliseconds(1));
    }

  } catch (std::exception& e) {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}
示例#2
0
std::string generate_random_node(int deep = 2) {
  std::string str;
  str += "{";
  do {
    // Generate key
    str += generate_random_value();
    str += ":";
    // Generate value
    str +=
        dis(gen) % deep == 0 ?
            generate_random_node(deep + 1) : generate_random_value();
    str += ",";
  } while (dis(gen) % 3 == 0);
  str.pop_back();
  str += "}";
  return str;
}
示例#3
0
Node NField::generate_node(const std::vector<cv::Mat_<float> >& img,
                   	   const cv::Mat_<uchar>& mask, 
			   std::vector<Pixel>& pixels) {

	std::vector<Node> nodes;
	for (int i = 0; i < 100 ; ++i) {
 	   Node node = generate_random_node();
    	   nodes.push_back(node);
  	}
  
  	double tmp_entropy = 1.0;  
  	int node_th;
  	for (size_t j = 0; j < nodes.size(); ++j) {
    	  double current_entropy = compute_entropy(nodes[j], pixels, img);
    	  if (tmp_entropy >= current_entropy) {
      		tmp_entropy = current_entropy;
                node_th = j;
    	  }
  	}

  return nodes[node_th];
}