Lua中的析构函数?(Destructors in Lua?)
是否有可能在Lua中使用userdata获取析构函数?
http://www.lua.org/notes/ltn006.html看起来很有前途(实际上正是我想要的); 除了它是Lua 4.0的路径。
基本上,我想要一种方法来收集表格时收集的函数。
谢谢!
Is it possible to get destructors in Lua w/o using userdata?
http://www.lua.org/notes/ltn006.html looks promising (in fact exactly what I want); except it's a path for Lua 4.0.
Basically, I want a way to have a function called when a table is collected.
Thanks!
原文:https://stackoverflow.com/questions/3078440
更新时间:2022-11-19 20:11
最满意答案
最后我找到了:
finalshortest = all_simple_paths(cGraph, from = c("n2"), to = V(cGraph)[color=="red"],mode="out") V(cGraph)$keep <- "NO" for (p in finalshortest) { V(cGraph)[p]$keep <- "YES" } finalsubgraph<-induced.subgraph(cGraph, which(V(cGraph)$keep=="YES"))
再次感谢您帮助Tamas
Finally I found it:
finalshortest = all_simple_paths(cGraph, from = c("n2"), to = V(cGraph)[color=="red"],mode="out") V(cGraph)$keep <- "NO" for (p in finalshortest) { V(cGraph)[p]$keep <- "YES" } finalsubgraph<-induced.subgraph(cGraph, which(V(cGraph)$keep=="YES"))
Thanks again for your help Tamas
相关问答
更多-
最后我找到了: finalshortest = all_simple_paths(cGraph, from = c("n2"), to = V(cGraph)[color=="red"],mode="out") V(cGraph)$keep <- "NO" for (p in finalshortest) { V(cGraph)[p]$keep <- "YES" } finalsubgraph<-induced.subgraph(cGraph, which(V(cGraph)$keep=="YES")) ...
-
使用subgraph()并使用igraph python保留顶点属性(Using subgraph() and preserving vertex attributes with igraph python)[2022-03-11]
使用Block1.vs[c]["name"]获取Block1中社区c中节点的名称。 说明: Block1.vs是整个Block1图的顶点序列。 Block1.vs[c]将此顶点序列子集设置为索引位于可迭代名为c的节点,这是for循环中的情况。 Block1.vs[c]["name"]检索您在上一步中选择的顶点的name顶点属性。 由于名称保存在子图中,因此应该允许您将Block1的节点与原始图形相关联。 Use Block1.vs[c]["name"] to get the names of the nod ... -
如何找到子图(How to find subgraph)[2023-04-14]
正如@aksam建议的那样: var selectedNode = cy.$('node:selected'); var visitedArr = [ selectedNode ]; cy.elements().bfs({ // or dfs roots: selectedNode, visit: function(i, depth, v, e, u){ visitedArr.push( v ); }, directed: false // or your preference } ... -
你有没有试过induced.subgraph()函数? new.vertices<- V(g)[-c(1,2,3,7,8)] g.sub <- induced.subgraph(graph = g, new.vertices) visIgraph(g.sub) %>% visHierarchicalLayout(sortMethod = "directed", direction = "LR",levelSeparation = 300) Have ...
-
您可以使用%in%运算符%in%来匹配列表中的任何值,而不是测试相等性。 只需使用 new_graph<-induced.subgraph(old_graph, which(V(old_graph)$city %in% c("LOS ANGELES","BOSTON","KALAMAZOO"))) Rather than testing for equality, you can use the %in% operator to match any value in a list. Just use ...
-
(R Igraph)使用affilliation从邻接矩阵创建子图((R Igraph) Using affilliation to create subgraph from adjacency matrix)[2022-06-22]
如果您的目标是: 过滤出邻接矩阵中的节点,其中相应的P在隶属矩阵中为1 将过滤后的邻接矩阵转换为igraph对象 然后你可以通过以下方式实现这一目标: # the names(which()) isn't needed for the subset of adj p_nodes <- names(which(aff[,"P"] == 1)) p_adj <- adj[p_nodes, p_nodes] p_graph <- igraph::graph.adjacency(p_graph) If yo ... -
E(subCluster)$text不起作用,因为tweets$text的值在制作时不会添加到图形中。 所以你必须手动完成。 这有点痛苦,但可行。 需要一些tweets数据框的子集和基于用户名的匹配。 首先,请注意边缘类型按特定顺序:转发,提及,回复。 来自特定用户的相同文本可以应用于所有这三个。 所以我认为连续添加文本是有意义的。 > unique(E(g_twitter_actor)$edgeType) [1] "Retweet" "Mention" "Reply" 使用dplry和reshape ...
-
如果将一个数字作为顶点id传递给induced.subgraph函数,它将按编号访问顶点(在图形编号1到23中),由于26,29之类的索引导致“无效顶点ID”错误你希望实际按名称引用顶点,你可以通过传递一个字符串而不是一个数字来实现: for (i in 1:length(cycles)){ vids <- as.character(unlist(cycles[[i]])) subgraph<- induced.subgraph(graph, vids) plot(subgraph) } 现在 ...
-
创建一个名称为数字的网络子图 - 带有R的igraph(Creating a subgraph of network whose names are numbers--igraph with R)[2022-02-16]
R-igraph中的顶点ID必须在[1; | V |]其中| V | 是顶点的数量。 当你的所有节点名都是数字时,igraph可能希望这个条件成立,并在它意识到条件不成立时挽救。 尝试将原始ID转换为字符串 - 从语义上讲,它们可以保持不变,但它们的R类型必须是字符串。 Vertex IDs in R-igraph have to be in the range [1; |V|] where |V| is the number of vertices. When all your node names ar ... -
这实际上非常简单,因为minimum.spanning.tree()保留了边缘属性。 所以你只需要指定一个边缘id属性,你就会看到哪些边缘颜色为红色。 它是这样的: # Some test data, no edge weights, quite boring g <- erdos.renyi.game(20,2/20) g # IGRAPH U--- 20 24 -- Erdos renyi (gnp) graph # + attr: name (g/c), type (g/c), loops (g/l) ...