예제 #1
0
def eval_func(chromosome):
    conf = LoadSystemConfiguration()
    if not initialPopulationSetted:
        setInitialPopulation(gaEngine)

    prop = DTIndividualPropertyVanillaEvolutive()
    if int(conf.getProperty("Concatenate walk cycles?")):
        embryo = DTIndividualGeneticMatrixWalk(chromosomeToLucyGeneticMatrix(chromosome))
    else:
        embryo = DTIndividualGeneticMatrix(chromosomeToLucyGeneticMatrix(chromosome))
    precycleFile = os.getcwd()+"/mocap/cmu_mocap/xml/util/walk_precycle.xml"
    preCycleEmbryo = DTIndividualGeneticTimeSerieFile(precycleFile)
    preCycleEmbryo.concatenate(embryo)
    newEmbryo = preCycleEmbryo
    #embryoLength = newEmbryo.getLength()
    individual = Individual(prop, newEmbryo)
    #individual.setLength(embryoLength)
    fitness = individual.execute() #return the fitness resulting from the simulator execution

    if int(conf.getProperty("re-evaluate fittest?"))==True:
        if fitness > max_score: #is really a better fitness ?
            candidateFitness = fitness
            fitness = individual.execute()
            print "candidateFitness: ", candidateFitness, "fitness: ", fitness
            while abs(candidateFitness-fitness) > 0.01:
                candidateFitness=fitness
                fitness = individual.execute()
                print "candidateFitness: ", candidateFitness, "fitness: ", fitness
            #the candidateFitness was validated!
            fitness = candidateFitness
    return fitness
예제 #2
0
def eval_func(chromosome):
    if not initialPopulationSetted:
        setInitialPopulation(gaEngine)    
    #prop = DTIndividualPropertyVanilla() #TODO create a vanilla property as default argument in Individual constructor
    prop = DTIndividualPropertyVanillaEvolutive()
    individual = Individual(prop, DTIndividualGeneticMatrix(chromosomeToLucyGeneticMatrix(chromosome)))
    fitness = individual.execute() #return the fitness resulting from the simulator execution
    return fitness
예제 #3
0
        walk = Individual(geneticVanillaProp, walkEmbryo)

    else:
        #TODO restructure the precycle for the case of phyisical and simulated
        walkEmbryo = DTIndividualGeneticTimeSerieFile(os.getcwd()+"/"+filename)
        precycleFile = os.getcwd()+"/mocap/cmu_mocap/xml/util/walk_precycle.xml"
        preCycleEmbryo = DTIndividualGeneticTimeSerieFile(precycleFile)
        preCycleEmbryo.concatenate(walkEmbryo)
        walkEmbryo = preCycleEmbryo
        walk = Individual(physicalProp, walkEmbryo)
        #TODO add support for walking cycle
    return walk

'''walk = Individual(geneticVanillaProp, DTIndividualGeneticMatrix()) #dummy individual to initialise the simulator and enable the time step configuration
walk.execute()
print "please set the proper time step in vrep"
time.sleep(5)'''
if arguments > 1:
    files = sys.argv[1:]
    for filename in files:
        print 'executing individual: ' + filename
        walk = createIndividual(filename)
        walk.execute()
else:
    for filename in glob.glob(os.path.join(geneticPoolDir, '*.xml')):
        print 'executing individual: ' + filename
        walk = Individual(geneticVanillaProp, DTIndividualGeneticTimeSerieFile(filename))
        walk.execute()


예제 #4
0
def setInitialPopulation(ga_engine):

    propCMUDaz = DTIndividualPropertyCMUDaz()
    propVanilla = DTIndividualPropertyVanilla()
    balieroProp = DTIndividualPropertyBaliero()

    conf = LoadSystemConfiguration()

    lucyCycles = os.getcwd()+conf.getDirectory("Lucy evolved walk cycles Files")
    CMUxmlDir = os.getcwd()+conf.getDirectory("Transformed CMU mocap Files")
    GAwalkDir = os.getcwd()+conf.getDirectory("GAWalk Files")
    UIBLHDir = os.getcwd()+conf.getDirectory("UIBLH mocap Files")
    BalieroDir = os.getcwd()+conf.getDirectory("Baliero transformed walk Files")
    ADHOCDir = os.getcwd()+conf.getDirectory("ADHOC Files")
    geneticPoolDir = os.getcwd()+conf.getDirectory("Genetic Pool")
    
    population = ga_engine.getPopulation()
    popSize = len(population)

    individualCounter = 0
    walk = Individual(propVanilla, DTIndividualGeneticMatrix()) #dummy individual to initialise the simulator and enable the time step configuration
    walk.execute()
    print "please set the proper time step in vrep"


    dtgenoma = DTGenomeFunctions()


    #the random initia population created is replaced by the imitation motion capture database
    if individualCounter < popSize:
        for filename in glob.glob(os.path.join(CMUxmlDir, '*.xml')):
            if individualCounter < popSize:
                print individualCounter, " individuals processed!"
                print 'inserting individual: ' + filename + " into the initial population"
                walk = Individual(propCMUDaz, DTIndividualGeneticTimeSerieFile(filename))
                teacherGeneticMatrix = walk.getGenomeMatrix()
                adan = population[individualCounter]
                adanIndividualLength=dtgenoma.getIndividualLength(adan)
                adanJointLength=dtgenoma.getIndividualFrameLength(adan)
                for i in xrange(adanIndividualLength):
                    for j in xrange(adanJointLength):
                        if i < len(teacherGeneticMatrix): #if the fixed gnoma representation size is less than the teacher size
                            adan.setItem(i,j,teacherGeneticMatrix[i][j])
                        else:
                            #put a sentinel joint value to mark the end of the individual
                            adan.setItem(i,j,sysConstants.JOINT_SENTINEL)
                population[individualCounter]=adan
                individualCounter = individualCounter + 1
            else:
                break
    #uncomment this block and comment the one above to use individuals with vainilla format

    '''if individualCounter < popSize:
        for filename in glob.glob(os.path.join(CMUxmlDir, '*.xml')):
            if individualCounter < popSize:
                print individualCounter, " individuals processed!"
                print 'inserting individual: ' + filename + " into the initial population"
                walk = Individual(propVanilla, DTIndividualGeneticTimeSerieFile(filename))
                teacherGeneticMatrix = walk.getGenomeMatrix()
                adan = population[individualCounter]
                adanIndividualLength=dtgenoma.getIndividualLength(adan)
                adanJointLength=dtgenoma.getIndividualFrameLength(adan)
                for i in xrange(adanIndividualLength):
                    for j in xrange(adanJointLength):
                        if i < len(teacherGeneticMatrix): #if the fixed gnoma representation size is less than the teacher size
                            adan.setItem(i,j,teacherGeneticMatrix[i][j])
                        else:
                            #put a sentinel joint value to mark the end of the individual
                            adan.setItem(i,j,sysConstants.JOINT_SENTINEL)
                population[individualCounter]=adan
                individualCounter = individualCounter + 1
            else:
                break
    '''

    global initialPopulationSetted
    initialPopulationSetted = True
예제 #5
0
from parser.LoadPoses                           import LoadPoses
from datatypes.DTIndividualProperty             import DTIndividualProperty, DTIndividualPropertyCMUDaz, DTIndividualPropertyVanilla, DTIndividualPropertyBaliero, DTIndividualPropertyVanillaEvolutive, DTIndividualPropertyPhysicalBioloid
from datatypes.DTIndividualGeneticMaterial      import DTIndividualGeneticMaterial, DTIndividualGeneticTimeSerieFile, DTIndividualGeneticMatrix
from Pose                                       import Pose
from configuration.LoadSystemConfiguration      import LoadSystemConfiguration
from simulator.LoadRobotConfiguration           import LoadRobotConfiguration
from Individual                                 import Individual

import os
import glob
import time
import sys

propCMUDaz = DTIndividualPropertyCMUDaz()
propVanilla = DTIndividualPropertyVanilla()
balieroProp = DTIndividualPropertyBaliero()
physicalProp = DTIndividualPropertyPhysicalBioloid()
geneticVanillaProp = DTIndividualPropertyVanillaEvolutive()

conf = LoadSystemConfiguration()

CMUxmlDir = os.getcwd()+conf.getDirectory("Transformed CMU mocap Files")


for filename in glob.glob(os.path.join(CMUxmlDir, '*.xml')):
    walk = Individual(propCMUDaz, DTIndividualGeneticTimeSerieFile(filename))
    fitness = walk.execute()
    length = walk.getLength()
    walk.persist("/tmp/"+str(fitness)+".xml")
    print "individual: ", filename, "fitness: ", fitness, "length: ", length