470,821 Members | 1,968 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

Steiner Tree

Hi,
I am looking for links to any implementation of Steiner Tree (
http://en.wikipedia.org/wiki/Steiner_tree ) construction in Python. I
could find GeoSteiner ( http://www.diku.dk/geosteiner/ ) which is
implemented as a C program. Anybody know python wrapper for this?
Anybody tried this program in a python program?

-
Suresh

Feb 5 '07 #1
2 2983
Suresh:
I could find GeoSteiner (http://www.diku.dk/geosteiner/) which is
implemented as a C program. Anybody know python wrapper for this?
Anybody tried this program in a python program?
Once compiled, you may just need to use it with files calling it
through the console with pipes from Python. If that isn't enough, you
can probably write a simple enough wrapper using Pyrex.
If you succed, I may be interested in the result.

Bye,
bearophile

Feb 6 '07 #2
On Feb 7, 4:11 am, bearophileH...@lycos.com wrote:
Suresh:
I could find GeoSteiner (http://www.diku.dk/geosteiner/) which is
implemented as a C program. Anybody know python wrapper for this?
Anybody tried this program in a python program?

Once compiled, you may just need to use it with files calling it
through the console with pipes from Python. If that isn't enough, you
can probably write a simple enough wrapper using Pyrex.
If you succed, I may be interested in the result.

Bye,
bearophile
bearophile,
Thanks for the response.
I could compile the program. I am now doing this with pipes only; but
only thing is that, I had to parse the ps output myself, to generate
the line segements, which looks ugly and fails in some cases. Did you
find any other way to directly get the new line segments and steiner
points.

import popen2,re
def steiner(points):
process = popen2.Popen3('/path/rfst |\
/path/prunefst \
| /path/bb')

for pt in points:
process.tochild.write('%f %f\n' % (pt[0], pt[1]))
process.tochild.close()

process.wait()

BeginPlot=False
EndPlot=False
lineSegments = []
for line in process.fromchild:
if not EndPlot:
if BeginPlot:
if line == 'EndPlot\n':
EndPlot = True
else:
if not (re.match('^\s.*%', line) \
or re.match('\s*Plot_Terminals', line) \
or re.match('^\s*\(', line)\
):
#print line
a,b,c,d,j = line.split()
if b == 'T':
p1 = points[int(a)]
else:
p1 = (float(a),float(b))
if d == 'T':
p2 = points[int(c)]
else:
p2 = (float(c), float(d))
if not(p1[0] == p2[0] and p1[1] == p2[1]):
lineSegments.append((p1,p2))
else:
if line == 'BeginPlot\n':
BeginPlot=True
return(lineSegments)

I want to write the code with pyrex, but the c program looks
complicated. Maybe with some help in understanding from you, we can
write the wrapper with pyrex.

-
Suresh
Feb 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jeffrey Silverman | last post: by
reply views Thread by Tree menu using XML | last post: by
4 posts views Thread by Tarique Jawed | last post: by
2 posts views Thread by New | last post: by
5 posts views Thread by Mike | last post: by
2 posts views Thread by Kiran | last post: by
1 post views Thread by Satish.Talyan | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.