Esempio n. 1
0
int main() {

  auto g = get_directory_generator(".");
  {
	  auto g2 = get_directory_generator(".");
  }

  std::vector<std::string> vgen(g.begin(), g.end());

  // Verify that we did the right thing by also checking using Filesystem TS
  // recursive_directory_iterator

  std::experimental::filesystem::recursive_directory_iterator begin{"."};
  std::vector<std::string> vrdi;

  for (auto &e : begin) {
    vrdi.push_back(e.path().string());
  }

  std::sort(vgen.begin(), vgen.end());
  std::sort(vrdi.begin(), vrdi.end());

  std::cout << "Generator matches recursive_directory_iterator = "
            << std::boolalpha
            << std::equal(vgen.begin(), vgen.end(), vrdi.begin(), vrdi.end())            << "\n";
}
bool do_test(int n, int max) {
    std::cout << "running piecewise_constant(p0, p1, ..., p" << n-1 << ")" << " " << max << " times: " << std::flush;

    std::vector<double> weights;
    {
        boost::mt19937 egen;
        for(int i = 0; i < n; ++i) {
            weights.push_back(egen());
        }
    }
    std::vector<double> intervals;
    for(int i = 0; i <= n; ++i) {
        intervals.push_back(i);
    }

    piecewise_constant expected(intervals, weights);
    
    boost::random::piecewise_constant_distribution<> dist(intervals, weights);
    boost::mt19937 gen;
    kolmogorov_experiment test(max);
    boost::variate_generator<boost::mt19937&, boost::random::piecewise_constant_distribution<> > vgen(gen, dist);

    double prob = test.probability(test.run(vgen, expected));

    bool result = prob < 0.99;
    const char* err = result? "" : "*";
    std::cout << std::setprecision(17) << prob << err << std::endl;

    std::cout << std::setprecision(6);

    return result;
}
Esempio n. 3
0
	std::set<port_index_type> switch_::get_targets_for(port_index_type index, boost::asio::const_buffer data)
	{
		const port_list_type::iterator source_port_entry = m_ports.find(index);

		if (source_port_entry != m_ports.end())
		{
			switch (m_configuration.routing_method)
			{
				case switch_configuration::RM_HUB:
				{
					return get_targets_for(source_port_entry);
				}
				case switch_configuration::RM_SWITCH:
				{
					asiotap::osi::const_helper<asiotap::osi::ethernet_frame> ethernet_helper(data);

					const ethernet_address_type target_address = to_ethernet_address(ethernet_helper.target());

					if (is_multicast_address(target_address))
					{
						return get_targets_for(source_port_entry);
					}
					else
					{
						m_ethernet_address_map[to_ethernet_address(ethernet_helper.sender())] = index;

						// We exceeded the maximum count for entries: we delete random entries to fix it.
						while (m_ethernet_address_map.size() > m_max_entries)
						{
							ethernet_address_map_type::iterator entry = m_ethernet_address_map.begin();

#if BOOST_VERSION >= 104700
							boost::random::mt19937 gen;

							std::advance(entry, boost::random::uniform_int_distribution<>(0, static_cast<int>(m_ethernet_address_map.size()) - 1)(gen));
#else
							boost::mt19937 gen;

							boost::variate_generator<boost::mt19937&, boost::uniform_int<> > vgen(gen, boost::uniform_int<>(0, m_ethernet_address_map.size() - 1));
							std::advance(entry, vgen());
#endif

							m_ethernet_address_map.erase(entry);
						}

						// We look in the ethernet address map

						const ethernet_address_map_type::iterator target_entry = m_ethernet_address_map.find(target_address);

						if (target_entry == m_ethernet_address_map.end())
						{
							// No target entry: we send the message to everybody.
							return get_targets_for(source_port_entry);
						}

						const port_index_type target_port_index = target_entry->second;

						if (!is_registered(target_port_index))
						{
							// The port does not exist: we delete the entry and send to everybody.
							m_ethernet_address_map.erase(target_entry);

							return get_targets_for(source_port_entry);
						}

						std::set<port_index_type> targets;

						targets.insert(target_port_index);

						return targets;
					}
				}
			}
		}

		return std::set<port_index_type>();
	}
bool do_test(std::vector<double> const& probabilities,
             std::vector<double> const& rates,
             long long max,
             boost::mt19937& gen)
{
    std::cout << "running hyperexponential(probabilities,rates) " << max << " times: " << std::flush;

    boost::math::hyperexponential_distribution<> expected(probabilities, rates);

    boost::random::hyperexponential_distribution<> dist(probabilities, rates);

    kolmogorov_experiment test(boost::numeric_cast<int>(max));
    boost::variate_generator<boost::mt19937&, boost::random::hyperexponential_distribution<> > vgen(gen, dist);

    const double prob = test.probability(test.run(vgen, expected));

    const bool result = prob < BOOST_RANDOM_P_CUTOFF;
    const char* err = result? "" : "*";
    std::cout << std::setprecision(17) << prob << err << std::endl;

    std::cout << std::setprecision(6);

    return result;
}