summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2022-04-22 00:17:22 -0500
committerMitsuo Tokumori <[email protected]>2022-04-22 00:17:22 -0500
commit2e0e9e102313ff7b0c040aa7008be59263f40731 (patch)
tree6b5a26779d6a597a849f273b1dd95e9f0a415e32 /test
parent5647ee75b3b0c69ac053cf133c7110a8f8079efa (diff)
downloadDP1_project-2e0e9e102313ff7b0c040aa7008be59263f40731.tar.gz
DP1_project-2e0e9e102313ff7b0c040aa7008be59263f40731.tar.bz2
DP1_project-2e0e9e102313ff7b0c040aa7008be59263f40731.zip
Stop tracking test/.ipynb_checkpoints
Diffstat (limited to 'test')
-rw-r--r--test/.ipynb_checkpoints/GA-checkpoint.ipynb112
1 files changed, 0 insertions, 112 deletions
diff --git a/test/.ipynb_checkpoints/GA-checkpoint.ipynb b/test/.ipynb_checkpoints/GA-checkpoint.ipynb
deleted file mode 100644
index bab966d..0000000
--- a/test/.ipynb_checkpoints/GA-checkpoint.ipynb
+++ /dev/null
@@ -1,112 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "id": "2fd45b3a-9a24-4782-812c-08223edb750e",
- "metadata": {},
- "source": [
- "# Prueba del algoritmo genetico"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f6b4829a-9001-410c-b20c-01c65c777d8a",
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "2c3c85e0-a90c-4fda-86f7-778d7328c74d",
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "511ff788-0d1a-4ac7-9575-de182d236574",
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "078280b5-70ef-4691-8798-a686d85d188c",
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "b3ad92de-b2ed-4f21-a696-1fa2981f89dc",
- "metadata": {},
- "outputs": [],
- "source": [
- "def genetic_algorithm(population, fitness_fn, ngen=100, pmut=0.1):\n",
- " \"Algoritmo Genetico \"\n",
- " \n",
- " popsize = len(population)\n",
- " evaluate_population(population, fitness_fn) # evalua la poblacion inicial\n",
- " ibest = sorted(range(len(population)), key=lambda i: population[i].fitness, reverse=True)[:1]\n",
- " bestfitness = [population[ibest[0]].fitness]\n",
- " print(\"Poblacion inicial, best_fitness = {}\".format(population[ibest[0]].fitness))\n",
- " \n",
- " for g in range(ngen): # Por cada generacion\n",
- " \n",
- " ## Selecciona las parejas de padres para cruzamiento \n",
- " mating_pool = []\n",
- " for i in range(int(popsize/2)): mating_pool.append(select_parents_roulette(population)) \n",
- " \n",
- " ## Crea la poblacion descendencia cruzando las parejas del mating pool con Recombinación de 1 punto\n",
- " offspring_population = []\n",
- " for i in range(len(mating_pool)): \n",
- " #offspring_population.extend( mating_pool[i][0].crossover_onepoint(mating_pool[i][1]) )\n",
- " offspring_population.extend( mating_pool[i][0].crossover_uniform(mating_pool[i][1]) )\n",
- "\n",
- " ## Aplica el operador de mutacion con probabilidad pmut en cada hijo generado\n",
- " for i in range(len(offspring_population)):\n",
- " if random.uniform(0, 1) < pmut: \n",
- " offspring_population[i] = offspring_population[i].mutate_position()\n",
- " \n",
- " ## Evalua la poblacion descendencia\n",
- " evaluate_population(offspring_population, fitness_fn) # evalua la poblacion inicial\n",
- " \n",
- " ## Selecciona popsize individuos para la sgte. generación de la union de la pob. actual y pob. descendencia\n",
- " population = select_survivors(population, offspring_population, popsize)\n",
- "\n",
- " ## Almacena la historia del fitness del mejor individuo\n",
- " ibest = sorted(range(len(population)), key=lambda i: population[i].fitness, reverse=True)[:1]\n",
- " bestfitness.append(population[ibest[0]].fitness)\n",
- " print(\"generacion {}, best_fitness = {}\".format(g, population[ibest[0]].fitness))\n",
- " \n",
- " return population[ibest[0]], bestfitness "
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.9.2"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}