Turtles dying according to slider - slider

I want to make a certain number of turtles (controlled by a slider) die every year. So far I got this, it is probably very straightforward but I can't seem to make it work.
Thanks a lot!
to hunting
let huntedturtles (count turtles = hunted-turtles) ; Hunted-turtles is the slider.
if ticks mod 365 = 0
[ask huntedturtles [die]]
set hunted hunted + hunted-monkeys
end

You're getting an error like ERROR: ASK expected this input to be an agent or agentset, but got a TRUE/FALSE instead, correct?
count turtles = hunted-turtles is checking whether or not the total number of turtles is equal to hunted-turtles. I don't think that's what you want. Instead, you probably want something like
let huntedturtles n-of hunted-turtles turtles
That's going to randomly choose hunted-turtles turtles.
Side note: huntedturtles and hunted-turtles are easily confusable variable names. Consider making the slider num-hunted-turtles or something similar, and the set of hunted turtles themselves hunted-turtles.

Related

X and Y inputs in LabVIEW

I am new to LabVIEW and I am trying to read a code written in LabVIEW. The block diagram is this:
This is the program to input x and y functions into the voltage input. It is meant to give an input voltage in different forms (sine, heartshape , etc.) into the fast-steering mirror or galvano mirror x and y axises.
x and y function controls are for inputting a formula for a function, and then we use "evaluation single value" function to input into a daq assistant.
I understand that { 2*(|-Mpi|)/N }*i + -Mpi*pi goes into the x value. However, I dont understand why we use this kind of formula. Why we need to assign a negative value and then do the absolute value of -M*pi. Also, I don`t understand why we need to divide to N and then multiply by i. And finally, why need to add -Mpi again? If you provide any hints about this I would really appreciate it.
This is just a complicated way to write the code/formula. Given what the code looks like (unnecessary wire bends, duplicate loop-input-tunnels, hidden wires, unnecessary coercion dots, failure to use appropriate built-in 'negate' function) not much care has been given in writing it. So while it probably yields the correct results you should not expect it to do so in the most readable way.
To answer you specific questions:
Why we need to assign a negative value and then do the absolute value
We don't. We can just move the negation immediately before the last addition or change that to a subtraction:
{ 2*(|Mpi|)/N }*i - Mpi*pi
And as #yair pointed out: We are not assigning a value here, we are basically flipping the sign of whatever value the user entered.
Why we need to divide to N and then multiply by i
This gives you a fraction between 0 and 1, no matter how many steps you do in your for-loop. Think of N as a sampling rate. I.e. your mirrors will always do the same movement, but a larger N just produces more steps in between.
Why need to add -Mpi again
I would strongly assume this is some kind of quick-and-dirty workaround for a bug that has not been fixed properly. Looking at the code it seems this +Mpi*pi has been added later on in the development process. And while I don't know what the expected values are I would believe that multiplying only one of the summands by Pi is probably wrong.

What is mouseResponse threshold and why should we set a specific threshold?

I am beginner.I just started coding in codeacademy.In a certain level,the gave me a task which is relatate with threshold.So,my question is what is mouseResponse threshold and why should we set a specific threshold?
The actual question is give below:
1.
Three variables let you experiment with the animation physics: mouseResponseThreshold, friction, and rotationForce.
mouseResponseThreshold affects how close the mouse pointer needs to be to affect the dots that make up the letters. The larger the number, the more powerful the effect of the mouse interaction. Experiment with changing the mouseResponseThreshold to different numbers and running your code!
And the hint is "Try starting out by setting the threshold to 150."
What is mouseResponse threshold
This is distance from the mouse position to your target's position (in this case, the target is the "...dots that make up your letters").
Why should I set it
You need to set it so that your code knows at what distance it needs to do a certain operation.

Netlogo: Choosing an agent to run a procedure from variable values

I am creating a taxi-like simulation in which vehicles search for customers. When a vehicle is within 1 unit distance of the customer, it picks up the customer and takes it to its destination (and begins searching for customers again, etc.).
My issue: if 2 vehicles come within 1 unit distance of the same customer within the same time-step, I need the vehicle with the highest [rating] (vehicles-own variable) to always get the customer. This is my code (updated from a previous post):
to find-customers
if (distance closest-customer <= 1)
[ask closest-customer [check-for-vehicles]]
end
to check-for-vehicles
set competitors vehicles in-radius 1
determine-highest-rated
end
to determine-highest-rated
set highest-rated max-one-of competitors [rating]
ask highest-rated [set color red]
end
[competitors] and [highest-rated] are waiting-customer-own variables. closest-customer is min-one of waiting-customers (distance myself). Normally [set color red] would run the procedure in which the vehicle gets the customer transport information. When forcing two vehicles on the same customer, the correct vehicle always sets its color red. Sometimes the incorrect vehicle also sets its color red. When I check the variable values for the waiting-customer, the correct vehicle is identified as highest-rated, yet sometimes the other vehicle still turns red. There is obviously a mistake with how I've set up the procedures. If anyone has suggestions on how to fix this (or how to approach this task differently) it would be appreciated.
I think the reason why your ifelse always return false is because the ifelse is placed at the same time step as the initialization of identificationfor each taxi.
The way netlogo works when running some function to an agenset is, each agent, one by one will individually run the function in random order, not in the same time.
So, if the ifelse is placed just right after the identification is set and in the same function, it will always return false since the other vehicles haven't got their identification set yet. Then it will directly run make-deal before even compare it to other-vehicles.
for example:
ask vehicle [
set identification ...
ifelse ... [..]
[..]
]
is different with
ask vehicle [set identification ...]
ask vehicle [ifelse .... [...][...] ]
The first one will make each agent set their identification and do the ifelse statement before make other agent do.
The second one will make every agent set their identification first then make every agent do the ifelse statement.
The conclusion is, I suggest you to separate the find-costumer function and the make-deal function.
I hope this helps

Constrained Optimization in Mathematica

I am trying to do the simplest of constrained optimizations in Mathematica but it just wont work and I dont know what I am doing wrong.
I just want max ln[x]+ln[y] subject to 10=x+y. This can simply be done by hand but Mathematica keeps spitting this out:
NMaximize::nrnum: The function value -2.19476-3.14159 I is not a real number at {x,y} = {10.8291,-0.829053}. >>
General::stop: Further output of NMaximize::nrnum will be suppressed during this calculation. >>
What's going on? Why cant it solve for the optimal x and y values?
Thanks

Is there a workaround for using the > operator on more than one turtle breed?

My model has a a number of turtle breeds and I want them to avoid each other according to size. So turtle 1 with size = 1 will avoid turtle 2 with size = 2 and so on.
The code that generates the error is:
ask turtles with [color = green]
[if not any? turtles in-radius vision with [size > self][avoid]
And the error I get is
"The > operator can only be used on two numbers, two strings, or two agents of the same type, but not on a number and a turtle."
I think I understand the error but my question is is there a workaround for this problem?
Thanks
This has nothing to do with breeds. The problem is the one described by the error: you can't compare size directly with self (which is a turtle, not a number).
You need to do:
with [ size > [ size ] of myself ]
(And note that inside the with block, you need to use myself instead of self.)