{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# IN4050 - Week 5\n",
    "## Representations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. ![Naming_Question](EA_Terms.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name the terms shown in the picture above."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add your solution here\n",
    "# A: \n",
    "\n",
    "# B: \n",
    "\n",
    "# C: \n",
    "\n",
    "# D:\n",
    "\n",
    "# E: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Mention some of the most common representations of genomes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add your solution here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Perform a mutation operation on the representations given below.\n",
    "\n",
    "binary = $[1, 0, 1, 1]$;\n",
    "integer = $[4, 2, 4, 1]$;\n",
    "real_valued = $[2.53, 1.42, 3.14, 1.68]$;\n",
    "permutation = $[3, 4, 1, 2]$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add your solution here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. Given the sequences (2,4,7,1,3,6,8,9,5) and (5,9,8,6,2,4,1,3,7). Implement these algorithms to create a new pair of solutions: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### a. Partially mapped crossover (PMX)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add your solution here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### b. Order crossover"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add your solution here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### c. Cycle crossover"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add your solution here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Test crossovers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Parents: [2, 4, 7, 1, 3, 6, 8, 9, 5] and [5, 9, 8, 6, 2, 4, 1, 3, 7]\n",
      "Children after PMX: None and None\n",
      "Children after Order Crossover: None and None\n",
      "Children after Cycle Crossover: None and None\n"
     ]
    }
   ],
   "source": [
    "a = [2, 4, 7, 1, 3, 6, 8, 9, 5]\n",
    "b = [5, 9, 8, 6, 2, 4, 1, 3, 7]\n",
    "c, d = pmx_pair(a, b)\n",
    "e, f = order_crossover_pair(a, b)\n",
    "g, h = cycle_crossover_pair(a, b)\n",
    "print(f\"Parents: {a} and {b}\")\n",
    "print(f\"Children after PMX: {c} and {d}\")\n",
    "print(f\"Children after Order Crossover: {e} and {f}\")\n",
    "print(f\"Children after Cycle Crossover: {g} and {h}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
