#!/usr/bin/env python # -*- coding: utf-8 -*- # example based on: http://www.thenumber42.net/2008/03/31/how-to-use-jpype/ # Simple little JPype test. Note: This test assumes # that the jar file is in the build/jar directory # relative to the current directory import jpype import os.path #jpype configuration systemPath = "/usr/share/eva/lib" if os.path.exists(os.path.abspath('.') + "/EvA2Base.jar"): jarpath = os.path.abspath('.') elif os.path.exists(systemPath + "/EvA2Base.jar"): jarpath = systemPath else: print "Cannot find EvA2 jar file" jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath) #get needed classes ExternalProblemClass = jpype.JClass('eva2.server.go.problems.ExternalRuntimeProblem') OptimizerFactoryClass = jpype.JClass('eva2.OptimizerFactory') #External Problem ExProblem = ExternalProblemClass() ExProblem.setCommand("./F1ProblemTest.py") ExProblem.setWorkingDirectory(os.path.abspath('.')) OptimizerFactoryClass.setEvaluationTerminator(1000) result = OptimizerFactoryClass.optimizeToDouble(OptimizerFactoryClass.PSO, ExProblem, None) print "Found solution:" for i in range(ExProblem.getProblemDimension()): print result[i] #jpype closing jpype.shutdownJVM()