|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 51, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import numpy as np\n", |
| 10 | + "def ConfigurationToGridCoord(config):\n", |
| 11 | + " \n", |
| 12 | + " # TODO:\n", |
| 13 | + " # This function maps a configuration in the full configuration space\n", |
| 14 | + " # to a grid coordinate in discrete space\n", |
| 15 | + " #\n", |
| 16 | + " coord = [0] * 2\n", |
| 17 | + " lower_lims = [0, 0]\n", |
| 18 | + " for i in range(0, len(coord)):\n", |
| 19 | + " start = lower_lims[i] # start of the configuration space\n", |
| 20 | + " coord[i] = np.around((config[i] - start)/ 1)\n", |
| 21 | + " return coord" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "code", |
| 26 | + "execution_count": 52, |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [ |
| 29 | + { |
| 30 | + "data": { |
| 31 | + "text/plain": [ |
| 32 | + "[2.0, 1.0]" |
| 33 | + ] |
| 34 | + }, |
| 35 | + "execution_count": 52, |
| 36 | + "metadata": {}, |
| 37 | + "output_type": "execute_result" |
| 38 | + } |
| 39 | + ], |
| 40 | + "source": [ |
| 41 | + "coord = ConfigurationToGridCoord([2,1])\n", |
| 42 | + "coord" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "code", |
| 47 | + "execution_count": 158, |
| 48 | + "metadata": {}, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "def GridCoordToNodeId(coord):\n", |
| 52 | + " upper_limits = [4, 3]\n", |
| 53 | + " lower_limits = [0, 0]\n", |
| 54 | + " num_cells = []\n", |
| 55 | + " for idx in range(2):\n", |
| 56 | + " num_cells.append(np.ceil((upper_limits[idx] - lower_limits[idx])/1))\n", |
| 57 | + " node_id = 0\n", |
| 58 | + " print(\"num_cells \", num_cells)\n", |
| 59 | + " for i in range(len(coord) - 1, -1, -1):\n", |
| 60 | + " # Get product of the grid space maximums\n", |
| 61 | + " prod = 1\n", |
| 62 | + " for j in range(0, i):\n", |
| 63 | + " print(\"j: \", j)\n", |
| 64 | + " prod = prod * num_cells[j]\n", |
| 65 | + " print(\"prod: \", prod)\n", |
| 66 | + " # Add the product to the sum\n", |
| 67 | + " node_id = node_id + coord[i] * prod\n", |
| 68 | + " print(\"n: \", node_id)\n", |
| 69 | + " return int(node_id)" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "cell_type": "code", |
| 74 | + "execution_count": 159, |
| 75 | + "metadata": {}, |
| 76 | + "outputs": [ |
| 77 | + { |
| 78 | + "name": "stdout", |
| 79 | + "output_type": "stream", |
| 80 | + "text": [ |
| 81 | + "num_cells [4.0, 3.0]\n", |
| 82 | + "j: 0\n", |
| 83 | + "prod: 4.0\n", |
| 84 | + "n: 8.0\n", |
| 85 | + "n: 10.0\n" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "data": { |
| 90 | + "text/plain": [ |
| 91 | + "10" |
| 92 | + ] |
| 93 | + }, |
| 94 | + "execution_count": 159, |
| 95 | + "metadata": {}, |
| 96 | + "output_type": "execute_result" |
| 97 | + } |
| 98 | + ], |
| 99 | + "source": [ |
| 100 | + "GridCoordToNodeId([2, 2])" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "code", |
| 105 | + "execution_count": null, |
| 106 | + "metadata": {}, |
| 107 | + "outputs": [], |
| 108 | + "source": [] |
| 109 | + } |
| 110 | + ], |
| 111 | + "metadata": { |
| 112 | + "kernelspec": { |
| 113 | + "display_name": "Python 3", |
| 114 | + "language": "python", |
| 115 | + "name": "python3" |
| 116 | + }, |
| 117 | + "language_info": { |
| 118 | + "codemirror_mode": { |
| 119 | + "name": "ipython", |
| 120 | + "version": 3 |
| 121 | + }, |
| 122 | + "file_extension": ".py", |
| 123 | + "mimetype": "text/x-python", |
| 124 | + "name": "python", |
| 125 | + "nbconvert_exporter": "python", |
| 126 | + "pygments_lexer": "ipython3", |
| 127 | + "version": "3.6.3" |
| 128 | + } |
| 129 | + }, |
| 130 | + "nbformat": 4, |
| 131 | + "nbformat_minor": 2 |
| 132 | +} |
0 commit comments