How to move to another agent with the highest value? - process

my agents set trade_Price than when they trade and they save their profit to their payoff variable. in ai process I have to code that my agents have to look around and choose the neighbor agent with the highest payoff. and than the agent has to give his decision value to this agent. I asked it before and got this code:
ask buyers [
let current-buyer self
ask sellers [
let current-seller self
let how-much 1
set decision ;some number
ask current-buyer [
set decision ;some number
]]]
but got something else what i wanted. Than I code it myself so:
ask sellers
[ let partner one-of buyers-here if partner != nobody
[ move-to one-of partner with-max [decision] of buyers]]
But there are also mistakes, could you give a tip or at least which code is the right way?

Revised in response to comment:
ask sellers [
let candidates (buyers-on neighbors)
ifelse any? candidates [
let partner one-of (candidates with-max [decision])
move-to partner
][
die ;; or whatever you want to do in this case
]
]

Related

Netlogo - Turtles on more than one Patch - Item vs Who

How are you? I guess there is no way to visually represent in the Netlogo Interface a system with a "many-to-many" relationship, where turtles belong to more than one patch, and of course patches host more than one turtle. Correct?
I have a model where Banks (my turtles) operate on more than one Country (my patches). So I think my only option is to have two breeds of turtles, i.e. Banks and Countries, and connect Banks to Countries with link agents. Correct?
(I will also need interbank links, so I will need to set up a different breed of links. Correct?)
Now: I need to identify countries by name (i.e. Italy, France, Spain, etc.). I am reading a CSV file with country names and feeding it into a Netlogo list, but I am not sure how to have a country agent "be" a name. I created a country breed-specific variable called "country-name", and I am trying to use "item" to sequentially access each next name in the list of country names and assign it to the country-name variable of the next country agent in the Countries breed. However, I cannot relate "item" to "who" here, because "who" is not breed-specific. So I am thinking of setting up a separate breed-specific numbered index, but something like this has been asked in a previous question (trying to create a sequential ID variable for breeds in netlogo) and it was strongly suggested NOT to do so. Any suggestions on how to proceed?
I agree with the comment by Matteo. That said,
You don't ever need to use "who". Identify your banks and your countries with a "name" field that the breed owns. For example
banks-own [ name ]
counties-own [ name ]
;; then somewhere in your loop as you read them in...
create-banks 1 [ set name "Chase" ... ]
create-countries 1 [ set name "England" ...]
Below I use 'one-of' but there will only be one hit.
This makes the syntax work converting a list item to a specific turtle.
You never should need to know or care about the "who" value of a bank
or country.
to make-branches
;; read this list in from a csv file, etc. or hard code it
set branchlist [[ "Lloyds" "England"] ["Lloyds" "France"] [ "Chase" "USA"]["Chase" "France" ]]
;; then work the list. Again, you never need "who".
foreach branchlist [
z -> ask one-of banks with [name = item 0 z ]
[ create-link-with one-of countries with [ name = item 1 z ]]
]
end

Pine Script TradingView Query

I'm quite new to PINE and I'm hoping for some assistance, or to be pointed in the right direction. My goal is to script BUY/SELL signals which will use a PERCENTAGE of an available sum for use with a trading bot via TradingView.
For example, starting capital $100, buy signal comes through, which triggers buy of of 25% ($25) worth of X coin.
I have been unable to find the code to setup the more complicated percentage-based buy/sell orders. Perhaps I'm blind, if so, tell me! :) The below code provided by TradingView would use all available capital in the account to make 1 x buy trade... which is not ideal.
{
"action": "BUY",
"botId": "1234"
}
I have tried this to add % but to no avail:
{
"action": "BUY" percent_of_equity 25,
"botId": "1234"
}
Any suggestions? Am I missing anything obvious?
Related Articles:
Quadency
TradingView
The code above is not related to pine-script, but is part of alarm/webhook action.
If you want to declare equity in your (back)order, inside pine-script, you have to use strategy like something this:
strategy(title = "example",
shorttitle = "myscript",
overlay = true,
pyramiding = 1,
default_qty_type = strategy.percent_of_equity,
default_qty_value = 50,
initial_capital = 1000)
This get the type as percent of equity, which is 50% declared on qty_value

