コード例 #1
0
    def sapienz_mut_suite(self, individual: Individual,
                          indpb: float) -> Tuple[Individual]:
        # shuffle seq
        individual, = tools.mutShuffleIndexes(individual, indpb)

        # crossover inside the suite
        # perform one point crossover between odd and even pair positions of test cases
        for i in range(1, len(individual), 2):
            if random.random() < settings.MUTPB:
                if len(individual[i - 1]) <= 2:
                    continue
                if len(individual[i]) <= 2:
                    continue

                individual[i - 1], individual[i] = tools.cxOnePoint(
                    individual[i - 1], individual[i])

        # shuffle events inside each test case
        for i in range(len(individual)):
            if random.random() < settings.MUTPB:
                if len(individual[i]) <= 2:
                    continue
                individual[i], = tools.mutShuffleIndexes(individual[i], indpb)

        return individual,
コード例 #2
0
def mut_suite(individual, indpb):
    # shuffle seq
    individual, = tools.mutShuffleIndexes(individual, indpb)

    # crossover inside the suite
    for i in range(1, len(individual), 2):
        if random.random() < settings.MUTPB:
            if len(individual[i - 1]) <= 2:
                print "\n\n### Indi Length =", len(individual[i - 1]), " ith = ", i - 1, individual[i - 1]
                continue  # sys.exit(1)
            if len(individual[i]) <= 2:
                print "\n\n### Indi Length =", len(individual[i]), "ith = ", i, individual[i]
                continue  # sys.exit(1)

            individual[i - 1], individual[i] = tools.cxOnePoint(individual[i - 1], individual[i])
            # individual[i - 1], individual[i] = tools.cxUniform(individual[i - 1], individual[i], indpb=0.5)

    # shuffle events
    for i in range(len(individual)):
        if random.random() < settings.MUTPB:
            if len(individual[i]) <= 2:
                print "\n\n### Indi Length =", len(individual[i]), "ith = ", i, individual[i]
                continue  # sys.exit(1)
            individual[i], = tools.mutShuffleIndexes(individual[i], indpb)

    return individual,
コード例 #3
0
ファイル: main.py プロジェクト: terminiter/sapienz
def mut_suite(individual, indpb):
	# shuffle seq
	individual, = tools.mutShuffleIndexes(individual, indpb)

	# crossover inside the suite
	for i in range(1, len(individual), 2):
		if random.random() < settings.MUTPB:
			if len(individual[i - 1]) <= 2:
				print "\n\n### Indi Length =", len(individual[i - 1]), " ith = ", i - 1, individual[i - 1]
				continue  # sys.exit(1)
			if len(individual[i]) <= 2:
				print "\n\n### Indi Length =", len(individual[i]), "ith = ", i, individual[i]
				continue  # sys.exit(1)

			individual[i - 1], individual[i] = tools.cxOnePoint(individual[i - 1], individual[i])

	# shuffle events
	for i in range(len(individual)):
		if random.random() < settings.MUTPB:
			if len(individual[i]) <= 2:
				print "\n\n### Indi Length =", len(individual[i]), "ith = ", i, individual[i]
				continue  # sys.exit(1)
			individual[i], = tools.mutShuffleIndexes(individual[i], indpb)

	return individual,
コード例 #4
0
def mutate_permutation(individual, solver):
    method, parameters = solver.current_step.method, solver.current_step.parameters
    # print("Before: {}".format(individual))

    if method in (SolverMethod.CLUSTERING, SolverMethod.BOTH):
        # mutate_assignment(individual, solver, parameters['inpdb'])
        for item in individual[:-1]:
            tools.mutShuffleIndexes(item, parameters['inpdb'])

    if method in (SolverMethod.SCHEDULING, SolverMethod.BOTH):
        tools.mutShuffleIndexes(individual[-1], parameters['inpdb'])

    # print("After: {}".format(individual))
    return individual,
コード例 #5
0
 def __mutate(ind, indpb):
     """
     该函数为变异函数,对ind执行变异操作。
     在Deap中,可以使用的函数只有mutShuffleIndexes。
     具体查看https://deap.readthedocs.io/en/master/api/tools.html#operators
     """
     return tools.mutShuffleIndexes(ind, indpb)
