本文整理汇总了C++中TIntV::Swap方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntV::Swap方法的具体用法?C++ TIntV::Swap怎么用?C++ TIntV::Swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIntV
的用法示例。
在下文中一共展示了TIntV::Swap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BurnExpFire
// burn each link independently (forward with FwdBurnProb, backward with BckBurnProb)
void TForestFire::BurnExpFire() {
const double OldFwdBurnProb = FwdBurnProb;
const double OldBckBurnProb = BckBurnProb;
const int NInfect = InfectNIdV.Len();
const TNGraph& G = *Graph;
TIntH BurnedNIdH; // burned nodes
TIntV BurningNIdV = InfectNIdV; // currently burning nodes
TIntV NewBurnedNIdV; // nodes newly burned in current step
bool HasAliveNbrs; // has unburned neighbors
int NBurned = NInfect, NDiedFire=0;
for (int i = 0; i < InfectNIdV.Len(); i++) {
BurnedNIdH.AddDat(InfectNIdV[i]); }
NBurnedTmV.Clr(false); NBurningTmV.Clr(false); NewBurnedTmV.Clr(false);
for (int time = 0; ; time++) {
NewBurnedNIdV.Clr(false);
// for each burning node
for (int node = 0; node < BurningNIdV.Len(); node++) {
const int& BurningNId = BurningNIdV[node];
const TNGraph::TNodeI Node = G.GetNI(BurningNId);
HasAliveNbrs = false;
NDiedFire = 0;
// burn forward links (out-links)
for (int e = 0; e < Node.GetOutDeg(); e++) {
const int OutNId = Node.GetOutNId(e);
if (! BurnedNIdH.IsKey(OutNId)) { // not yet burned
HasAliveNbrs = true;
if (Rnd.GetUniDev() < FwdBurnProb) {
BurnedNIdH.AddDat(OutNId); NewBurnedNIdV.Add(OutNId); NBurned++; }
}
}
// burn backward links (in-links)
if (BckBurnProb > 0.0) {
for (int e = 0; e < Node.GetInDeg(); e++) {
const int InNId = Node.GetInNId(e);
if (! BurnedNIdH.IsKey(InNId)) { // not yet burned
HasAliveNbrs = true;
if (Rnd.GetUniDev() < BckBurnProb) {
BurnedNIdH.AddDat(InNId); NewBurnedNIdV.Add(InNId); NBurned++; }
}
}
}
if (! HasAliveNbrs) { NDiedFire++; }
}
NBurnedTmV.Add(NBurned);
NBurningTmV.Add(BurningNIdV.Len() - NDiedFire);
NewBurnedTmV.Add(NewBurnedNIdV.Len());
//BurningNIdV.AddV(NewBurnedNIdV); // node is burning eternally
BurningNIdV.Swap(NewBurnedNIdV); // node is burning just 1 time step
if (BurningNIdV.Empty()) break;
FwdBurnProb = FwdBurnProb * ProbDecay;
BckBurnProb = BckBurnProb * ProbDecay;
}
BurnedNIdV.Gen(BurnedNIdH.Len(), 0);
for (int i = 0; i < BurnedNIdH.Len(); i++) {
BurnedNIdV.Add(BurnedNIdH.GetKey(i)); }
FwdBurnProb = OldFwdBurnProb;
BckBurnProb = OldBckBurnProb;
}
示例2: BurnGeoFire
// Node selects N~geometric(1.0-FwdBurnProb)-1 out-links and burns them. Then same for in-links.
// geometirc(p) has mean 1/(p), so for given FwdBurnProb, we burn 1/(1-FwdBurnProb)
void TForestFire::BurnGeoFire() {
const double OldFwdBurnProb = FwdBurnProb;
const double OldBckBurnProb = BckBurnProb;
const int& NInfect = InfectNIdV.Len();
const TNGraph& G = *Graph;
TIntH BurnedNIdH; // burned nodes
TIntV BurningNIdV = InfectNIdV; // currently burning nodes
TIntV NewBurnedNIdV; // nodes newly burned in current step
bool HasAliveInNbrs, HasAliveOutNbrs; // has unburned neighbors
TIntV AliveNIdV; // NIds of alive neighbors
int NBurned = NInfect, time;
for (int i = 0; i < InfectNIdV.Len(); i++) {
BurnedNIdH.AddDat(InfectNIdV[i]);
}
NBurnedTmV.Clr(false); NBurningTmV.Clr(false); NewBurnedTmV.Clr(false);
for (time = 0;; time++) {
NewBurnedNIdV.Clr(false);
for (int node = 0; node < BurningNIdV.Len(); node++) {
const int& BurningNId = BurningNIdV[node];
const TNGraph::TNodeI Node = G.GetNI(BurningNId);
// find unburned links
HasAliveOutNbrs = false;
AliveNIdV.Clr(false); // unburned links
for (int e = 0; e < Node.GetOutDeg(); e++) {
const int OutNId = Node.GetOutNId(e);
if (!BurnedNIdH.IsKey(OutNId)) {
HasAliveOutNbrs = true; AliveNIdV.Add(OutNId);
}
}
// number of links to burn (geometric coin). Can also burn 0 links
const int BurnNFwdLinks = Rnd.GetGeoDev(1.0 - FwdBurnProb) - 1;
if (HasAliveOutNbrs && BurnNFwdLinks > 0) {
AliveNIdV.Shuffle(Rnd);
for (int i = 0; i < TMath::Mn(BurnNFwdLinks, AliveNIdV.Len()); i++) {
BurnedNIdH.AddDat(AliveNIdV[i]);
NewBurnedNIdV.Add(AliveNIdV[i]); NBurned++;
}
}
// backward links
if (BckBurnProb > 0.0) {
// find unburned links
HasAliveInNbrs = false;
AliveNIdV.Clr(false);
for (int e = 0; e < Node.GetInDeg(); e++) {
const int InNId = Node.GetInNId(e);
if (!BurnedNIdH.IsKey(InNId)) {
HasAliveInNbrs = true; AliveNIdV.Add(InNId);
}
}
// number of links to burn (geometric coin). Can also burn 0 links
const int BurnNBckLinks = Rnd.GetGeoDev(1.0 - BckBurnProb) - 1;
if (HasAliveInNbrs && BurnNBckLinks > 0) {
AliveNIdV.Shuffle(Rnd);
for (int i = 0; i < TMath::Mn(BurnNBckLinks, AliveNIdV.Len()); i++) {
BurnedNIdH.AddDat(AliveNIdV[i]);
NewBurnedNIdV.Add(AliveNIdV[i]); NBurned++;
}
}
}
}
NBurnedTmV.Add(NBurned); NBurningTmV.Add(BurningNIdV.Len()); NewBurnedTmV.Add(NewBurnedNIdV.Len());
// BurningNIdV.AddV(NewBurnedNIdV); // node is burning eternally
BurningNIdV.Swap(NewBurnedNIdV); // node is burning just 1 time step
if (BurningNIdV.Empty()) break;
FwdBurnProb = FwdBurnProb * ProbDecay;
BckBurnProb = BckBurnProb * ProbDecay;
}
BurnedNIdV.Gen(BurnedNIdH.Len(), 0);
for (int i = 0; i < BurnedNIdH.Len(); i++) {
BurnedNIdV.Add(BurnedNIdH.GetKey(i));
}
FwdBurnProb = OldFwdBurnProb;
BckBurnProb = OldBckBurnProb;
}