I'm getting a problem with a reporter from a custom extension "myextension". I'm using NetLogo v.5.0.5.
Here's the code of the Java class reporter:
public class DoActionPrimitive extends DefaultReporter {
#Override
public Syntax getSyntax() {
return Syntax.commandSyntax(
new int[]{
Syntax.WildcardType(), // Platform
Syntax.StringType(), // Action
Syntax.ListType()}, // Parameters
Syntax.WildcardType());
}
public Object report(Argument[] args, Context context)
throws LogoException, ExtensionException {
// Reporter code
}
}
And here's the code which gives a NetLogo compilation error:
extensions [myextension]
globals [platform]
turtles-own [logged-in?]
to setup
clear-all
reset-ticks
create-turtles population
set platform myextension:create "Platform"
ask turtles [ set logged-in? login ]
end
to-report login
report myextension:do-action platform "login" ["test-user" "123456"]
end
The NetLogo code tab gives a syntax error on the line :
report myextension:do-action platform "login" ["test-user" "123456"]
with the message:
"MYEXTENSION:DO-ACTION expected 8191 inputs, any input, a string and a list."
I guess something is wrong with the reporter syntax, maybe is not possible to have a WildcardType mixed with other parameters. I've also tried switching the first and second parameters, so having StringType before WildcardType but the error is the same but switching the parameters in the error message.
Why NetLogo expects 8191 inputs before my specified syntax inputs?
Thanks!
You're using Syntax.commandSyntax which is only for commands. You want Syntax.reporterSyntax. Assuming Syntax.WildcardType() was meant to be your return type and you want the reporter to be runnable by any agent, you can just change Syntax.commandSyntax to Syntax.reporterSyntax I believe. That invokes this implementation of reporterSyntax.
The reason you were getting that error message (if you're curious) is because your code was calling this implementation of commandSyntax. The second parameter is then interpreted as the default number of arguments of the command (it's intended to be used with variadic commands). Types in NetLogo are numbers where each binary digit corresponds to some basic type. The number has 1s for all the types that are allowed and 0s for those that are not in its binary representation. So the basic types (NumberType, StringType, etc) have a 1 in exactly one digit. WildcardType is supposed to be anything, so it should have 1s in all digits that correspond to that type. Its binary representation is 1111111111111, which in decimal is 8191, the number from the error message.
Related
Im having trouble including a formula in the input box into my model and hoped someone could help. In short I want the global variable "subsidy_absolute_threshold" to be read as "100 + m2 / 1600". So that wherever that variable is implemented, that code is implemented instead. The current code reads something like
turtles-own [m2 subsidy_eligible]
globals [subsidy_absolute_threshold]
[...]
set subsidy_absolute_threshold "100 + m2 / 1600"
[...]
ask turtles [
if ambition < read-from-string subsidy_absolute_threshold [set subsidy_eligible true]
]
Technically the global value is an input box set as a string, but it should be functionally the same thing. The error message I get is "Extra characters after literal." which I struggle to understand.
I have tried all the "types" of input boxes, but none work. I have also tried directly writing in the formula, as in replacing subsidy_absolute_threshold with 100 + m2 / 1600, which works.
Use the native command runresult instead of read-from-string.
I'm somewhat unsure exactly why read-from-string does not work, so if someone wants to present an explanation please do.
Good day,
I am working with Levelspace since I want to create a model of Agents with brains. I have two files:
the master containing the environnement within which agents without brain can evolve with simple rules
the child containing the brain every agent will have after binding the two files.
I want to pass informations from the child models to the master so I am using this kind of code in the master:
print [vecteur_binaire] ls:of ls:models
with vecteur_binaire a function of the child model. But I noticed that the code above do work only for globals and that it doesn't work for functions. For example, with the code above, it will return :
" Extension exception: Model 0 (brain of (herbivore 0)) encountered an error: ITEM expected input to be a string or list but got the number 0 instead.
error while herbivore 1 running LS:OF
called by procedure CHOOSE_AND_MOVE_HERBIVORE
called by procedure MOVE
called by procedure GO
called by Button 'go'"
this error highlighting the "ls:of" of the code. I really do not understand what is happening and why I have this error message. Moreover, becuause of this, I can't run my child model and so make brains work well.
Do you know houw to solve it?
Thank you very much in advance for your reponse!
Juliette
More complete code:
In the master:
to choose_and_move_herbivore [in]
(ls:assign in visual_input [ vision ] of self )
print [vecteur_binaire] ls:of in
end
with "in" the id number of the child model.
In the child model:
to-report vecteur_binaire
go
report o_t
end
with "go" another function calling other functions in the programm to make brains work, and o_t the value that interests me.
I am trying to do a similar simulation to this.
Parking randomly in Anylogic
in addition, I would also want to generate graphs for the output
i.e total number of cars leaving the car park garage.
I am facing the issue of
"Description: Parameter type is not specified" under the "isThereParking" function from the solution above.
Also the error "Description: Void methods cannot return a value.- Function"
for the "selectRandomParkinSpace" Function
What should be the return for both these functions?
Thank you for helping!
boolean
isThereParking( ~Object~ ) {
for(ParkingLot p : parkingSpaces){
if(p.nFree()>0)
return true;
}
return false;
}
Description: Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList. - Agent Type
It seems to me that you are not sure how to properly set up a function with the graphical function symbol. The function name, input and output parameters are defined in the fields of the function's properties section, not in the code itself if you use this module.
Have a look at the screenshot:
I marked the name definition, the return parameter definition and then the input parameter definition.
One thing that is unclear to me however is why you want an input parameter of type object, but do not give it a name or use it for anything...not sure what you want to do with this.
I'm building a model where turtles "search" a subset of patches for a resource according to different search criteria.
I'm trying to build reports that return a sorted list or agentset of patches that a turtle can then use as an itinerary for it's search.
For some reason I'm having trouble storing the itinerary in a turtle owned variable.
an example reporter is:
to-report availability
let sorted-patches sort-on [ ( (space - occupants) / space ) ] patches with [space > 0]
report sorted-patches
end
when I do show availability in the console, it prints out what I expect, an ordered list of patches.
But if I do
let test-variable availability
show test-variable
it returns
ERROR: Nothing named TEST-VARIABLE has been defined.
is this a problem of scope somehow, can I not use let as an observer?
Is it a problem of type? Can I not store an agentset as a named turtle-owned variable?
Is there a way to do the same thing with a list instead of an agent set?
Thanks
From your description, it's a scoping problem. But the problem is not that you are trying to use let with an observer, it's the scope of let. NetLogo is not really interactive in the sense you are trying to do - the variable created by let is thrown away at the end of the line.
If you type let test 3, hit enter, then type show test, you will get the same error. However if you type let test 3 show test, then it will return 3.
Why are you needing this from the console? If it's for testing, then you can look at it the way you have already found - simply by show availability. If you are using it for turtles while the model is running, then it is not interactive and there's no problem.
I have written a macro for ImageJ/FIJI to deconvolve my confocal microscopy images and run the "3D Object Counter" plugin. The macro successfully runs all required commands and saves all required data in the specified places.
However, I have found that the 3D-OC autothreshold (as shown in the plugin dialog box) is to stringent resulting in objects being lost or divided.
To remedy this I would like to reduce the autothreshold by a predetermined function something similar to what was done here (from:How to get threshold value used by auto threshold Plugin) which resulted in this code:
setAutoThreshold();
getThreshold(lower,upper);
v=setThreshold(lower,upper*0.5);
run("3D Objects Counter", "threshold="v" slice=10 min.=400 max.=20971520 objects statistics summary");
The idea was to call the AutoThreshold values, modify them and set them to a variable. However when these lines are run the following error is returned:
Number or numeric function expected in line 3.
v=<setThreshold>(lower,upper*0.5);
And if the variable is inserted directly into the threshold key for run(3D-OC) the following msg is encountered:
Numeric value expected in run() function
Key:"threshold"
Value or variable name:"setThreshold(lower,upper*0.5"
Any suggestions or help on how to designate the 3D-OC threshold value as a variable as described would be greatly appreciated (as would any work arounds of course :) ).
Cheers
Edit: After testing Jan's response below (which works perfectly), it appears I need to call the threshold set by the 3D-OC plugin. Anyone know how to do this?
The getThreshold(lower, upper) function returns the lower and upper threshold levels in the provided variables. There is no need to assign any value to a new variable, and as you observed, setThreshold does not have any return value.
Instead, you can use the value(s) returned from getThreshold and use them as parameters in the run method (in the correct way, by string concatenation, see here):
setAutoThreshold();
getThreshold(lower, v);
run("3D Objects Counter", "threshold=" + v + " slice=10 min.=400 max.=20971520 objects statistics summary");
Alternatively, you can use &v in the second parameter to avoid string concatenation in the last line (see the documentation for the run() macro function):
run("3D Objects Counter", "threshold=&v slice=10 min.=400 max.=20971520 objects statistics summary");
You might have to use the lower instead of the upper threshold value, depending on whether you count bright or dark objects.