- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
鉴于此初始图表:
import networkx as nx
G=nx.MultiGraph()
fromnodes=[0,0,1,1,1,1,1,2,3,4,5,5,5,7,8,9,10]
tonodes=[1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
dupedgeind=0
for x,y in zip(fromnodes,tonodes):
if G.has_edge(x,y):
dupedgeind=dupedgeind+1
G.add_edge(x,y,key=dupedgeind)
else:
dupedgeind=0
G.add_edge(x,y,key=dupedgeind)
谁能重现这个错误?
pos=nx.nx_agraph.pygraphviz_layout(G,prog='sfdp')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\networkx\drawing\nx_agraph.py", line 262, in pygraphviz_layout
A=to_agraph(G)
File "C:\Python27\lib\site-packages\networkx\drawing\nx_agraph.py", line 155, in to_agraph
A.add_edge(u,v,key=str(key),**str_edgedata)
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 484, in add_edge
eh = gv.agedge(self.handle, uh, vh, key, _Action.find)
KeyError: 'agedge: no key'
问题与调用graphviz的agege函数有关,好像和key
参数的格式不一样;当我更改时(agraph.py
的第 480 行):
...
eh = gv.agedge(self.handle, uh, vh, key , _Action.create)
...
到
...
eh = gv.agedge(self.handle, uh, vh, "a_string" , _Action.create)
...
它不再失败(但丢失了关键标签)。
是否有明显的方法来解决此问题(以便保留 key
参数值)? - 我尝试的任何方法似乎都不起作用。
接下来最明智的调试步骤是什么?
来自 here ,看来 c
老化函数(我看不到,因为它在 .pyd 二进制文件中)具有以下格式:
*agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
其中 char *name
是键。
我无法弄清楚为什么它不会像初始错误那样接受 str
dtype。
注释版本:
networkx - 1.11,pygraphviz - 1.3.1 (从 http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygraphviz 安装)Windows 7(64 位)上的 Python 2.7(32 位 - 通过 python(x,y) 安装),GraphViz - 2.38
我也看到这个问题出现在这些问题中:
更新 1
我已经尝试将 agege 函数的 key
输入调整为许多 char 数组的变体(例如 (ct.c_char_p * len(key))(key)
(ct 是 ctypes 模块)基于 this )。这会将错误更改为:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\networkx\drawing\nx_agraph.py", line 262, in pygraphviz_layout
A=to_agraph(G)
File "C:\Python27\lib\site-packages\networkx\drawing\nx_agraph.py", line 155, in to_agraph
A.add_edge(u,v,str(key),**str_edgedata)
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 482, in add_edge
eh = gv.agedge(self.handle, uh, vh, (ct.c_char_p * len(key))(key), _Action.create)
TypeError: in method 'agedge', argument 4 of type 'char *'
更新 2
如果我这样做,我可以让它运行(但不返回多图):
在 agraph.py
中替换行
eh = gv.agedge(self.handle, uh, vh, key , _Action.create)
与
try:
# new
if key==0:
eh = gv.agedge(self.handle, uh, vh, str(0), _Action.create)
else:
eh = gv.agedge(self.handle, uh, vh, str(1), _Action.create)
我不知道为什么只转换为字符串 str(key)
不起作用。
更新 3 - 使用函数编辑
在这里找到函数 - https://github.com/ellson/graphviz/blob/master/lib/cgraph/edge.c
Agedge_t *agedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, char *name,
int cflag)
{
Agedge_t *e;
IDTYPE id;
int have_id;
have_id = agmapnametoid(g, AGEDGE, name, &id, FALSE);
if (have_id || ((name == NILstr) && (NOT(cflag) || agisstrict(g)))) {
/* probe for pre-existing edge */
Agtag_t key;
key = Tag;
if (have_id) {
key.id = id;
key.objtype = AGEDGE;
} else {
key.id = key.objtype = 0;
}
/* might already exist locally */
e = agfindedge_by_key(g, t, h, key);
if ((e == NILedge) && agisundirected(g))
e = agfindedge_by_key(g, h, t, key);
if (e)
return e;
if (cflag) {
e = agfindedge_by_key(agroot(g), t, h, key);
if ((e == NILedge) && agisundirected(g))
e = agfindedge_by_key(agroot(g), h, t, key);
if (e) {
subedge(g,e);
return e;
}
}
}
更新 4:
错误的来源在this内pygraphviz 文件,graphviz_wrap.c,第 3921 行:
SWIGINTERN PyObject *_wrap_agedge(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
Agraph_t *arg1 = (Agraph_t *) 0 ;
Agnode_t *arg2 = (Agnode_t *) 0 ;
Agnode_t *arg3 = (Agnode_t *) 0 ;
char *arg4 = (char *) 0 ;
int arg5 ;
void *argp1 = 0 ;
int res1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
void *argp3 = 0 ;
int res3 = 0 ;
int res4 ;
char *buf4 = 0 ;
int alloc4 = 0 ;
int val5 ;
int ecode5 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
PyObject * obj4 = 0 ;
Agedge_t *result = 0 ;
if (!PyArg_ParseTuple(args, char*)"OOOOO:agedge",&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Agraph_t, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '""agedge" "', argument " "1"" of type '" "Agraph_t *""'");
}
arg1 = (Agraph_t *)(argp1);
res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_Agnode_t, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "agedge" "', argument " "2"" of type '" "Agnode_t *""'");
}
arg2 = (Agnode_t *)(argp2);
res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_Agnode_t, 0 | 0 );
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "agedge" "', argument " "3"" of type '" "Agnode_t *""'");
}
arg3 = (Agnode_t *)(argp3);
res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
if (!SWIG_IsOK(res4)) {
SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "agedge" "', argument " "4"" of type '" "char *""'");
}
arg4 = (char *)(buf4);
ecode5 = SWIG_AsVal_int(obj4, &val5);
if (!SWIG_IsOK(ecode5)) {
SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "agedge" "', argument " "5"" of type '" "int""'");
}
arg5 = (int)(val5);
{
result = (Agedge_t *)agedge(arg1,arg2,arg3,arg4,arg5);
if (!result) {
PyErr_SetString(PyExc_KeyError,"agedge: no key");
return NULL;
}
}
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Agedge_t, 0 | 0 );
if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
return resultobj;
fail:
if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
return NULL;
}
或者,它在 this one 内,graphviz.i,第 68 行。
无论哪种方式,如果 agege
因任何原因失败,似乎返回错误字符串“agege: no key”......也许这与 SWIG 有关。
最佳答案
尝试将变量名称从“key”更改为“temp_key”等其他名称。我的意思是,您(或任何以前导入的模块)可能在...之前声明了一个非字符串类型的“key”变量?
显然如果运行:
eh = gv.agedge(self.handle, uh, vh, key , _Action.create)
失败但正在运行:
eh = gv.agedge(self.handle, uh, vh, "key" , _Action.create)
没有问题,它只能与“关键”变量类型相关..你试过这个吗:
eh = gv.agedge(self.handle, uh, vh, str(key) , _Action.create)
或eh = gv.agege(self.handle, uh, vh, unicode(key) , _Action.create)
将 str()/unicode() 集成到您的原始代码中:
import networkx as nx
G=nx.MultiGraph()
fromnodes=[0,0,1,1,1,1,1,2,3,4,5,5,5,7,8,9,10]
tonodes=[1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
dupedgeind=0
for x,y in zip(fromnodes,tonodes):
if G.has_edge(x,y):
dupedgeind=dupedgeind+1
G.add_edge(x,y,key=str(dupedgeind))
#G.add_edge(x,y,key=unicode(dupedgeind))
else:
dupedgeind=0
G.add_edge(x,y,key=str(dupedgeind))
#G.add_edge(x,y,key=unicode(dupedgeind))
两者(str 和 unicode 版本)都可以在 Linux 上正常运行。
最好的问候
关于python - 在 agraph.py 中将字符串传递给agedge。 networkx 和 pygraphviz 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35610736/
如何使用 SPListCollection.Add(String, String, String, String, Int32, String, SPListTemplate.QuickLaunchO
我刚刚开始使用 C++ 并且对 C# 有一些经验,所以我有一些一般的编程经验。然而,似乎我马上就被击落了。我试过在谷歌上寻找,以免浪费任何人的时间,但没有结果。 int main(int argc,
这个问题已经有答案了: In Java 8 how do I transform a Map to another Map using a lambda? (8 个回答) Convert a Map>
我正在使用 node + typescript 和集成的 swagger 进行 API 调用。我 Swagger 提出以下要求 http://localhost:3033/employees/sear
我是 C++ 容器模板的新手。我收集了一些记录。每条记录都有一个唯一的名称,以及一个字段/值对列表。将按名称访问记录。字段/值对的顺序很重要。因此我设计如下: typedef string
我需要这两种方法,但j2me没有,我找到了一个replaceall();但这是 replaceall(string,string,string); 第二个方法是SringBuffer但在j2me中它没
If string is an alias of String in the .net framework为什么会发生这种情况,我应该如何解释它: type JustAString = string
我有两个列表(或字符串):一个大,另一个小。 我想检查较大的(A)是否包含小的(B)。 我的期望如下: 案例 1. B 是 A 的子集 A = [1,2,3] B = [1,2] contains(A
我有一个似乎无法解决的小问题。 这里...我有一个像这样创建的输入... var input = $(''); 如果我这样做......一切都很好 $(this).append(input); 如果我
我有以下代码片段 string[] lines = objects.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.No
这可能真的很简单,但我已经坚持了一段时间了。 我正在尝试输出一个字符串,然后输出一个带有两位小数的 double ,后跟另一个字符串,这是我的代码。 System.out.printf("成本:%.2
以下是 Cloud Firestore 列表查询中的示例之一 citiesRef.where("state", ">=", "CA").where("state", "= 字符串,我们在Stack O
我正在尝试检查一个字符串是否包含在另一个字符串中。后面的代码非常简单。我怎样才能在 jquery 中做到这一点? function deleteRow(locName, locID) { if
这个问题在这里已经有了答案: How to implement big int in C++ (14 个答案) 关闭 9 年前。 我有 2 个字符串,都只包含数字。这些数字大于 uint64_t 的
我有一个带有自定义转换器的 Dozer 映射: com.xyz.Customer com.xyz.CustomerDAO customerName
这个问题在这里已经有了答案: How do I compare strings in Java? (23 个回答) 关闭 6 年前。 我想了解字符串池的工作原理以及一个字符串等于另一个字符串的规则是
我已阅读 this问题和其他一些问题。但它们与我的问题有些无关 对于 UILabel 如果你不指定 ? 或 ! 你会得到这样的错误: @IBOutlet property has non-option
这两种方法中哪一种在理论上更快,为什么? (指向字符串的指针必须是常量。) destination[count] 和 *destination++ 之间的确切区别是什么? destination[co
This question already has answers here: Closed 11 years ago. Possible Duplicates: Is String.Format a
我有一个Stream一个文件的,现在我想将相同的单词组合成 Map这很重要,这个词在 Stream 中出现的频率. 我知道我必须使用 collect(Collectors.groupingBy(..)
我是一名优秀的程序员,十分优秀!