我想在模拟运行期间修改 OMNeT++ 中元素的.ini文件的一些参数,例如节点的传输速率,例如当节点接收到一些控制消息时。
我发现信息说有可能以某种方式循环配置为:some_variable = ${几个值},但.ini文件中没有条件子句,也无法将任何来自C++函数的数据传递给这些文件(至于我很关心)。
我使用 INET,但也许其他一些模型的用户已经为这样的问题而烦恼。
我发现有信息说可以以某种方式循环配置为:some_variable = ${several values},但.ini 文件中没有条件子句,也无法将 C++ 函数中的任何数据传递给这些文件(就我很关心)。
事实上,您可以使用 INI 文件中的内置约束表达式。这将允许您在尊重指定约束(条件)的同时为给定配置创建运行。
但是,此约束仅适用于 .ini 文件中指定的参数,即如果您尝试更改的变量是作为代码的一部分动态计算的,这将无济于事
下面,我给你一个来自 .ini 文件的相当复杂的“代码片段”,它使用了你提到的许多内置函数(变量迭代、条件等)
# Parameter assignment using iteration loops and constrains #
# first define the static values on which the others depend #
scenario.node[*].application.ADVlowerBound = ${t0= 0.1}s
scenario.node[*].application.aggToServerUpperBound = ${t3= 0.9}s
#
## assign values to "dependent" parameters using variable names and loop iterations #
scenario.node[*].application.ADVupperBound = ${t1= ${t0}..${t3} step 0.1}s # ADVupperBound == t1; t1 will take values starting from t0 to t3 (0.1 - 0.9) iterating 0.1
scenario.node[*].application.CMtoCHupperBound = ${t2= ${t0}..${t3} step 0.1}s
#
## connect "dependent" parameters to their "copies" -- this part of the snippet is only variable assignment.
scenario.node[*].application.CMtoCHlowerBound = ${t11 = ${t1}}s
scenario.node[*].application.joinToServerLowerBound = ${t12 = ${t1}}s
#
scenario.node[*].application.aggToServerLowerBound = ${t21 = ${t2}}s
scenario.node[*].application.joinToServerUpperBound = ${t22 = ${t2}}s
#
constraint = ($t0) < ($t1) && ($t1) < ($t2) && ($t2) < ($t3)
# END END END #
t0上面的代码为to创建所有可能的时间值组合,它们可以在和t3之间取值。0.10.9
t0和t3分别是起点和终点。t1并t2根据它们取值。
t1将在每次递增t0之间取值(参见上面的语法)。也是如此。t30.1t2
但是,我希望t0始终小于t1、t1小于t2和t2小于t3。constraint我在本节中指定了这些条件。
我敢肯定,通读本手册的这一部分,将帮助您找到解决方案。
If you want to change some value during the simulation you can just do that in your C++ code. Something like:
handleMessage(cMessage *msg){
if(msg->getKind() == yourKind){ // replace yourKind with the one you are using for these messages
transmission_rate = new_value;
}
What you are refering to as some_variable = ${several values} can be used to perform multiple runs with different parameters. For example one run with a rate of 1s, one with 2s and one with 10s. That would then be:
transsmission_rate = ${1, 2, 10}s
For more detailed information how to use such values (like to do loops) see the relevant section in the OMNeT++ User Manual
虽然您当然可以手动更改volatile 参数,但 OMNeT++(据我所知)不提供在运行时自动更改参数的集成支持。
但是,您可以编写一些以编程方式更改易失性参数的模型代码。