Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns::RandomGateQMap Class Referencefinal

QMap that samples one gate from a weighted distribution and applies it. More...

#include <q2ns-qmap.h>

Inheritance diagram for q2ns::RandomGateQMap:
Collaboration diagram for q2ns::RandomGateQMap:

Public Member Functions

void SetDistribution (std::vector< QGate > gates, std::vector< double > weights)
 Replace the weighted gate distribution.
 
void AddGate (const QGate &gate, double weight)
 Append one weighted gate to the distribution.
 
void Clear ()
 Clear the weighted gate distribution.
 
QMapInstance Sample (ns3::Ptr< ns3::UniformRandomVariable > u, const QMapContext &ctx=QMapContext{}) const override
 Sample a per-transmission QMapInstance.
 
- Public Member Functions inherited from q2ns::QMap
 ~QMap () override=default
 Virtual destructor.
 

Static Public Member Functions

static ns3::TypeId GetTypeId ()
 Get the ns-3 TypeId.
 
- Static Public Member Functions inherited from q2ns::QMap
static ns3::TypeId GetTypeId ()
 Get the ns-3 TypeId.
 
static ns3::Ptr< QMapCompose (const ns3::Ptr< QMap > &a, const ns3::Ptr< QMap > &b)
 Compose two QMaps into one sequential composite QMap.
 
static ns3::Ptr< QMapCompose (const std::vector< ns3::Ptr< QMap > > &maps)
 Compose a sequence of QMaps into one sequential composite QMap.
 
static ns3::Ptr< QMapFromLambda (std::function< void(QNode &, std::shared_ptr< Qubit > &)> f)
 Build a QMap from a simple lambda.
 
static ns3::Ptr< QMapFromLambda (std::function< void(QNode &, std::shared_ptr< Qubit > &, ns3::Ptr< ns3::UniformRandomVariable >, const QMapContext &)> f)
 Build a QMap from an advanced lambda.
 
static double RateToProb (double rate_per_s, const ns3::Time &t)
 Convert a Poisson rate and elapsed time into an event probability.
 

Private Member Functions

std::size_t PickIndex_ (ns3::Ptr< ns3::UniformRandomVariable > u) const
 Pick one gate index from the configured weighted distribution.
 

Private Attributes

std::vector< QGategates_
 Candidate gates.
 
std::vector< double > weights_
 Selection weights.
 
double totalWeight_ = 0.0
 Sum of all selection weights.
 

Additional Inherited Members

- Protected Member Functions inherited from q2ns::QMap
double GetProb_ (const QMapContext &ctx) const
 Return the effective application probability for this transmission.
 
bool Bernoulli_ (ns3::Ptr< ns3::UniformRandomVariable > u, const QMapContext &ctx) const
 Perform one Bernoulli trial using the effective probability.
 
- Static Protected Member Functions inherited from q2ns::QMap
static void SetLost_ (Qubit &q)
 Mark a qubit lost through the standard registry-backed location path.
 
- Protected Attributes inherited from q2ns::QMap
double p_ = 0.0
 Direct per-transmission probability.
 
double rate_ = 0.0
 Poisson event rate in 1/s. Overrides p_ when positive.
 

Detailed Description

QMap that samples one gate from a weighted distribution and applies it.

The sampled gate is chosen once per transmission. As with other probabilistic QMaps, the overall application event may itself be gated by Probability or Rate.

Definition at line 404 of file q2ns-qmap.h.

Member Function Documentation

◆ AddGate()

void q2ns::RandomGateQMap::AddGate ( const QGate gate,
double  weight 
)

Append one weighted gate to the distribution.

Parameters
gateGate to add.
weightNon-negative selection weight.

Definition at line 354 of file q2ns-qmap.cc.

◆ Clear()

void q2ns::RandomGateQMap::Clear ( )

Clear the weighted gate distribution.

Definition at line 346 of file q2ns-qmap.cc.

References gates_, totalWeight_, and weights_.

◆ GetTypeId()

ns3::TypeId q2ns::RandomGateQMap::GetTypeId ( )
static

Get the ns-3 TypeId.

Returns
TypeId for q2ns::RandomGateQMap.

Definition at line 336 of file q2ns-qmap.cc.

◆ PickIndex_()

std::size_t q2ns::RandomGateQMap::PickIndex_ ( ns3::Ptr< ns3::UniformRandomVariable >  u) const
private

Pick one gate index from the configured weighted distribution.

Parameters
uUniform random source.
Returns
Selected gate index.

Definition at line 379 of file q2ns-qmap.cc.

◆ Sample()

QMapInstance q2ns::RandomGateQMap::Sample ( ns3::Ptr< ns3::UniformRandomVariable >  u,
const QMapContext ctx = QMapContext{} 
) const
overridevirtual

Sample a per-transmission QMapInstance.

Parameters
uUniform random source.
ctxPer-transmission context.
Returns
Sampled random-gate instance.

Implements q2ns::QMap.

Definition at line 396 of file q2ns-qmap.cc.

◆ SetDistribution()

void q2ns::RandomGateQMap::SetDistribution ( std::vector< QGate gates,
std::vector< double >  weights 
)

Replace the weighted gate distribution.

Parameters
gatesCandidate gates.
weightsNon-negative weights associated with the gates.

Definition at line 363 of file q2ns-qmap.cc.

Member Data Documentation

◆ gates_

std::vector<QGate> q2ns::RandomGateQMap::gates_
private

Candidate gates.

Definition at line 448 of file q2ns-qmap.h.

Referenced by Clear().

◆ totalWeight_

double q2ns::RandomGateQMap::totalWeight_ = 0.0
private

Sum of all selection weights.

Definition at line 450 of file q2ns-qmap.h.

Referenced by Clear().

◆ weights_

std::vector<double> q2ns::RandomGateQMap::weights_
private

Selection weights.

Definition at line 449 of file q2ns-qmap.h.

Referenced by Clear().


The documentation for this class was generated from the following files: