diff --git a/src/cython_rbfopt/rbfopt_aux_problems.pyx b/src/cython_rbfopt/rbfopt_aux_problems.pyx index 307c8f6..23f4510 100644 --- a/src/cython_rbfopt/rbfopt_aux_problems.pyx +++ b/src/cython_rbfopt/rbfopt_aux_problems.pyx @@ -1076,13 +1076,14 @@ def ga_optimize(settings, n, var_lower, var_upper, integer_vars, objfun): # Crossover: select how mating is done, then create offspring father = np.random.permutation(best_individuals) mother = np.random.permutation(best_individuals) - offspring = map(ga_mate, father, mother) + offspring = np.array(map(ga_mate, father, mother)) # New individuals new_individuals = generate_sample_points(settings, n, var_lower, var_upper, integer_vars, num_new) # Make a copy of best individual, and mutate it best_mutated = best_individuals[0, :].copy() + best_mutated = best_mutated.reshape((1, best_individuals.shape[1])) ga_mutate(n, var_lower, var_upper, is_integer, best_mutated, max_size_pert) # Mutate surviving (except best) if necessary @@ -1091,8 +1092,9 @@ def ga_optimize(settings, n, var_lower, var_upper, integer_vars, objfun): ga_mutate(n, var_lower, var_upper, is_integer, point, max_size_pert) # Generate new population - population = np.vstack((best_individuals, offspring, new_individuals, - best_mutated)) + proposal = (best_individuals, offspring, new_individuals, best_mutated) + population = np.concatenate([new_indiv for new_indiv in proposal + if len(new_indiv.shape) > 0]) # Determine ranking of last generation. # Compute fitness score to determine remaining individuals fitness_val = objfun(population) @@ -1170,10 +1172,12 @@ def ga_mutate(n, var_lower, var_upper, is_integer, individual, assert(isinstance(is_integer, np.ndarray)) assert(isinstance(individual, np.ndarray)) + individual = individual.flatten() + # Randomly mutate some of the coordinates. First determine how # many are mutated, then pick them randomly. size_pert = np.random.randint(max_size_pert) perturbed = np.random.choice(np.arange(n), size_pert, replace=False) new = (var_lower[perturbed] + np.random.rand(size_pert) * (var_upper[perturbed] - var_lower[perturbed])) new[is_integer[perturbed]] = np.around(new[is_integer[perturbed]]) diff --git a/src/rbfopt_aux_problems.py b/src/rbfopt_aux_problems.py index 1b9df0c..e178e4b 100644 --- a/src/rbfopt_aux_problems.py +++ b/src/rbfopt_aux_problems.py @@ -1076,13 +1076,14 @@ def ga_optimize(settings, n, var_lower, var_upper, integer_vars, objfun): # Crossover: select how mating is done, then create offspring father = np.random.permutation(best_individuals) mother = np.random.permutation(best_individuals) - offspring = map(ga_mate, father, mother) + offspring = np.array(map(ga_mate, father, mother)) # New individuals new_individuals = generate_sample_points(settings, n, var_lower, var_upper, integer_vars, num_new) # Make a copy of best individual, and mutate it best_mutated = best_individuals[0, :].copy() + best_mutated = best_mutated.reshape((1, best_individuals.shape[1])) ga_mutate(n, var_lower, var_upper, is_integer, best_mutated, max_size_pert) # Mutate surviving (except best) if necessary @@ -1091,8 +1092,9 @@ def ga_optimize(settings, n, var_lower, var_upper, integer_vars, objfun): ga_mutate(n, var_lower, var_upper, is_integer, point, max_size_pert) # Generate new population - population = np.vstack((best_individuals, offspring, new_individuals, - best_mutated)) + proposal = (best_individuals, offspring, new_individuals, best_mutated) + population = np.concatenate([new_indiv for new_indiv in proposal + if len(new_indiv.shape) > 0]) # Determine ranking of last generation. # Compute fitness score to determine remaining individuals fitness_val = objfun(population) @@ -1170,10 +1172,12 @@ def ga_mutate(n, var_lower, var_upper, is_integer, individual, assert(isinstance(is_integer, np.ndarray)) assert(isinstance(individual, np.ndarray)) + individual = individual.flatten() + # Randomly mutate some of the coordinates. First determine how # many are mutated, then pick them randomly. size_pert = np.random.randint(max_size_pert) perturbed = np.random.choice(np.arange(n), size_pert, replace=False) new = (var_lower[perturbed] + np.random.rand(size_pert) * (var_upper[perturbed] - var_lower[perturbed])) new[is_integer[perturbed]] = np.around(new[is_integer[perturbed]]) diff --git a/src/rbfopt_cl_interface.py b/src/rbfopt_cl_interface.py index 554e0ed..88df984 100644 --- a/src/rbfopt_cl_interface.py +++ b/src/rbfopt_cl_interface.py @@ -82,7 +82,7 @@ def register_options(parser): metavar = 'LOG_FILE_NAME', dest = 'output_stream', help = 'Name of log file for output redirection') intset.add_argument('--pause', '-p', action = 'store', dest = 'pause', - default = sys.maxint, type = int, + default = sys.maxsize, type = int, help = 'Number of iterations after which ' + 'the optimization process should be paused') intset.add_argument('--points_from_file', '-f', action = 'store', diff --git a/tests/rbfopt_test_interface.py b/tests/rbfopt_test_interface.py index f9bb581..990851d 100644 --- a/tests/rbfopt_test_interface.py +++ b/tests/rbfopt_test_interface.py @@ -112,10 +112,10 @@ class TestNoisyBlackBox(BlackBox): # -- end class if (__name__ == "__main__"): - if (sys.version_info[0] >= 3): - print('Error: Python 3 is currently not tested.') - print('Please use Python 2.7') - exit() + # if (sys.version_info[0] >= 3): + # print('Error: Python 3 is currently not tested.') + # print('Please use Python 2.7') + # exit() # Create command line parsers parser = argparse.ArgumentParser(description = 'Test RBF method') # Add the main test function option