Moving parameters for variable to set up - model behaviour changes

This one stumping me...
I have an ABM which generates new patients arriving to a hospital unit by random-poisson on a single patch (spout procedure). Each patient is assigned an area to go to and a time to spend in the unit according to the area and other assigned variables. When I created this with the distributions embedded in the procedures or reporters it worked fine every time, but when I code the random variables into the set up to make it easier to manipulate it regularly generates grossly abnormally low/high values (ranges not seen when run in original format) and sometimes the creation of new patients doesn't happen at all though the model still ticks on... The only things changed are the placement of the variables in set up and and not in the body of the code.
I can't figure out why it would randomly have no patients entering the system which makes me mistrusting of anything else it generates. Is this just a formatting style that Netlogo doesn't like? Or am I missing something?
Thanks for any advice/help in solving this one
original code:
if ticks = 1000 [stop]
ask arrivals
[
assess
crowding-check
relocate
]
end
to assess
sprout-patients random-poisson 1.5
[set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
]
end
to-report AEC_treatment_time ;; gamma dist
let result random-gamma 3.478 0.525
if result < 2 [ report 2 ]
if result > 20 [ report 20]
report result
end
to-report AMU_treatment_time ; gamma dist
let result random-gamma 5.7716 0.3
if result < 4 [ report 4]
if result > 48 [ report 48]
report result
end
new code:
ca
set new-patients random-poisson 1.5
set AEC-los random-gamma 3.478 0.525
set AMU-los random-gamma 5.7716 0.3
reset-ticks
end
to go
if ticks = 1000 [stop]
ask arrivals
[
sprout-patients new-patients
assess
crowding-check
relocate
]
end
to assess
ask patients-here
[set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
]
end
...
to-report AEC_treatment_time ;; gamma dist
let los-AEC AEC-los
if los-AEC < 2 [ report 2 ]
if los-AEC > 20 [ report 20]
report los-AEC
end
to-report AMU_treatment_time ; gamma dist ;; reports treatment time for patients in AMU
let los-AMU AMU-los
if los-AMU < 4 [ report 4]
if los-AMU > 48 [ report 48]
report los-AMU
end
ps trying multiple iterations, it seems to be the random-poisson change that is the one causing the issues
It's pretty hard to see without the full code as it looks to be a problem with the way procedures connect, but your new structure has ask patients-here (at the start of the assess procedure) inside a loop through ask arrivals (go procedure). Is arrivals a breed?
Generally it is a bad thing to have nested ask turtles type structures because each turtle ask all turtles that satisfy the conditions so you can get subtle errors. Anyway, this will probably get you back to what you were doing before:
to go
if ticks = 1000 [stop]
ask arrivals
[ sprout-patients new-patients [assess]
crowding-check
relocate
]
end
to assess
set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
end
This structure makes the assess procedure into a procedure that runs from the turtle's perspective (or context) and has it run immediately as the turtle calling it is created.

Creation of a flexible but on variables depending hierarchical structure in Netlogo

