how to assign value to an array of nodes in OMNETPP.INI - omnet++

There are 10 nodes in the network and I wanted to assign Node [0] to Node [4] with ValueA= 10, the rest with Value=90 in OMNETPP.INI. The only silly way I could think of to assign the value as follows:
**.*Node[0].ValueA= "10"
**.*Node[1].ValueA= "10"
......
......
**.*Node[5].ValueA= "90"
**.*Node[6].ValueA= "90"
.......
.......
I'm thinking to assign the value with a more efficient way with FOR loop but I don't think it is possible in the OMNETPP.INI.
Can anyone help to enlighten me how to achieve this? thank you.

Various options and ways to do this are available.
You could for example use:
**.Node[0..4].ValueA = "10"
**.Node[5..9].ValueA = "90"
Check the OMNET Simulation manual -> Chapter Wildcard patterns for additional information.

Related

Is there a way to count the number of nodes given that a sibling node condition is true?

I am trying to count the number of nodes that exist given a condition in a sibling node is met.
I have tried several XPath combinations, but I'm not sure it's possible.
<ab:Person>
<ab:Gender ab:Descriptor="Girl">
</ab:Gender>
<ab:body>
<ab:finger>1</ab:finger>
</ab:body>
<ab:body>
<ab:finger>2</ab:finger>
</ab:body>
<ab:body>
<ab:finger>3</ab:finger>
</ab:body>
</ab:Person>
<ab:Person>
<ab:Gender ab:Descriptor="Boy">
</ab:Gender>
<ab:body>
<ab:finger>4</ab:finger>
</ab:body>
<ab:body>
<ab:finger>5</ab:finger>
</ab:body>
</ab:Person>
I want to count the number of nodes for each Gender -- i.e. count(ab:finger, given that ab:Person/ab:Gender ab:Descriptor="Boy") and (ab:finger, given that ab:Person/ab:Gender ab:Descriptor="Girl").
My desired output for the two xpath functions above would be 2 and 3...as the number of ab:finger nodes that exist for "Boy" is 2, and "Girl" is 3.
Please let me know if the question doesn't make sense - I can elaborate further!
If there were a variable number of genders then this would become a grouping problem. But if there are only two, then it's very simple:
count(ab:Person[ab:Gender/#ab:Descriptor="Boy"]/ab:body/ab:finger)
count(ab:Person[ab:Gender/#ab:Descriptor="Girl"]/ab:body/ab:finger)

Verifying transformed string was actually changed (according to mapping table)

I have a mapping table, M:
And using this, I've performed a find & replace on string S which gives me the transformed string S':
S: {"z" "y" "g" "k"} -> S':{"z" "y" "h" "k"}
Now I wish to verify if my mapping transformation was actually applied to S'. The psudo-code I came up for doing so is as follows:
I. Call function searchCol(x, “h”); // returns true if “h” can be found in column x in M.
II. If searchCol(x, “h”); returns true {
// assume mapping transformation was not applied to S'
// S'' after transforming S': {“z”, “y”, “i”, “j”}
}
III.If searchCol(x, “h”); returns false {
// assume mapping transformation was already applied to S'
// do nothing
}
IV. // log and continue …
However, as you can see, for the case above the algorithm doesn't work. Does anyone know a better way of going about this?
Cheers for your help.
Note: As my codebase is in Java, if you do provide any code examples, I'd prefer it if you posted them in the same language :)
Can you instead keep track of transformations? There are some cases where it's impossible to determine if a transformation took place, imagine this mapping table:
x -> y
y -> x
Now given the String yxyxyxyx, was it already transformed? And how many times?
But even if your mapping table is free of circles, the only thing you can say is:
If the string contains a char that is on the left side and not on the right side,
then it was not yet transformed.
But if the above condition is not fulfilled, then you can not be sure of anything.

Multiple unique random values in a single request in JMeter

I am trying to make an HTTP request in JMeter that contains multiple random numbers within a fixed range (specifically 0-50). With each request, I need to send out about 45 different integers, so on any given request, there are six integers within said range that are not included. Obviously {__Random()} doesn't work, as it will inevitably generate some equal values. My idea, and please bear with me because I am very new to this, was to create an array with the integers, such as:
String line = "0, 1, 2, 3, 4, 5.....";
String[] numbers = line.split(",");
and then assign them fixed variable names to include in the request. I can do this with counter with CSV data, but I'm unsure about how to do this with an array.
vars.put("VAR_" + counter, line);
VAR_1 = 1
VAR_2 = 2
and so on...
then shuffle the array (which I do not know how to do in Beanshell) and generate something like:
VAR_1 = 16
VAR_2 = 27
...
to send with the next request.
If anyone could help me with this, or suggest a simpler way, I would great appreciate it. Thanks.
To shuffle the list just use Collections.shuffle() method
Consider using JSR223 Test Elements and Groovy language instead of Beanshell as it is:
More Java compliant
Has better performance
Has built-in support of JSON, XML and some "syntax sugar" which minimises and simplifies code
Check out Groovy Is the New Black article for more details
I figured it out. It's kind of ugly and cumbersome, but fairly simple and does exactly what I needed it to do. In JSR223 PreProcessor, my code is
def list = [0,1,2,3,4,5,.....];
Collections.shuffle(list);
String VAR_1 = Integer.toString(list.getAt(0));
vars.put("VAR_1", VAR_1);
String VAR_2 = Integer.toString(list.getAt(1));
vars.put("VAR_2", VAR_2);
String VAR_3 = Integer.toString(list.getAt(2));
and so on.....
I had to input the 50 variables manually. I'm sure there was a simpler way, but I'm quite satisfied. Thanks for the suggestions.

Generate a random number in ruby with some conditions

I have no idea of how to proceed, I've been learning ruby for just one week. I thought I'd create an array filled by an external source, such as a database and forbid these elements inside to be picked up by the script. Is it possible? I just want to have a general idea of how creating such script.
Do you mean some thing like this?
forbidden_numbers = [ 5 , 6 , 3 , 4]
new_number = loop do
tmp_number = rand 1_000_000
break tmp_number unless forbidden_numbers.include?(tmp_number)
end
puts new_number
In general, you have two choices:
Remove the ineligible elements, then choose one at random:
arr.reject {...}.sample
Choose an element at random. If it is disallowed, repeat, continuing until a valid element is found:
until (n=arr.sample) && ok?(n) end
n
Without additional information we cannot say which approach is best in this case.

Seeking alternative strategy for forming assortative network in netlogo

In my netlogo simulation, I have a population of turtles that have several sociologically-relevant attributes (e.g., gender, race, age, etc.). I want them to form a network that is assortative on multiple of these attributes. The strategy that I’ve been trying to use to accomplish this is to: (i) form all possible links among the turtles, (ii) calculate a propensity to pair index for each of these “potential” links which is a weighted linear combination of how similar two turtles on the relevant attributes, and (iii) then run a modified version the “lottery” code from the models library so that links with higher propensities to pair are more likely to be selected, the selected links are then set to be “real” and all the potential links that didn’t win the lottery (i.e., are not set to real) are deleted. The problem that I’m running into is that forming all possible links in the first steps is causing me to run out of memory. I’ve done everything I can to maximize the memory that netlogo can use on my system, so this question isn’t about memory size. Rather, it’s about modeling strategy. I was wondering whether anyone might have a different strategy for forming a network that is assortative on multiple turtle attributes without having to form all potential links. The reason I was forming all potential links was because it seemed necessary to do so in order to calculate a propensity to pair index to use in the lottery code, but I’m open to any other ideas and any suggestions would be greatly appreciated.
I’m including a draft of the modified version of the lottery code I’ve been working, just in case it’s helpful to anyone, but it may be a little tangential since my question is more about strategy than particular coding issues. Thank you!
to initial-pair-up
ask winning-link [set real? true]
end
to-report winning-link
let pick random-float sum [propensitypair] of links
let winner nobody
ask not real? links
[if winner=nobody
[ifelse similarity > pick
[set winner self] [set pick pick-similarity] ] ]
report winner
end
For a "lottery" problem, I would normally suggest using the Rnd extension, but I suspect it would not help you here, because you would still need to create a list of all propensity pairs which would still be too big.
So, assuming that you have a propensity reporter (for which I've put a dummy reporter below) here is one way that you could avoid blowing up the memory:
to create-network [ nb-links ]
; get our total without creating links:
let total 0
ask turtles [
ask turtles with [ who > [ who ] of myself ] [
set total total + propensity self myself
]
]
; pre-pick all winning numbers of the lottery:
let picks sort n-values nb-links [ random-float total ]
let running-sum 0
; loop through all possible pairs...
ask turtles [
if empty? picks [ stop ]
ask turtles with [ who > [ who ] of myself ] [
if empty? picks [ stop ]
set running-sum running-sum + propensity self myself
if first picks < running-sum [
; ...and create a link if we have a winning pair
create-link-with myself
set picks but-first picks
]
]
]
end
to-report propensity [ t1 t2 ]
; this is just an example, your own function is probably very different
report
(1 / (1 + abs ([xcor] of t1 - [xcor] of t2))) +
(1 / (1 + abs ([ycor] of t1 - [ycor] of t2)))
end
I have tried it with 10000 turtles:
to setup
clear-all
create-turtles 10000 [
set xcor random-xcor
set ycor random-ycor
]
create-network 1000
end
It takes a while to run, but it doesn't take take much memory.
Maybe I have misunderstood, but I am unclear why you need to have the (potential) link established to run your lottery code. Instead, you could calculate the propensity for a pair of nodes (nodeA and nodeB) and create a link between them if the random-float is lower than the propensity. If you want it proportional to the 'share' of the propensity, calculate the total propensity over all pairs first and then the probability of creating the link is this-pair-propensity / total-propensity.
Then the only issue is running through each pair exactly once. The easiest way is probably an outer loop (nodeA) of all agents and an inner loop of agents (nodeB) with a who number that is greater than the outer loop asker (myself). Something like:
to setup
clear-all
create-turtles 30
[ set xcor random-xcor
set ycor random-ycor
]
ask turtles
[ ask turtles with [ who > [who] of myself ]
[ if random-float 1 < 0.4 [create-link-with myself]
]
]
end

Resources