I need to convert a code from version 3 of to netlogo to version 6. Until now everything was going just fine, but i got stucked in a line of code that I couldn't convert. Can somebody help me with it?
The code is the following:
let list-temp1 values-from aircrafts with [Team != Team-of myself and distance-nowrap myself <= radius][self]
where aircrafts is a breed and Team is a variable of aircraft
The problem is that values-from has been deprecated. I tryied what the transition guide suggests on section "new 'of' syntax", and thas the result:
let list-temp1 of aircrafts with [Team != [Team] of myself and distance-nowrap myself <= radius][self]
But I got an error message that says: OF expected this input to be a reporter block, but got anything instead.
Hope I have provided enough information, if not please let me know.
I think it might help to split this up into parts. The original code is:
let list-temp1 values-from aircrafts with [Team != Team-of myself and distance-nowrap myself <= radius][self]
This is rather hard to follow. I think it's easier if we split it up into two steps:
let agentset-temp1 aircrafts with [Team != Team-of myself and distance-nowrap myself <= radius]
let list-temp1 values-from temp0 [self]
to convert to NetLogo 6, both lines need changes, as follows:
let agentset-temp1 aircrafts with [Team != [Team] of myself and distance-nowrap myself <= radius]
let list-temp1 [self] of temp0
I don't have your whole model to actually try this in, but I think this is right or nearly right.
Related
I have an agent set named "open patches", which I found using the following, in which "number_open_patches" is a specific radius depending on "length":
`ask turtles ['
let my_patch self
set number_open_patches ((50 * (length ^ 2)) / 100) / resolution
let open_patches patches in-radius number_open_patches
I found the distance of these patches to a particular turtle "my_patch" using:
let distance_patch [distance my_patch] of open_patches
I then calculate "patch attractiveness", which is just the distance of each of the patches ("distance_patch") in "open_patches" plugged into the equation below:
let patch_attractiveness ( map [[x] -> exp ((x / open_patches) * (log e (.2 / 1)))] distance_patch)
I would finally like to select the patch within "open_patches" that has the greatest value of "patch_attractiveness". I am using the code below:
let destination max-one-of open_patches [patch_attractiveness]
I get an error as it returns 'nobody'. Why would this be? How do I know that I would actually be selecting the right patch as "distance_patch" is just a list in random order?
EDIT: I also tried the code below, but am getting a "division by zero" error when I try to calculate patch attractiveness.
ask turtles [
let my_patch self
set number_open_patches ((50 * (length ^ 2)) / 100) / resolution
let open_patches patches in-radius number_open_patches
ask open_patches [
set distance_patch [distance self] of my_patch
set patch_attractiveness exp ((distance_patch / number_open_patches) * (log e (.2 / 1)))
]
]
You didn't give enough code to see what the problems are. Your line with the exponential dividing by an agent set doesn't seem syntactically correct. You don't show the code for calculating open_patches_in_radius and I suspect there are none and the rest of the line using that is just a distraction.
That said, I'd suggest going the opposite way.
let the patches own a distance and an attractiveness variable
but "distance" is a reserved word so it needs a different name.
ask the open-patches to determine their distance to your "my_patch" turtle and store that in their distance slot. ( instead of asking your patch )
compute whatever global things you need for your formula
ask open-patches to set their attractiveness based on their distance ( already computed) and some exponential decay formula that apparently includes some global factor.
then finally let your destination be the open-patch with the max attractiveness, which now has a much simpler formula using
"max-one-of agentset [reporter]" syntax, such as
let dest max-one-of open-patch [ attractiveness ]
or possibly you want only open-patches within a given radius, but again depending on the scattering of open-patches and the size of the radius, there may be none. Check for none when setting open-patches-in-radius because that's a valid subcase.
I am trying to develop an agent-based model of a Rock-Paper-Scissors game but want to know how this dynamic shifts once spatial interactions are turned on (spatial-interactions? is my boolean variable). The model runs fine when the boolean switch is turned off however, once I turn it on, NetLogo throws out an error (pasted below). There seems to be an error in the play-game procedure but the error is not obvious to me. I suspect that I am not using the netlogo primitive "with" correctly but I have looked at many examples and I dont see the problem with how I have it written in the code. Any help y'all can provide would be appreciated! I have also pasted the code below.
WITH expected input to be an agentset but got NOBODY instead.
error while turtle 8 running WITH
called by procedure PLAY-GAME
called by procedure GO
called by Button 'go'
to play-game
let orange-morphs count co-players with [strategy = "orange"]
let yellow-morphs count co-players with [strategy = "yellow" ]
let blue-morphs count co-players with [strategy = "blue" ]
if strategy = "orange" [
set payoff payoff + (0 * yellow-morphs) + (1 * orange-morphs) + (win-payoff * blue-morphs)
]
if strategy = "yellow" [
set payoff payoff + (1 * yellow-morphs) + (win-payoff * orange-morphs) + (0 * blue-morphs)
]
if strategy = "blue" [
set payoff payoff + (win-payoff * yellow-morphs) + (0 * orange-morphs) + (1 * blue-morphs)
]
end
With your spatial dynamics, I assume that you get cases when your agents are not close enough to any other agents so that they have nobody to play against. This error happens when there are no agents grouped in the agentset co-players.
You can circumvent this by adding if (any? co-players) [ ... ] at the start of this procedure, with the entire rest of the procedure within the square brackets. That causes them not to try playing if there is nobody around to play with.
I am trying to count the number of "buyer" type turtles, which have a certain surplus (turtle variable) greater than or equal to zero, and price (another turtle variable) greater than the current turtle's price (already grabbed in local variable myprice...although there may be a more direct way to put it in)
let countup count buyers with ([surplus >= 0] and [price > myprice])
NetLogo returns
Expected a TRUE/FALSE here, rather than a list or block.
let countup count buyers with (surplus >= 0 and price > myprice) returns
WITH expected this input to be a TRUE/FALSE block, but got a TRUE/FALSE instead
Close! You're looking for:
let countput count buyers with [ surplus >= 0 and price > myprice ]
with is a report that takes two arguments, like so
<turtleset> with <report block>
where the reporter block is a clump of code surrounded by [ ] that will result in either true or false. In general [ ] is netlogo's way of grouping together code so you can doing something special with it, such as having each agent in an agentset run it. Hope that helps!
Also, I assume you've got something like let myprice price on, say, the line above this one. You can combine those lines like so (not saying this code is the right way to do it, just wanted to show another option):
let countput count buyers with [ surplus >= 0 and price > [ price ] of myself ]
Checkout the docs for (the very poorly named) myself.
I'm new in Netlogo . I'm trying to use the code included in the Many Regions Example of the library. But I get one error in this procedure
to keep-in-region [ which-region ]
if region != which-region [
let region-min-pxcor first item (which-region - 1) region-boundaries
let region-max-pxcor last item (which-region - 1) region-boundaries
let region-width (region-max-pxcor - region-min-pxcor) + 1
ifelse xcor < region-min-pxcor [
set xcor xcor + region-width ]
[if xcor > region-max-pxcor [
set xcor xcor - region-width
]
]
]
The error I get is .... any advices? Thanks in advance
-1 no esta mas que o iqual a cero.
error while a-seller 31 running ITEM
called by procedure KEEP-IN-REGION
called by procedure ADJUST
called by procedure GO
called by Botón 'go'
The error you are getting ("-1 isn't greater than or equal to zero.", once translated to English) is caused by passing -1 as an index for the item primitive.
There are two lines in the code that make use of item:
let region-min-pxcor first item (which-region - 1) region-boundaries
let region-max-pxcor last item (which-region - 1) region-boundaries
As you can see (which-region - 1) is the expression passed to item as index. If you are getting -1, it must be because which-region = 0.
In the "Many Regions Example" model, region 0 is reserved for the patches that are not part of any regions, namely, the patches that act as region boundaries. The regions themselves are numbered from 1.
Look in your code for the place where keep-in-region is called and make sure that you are using a region number that is between 1 and the number of regions you have (inclusively).
Disclaimer: I originally wrote the "Many Regions" code example. Maybe I could have used a value like nobody for the patches outside of any region and number the actual regions starting from 0 instead of one, but I don't remember if I actively decided against it or just didn't think of it.
I am trying to set angle constraints for body parts in Swift 2.0.
I have tried to automatically set them in the scene editor under IK Constraints and this failed.
I subsequently set them in the code:
lowerArmBack.reachConstraints?.lowerAngleLimit = 0
lowerArmBack.reachConstraints?.upperAngleLimit = CGFloat(10)
Neither has worked (with or without CGFloat). I am trying to follow this tutorial: http://www.raywenderlich.com/80917/sprite-kit-inverse-kinematics-swift but have stumbled in to issues since the Swift update.
Essentially I want to limit angles to prevent the arms moving in all 360 degrees but this isn't happening.
You need to set a zRotation constraint with a range for the body part you want:
let range = SKRange(lowerLimit: CGFloat(0).degreesToRadians(),
upperLimit: CGFloat(160).degreesToRadians())
let rotationConstraint = SKConstraint.zRotation(range)
lowerArmFront.constraints = [rotationConstraint]
Regarding the tutorial, I'm actually working on it's update fixing the issue.
You can also add a SKReachConstraint in the following way:
lowerLeg.reachConstraints = SKReachConstraints(lowerAngleLimit: CGFloat(-45).degreesToRadians(), upperAngleLimit: 0)
upperLeg.reachConstraints = SKReachConstraints(lowerAngleLimit: CGFloat(-45).degreesToRadians(), upperAngleLimit: CGFloat(160).degreesToRadians())
Hope it helps!