def meta_DE(objective_function,
            initial_population,
            F,
            C,
            convergence_tolerance,
            convergence_history_length,
            max_unconverged_iterations,
            mutation_method="rand/1",
            selection_method="Storn-Price",
            output_function=None):

    if 0 < F and F <= 2 and 0 < C and C <= 1:
        (iterations, (costs,
                      final_population)) = differential_evolution.minimize(
                          objective_function,
                          initial_population,
                          F,
                          C,
                          convergence_tolerance,
                          convergence_history_length,
                          max_unconverged_iterations,
                          mutation_method=mutation_method,
                          selection_method=selection_method,
                          output_function=output_function)

        mean_cost = numpy.mean(costs)

        print "F = %16.15f, C = %16.15f --> %16.15e after %d iterations." % (
            F, C, mean_cost, iterations)

        return mean_cost
    else:
        print "(Constraint violation.)"

        return inf
def meta_DE(objective_function, initial_population, F, C,
            convergence_tolerance, convergence_history_length, max_unconverged_iterations,
            mutation_method="rand/1", selection_method="Storn-Price",
            output_function=None):

    if 0 < F and F <= 2 and 0 < C and C <= 1:
        (iterations, (costs, final_population)) = differential_evolution.minimize(
           objective_function, initial_population, F, C,
           convergence_tolerance, convergence_history_length, max_unconverged_iterations,
           mutation_method=mutation_method, selection_method=selection_method,
           output_function=output_function
          )

        mean_cost = numpy.mean(costs)

        print "F = %16.15f, C = %16.15f --> %16.15e after %d iterations." % (F, C, mean_cost, iterations)

        return mean_cost
    else:
        print "(Constraint violation.)"

        return inf
        return mean_cost
    else:
        print "(Constraint violation.)"

        return inf


def meta_DE_harness(vec):

    (F, C) = vec

    return meta_DE(
            function, numpy.random.uniform(-1.0, 1.0, (50, 9)),
            F, C, 0.1, 10, 1000,
            mutation_method="MDE5", selection_method="Storn-Price"
           )


(iterations, (costs, population)) = differential_evolution.minimize(
                                     meta_DE_harness, numpy.random.uniform(0, 1, (20, 2)),
                                     0.60, 0.90, 0.01, 10, 100,
                                     mutation_method="MDE5", selection_method="elitist",
                                     stochastic=True
                                    )

print "Performed", iterations, "iterations."

best_index = numpy.argmin(costs)
print "Optimized function value:", costs[best_index]
print "Optimized parameter vector:\n", population[best_index]
    var88 = abs(var87)
    var89 = var86 + var88
    var90 = var89**2

    return (var4 * var29 + var32 * var37 + var40 * var60 + var63 * var68 +
            var71 * var82 + var85 * var90) / 4


t_start = time.clock()

(iterations, (costs, population)) = differential_evolution.minimize(
    function,
    numpy.random.uniform(-1.0, 1.0, (50, 9)),
    0.850,
    0.975,
    1.0e-12,
    250,
    12500,
    mutation_method="MDE5",
    selection_method="Storn-Price",
    output_function=None)

t_total = time.clock() - t_start

print "Performed", iterations, "iterations, taking", t_total, "seconds."

numpy.set_printoptions(precision=16, linewidth=109)
best_index = numpy.argmin(costs)
print "Optimized function value:", costs[best_index]
print "Optimized parameter vector:\n", population[best_index]
    (F, C) = vec

    return meta_DE(function,
                   numpy.random.uniform(-1.0, 1.0, (50, 9)),
                   F,
                   C,
                   0.1,
                   10,
                   1000,
                   mutation_method="MDE5",
                   selection_method="Storn-Price")


(iterations, (costs, population)) = differential_evolution.minimize(
    meta_DE_harness,
    numpy.random.uniform(0, 1, (20, 2)),
    0.60,
    0.90,
    0.01,
    10,
    100,
    mutation_method="MDE5",
    selection_method="elitist",
    stochastic=True)

print "Performed", iterations, "iterations."

best_index = numpy.argmin(costs)
print "Optimized function value:", costs[best_index]
print "Optimized parameter vector:\n", population[best_index]