netlogo Hatched turtles using parent variable value in calculation - parent-child

I have two breeds (workplaces and workers). I've made 3 workplaces and they each hatch 100 workers. I use hatching to be able to assign some features of the workplace to the workers. Specifically, I want to assign Size-Of-Location, which is different for each of the workplaces, to the workers and then use that in calculating something for each worker. The result will differ across workers even in the same workplace but the common variable is also important to that calculation. So, for example, after setting up two breeds--workplaces and workers, I have tried variations on:
hatch-workers 100 [ move-to one-of patches
create-size-of-location-to myself
. . . ]
and I've also tried many other variants, including using links instead. The one above is my 20th iteration of the code, and I confess it may look completely brain dead because I am getting more and more confused with each failure.
I can't use proximity to the workplace because the workers are located in residences everywhere, not necessarily close to their workplace. I've read in various places (e.g., Railsback & Grimm) that hatched entities take the characteristics of the parent, but my inspection of my workers doesn't confirm that, and when I try to use the parent variable I only get errors.
I believe the ability to use parents' information in "kids" calculation is a likely common need. Yet, I searched StackOverflow and other netlogo help sites, the netlogo manual, and several books, and if a discussion of this is present I have been unable to find it. Thus, I am stumped at this point. Any helpful suggestions are greatly appreciated!
Thanks!
SLuke

The scheme I use if I need to refer to the parents variables is
When creating the children I include.
set parent myself
then when I need to use a parent variable I use
[name-of-variable] of parent
for the set of sisters
set sisters turtles with [parent = [parent] of myself]
for the set of children
set children turtles with [parent = myself]

Related

Graph database design: Should I add relationships, or just traverse

I have recently started exploring graph databases and Neo4J, and would like to work with my own data. At the moment I've hit some confusion. I've created an example image to illustrate my issue. In terms of efficiency, I'm wondering which option is better (and I want to get it right now in early days before I start handling larger amounts).
Option A: Using only the blue relationships, I can work out whether things are related to, or come under, the Ancient group. This process will be done many many times, however it is unlikely to be more than ~6 generations.
Option B: I implement the red relationships, so that it is much faster to work out if young structures belong to the Ancient group.
I'm trying not to use Labels in this scenario, as I'm trying to use labels for a specific purpose to simplify my life (linking structures across seperate networks), and I'm not sure if I should have a label to represent a node that already exists.
In summary, I'm wondering whether adding a whole new bunch of relationships, whilst taking more space, is worth it, or whether traversing to find all relatives is such a simple/inexpensive task that it isn't worth doing so. Or alternatively, both options are viable and this isn't a real issue at all. Thanks for reading.
I'd go with Option A. One of the strengths of Neo4j is that it traverses relationships very efficiently and quickly, and so, there is no need to materialise relationships (sometimes, relationships are materialised in complex and/or extremely large graphs, but this is not your case).
Not sure why you don't want to use labels? Labels serve to group nodes into sets of the same type, and are also index backed- this makes it much faster to find the starting point of your query (index lookup over full database scan).

How to save and restore turtles and links without using an external file

I need to save all the turtles and links, so that if I make some modifications to the graph topology I'm able to restore it later. For now the method that I'm using is to load/save through an external file:
to save-graph
nw:save-graphml "mygraph.graphml"
end
to load-graph
ask turtles [ die ]
nw:load-graphml "mygraph.graphml"
end
But it's very slow, specially for big graphs. I tried to simply assign the turtles and links to other variables:
globals [saved-turtles saved-links]
to save-graph
set saved-turtles turtles
set saved-links links
end
to load-graph
set turtles saved-turtles
set links saved-links
end
But it says that I cannot simply assign turtles and links this way:
And it highlights the line in which I set turtles and links. Is there a way to do it without using an external file?
The way to do it can depend a lot on your goals and the differences between both versions of the graph. It is almost sure that the save/load graphml procedures are not the best ones to do it, and it is not possible to "keep" all the turtles and links with all their properties and restore them later... agentsets are very big data structures with references to real agents, not the real agents themselves (as far as I know), so if you change an agent later, the information about it in the agentset variable it is not of high value after that.
If you have only a small amount of differences between the versions of the graph and this graph is really big maybe it is better to add some new property (version, for example) to turtles and links to inform you about the version the element belongs to (for example, 0:old, 1:new, 2:both) and having a way programmed by you to restore the previous state easily and fast. In this way, you never erase an old element, only hide it to the new state, and you keep the real difference between states.
I've used a similar method in some operations to manage big graphs in previous NetLogo projects, and it works fine. Hope this will help you.

