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

    prop = DTIndividualPropertyVanillaEvolutive()

    precycleFile = os.getcwd()+"/mocap/cmu_mocap/xml/util/walk_precycle.xml"
    preCycleEmbryo = DTIndividualGeneticTimeSerieFile(precycleFile)
    preCycleLength = preCycleEmbryo.getLength()

    if int(conf.getProperty("Concatenate walk cycles?")):
        embryo = DTIndividualGeneticMatrixWalk(chromosomeToLucyGeneticMatrix(chromosome))
        embryoCycleLength = (embryo.getLength() - preCycleLength) / int(conf.getProperty("Concatenate walk cycles?"))

    else:
        embryo = DTIndividualGeneticMatrix(chromosomeToLucyGeneticMatrix(chromosome))
        embryoCycleLength = embryo.getLength() - preCycleLength

    if int(conf.getProperty("concatenate external cycle file?")):
        externalFirstCycleFile = os.getcwd() + conf.getFile("external cycle file")
        externalFirstCycle = DTIndividualGeneticTimeSerieFile(externalFirstCycleFile)
        preCycleEmbryo.concatenate(externalFirstCycle)
        preCycleLength = preCycleEmbryo.getLength()
        embryoCycleLength = embryoCycleLength - externalFirstCycle.getLength()

    preCycleEmbryo.concatenate(embryo)
    newEmbryo = preCycleEmbryo
    #embryoLength = newEmbryo.getLength()
    individual = Individual(prop, newEmbryo)
    individual.setPrecycleLength(preCycleLength)

    individual.setCycleLength(embryoCycleLength)
    print "el cycle length seteado es: ", embryoCycleLength

    ##print "precyclelength:  ", preCycleLength
    ##print "cyclelength:  ", embryoCycleLength
    #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 createIndividual(filename):
    if int(conf.getProperty("Lucy simulated?"))==1:

        precycleFile = os.getcwd()+"/mocap/cmu_mocap/xml/util/walk_precycle.xml"
        preCycleEmbryo = DTIndividualGeneticTimeSerieFile(precycleFile)
        preCycleLength = preCycleEmbryo.getLength()

        if int(conf.getProperty("Concatenate walk cycles?")):
            walkEmbryo = DTIndividualGeneticTimeSerieFileWalk(os.getcwd()+"/"+filename)
            embryoCycleLength = (walkEmbryo.getLength() - preCycleLength) / int(conf.getProperty("Concatenate walk cycles?"))
        else:
            walkEmbryo = DTIndividualGeneticTimeSerieFile(os.getcwd()+"/"+filename)
            embryoCycleLength = walkEmbryo.getLength() - preCycleLength
        #walk = Individual(geneticVanillaPropNothingToAvoid, DTIndividualGeneticTimeSerieFile(os.getcwd()+"/"+filename)) #For Reda Al-Bahrani work compability


        if int(conf.getProperty("concatenate external cycle file?")):
            externalFirstCycleFile = os.getcwd() + conf.getFile("external cycle file")
            externalFirstCycle = DTIndividualGeneticTimeSerieFile(externalFirstCycleFile)
            preCycleEmbryo.concatenate(externalFirstCycle)
            preCycleLength = preCycleEmbryo.getLength()
            embryoCycleLength = embryoCycleLength - externalFirstCycle.getLength()


        preCycleEmbryo.concatenate(walkEmbryo)
        walkEmbryo = preCycleEmbryo
        walk = Individual(geneticVanillaProp, walkEmbryo)
        walk.setPrecycleLength(preCycleLength)
        walk.setCycleLength(embryoCycleLength)

    else:
        #TODO physical stage
        #TODO restructure the precycle for the case of physical and simulated
        walkEmbryo = DTIndividualGeneticTimeSerieFile(os.getcwd()+"/"+filename)
        precycleFile = os.getcwd()+"/mocap/cmu_mocap/xml/util/walk_precycle.xml"
        preCycleEmbryo = DTIndividualGeneticTimeSerieFile(precycleFile)
        preCycleEmbryo.concatenate(walkEmbryo)

        if int(conf.getProperty("concatenate external cycle file?")):
            precycleFile = os.getcwd() + conf.getFile("external cycle file")
            firstCycle = DTIndividualGeneticTimeSerieFile(precycleFile)
            preCycleEmbryo.concatenate(firstCycle)

        walkEmbryo = preCycleEmbryo
        walk = Individual(physicalProp, walkEmbryo)
        #TODO add support for walking cycle
    return walk