예제 #1
0
def setInitialPopulation (ga_engine):

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

    conf = LoadSystemConfiguration()

    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
    
#    if individualCounter < popSize:
#        for filename in glob.glob(os.path.join(GAwalkDir, '*.xml')):
#            print individualCounter, " individuals processed!"
#            print 'inserting individual: ' + filename + " into the initial population"
#            walk = Individual(propVanilla, DTIndividualGeneticTimeSerieFile(filename))
#            geneticMatrix = walk.getGenomeMatrix()
#            if individualCounter < popSize:
#                adan = population[individualCounter]
#                for i in xrange(adan.getHeight()):
#                    if i == len(geneticMatrix):
#                            break
#                    for j in xrange(adan.getWidth()):
#                        adan.setItem(i,j,geneticMatrix[i][j])
#                population[individualCounter]=adan
#                individualCounter = individualCounter + 1
#            else:
#                break
        
    if individualCounter < popSize:
        for filename in glob.glob(os.path.join(CMUxmlDir, '*.xml')):
            print individualCounter, " individuals processed!"
            print 'inserting individual: ' + filename + " into the initial population"
            walk = Individual(prop, DTIndividualGeneticTimeSerieFile(filename))
            geneticMatrix = walk.getGenomeMatrix()
            if individualCounter < popSize:
                adan = population[individualCounter]
                for i in xrange(adan.getHeight()):
                    if i == len(geneticMatrix):
                            break
                    for j in xrange(adan.getWidth()):
                        adan.setItem(i,j,geneticMatrix[i][j])
                population[individualCounter]=adan
                individualCounter = individualCounter + 1
            else:
                break

    global initialPopulationSetted
    initialPopulationSetted = True
예제 #2
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