D3.js force layout: How to isolate node groups?

What I'm trying to achieve?
I would like to have groups of nodes, in a tree-like structure where each root is either the main root, or is a descendant of a leaf from another tree.
Generating what you see below is easy, but what I'd really like to see is complete circles around each root. However, since the nodes are repelling each other the below gaps are present between each cluster. I assume the solution involves ignoring the repulsion caused by charges between leaves coming from different roots.
My ideas
Set some sort of radius around each root which repels other nodes in all directions beyond that radius, allowing the leaves to be circular within it
Use linkDistances and linkStrengths to somehow arrange the clusters in a way that they do not interact significantly
Is this possible?
Other than my vague ideas, I really have no clue how to do this!
From reading the D3 docs, I found that unlike the dynamic linkDistance and linkStrength methods, node charge manipulations seem to be universal:
"All nodes are assumed to be infinitesimal points with equal charge and mass."
If this statement is true, can one of you guys please guide me in the right direction?
I'm not sure exactly how you would approach it, but I found an example in which clusters have charge only within themselves and nodes don't interact with different ones: http://bl.ocks.org/mbostock/1804889
I'm think the beginning of an answer might be in this stackoverflow question, Space out nodes evenly around root node in D3 force layout
Do know that is possible to make each node's charge dependent on some attribute of same.
Try it with something like
.charge(function(d) { console.log(d); //you'll see this brings up the nodes
if (d.something == onething) {
return -1300;}
else {
return -100; }
})
As the linked-to answer mentions, you'll almost certainly have to experiment with "friction" and "linkDistance." Don't be afraid of trial and error--I at least have been intermittently dealing with this kind of issue for a few months now, and haven't yet found a "general" solution.

Give me a practical use-case of Multi-set

I would like to know a few practical use-cases (if they are not related/tied to any programming language it will be better).I can associate Sets, Lists and Maps to practical use cases.
For example if you wanted a glossary of a book where terms that you want are listed alphabetically and a location/page number is the value, you would use the collection TreeMap(OrderedMap which is a Map)
Somehow, I can't associate MultiSets with any "practical" usecase. Does someone know of any uses?
http://en.wikipedia.org/wiki/Multiset does not tell me enough :)
PS: If you guys think this should be community-wiki'ed it is okay. The only reason I did not do it was "There is a clear objective way to answer this question".
Lots of applications. For example, imagine a shopping cart. That can contain more than one instance of an item - i.e. 2 cpu's, 3 graphics boards, etc. So it is a Multi-set. One simple implementation is to also keep track of the number of items of each - i.e. keep around the info 2 cpu's, 3 graphics boards, etc.
I'm sure you can think of lots of other applications.
A multiset is useful in many situations in which you'd otherwise have a Map. Here are three examples.
Suppose you have a class Foo with an accessor getType(), and you want to know, for a collection of Foo instances, how many have each type.
Similarly, a system could perform various actions, and you could use a Multiset to keep track of how many times each action occurred.
Finally, to determine whether two collections contain the same elements, ignoring order but paying attention to how often instances are repeated, simply call
HashMultiset.create(collection1).equals(HashMultiset.create(collection2))
In some fields of Math, a set is treated as a multiset for all purposes. For example, in Linear Algebra, a set of vectors is teated as a multiset when testing for linear dependancy.
Thus, implementations of these fields should benefit from the usage of multisets.
You may say linear algebra isn't practical, but that is a whole different debate...
A Shopping Cart is a MultiSet. You can put several instances of the same item in a Shopping Cart when you want to buy more than one.

Visualisation of Tree Hierarchy in HTML

I am looking of inspiration for doing interaction design on a hierachy/tree structure. (products with a number of subproducts, rules that apply for selecting subproducts).
I want to have a tree where there is a visible connection between sub-nodes and their parent node. And i also want to visualize which rules that apply for selecting them.
Typical rules:
mandatory: select only one of one sub-product
optional: select 0 or more of several subproducts
mutual exclusive: select only one of several subproducts
I hope you get the idea.
I am looking for any inspiration in this area. Any suggestions, examples, tips are welcome
Here are several:
http://thejit.org/
http://www.jsviz.org/blog/
http://vis.stanford.edu/protovis/
If you are willing to use something other than html/javascript, Flare is an excellent library for Adobe Flash.
I've used Infoviz library for such scenario (here's the demo). You could use distinct node colors for different selection rules together with some textual description, although it wouldn't be very intuitive at first.
Default tree orientation is horizontal, which may look odd, but makes sense when you add textual node names of variable length.

Resources