hierarchy

r - hierarchical data frame from child/parent relations

只谈情不闲聊 提交于 2019-12-22 05:01:08
问题 I have a child - parent data.frame that I want to transform to a complete hierarchical list with all levels and a level number. The example data below goes to three levels, but it could be more. What function can I use to transform the data? Source: data.frame(name = c("land", "water", "air", "car", "bicycle", "boat", "balloon", "airplane", "helicopter", "Ford", "BMW", "Airbus"), parent = c(NA, NA, NA, "land", "land", "water", "air", "air", "air", "car", "car", "airplane")) name parent 1 land

Getting a call hierarchy in java

心已入冬 提交于 2019-12-21 13:40:07
问题 I am having real trouble tracking down a bug and it would help be a lot to know which method called a certain method. Is there an easy way to get a call hierarchy from java? Java is a small part of the app so I cannot compile and run the whole app in eclipse/net beans so I don't have access to an IDE debugger's call hierarchy. 回答1: Thread.currentThread().getStackTrace(); or Exception ex = new Exception(); ex.printStackTrace(); It's fairly slow, but fine for debugging purposes. API docs here.

Maximum recursion depth error in Python when calling super's init. [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-21 08:08:22
问题 This question already has an answer here : How to avoid infinite recursion with super()? (1 answer) Closed 11 months ago . I have a class hierarchy A <- B <- C, in B, I need some processing in the constructor, so I came up with this code from this post: Understanding Python super() with __init__() methods #!/usr/bin/python class A(object): def __init__(self, v, v2): self.v = v self.v2 = v2 class B(A): def __init__(self, v, v2): # Do some processing super(self.__class__, self).__init__(v, v2)

Use d3 log scale instead of linear scale

假装没事ソ 提交于 2019-12-21 07:33:48
问题 I'm trying to do a chart based on http://mbostock.github.com/d3/talk/20111116/bar-hierarchy.html, the only difference being that I'd like to use a log scale for the x-axis. Here's my fiddle: http://jsfiddle.net/JhDVC/5/ As you can see, the x-axis is defined at line 4: x = d3.scale.linear().range([0, w]), If I change it for x = d3.scale.log().range([0, w]), Then it doesn't work (nothing is rendered), throwing these error messages: Error: Invalid value for <rect> attribute width="NaN" Changing

Traverse hierarchy object c#

耗尽温柔 提交于 2019-12-21 05:40:44
问题 If I have a Class like below. How do i traverse through it until its property SomeObjects.count = 0 public class SomeObject { public String Name { get; set; } public List<SomeObject> SomeObjects { get; set; } } Many Thanks 回答1: Here is a generic example of how you can traverse a composite object: public static class TraversalHelper{ public static void TraverseAndExecute<T>(this T composite, Func<T,IEnumerable<T>> selectChildren, Action<T> action) where T: class { action.Invoke(composite);

What's the best C# pattern for implementing a hierarchy with an enum?

为君一笑 提交于 2019-12-21 04:18:53
问题 I'm implementing value types which represents a distance (or length). There's an enum that represents the different units of measure, eg: public enum DistanceUnit { Millimeter, Centimeter, Meter, Kilometer, Inch, Foot, Yard, Mile }; These measurements fall into one of two systems - either metric or imperial. Since enum doesn't support hierachies, what's the best pattern for representing this hierarchy? Is it to use bit flags? Or use two seperate enums along with some methods to correlate them

d3.js Indented tree with straight links

痞子三分冷 提交于 2019-12-21 01:40:11
问题 My code is based on the D3.js Indented tree example. I want straight links instead of the curved links between parent/child-objects. I understand this has something to do with the following code, however, I can't find a solution. I want the links to be straight with a 90-degree turn. var diagonal = d3.svg.diagonal() .projection(function(d) { return [d.y, d.x]; }); 回答1: The problem is to extract the x and y points from the links. One way of doing this is: Link generator: self.diagonal = d3.svg

2D Game: Fast(est) way to find x closest entities for another entity - huge amount of entities, highly dynamic

本秂侑毒 提交于 2019-12-20 10:44:03
问题 I'm working on a 2D game that has a huge amount of dynamic entities. For fun's sake, let's call them soldiers, and let's say there are 50000 of them (which I just randomly thought up, it might be much more or much less :)). All these soldiers are moving every frame according to rules - think boids / flocking / steering behaviour. For each soldier, to update it's movement I need the X soldiers that are closest to the one I'm processing. What would be the best spatial hierarchy to store them to

Best Relational DataBase Representation Of Time Bound Hierarchies

青春壹個敷衍的年華 提交于 2019-12-20 09:47:33
问题 What in everyone's opinion is the best representation for a time-bound hierarchy in SQL? What I mean by this is: - On any given date you have a normal tree hierarchy - This hierarchy can change from day to date - Each child still only has one parent on any given date Day 1... Business | |-Joe | |-Happy | |-Sneezy | |-Doc(*) | |-Moe |-Bashfull |-Sleepy Day 2... Business | |-Joe | |-Happy | |-Sneezy | |-Moe |-Doc(*) |-Bashfull |-Sleepy At any time, a child can join the hierarchy for the first

How do you sort a tree stored using the nested set model?

会有一股神秘感。 提交于 2019-12-20 09:03:05
问题 When I refer to nested set model I mean what is described here. I need to build a new system for storing "categories" (I can't think of better word for it) in a user defined hierarchy. Since the nested set model is optimized for reads instead of writes, I decided to use that. Unfortunately during my research and testing of nested sets, I ran into the problem of how do I display the hierarchical tree with sorted nodes. For example if I have the hierarchy: root finances budgeting fy08 projects