NETLOGO: Distribution of variable on my-links - variables

I have network with number of nodes connected with links. I need to set variable (lets call it "trust") to links so that sum of variables from links from one agent to others makes 100. Example: Agent have 3 links to another agents. Their variables are "34 13 53" or "23 61 16" or " 37 16 47". Sum is always 100. Hope it makes sense. Is there some easy way to do it netlogo?

Just give them the values then normalise. Something like (not tested) ask agents [ ask my-links [ set trust [ 100 * trust / sum [ trust ] of my-links ] ]
The problem you are going to have is that the value will need to be different each way. For example, if A and B have a link between them, then trust might need to be 25 at A's end (because the other links total 75) and 50 at B's end. So you actually need the link to have two values - how much A trusts B and how much B trusts A.

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

Matching an element in a column, to others in the same column

I have columns taken from excel as a dataframe, the columns are as follows:
HolidayTourProvider|Packages|Meals|Accommodation|LocalTravelVehicle|Cancellationfee
Holiday Tour Provider has a couple of company names
Packages, the features provided in each package are mostly the same like
Meals,Accommodation etc... even though one company may call it "Saver", others may call it "Budget". (each of column mostly follow Yes/No, except Local travel vehicle are again car names like Ford Taurus,jeep cherokee etc..
Cancellation amount is integers)
I need to write a function like
match(HolidayTP,Package)
where the user can give input like
match(AdventureLife, Luxury)
then I need to return all the packages that have similar features with Luxury by other Holiday Tour Providers, no matter what name they give the package like 'Semi Lux', 'Comfort' etc...
I want to give a counter for every match and display all the packages that exceed the counter by 3 or 4.
This is my first python code. I am stuck here.
fb is the total df I exported to
def mapHol(HTP, PACKAGE):
mfb = (fb['HTP']== HTP)&(fb['package']== package)
B = fb[mfb]
for i in fb[i]:
for j in B[j]:
if fb[i]==B[j]:
count+=1
I dont know how to proceed, please help me this is my first major project, I started on my own.

How to find results being between two values of different keys with Redis?

I'm creating a game matchmaking system using Redis based on MMR, which is a number that pretty much sums up the skill of a player. Therefore the system can match him/her with others who are pretty much with the same skill.
For example if a player with MMR of 1000 joins the queue, system will try to find other ppl with MMR of range 950 to 1050 to match with this player. But if after one minute it cannot find any player with given stats it will scale up the range to 900 to 1100 (a constant threshold).
What I want to do is really easy with relational database design but I can't figure out how to do it with Redis.
The queue table implementation would be like this:
+----+---------+------+-------+
| ID | USER_ID | MMR | TRIES |
+----+---------+------+-------+
| 1 | 50 | 1000 | 1 |
| 2 | 70 | 1500 | 1 |
| 3 | 350 | 1200 | 1 |
+----+---------+------+-------+
So when a new player queues up, it will check it's MMR against other players in the queue if it finds one between 5% Threshold it will match the two players if not it will add the new player to the table and wait for new players to queue up to compare or to pass 1 minute and the cronjob increment the tries and retry to match players.
The only way I can imagine is to use two separate keys for the low and high of each player in the queue like this
MatchMakingQueue:User:1:Low => 900
MatchMakingQueue:User:1:High => 1100
but the keys will be different and I can't get for example all users in between range of low of 900 to high of 1100!
I hope I've been clear enough any help would be much appreciated.
As #Guy Korland had suggested, a Sorted Set can be used to track and match players based on their MMR, and I do not agree with the OP's "won't scale" comment.
Basically, when a new player joins, the ID is added to a zset with the MMR as its score.
ZADD players:mmr 1000 id:50
The matchmaking is made for each user, e.g. id:50 with the following query:
ZREVRANGEBYSCORE players:mmrs 1050 950 LIMIT 0 2
A match is found if two IDs are returned and at least one of them is different than that of the new player. To make the match, both IDs (the new player's and the matched with one) need to be removed from the set - I'd use a Lua script to implement this piece of logic (matching and removing) for atomicity and communication reduction, but it can be done in the client as well.
There are different ways to keep track of the retries, but perhaps the simplest one is to use another Sorted Set, where the score is that metric.
The following pseudo Redis Lua code is a minimal example of the approach:
local kmmrs, kretries = KEYS[1], KEYS[2]
local id = ARGV[1]
local mmr = redis.call('ZSCORE', kmmrs, id)
local retries = redis.call('ZSCORE', kretries, id)
local min, max = mmr*(1-0.05*retries), mmr*(1+0.05*retries)
local candidates = redis.call('ZREVRANGEBYSCORE', kmmrs, max, min, 'LIMIT', 0, 2)
if #candidates < 2 then
redis.call('ZINCRBY', kretries, 1, id)
return nil
end
local reply
if candidates[1] ~= id then
reply = candidates[1]
else
reply = candidates[2]
end
redis.call('ZREM', kmmrs, id, reply)
redis.call('ZREM', kretries, id, reply)
return reply
Let me get the problem right! Your problem is that you want to find all the users in a given range of MMR value. What if You make other users say that "I'm falling in this range".
Read about Redis Pub/Sub.
When a user joins in, publish its MMR to rest of the players.
Write the code on the user side to check if his/her MMR is falling in the range.
If it is, user will publish back to a channel that it is falling in that range. Else, user will silently discard the message.
repeat these steps if you get no response back in 1 minute.
You can make one channel (let's say MatchMMR) for all users to publish MMR for match request which should be suscribed by all the users. And make user specific channel in case somebody has a MMR in the calculated range.
Form you published messages such that you can send all the information like "retry count", "match range percentage", "MMR value" etc. so that your code at user side can calculate if it is the right fit for the MMR.
Read mode about redis Pub/Sub at: https://redis.io/topics/pubsub

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.

Related jobs in JSprit

Is it possible to handle relations between jobs (in this case services) in jsprit?
For instance one job has to start at the same time with one or more other jobs.
Or one job must not start before the end of another job (normal sequence).
If not, do you know other java libraries that can handle such kind of restrictions?
Thank you!
Yes you can handle such relations with jsprit.
It is a bit of coding, but - I think - easy to implement. To illustrate it, I prepared you five examples that are based on the Vehicle Routing Problems (VRP) developed by Christofides-Mingozzi-Toth's* (first benchmarking instance). Follow the links behind the individual headlines and you get to the code. Note that the first activity in a route is marked with a triangle. The labels denote jobIds.
noConstraints
capacityConstraints
job 13 and 21 in same route
job 13 and 21 in same route AND 21 before 13
job 13 and 21 in same route AND 13 right after 21
Visit http://jsprit.github.io/ and you get to a number of code examples and docs.
*N. Christofides, A. Mingozzi, and P. Toth. The vehicle routing problem. In N. Christofides, A. Mingozzi, P. Toth, and C. Sandi, editors, Combinatorial Optimization. John Wiley, Chichester, 1979.