如何随机制作链

发布于 2025-02-08 17:03:06 字数 809 浏览 3 评论 0原文

我正在根据文章实施模型。但是有一个我不知道的段落,我该怎么办?该段落说:

A flow f ∈ F is a sequence of 
data packets that are
generated at expected rate λf 
and sent from a source to a
destination node, traversing a 
sequence of intermediate nodes
and links in the network. Each 
flow f has a specified service
chain of NFs, denoted as
→S [f] = (S[1][f], S[2]. 
[f],..., S[J[f]][f]), which 
is an ordered sequence of 
required NFs that the flow’s 
packets must go through, 
where S[j][f] ∈ V denotes the 
j-th NF on flow f’s service 
chain and Jf := |→S [f] | is 
the length of the NF chain
of flow f.

我的代码中有这些信息:

int F = 50;
Nuflow = 1..F;
int V = 5;
Nuvnf = 1..V;

我知道λf按日志正常计算,平均速率为0.5,每个流的服务链的长度都在2至4 nfs的范围内变化,而服务类型则在每个流的链条都是随机选择的。 我是CPLEX的新手,我不知道如何为该参数编写代码。你能帮助我吗?非常感谢。

I'm implementing a model based on an article. But there is a paragraph that I don't know, what should I do? That paragraph says :

A flow f ∈ F is a sequence of 
data packets that are
generated at expected rate λf 
and sent from a source to a
destination node, traversing a 
sequence of intermediate nodes
and links in the network. Each 
flow f has a specified service
chain of NFs, denoted as
→S [f] = (S[1][f], S[2]. 
[f],..., S[J[f]][f]), which 
is an ordered sequence of 
required NFs that the flow’s 
packets must go through, 
where S[j][f] ∈ V denotes the 
j-th NF on flow f’s service 
chain and Jf := |→S [f] | is 
the length of the NF chain
of flow f.

I have these information in my code:

int F = 50;
Nuflow = 1..F;
int V = 5;
Nuvnf = 1..V;

I know λf calculate with log normal with average rate 0.5 and the length of the service chain for each flow is assumed to vary in the range of 2 to 4 NFs and the service types in the chain for each flow are selected randomly.
I am new in cplex and I don't know how to write code for that parameters. Can you help me? Thanks so much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2025-02-15 17:03:06

请参阅 httpps :/ https :/ https:/ 。在OPL中获得正态分布的两种方法。

int n=10000;
range r=1..n;

int m=10;
int M=21;

// uniform distribution

// choose randomly n numbers between 0 and M-1 bounds included
int random1[i in r]=rand(M);

float av1=1/n*sum(i in r)random1[i];

// choose randomly n numbers between m and M-1 bounds included
int random2[i in r]=m+rand(M-m);

float av2=1/n*sum(i in r)random2[i];

// choose randomly n float numbers between 0 and 1, 1 excluded
float random3[i in r]=rand(maxint)/maxint;

float av3=1/n*sum(i in r)random3[i];

// normal distribution through Box–Muller transform
int BIG=1000000;
float x[i in r]=-1+2*rand(BIG)/BIG;
float y[i in r]=-1+2*rand(BIG)/BIG;;
 
float w[i in r]=sqrt(x[i]*x[i]+y[i]*y[i]);
{int} subsetr={i | i in r:w[i]<=1};

float w2[i in subsetr]=(-2*ln(w[i])/w[i]);
float x2[i in subsetr]=x[i]*w2[i];
float y2[i in subsetr]=y[i]*w2[i];

// the values of x2 and y2  obey a normal distribution

float avx2=1/card(subsetr)*sum(i in subsetr) x2[i];
float avy2=1/card(subsetr)*sum(i in subsetr) y2[i];

float stddevx2=sqrt( 1/card(subsetr)*sum(i in subsetr) pow(x2[i]-avx2,2));
float stddevy2=sqrt( 1/card(subsetr)*sum(i in subsetr) pow(y2[i]-avy2,2));

execute
{
  writeln("av1 = ",av1);
  writeln("av2 = ",av2);
  writeln("av3 = ",av3);
  writeln("avx2 = ",avx2);
  writeln("avy2 = ",avy2);
  writeln("stddevx2 = ",stddevx2);
  writeln("stddevy2 = ",stddevy2);
}

// We can do the same by calling java from OPL

int N=100000;
range R=1..N;
float uniform[R];
float gaussian[R];