i am trying to model the following hierarchical structur in Netlogo:
Imagine a typical company or a a brach of public administration. There is one boss (turtle) on top and a number of employees (turtles) below him/her. There are two variables: span-of-control soc (how many employees can one Boss overwatch) and depth-of-control doc (how many hierarchical levels do exist in the structure). The total number of employees equals soc^doc. The total number of turtles equals 1+soc^doc (1 is the boss).
There are two Choosers in the Netlogo-Interface: soc and doc (ranging from 1 to 4).
What I imagine to code: Depending on the Variables chosen, the structure should arrange itself automatically by the following rule: Create as many links to employees as there have been employees on the higher hierarchical level until the doc is reached.
Example: doc:3 soc:3 1 Boss (always 1 so it can be used like an anchor)
1. Level: 3 links (1*3)
2. Level: 9 Links (3*3)
3. Level: 27 Links (9*3)
4. Level: Over as doc is reached
To realise this, I need to make the turtles kind of read the doc and soc variables and make them create links accordingly but I dont know how.
Here is my code so far:
globals [
information
]
undirected-link-breed [ Informationflows Informationflow ]
breed [ Employees Employee ]
breed [ tasks task ]
breed [ Bosses Boss ]
;#########SETUP########
to setup
clear-all
create-Bosses 1 [ set color red
set size 2 ]
set-default-shape Bosses "person"
ask Bosses [ setxy 0 15 ]
ask patches [ set pcolor white ]
set-default-shape Employees "person"
create-Employees ( span-of-control ^ depth-of-control) [set color blue
set size 2 ] ; absolute Number of Employees
;ask Boss 0 [ create-Informationflow-with random Employee 8] ; IDEA
;ask Employees [ create-Informationflow-with one-of other Employees] ; IDEA
;ask Employees [ create-Informationflow-with Boss 0 ] ; IDEA
repeat 100 [ layout ]
ask Employees [
setxy 0.95 * xcor 0.95 * ycor ]
end
to-report value-of-span-of-control? ; Just an idea
report span-of-control
end
;##########LAYOUT##########
to layout
; layout-radial Employees Informationflows (Boss 0) ;Problem: Boss is fixed in the Center
layout-spring Employees Informationflows 0 10 2
end
If anybody could hint me in the right direction, I would be very thankful.
Kind regards,
Jon
Okay, general coding advice first - do ONE thing, test it and fix it before moving on to the next thing.
Your question about how to 'read' the doc and soc variables makes me think you are very new to NetLogo. If so, please go and do the tutorials that are at the NetLogo site. Creating a chooser with the name 'XYZ' creates a global variable named 'XYZ', there is no additional step to read it. Since you are choosing numbers, you might want to use a slider instead of a chooser.
Try replacing your commented out ask Boss line with this:
ask one-of Boss [ create-Informationflow-with n-of soc Employees ]
It's generally bad practice to use who numbers because turtles can die or be generated in a different order because you change some code and then the who numbers are different. So I used one-of to randomly select any boss (of which there is only one anyway). I similarly used n-of to select Employees to create links with and specified the number n in the n-of to be the value from the soc variable.

NetLogo 5.3.1, error message "Expected [" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm learning ABM from a book called Agent-Based and Individual-Based Modeling by Railsback and Grimm. According to the book, the first complete model they walk through looks like this:
globals
turtles-own
[
time-since-last-found
]
num-clusters
]
[
time-since-last-found
]
[
num-clusters
]
to setup
clear-all
set num-clusters 4
ask n-of 4 patches
[
ask n-of 20 patches in-radius 5
[
set pcolor red
]
]
create-turtles 2
[
set size 2
set color yellow
set time-since-last-found 999
]
end
to go
ask turtles [search]
to search
if-else time-since-last-found <= 20
[right (random 181) -90]
[right (random 21) -10]
forward 1
ifelse pcolor = red
[
set time-since-last-found 0
set pcolor yellow
]
[
set time-since-last-found time-since-last-found + 1
]
end
The book says I should be able to to run the simple Mushroom Hunt model. But, instead, I keep getting an error message that says I need an extra [, "Expected [".
I have no idea where I need to put it. What's more, it really does seem to me that I don't need it and I don't understand why it's saying I do.
Thanks!
It might be helpful to check out the Netlogo Programming Guide as you read through Railsback and Grimm. It helps outline proper syntax and explains in a different way what code needs to go in what place.
With your code above, there are several problems- for example, review Globals and Turtles-own. Note how square brackets should contain the variables in each of those blocks. Next, look at how procedures all start with to and finish with end - you should see that there is a "search" procedure nested in your "go" procedure above.