コード例 #6
0
 def mutate(self, individual, probability):
     if self.method == 'Polynomial':
         return tools.mutPolynomialBounded(individual,
                                           eta=20.0,
                                           low=0.0,
                                           up=1.0,
                                           indpb=1 / len(individual))[0]
     elif self.method == 'Shuffle':
         return tools.mutShuffleIndexes(individual, probability)[0]
コード例 #7
0
ファイル: machauto_01.py プロジェクト: Bernolt/GAsEpaper
def mutation(ind,mu,sigma,pr,ll,ul):
    for i in xrange(len(ind[0])):
       if random.random() < pr:
          ind[0][i] += int(math.ceil(random.gauss(mu,sigma)))
          if ind[0][i] < 0:
             ind[0][i] = 0
    if random.random() < pr:
       ind[1] = tools.mutShuffleIndexes(ind[1],pr)[0]
    for i in xrange(len(ind[2])):
       if random.random() < pr:
          ind[2][i] = random.randint(ll,ul)

    return ind,
コード例 #8
0
ファイル: utils.py プロジェクト: karthik3583/MasterThesis
def mutate(individual, indpb):
    # shuffle seq
    individual, = tools.mutShuffleIndexes(individual, indpb)

    # crossover inside the suite
    for i in range(1, len(list(individual)), 2):
        if random.random() < MUTPB:
            if len(list(individual)) <= 2:
                continue  # sys.exit(1)
            if len(list(individual)) <= 2:
                continue  # sys.exit(1)

            individual[i - 1], individual[i] = tools.cxBlend(
                individual[i - 1], individual[i], 0.7)

    # shuffle events
    for i in range(len(list(individual))):
        if random.random() < MUTPB:
            if len(list(individual)) <= 2:
                continue  # sys.exit(1)
            list(individual)[i], = tools.mutShuffleIndexes(
                list(individual)[i], indpb)
    return individual
コード例 #9
0
 def custom_mutate(ind, indpb):
     i = random.randint(1, 3)
     if i == 1:
         tools.mutShuffleIndexes(ind[0], indpb)
     elif i == 2:
         tools.mutShuffleIndexes(ind[1], indpb)
     elif i == 3:
         tools.mutShuffleIndexes(ind[2], indpb)
     return ind,
コード例 #10
0
ファイル: machauto_02.py プロジェクト: jbmere/GAsEpaper
def mutation(ind, avail, mis, pr, ll, ul):
    nc = len(ind[0])
    j = random.randint(0, int(nc / 3))
    for ij in range(j):
        ind[0][random.randint(0, nc - 1)] = random.randint(0, avail / 2)
    while sum(ind[0]) > avail:
        ind[0] = [int(x / 2.0) for x in ind[0]]
    ind[0][0] = max(mis, ind[0][0])
    if random.random() < pr:
        ind[1] = tools.mutShuffleIndexes(ind[1], pr)[0]
    if ul > ll:
        j = random.randint(0, int(nc / 3))
        for ij in range(j):
            if random.random() < pr:
                ind[2][random.randint(0, nc - 1)] = random.randint(ll, ul)
    return (ind,)
コード例 #11
0
ファイル: machauto_02.py プロジェクト: Bernolt/GAsEpaper
def mutation(ind, avail, mis, pr, ll, ul):
    nc = len(ind[0])
    j = random.randint(0, int(nc / 3))
    for ij in range(j):
        ind[0][random.randint(0, nc - 1)] = random.randint(0, avail / 2)
    while sum(ind[0]) > avail:
        ind[0] = [int(x / 2.) for x in ind[0]]
    ind[0][0] = max(mis, ind[0][0])
    if random.random() < pr:
        ind[1] = tools.mutShuffleIndexes(ind[1], pr)[0]
    if ul > ll:
        j = random.randint(0, int(nc / 3))
        for ij in range(j):
            if random.random() < pr:
                ind[2][random.randint(0, nc - 1)] = random.randint(ll, ul)
    return ind,
コード例 #12
0
def mutate(x, indpb):
    for x_attr in x:
        tools.mutShuffleIndexes(x_attr, indpb)
