나는 파이썬에서 빠른 최소 스패닝 트리 프로그램을 만들기 위해 scipy.weave를 시험 중이다. 불행히도 scipy.weave를 C++ 라이브러리와 함께 사용하면 STANN이 더 어려워졌습니다. 다음은 STANN 라이브러리에 대한 링크입니다. http://sites.google.com/a/compgeom.com/stann/Python scipy.weave and STANN C++ Library
다음은 내가 작성한 scipy.weave 스크립트가있는 Python입니다.
import scipy.weave as weave
from scipy.weave import inline
import numpy
def gmst(points):
# computing GMST with STANN headers
assert(type(points) == type(numpy.array([])))
# now the c++ code
code = """
using namespace std;
typedef reviver::dpoint<double,2> Point;
typedef vector<Point>::size_type stype;
vector< std::pair<stype,stype> > outputmst;
PyArrayObject *py_val
gmst(points,outputmst);
return_val = outputmst;
"""
return inline(code,['points'],
headers = ["<iostream>","<gmst.hpp>","<dpoint.hpp>","<test.hpp>"],
include_dirs=["/home/tree/usr/STANN/include"])
지금까지는 직조 작업을 할 필요가 없습니다. 내가 왜 문제에 부딪 치고 있는지 어떤 아이디어가 있니? 도와 주셔서 감사합니다.
환호
당신의 질문은 아니지만 그래프가 얼마나 크고/얼마나 큽니까? (나는 단순한 순수 파이썬 MST, sort + Kruskal + unionfind를 사용하는데, 대부분 시간이 많이 걸린다.) – denis
나는 보통 300에서 30,000 개의 노드를 다루고있다. 때로는 더 커. 그러나 투영 분석 (3D 데이터)을 위해서는 MST를 계산해야합니다. networkx와 matplotlib.delaunay를 사용하여 파이썬에서 MST 프로그램을 작성하여 약 5 초 만에 50,000 개의 소스의 MST를 계산하는 방법을 찾았습니다. 지금은 충분히 빠릅니다. – ebressert