execute{ 

var rnd = IloOplCallJava("java.util.Random", "<init>", "()");
rnd.setSeed(1); 
for(var i in R)
{                             
 uniform[i]=rnd.nextDouble();
 
}

for(var i in R)
{                             
 gaussian[i] = rnd.nextGaussian();
 
}
}

float meanU=1/N*sum(i in R)uniform[i];
float meanG=1/N*sum(i in R)gaussian[i];

float stdU=sqrt(1/N*(sum(i in R) (uniform[i]-meanU)^2));
float stdG=sqrt(1/N*(sum(i in R) (gaussian[i]-meanG)^2));


execute
{
 writeln(); 
 writeln("And now using scripting"); 
 writeln("Uniform");
 writeln("Mean = ",meanU);
 writeln("Std dev = ",stdU);
 writeln("sqrt(1/12) = ",Math.sqrt(1/12)," which is std dev of uniform between 0 and 1");
 writeln();
 writeln("Gaussian");
 writeln("Mean = ",meanG);
 writeln("Std dev = ",stdG);
 
}

然后您可以使用EXP使日志正常

See https://github.com/AlexFleischerParis/howtowithopl/blob/master/randomnumber.mod in How to with OPL to see 2 ways to get normal distribution in OPL.

int n=10000;
range r=1..n;

int m=10;
int M=21;

// uniform distribution

// choose randomly n numbers between 0 and M-1 bounds included
int random1[i in r]=rand(M);

float av1=1/n*sum(i in r)random1[i];

// choose randomly n numbers between m and M-1 bounds included
int random2[i in r]=m+rand(M-m);

float av2=1/n*sum(i in r)random2[i];

// choose randomly n float numbers between 0 and 1, 1 excluded
float random3[i in r]=rand(maxint)/maxint;

float av3=1/n*sum(i in r)random3[i];

// normal distribution through Box–Muller transform
int BIG=1000000;
float x[i in r]=-1+2*rand(BIG)/BIG;
float y[i in r]=-1+2*rand(BIG)/BIG;;
 
float w[i in r]=sqrt(x[i]*x[i]+y[i]*y[i]);
{int} subsetr={i | i in r:w[i]<=1};

float w2[i in subsetr]=(-2*ln(w[i])/w[i]);
float x2[i in subsetr]=x[i]*w2[i];
float y2[i in subsetr]=y[i]*w2[i];

// the values of x2 and y2  obey a normal distribution

float avx2=1/card(subsetr)*sum(i in subsetr) x2[i];
float avy2=1/card(subsetr)*sum(i in subsetr) y2[i];

float stddevx2=sqrt( 1/card(subsetr)*sum(i in subsetr) pow(x2[i]-avx2,2));
float stddevy2=sqrt( 1/card(subsetr)*sum(i in subsetr) pow(y2[i]-avy2,2));

execute
{
  writeln("av1 = ",av1);
  writeln("av2 = ",av2);
  writeln("av3 = ",av3);
  writeln("avx2 = ",avx2);
  writeln("avy2 = ",avy2);
  writeln("stddevx2 = ",stddevx2);
  writeln("stddevy2 = ",stddevy2);
}

// We can do the same by calling java from OPL

int N=100000;
range R=1..N;
float uniform[R];
float gaussian[R];


execute{ 

var rnd = IloOplCallJava("java.util.Random", "<init>", "()");
rnd.setSeed(1); 
for(var i in R)
{                             
 uniform[i]=rnd.nextDouble();
 
}

for(var i in R)
{                             
 gaussian[i] = rnd.nextGaussian();
 
}
}

float meanU=1/N*sum(i in R)uniform[i];
float meanG=1/N*sum(i in R)gaussian[i];

float stdU=sqrt(1/N*(sum(i in R) (uniform[i]-meanU)^2));
float stdG=sqrt(1/N*(sum(i in R) (gaussian[i]-meanG)^2));


execute
{
 writeln(); 
 writeln("And now using scripting"); 
 writeln("Uniform");
 writeln("Mean = ",meanU);
 writeln("Std dev = ",stdU);
 writeln("sqrt(1/12) = ",Math.sqrt(1/12)," which is std dev of uniform between 0 and 1");
 writeln();
 writeln("Gaussian");
 writeln("Mean = ",meanG);
 writeln("Std dev = ",stdG);
 
}

And then you can use exp to get log normal

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文