Monday, March 12, 2007

AlgoAnalysis prototype version 0.0.1

Projek ni nak generate statistics for algorithm performance testing. Hence, the name 'AlgoAnalysis'. This is just a prototype but the random graph generator has been completed using python. This prototype tests if those classes can be called from a JAVA program which I have successfully demonstrated in the screenshot above as I use ANT to build my project.

Interaction antara JAVA ngan Python menggunakan JYTHON. Drawback nye is that JYTHON guna Python2.2 je. Tatau lak bile nak release one for 2.4 / 2.5. As a result, certain functions takde. Tapi there are ways around that.

Python leh interact ngan JAVA. Nak panggil JAVA class senang aje, tapi nak panggil Python nye class payah sikit. Kene buat an intermediary class and embed Python scripts in the JAVA program as if sending commands to the interpreter.
Python :

import random
class Graph:
def __init__(self):
self.nodeIDList = []
self.nodeEdgelistDict = {}
self.nodeEdgelistWeightDict = {}

self.allowLoops = 0
self.allowMultipleEdges = 0
self.directedGraphType = 1

self.edgeWeightUpperLimit = 10
self.edgeWeightLowerLimit = -10

def generateGraph(self,nodeTotal,edgeTotal):
# add nodes first and define edge list
for currNodeCount in range(nodeTotal):
nodeID = self.getNextUniqueID()
self.nodeIDList.append(nodeID)
self.nodeEdgelistDict[nodeID] = []
.
.
.

JAVA :

package AlgoAnalysis;

import org.python.util.PythonInterpreter;
import org.python.core.*;

public class Graph {
private String variableName = "";
private PythonInterpreter interp = new PythonInterpreter();

public Graph(String newVariableName) throws PyException {
this.variableName=newVariableName;
interp.exec("import graphGenerator, graphAnalysis");
interp.exec(variableName+" = graphGenerator.Graph()");
}
public void generateGraph(int nodeTotal,int edgeTotal){
interp.exec(variableName+".generateGraph("+nodeTotal+","+edgeTotal+")");
}
public void toFile(String filename){
interp.exec(variableName+".toFile(\""+filename+"\")");
}
.
.
.



As a result the python scripts are translated and compiled into
JAVA classes like so:

Labels:

0 Comments:

Post a Comment

<< Home