Changeset 1081
- Timestamp:
- 02/17/21 16:59:46 (4 years ago)
- Location:
- framspy
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/FramsticksLib.py
r1078 r1081 11 11 You can perform basic operations like mutation, crossover, and evaluation of genotypes. 12 12 This way you can perform evolution controlled by python as well as access and manipulate genotypes. 13 You can even design and use in evolution your own genetic representation implemented entirely in python. 13 You can even design and use in evolution your own genetic representation implemented entirely in python, 14 or access and control the simulation and simulated creatures step by step. 14 15 15 16 You need to provide one or two parameters when you run this class: the path to Framsticks CLI where .dll/.so resides -
framspy/frams-test.py
r1078 r1081 1 import sys 1 2 import frams 2 3 3 framspath = "" # set towhere Framsticks binaries and libraries exist4 framspath = sys.argv[1] # set to the directory where Framsticks binaries and libraries exist 4 5 frams.init(framspath, "-Ddata") # "-D"+os.path.join(framspath,"data")) # not possible (maybe python windows issue) because of the need for os.chdir(). So we assume "data" is where the dll/so is 5 6 -
framspy/frams.py
r1078 r1081 12 12 All non-Framsticks Python attributes start with '_' to avoid conflicts with Framsticks attributes. 13 13 Framsticks names that are Python reserved words are prefixed with 'x' (currently just Simulator.ximport). 14 15 14 """ 16 15 … … 21 20 22 21 class ExtValue(object): 22 """All Framsticks objects and values are instances of this class.""" 23 23 24 _reInsideParens = re.compile('\((.*)\)') 24 25 _reservedWords = ['import'] # this list is scanned during every attribute access, only add what is really clashing with framsticks properties … … 247 248 248 249 249 def init( dllpath, *args):250 def init(lib_path, *args): 250 251 original_dir = os.getcwd() 251 os.chdir( dllpath) # because under Windows, frams.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found252 global c_api 253 c_api = ctypes.CDLL('frams _c_api.so' if os.name == 'posix' else 'frams.dll')252 os.chdir(lib_path) # because under Windows, frams.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll 253 global c_api # access global variable 254 c_api = ctypes.CDLL('frams-objects.so' if os.name == 'posix' else 'frams-objects.dll') 254 255 os.chdir(original_dir) 255 256
Note: See TracChangeset
for help on using the changeset viewer.