コード例 #13
0
def mutation_main(individual, indpb, column_names, heating_unit_names_share,
                  cooling_unit_names_share, column_names_buildings_heating,
                  column_names_buildings_cooling, district_heating_network,
                  district_cooling_network):
    # create dict of individual with his/her name
    individual_with_name_dict = dict(zip(column_names, individual))

    if district_heating_network:

        # MUTATE BUILDINGS CONNECTED
        buildings_heating = [
            individual_with_name_dict[column]
            for column in column_names_buildings_heating
        ]
        # apply mutations
        buildings_heating_mutated = tools.mutFlipBit(buildings_heating,
                                                     indpb)[0]
        # take back to the individual
        for column, mutated_value in zip(column_names_buildings_heating,
                                         buildings_heating_mutated):
            individual_with_name_dict[column] = mutated_value

        # MUTATE SUPPLY SYSTEM UNITS SHARE
        heating_units_share = [
            individual_with_name_dict[column]
            for column in heating_unit_names_share
        ]
        # apply mutations
        heating_units_share_mutated = tools.mutShuffleIndexes(
            heating_units_share, indpb=indpb)[0]
        # takeback to teh individual
        for column, mutated_value in zip(heating_unit_names_share,
                                         heating_units_share_mutated):
            individual_with_name_dict[column] = mutated_value

    if district_cooling_network:

        # MUTATE BUILDINGS CONNECTED
        buildings_cooling = [
            individual_with_name_dict[column]
            for column in column_names_buildings_cooling
        ]
        # apply mutations
        buildings_cooling_mutated = tools.mutFlipBit(buildings_cooling,
                                                     indpb)[0]
        # take back to teh individual
        for column, mutated_value in zip(column_names_buildings_cooling,
                                         buildings_cooling_mutated):
            individual_with_name_dict[column] = mutated_value

        # MUTATE SUPPLY SYSTEM UNITS SHARE
        cooling_units_share = [
            individual_with_name_dict[column]
            for column in cooling_unit_names_share
        ]
        # apply mutations
        cooling_units_share_mutated = tools.mutShuffleIndexes(
            cooling_units_share, indpb)[0]
        # takeback to teh individual
        for column, mutated_value in zip(cooling_unit_names_share,
                                         cooling_units_share_mutated):
            individual_with_name_dict[column] = mutated_value

    # now validate individual
    individual_with_name_dict = validation_main(
        individual_with_name_dict, column_names_buildings_heating,
        column_names_buildings_cooling, district_heating_network,
        district_cooling_network)

    # now pass all the values mutated to the original individual
    for i, column in enumerate(column_names):
        individual[i] = individual_with_name_dict[column]

    return individual,  # add the, because deap needs this
コード例 #14
0
ファイル: utils.py プロジェクト: taintpro98/Localization
def mutate(ind, all_relays=None):
    _ind = ind.clone()
    return tools.mutShuffleIndexes(_ind, 0.2)[0]
コード例 #15
0
 def mutate(self, individual, probability):
     if self.method == 'Shuffle':
         return tools.mutShuffleIndexes(individual, probability)[0]
     elif self.method == 'Flipbit':
         return tools.mutFlipBit(individual, probability)[0]
コード例 #16
0
def mixed_mutate(individual, indpb):
    tools.mutShuffleIndexes(individual[0], indpb)
    toolsx.mut_uniform_unique(individual[1], 1, len(df_service) - 1, 0.2)
    return individual,
コード例 #17
0
def tspd_mutation(ind, indpb_cities, indpb_drone_visiting):
    tools.mutShuffleIndexes(ind[0], indpb_cities)
    tools.mutFlipBit(ind[1], indpb_drone_visiting)
    return ind,
コード例 #18
0
import random

from deap import tools

random.seed(0)

x = random.sample(range(10), 10)
print(x)
print(tools.mutShuffleIndexes(x, 1))
print(x)

ind1 = random.sample(range(10), 10)
ind2 = random.sample(range(10), 10)

tools.cxTwoPoint(ind1, ind2)
ind = [ind1, ind2]

tools.cxOrdered(ind1, ind2)

for i in range(100):
    ind1 = random.sample(range(10), 10)
    ind2 = random.sample(range(10), 10)
    tools.mutShuffleIndexes(ind1, 1)
    print(ind1)

for i in range(100):
    ind1 = random.sample(range(10), 10)
    tools.mutUniformInt(ind1, 20, 100, 1)
    print(ind1)

for i in range(100):
コード例 #19
0
ファイル: operators.py プロジェクト: takenbymood/optihedron
def fixedActivationMut(individual, MINPDB):
    return tools.mutShuffleIndexes(individual, MINPDB)