Beispiel #1
0
import sys
import naturalSelection as ns
import networkx as nx
import matplotlib.pyplot as plt
if len(sys.argv) < 2:
    print("usage is: " + sys.argv[0] + " <graphFilename>")
    sys.exit(1)
with open(sys.argv[1]) as f:
    simulation = ns.loadGraph(f)

nx.draw_networkx(simulation['graph'])
print(ns.MRCA(simulation))
plt.show()

# TODO testcase
# print([(i, simulation["graph"].node[i]["descendants"]) for i in simulation["graph"].node])
# print([(i, simulation["graph"].node[i]["genotype"]) for i in simulation["graph"].node])
# TODO testcase
# for key in simulation["graph"].node:
#   print(simulation["graph"].node[key]["descendants"])

#for key in simulation["graph"].node:
#   print(simulation["graph"].node[key]["visitedBy"])

#print(len(simulation["lastGeneration"]))
def generateRandomBreeding(fileObj):
    def firstGeneration():
        return ns.simsFrame(populationSize=100, mutator=ns.oneDominantAlleleMutator)

    def nextGeneration(nextFrame):
        return nextFrame(migrator=ns.wandererMigrator, breeder=ns.simpleProximityBreeder)

    ns.generatePopulation(fileObj, 10, firstGeneration, nextGeneration)


def generateMutationBreeding(fileObj):
    def firstGeneration():
        return ns.simsFrame(populationSize=10, mutator=ns.oneDominantAlleleMutator)

    def nextGeneration(nextFrame):
        return nextFrame(migrator=ns.wandererMigrator, breeder=ns.simpleProximityBreeder)

    ns.generatePopulation(fileObj, 3, firstGeneration, nextGeneration)


randomBreeding = "data/randomBreeding"
solutions = []
for i in range(10):
    with open(randomBreeding + str(i), "w") as fileObj:
        generateRandomBreeding(fileObj)
    with open(randomBreeding + str(i), "r") as fileObj:
        simulation = ns.loadGraph(fileObj)
    solutions.append(ns.MRCA(simulation)[1])
print solutions
import sys
import naturalSelection as ns
import networkx as nx
import matplotlib.pyplot as plt
if len(sys.argv) < 2:
    print("usage is: " + sys.argv[0] + " <graphFilename>")
    sys.exit(1)
with open(sys.argv[1]) as f:
    simulation = ns.loadGraph(f)

nx.draw_networkx(simulation['graph'])
print(ns.MRCA(simulation))
plt.show()


# TODO testcase
# print([(i, simulation["graph"].node[i]["descendants"]) for i in simulation["graph"].node])
# print([(i, simulation["graph"].node[i]["genotype"]) for i in simulation["graph"].node])
# TODO testcase
# for key in simulation["graph"].node:
#   print(simulation["graph"].node[key]["descendants"])

#for key in simulation["graph"].node:
#   print(simulation["graph"].node[key]["visitedBy"])

#print(len(simulation["lastGeneration"]))