在ns-2中的EnergyModule()方法中有参数l1
和l2
,我想知道级别的含义,为什么我们调用它有级别。设定它的目的是什么?
EnergyModel::EnergyModel (
MobileNode * n,
double energy,
double l1,
double l2
)
答案 0 :(得分:1)
L1和L1是用于改变节点颜色相对于能量消耗的值。 double l1 = 0.5; double l2 = 0.2;
if (srcnode) {
if (srcnode->energy_model()) {
energy = srcnode->energy_model()->energy();
initenergy = srcnode->energy_model()->initialenergy();
l1 = srcnode->energy_model()->level1();
l2 = srcnode->energy_model()->level2();
}
}
int energyLevel = 0 ;
double energyLeft = (double)(energy/initenergy) ;
if ((energyLeft <= 1 ) && (energyLeft >= l1 )) energyLevel = 3;
if ((energyLeft >= l2 ) && (energyLeft < l1 )) energyLevel = 2;
if ((energyLeft > 0 ) && (energyLeft < l2 )) energyLevel = 1;
if (energyLevel == 0)
strcpy(colors,"-c black -o red");
else if (energyLevel == 1)
strcpy(colors,"-c red -o yellow");
else if (energyLevel == 2)
strcpy(colors,"-c yellow -o green");
else if (energyLevel == 3)
strcpy(colors,"-c green -o black");