From 754e9f0e24099e77f559f3d445d580465cda1724 Mon Sep 17 00:00:00 2001 From: Aaron Ang Date: Fri, 19 Oct 2018 13:29:09 -0700 Subject: [PATCH 1/9] Change `type` to `struct` --- examples/demo.ipynb | 3627 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 3469 insertions(+), 158 deletions(-) diff --git a/examples/demo.ipynb b/examples/demo.ipynb index 5e7e974..6e7d7f0 100644 --- a/examples/demo.ipynb +++ b/examples/demo.ipynb @@ -2,10 +2,8 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, + "execution_count": 33, + "metadata": {}, "outputs": [], "source": [ "using RegionTrees\n", @@ -15,18 +13,16 @@ }, { "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, + "execution_count": 34, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[1.0,1.0])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 2, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -41,10 +37,8 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, + "execution_count": 35, + "metadata": {}, "outputs": [ { "data": { @@ -52,7 +46,7 @@ "true" ] }, - "execution_count": 3, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -65,18 +59,16 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, + "execution_count": 36, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[1.0,1.0])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 4, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -88,10 +80,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, + "execution_count": 37, + "metadata": {}, "outputs": [ { "data": { @@ -99,7 +89,7 @@ "false" ] }, - "execution_count": 5, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -111,10 +101,8 @@ }, { "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": false - }, + "execution_count": 38, + "metadata": {}, "outputs": [], "source": [ "@assert length(children(root)) == 4" @@ -122,18 +110,16 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false - }, + "execution_count": 39, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[0.5,0.5])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.5, 0.5])" ] }, - "execution_count": 7, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -147,18 +133,16 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": false - }, + "execution_count": 40, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[0.5,0.5])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.5, 0.5])" ] }, - "execution_count": 8, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -170,18 +154,16 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": { - "collapsed": false - }, + "execution_count": 41, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[0.5,0.5])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.5, 0.5])" ] }, - "execution_count": 9, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -193,18 +175,16 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": false - }, + "execution_count": 42, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[0.25,0.25])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.25, 0.25])" ] }, - "execution_count": 10, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -216,18 +196,16 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": { - "collapsed": false - }, + "execution_count": 43, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.25],[0.25,0.25])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.25], [0.25, 0.25])" ] }, - "execution_count": 11, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -238,18 +216,179 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, + "execution_count": 44, + "metadata": {}, "outputs": [ { "data": { - "text/html": [ - "" + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "0.2\n", + "\n", + "\n", + "0.4\n", + "\n", + "\n", + "0.6\n", + "\n", + "\n", + "0.8\n", + "\n", + "\n", + "1.0\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "0.2\n", + "\n", + "\n", + "0.4\n", + "\n", + "\n", + "0.6\n", + "\n", + "\n", + "0.8\n", + "\n", + "\n", + "1.0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" ] }, - "execution_count": 12, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -266,20 +405,9 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python2.7/site-packages/matplotlib/font_manager.py:1282: UserWarning: findfont: Font family [u'Helvetica'] not found. Falling back to Bitstream Vera Sans\n", - " (prop.get_family(), self.defaultFamily[fontext]))\n" - ] - } - ], + "execution_count": 45, + "metadata": {}, + "outputs": [], "source": [ "# Now, so far just splitting cells is not super useful. Let's\n", "# try adding some data to each cell:" @@ -287,18 +415,16 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": { - "collapsed": false - }, + "execution_count": 46, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[1.0,1.0])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 14, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -309,10 +435,8 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": false - }, + "execution_count": 47, + "metadata": {}, "outputs": [ { "data": { @@ -320,7 +444,7 @@ "\"A\"" ] }, - "execution_count": 15, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -333,18 +457,16 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": { - "collapsed": false - }, + "execution_count": 48, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "RegionTrees.Cell{String,2,Float64,4}" + "Cell{String,2,Float64,4}" ] }, - "execution_count": 16, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -357,18 +479,16 @@ }, { "cell_type": "code", - "execution_count": 17, - "metadata": { - "collapsed": false - }, + "execution_count": 49, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[1.0,1.0])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 17, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -383,10 +503,8 @@ }, { "cell_type": "code", - "execution_count": 18, - "metadata": { - "collapsed": false - }, + "execution_count": 50, + "metadata": {}, "outputs": [ { "data": { @@ -394,7 +512,7 @@ "\"B\"" ] }, - "execution_count": 18, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -405,10 +523,8 @@ }, { "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": false - }, + "execution_count": 51, + "metadata": {}, "outputs": [ { "data": { @@ -416,7 +532,7 @@ "\"C\"" ] }, - "execution_count": 19, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -427,18 +543,16 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "collapsed": false - }, + "execution_count": 52, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.25,0.75],[0.25,0.25])" + "Cell: HyperRectangle{2,Float64}([0.25, 0.75], [0.25, 0.25])" ] }, - "execution_count": 20, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -465,18 +579,16 @@ }, { "cell_type": "code", - "execution_count": 21, - "metadata": { - "collapsed": false - }, + "execution_count": 53, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "\"root child (1,2) child (2,2) child (1,1)\"" + "\"root child (1, 2) child (2, 2) child (1, 1)\"" ] }, - "execution_count": 21, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -487,18 +599,16 @@ }, { "cell_type": "code", - "execution_count": 22, - "metadata": { - "collapsed": false - }, + "execution_count": 54, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([0.0,0.0],[1.0,1.0])" + "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 22, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -526,7 +636,7 @@ "# its width is less than a given tolerance:\n", "import RegionTrees: AbstractRefinery, needs_refinement, refine_data\n", "\n", - "type MyRefinery <: AbstractRefinery\n", + "struct MyRefinery <: AbstractRefinery\n", " tolerance::Float64\n", "end\n", "\n", @@ -548,18 +658,16 @@ }, { "cell_type": "code", - "execution_count": 23, - "metadata": { - "collapsed": false - }, + "execution_count": 55, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "\"child with widths: [0.03125,0.03125]\"" + "\"child with widths: [0.03125, 0.03125]\"" ] }, - "execution_count": 23, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -570,18 +678,3230 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": false - }, + "execution_count": 56, + "metadata": {}, "outputs": [ { "data": { - "text/html": [ - "" + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "0.2\n", + "\n", + "\n", + "0.4\n", + "\n", + "\n", + "0.6\n", + "\n", + "\n", + "0.8\n", + "\n", + "\n", + "1.0\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "0.2\n", + "\n", + "\n", + "0.4\n", + "\n", + "\n", + "0.6\n", + "\n", + "\n", + "0.8\n", + "\n", + "\n", + "1.0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" ] }, - "execution_count": 24, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -594,28 +3914,19 @@ "end\n", "plt" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Julia 0.5.0", + "display_name": "Julia 1.0.1", "language": "julia", - "name": "julia-0.5" + "name": "julia-1.0" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.5.0" + "version": "1.0.1" } }, "nbformat": 4, From 555d2f58d06f0440aa26e5cc3253af1a9b0a3929 Mon Sep 17 00:00:00 2001 From: Aaron Ang Date: Fri, 19 Oct 2018 13:47:51 -0700 Subject: [PATCH 2/9] Change `immutable` to `struct` --- examples/adaptive_mpc.ipynb | 3761 +---------------------------------- 1 file changed, 43 insertions(+), 3718 deletions(-) diff --git a/examples/adaptive_mpc.ipynb b/examples/adaptive_mpc.ipynb index 1b14fda..14d31a6 100644 --- a/examples/adaptive_mpc.ipynb +++ b/examples/adaptive_mpc.ipynb @@ -11,22 +11,9 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "Plots.GRBackend()" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "using RegionTrees\n", "import StaticArrays: SVector\n", @@ -36,22 +23,9 @@ }, { "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "mpc" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# This module implements our MPC code, which consists of a 1-dimensional\n", "# double-integrator system, forward-euler time-stepping dynamics, and a \n", @@ -96,7 +70,7 @@ "# The MPCRefinery provides enough behavior to implement the \n", "# RegionTrees AdaptiveSampling interface, which lets us generate\n", "# a quadtree of initial states and their corresponding MPC solutions.\n", - "immutable MPCRefinery <: AbstractRefinery\n", + "struct MPCRefinery <: AbstractRefinery\n", "end\n", "\n", "function evaluate(cell, point)\n", @@ -138,22 +112,9 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "simulate (generic function with 1 method)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# Simulate a given control function for the double integerator\n", "# model.\n", @@ -179,22 +140,9 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "(::#1) (generic function with 1 method)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "controller = (t, q, v) -> begin\n", " q, v, u = mpc.run_mpc(q, v)\n", @@ -204,182 +152,18 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "([0.0,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8 … 9.1,9.2,9.3,9.4,9.5,9.6,9.7,9.8,9.9,10.0],[10.0,10.0,9.97,9.91,9.82,9.7,9.55,9.37,9.16,8.92 … 8.59724e-5,5.36258e-5,2.83979e-5,9.84092e-6,-2.88847e-6,-1.08171e-5,-1.50039e-5,-1.64406e-5,-1.59925e-5,-1.43722e-5],[0.0,-0.3,-0.6,-0.9,-1.2,-1.5,-1.8,-2.1,-2.4,-2.7 … -0.000323466,-0.000252279,-0.00018557,-0.000127294,-7.9286e-5,-4.18688e-5,-1.43665e-5,4.48084e-6,1.6203e-5,2.23757e-5])" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "t, q, v = simulate(controller, 10.0, 0.0, 0.1, 10)" ] }, { "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "-10\n", - "\n", - "\n", - "-5\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "5\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "-10\n", - "\n", - "\n", - "-5\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "5\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "q\n", - "\n", - "\n", - "v\n", - "\n", - "\n", - "\n" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# State space portrait of the solution, starting from q=10, v=0\n", "plot(q, v, xlim=(-10, 10), ylim=(-10, 10), xlabel=\"q\", ylabel=\"v\", legend=nothing)" @@ -387,320 +171,18 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "2\n", - "\n", - "\n", - "4\n", - "\n", - "\n", - "6\n", - "\n", - "\n", - "8\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "0.0\n", - "\n", - "\n", - "2.5\n", - "\n", - "\n", - "5.0\n", - "\n", - "\n", - "7.5\n", - "\n", - "\n", - "10.0\n", - "\n", - "\n", - "t\n", - "\n", - "\n", - "q\n", - "\n", - "\n", - "\n" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "plot(t, q, xlabel=\"t\", ylabel=\"q\", legend=nothing)" ] }, { "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "2\n", - "\n", - "\n", - "4\n", - "\n", - "\n", - "6\n", - "\n", - "\n", - "8\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "-5.0\n", - "\n", - "\n", - "-2.5\n", - "\n", - "\n", - "0.0\n", - "\n", - "\n", - "t\n", - "\n", - "\n", - "v\n", - "\n", - "\n", - "\n" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "plot(t, v, xlabel=\"t\", ylabel=\"v\", legend=nothing)" ] @@ -715,22 +197,9 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([-10.0,-10.0],[20.0,20.0])" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "boundary = RegionTrees.HyperRectangle(SVector(-10., -10), SVector(20., 20))\n", "refinery = mpc.MPCRefinery()\n", @@ -740,2967 +209,9 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "-10\n", - "\n", - "\n", - "-5\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "5\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "-10\n", - "\n", - "\n", - "-5\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "5\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# Now we can plot each region in the quadtree. Note that we end up with\n", "# a lot of detail along the switching surface from maximum acceleration\n", @@ -3723,22 +234,9 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "(::#3) (generic function with 1 method)" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "approx_controller = (t, q, v) -> begin\n", " x = [q, v]\n", @@ -3750,209 +248,36 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "([0.0,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8 … 9.1,9.2,9.3,9.4,9.5,9.6,9.7,9.8,9.9,10.0],[10.0,10.0,9.97,9.91,9.82,9.7,9.55,9.37,9.16,8.92 … 0.000117648,7.38866e-5,3.96448e-5,1.43656e-5,-3.05489e-6,-1.39802e-5,-1.98267e-5,-2.19265e-5,-2.14469e-5,-1.93518e-5],[0.0,-0.3,-0.6,-0.9,-1.2,-1.5,-1.8,-2.1,-2.4,-2.7 … -0.000437612,-0.000342419,-0.000252791,-0.000174205,-0.000109253,-5.84649e-5,-2.09982e-5,4.7965e-6,2.0951e-5,2.95725e-5])" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "t, q, v = simulate(approx_controller, 10.0, 0.0, 0.1, 10)" ] }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "-10\n", - "\n", - "\n", - "-5\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "5\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "-10\n", - "\n", - "\n", - "-5\n", - "\n", - "\n", - "0\n", - "\n", - "\n", - "5\n", - "\n", - "\n", - "10\n", - "\n", - "\n", - "q\n", - "\n", - "\n", - "v\n", - "\n", - "\n", - "\n" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# The results are similar to, but not quite as good as, the \n", "# values obtained from the exact MPC solution. \n", "plot(q, v, xlim=(-10, 10), ylim=(-10, 10), xlabel=\"q\", ylabel=\"v\", legend=nothing)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Julia 0.5.0", + "display_name": "Julia 1.0.1", "language": "julia", - "name": "julia-0.5" + "name": "julia-1.0" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.5.0" + "version": "1.0.1" } }, "nbformat": 4, From 199f1248a1bf761be3d31e0fc3030e52165c9598 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Nov 2018 08:07:57 -0500 Subject: [PATCH 3/9] Regenerate all notebooks, and add project and manifest files --- .gitignore | 1 + .../adaptive_distance_fields/Manifest.toml | 260 + .../adaptive_distance_fields/Project.toml | 5 + .../adaptive_distance_fields.jl | 7 +- .../adaptive_distances.ipynb | 2652 ++++++++ examples/adaptive_distances.ipynb | 1416 ----- examples/adaptive_mpc.ipynb | 285 - examples/adaptive_mpc/Manifest.toml | 350 ++ examples/adaptive_mpc/Project.toml | 7 + examples/adaptive_mpc/adaptive_mpc.ipynb | 5403 +++++++++++++++++ examples/demo/Manifest.toml | 230 + examples/demo/Project.toml | 4 + examples/{ => demo}/demo.ipynb | 2392 ++++---- test/REQUIRE | 2 +- test/asdfs.jl | 2 +- 15 files changed, 10118 insertions(+), 2898 deletions(-) create mode 100644 .gitignore create mode 100644 examples/adaptive_distance_fields/Manifest.toml create mode 100644 examples/adaptive_distance_fields/Project.toml rename examples/{ => adaptive_distance_fields}/adaptive_distance_fields.jl (93%) create mode 100644 examples/adaptive_distance_fields/adaptive_distances.ipynb delete mode 100644 examples/adaptive_distances.ipynb delete mode 100644 examples/adaptive_mpc.ipynb create mode 100644 examples/adaptive_mpc/Manifest.toml create mode 100644 examples/adaptive_mpc/Project.toml create mode 100644 examples/adaptive_mpc/adaptive_mpc.ipynb create mode 100644 examples/demo/Manifest.toml create mode 100644 examples/demo/Project.toml rename examples/{ => demo}/demo.ipynb (73%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..763513e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints diff --git a/examples/adaptive_distance_fields/Manifest.toml b/examples/adaptive_distance_fields/Manifest.toml new file mode 100644 index 0000000..7d214de --- /dev/null +++ b/examples/adaptive_distance_fields/Manifest.toml @@ -0,0 +1,260 @@ +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "2d9e14d19bad3f9ad5cc5e4cffabc3cfa59de825" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.3.0" + +[[Contour]] +deps = ["LinearAlgebra", "StaticArrays", "Test"] +git-tree-sha1 = "b974e164358fea753ef853ce7bad97afec15bb80" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.5.1" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "8fc6e166e24fda04b2b648d4260cdad241788c54" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.14.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[GR]] +deps = ["Base64", "DelimitedFiles", "Pkg", "Random", "Serialization", "Sockets", "Test"] +git-tree-sha1 = "18e3aa0f988f6e94c90394deaa76cb095bf87469" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.35.0" + +[[InteractiveUtils]] +deps = ["LinearAlgebra", "Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "56691033f157dd1ee1d2aa042114caeefefa897b" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.10.5" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "fec8e4d433072731466d37ed0061b3ba7f70eeb9" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.19.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Measures]] +deps = ["Test"] +git-tree-sha1 = "ddfd6d13e330beacdde2c80de27c1c671945e7d9" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "adc26d2ee85a49c413464110d922cf21efc9d233" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.3.1" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "f8cd140824f74f2948ff8660bc2292e16d29c1b7" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.8.1" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[PlotThemes]] +deps = ["PlotUtils", "Requires", "Test"] +git-tree-sha1 = "f3afd2d58e1f6ac9be2cea46e4a9083ccc1d990b" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "0.3.0" + +[[PlotUtils]] +deps = ["Colors", "Dates", "Printf", "Random", "Reexport", "Test"] +git-tree-sha1 = "fd28f30a294a38ec847de95d8ac7ac916ccd7c06" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "0.5.5" + +[[Plots]] +deps = ["Base64", "Contour", "Dates", "FixedPointNumbers", "GR", "JSON", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "Random", "RecipesBase", "Reexport", "Requires", "Showoff", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "UUIDs"] +git-tree-sha1 = "a36cbf119f1605268d0457e04e717901ae88b68c" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "0.21.0" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[RecipesBase]] +deps = ["Random", "Test"] +git-tree-sha1 = "0b3cb370ee4dc00f47f1193101600949f3dcf884" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "0.6.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[RegionTrees]] +deps = ["IterTools", "LinearAlgebra", "StaticArrays", "Test"] +path = "../.." +uuid = "dee08c22-ab7f-5625-9660-a9af2021b33f" +version = "0.2.0+" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Showoff]] +deps = ["Compat"] +git-tree-sha1 = "276b24f3ace98bec911be7ff2928d497dc759085" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "0.2.1" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "ebc5c2a27d91d5ec611a9861168182e2168effd3" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.9.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "723193a13e8078cec6dcd0b8fe245c8bfd81690e" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.25.0" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" diff --git a/examples/adaptive_distance_fields/Project.toml b/examples/adaptive_distance_fields/Project.toml new file mode 100644 index 0000000..bbf2d18 --- /dev/null +++ b/examples/adaptive_distance_fields/Project.toml @@ -0,0 +1,5 @@ +[deps] +Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/examples/adaptive_distance_fields.jl b/examples/adaptive_distance_fields/adaptive_distance_fields.jl similarity index 93% rename from examples/adaptive_distance_fields.jl rename to examples/adaptive_distance_fields/adaptive_distance_fields.jl index 4331e0a..b67d2cd 100644 --- a/examples/adaptive_distance_fields.jl +++ b/examples/adaptive_distance_fields/adaptive_distance_fields.jl @@ -6,11 +6,11 @@ import RegionTrees: needs_refinement, refine_data using Interpolations @generated function evaluate(itp::AbstractInterpolation, point::SVector{N}) where N - Expr(:ref, :itp, [:(point[$i]) for i in 1:N]...) + Expr(:call, :itp, [:(point[$i]) for i in 1:N]...) end function evaluate(itp::AbstractInterpolation, point::AbstractArray) - itp[point...] + itp(point...) end function evaluate(cell::Cell{D}, point::AbstractArray) where D <: AbstractInterpolation @@ -50,8 +50,7 @@ end function refine_data(refinery::SignedDistanceRefinery, boundary::HyperRectangle) interpolate!(refinery.signed_distance_func.(vertices(boundary)), - BSpline(Linear()), - OnGrid()) + BSpline(Linear())) end function ASDF(signed_distance::Function, origin::AbstractArray, diff --git a/examples/adaptive_distance_fields/adaptive_distances.ipynb b/examples/adaptive_distance_fields/adaptive_distances.ipynb new file mode 100644 index 0000000..396513a --- /dev/null +++ b/examples/adaptive_distance_fields/adaptive_distances.ipynb @@ -0,0 +1,2652 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "using Pkg\n", + "pkg\"activate .\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import StaticArrays: SVector\n", + "using RegionTrees" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "include(\"adaptive_distance_fields.jl\")\n", + "using .AdaptivelySampledDistanceFields: ASDF, evaluate" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Cell: HyperRectangle{2,Float64}([-1.0, -1.0], [2.0, 2.0])" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s = x -> sqrt(sum((x - SVector(0, 0)).^2))\n", + "adf = ASDF(s, SVector(-1., -1), SVector(2., 2))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "using Plots" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "-1.0\n", + "\n", + "\n", + "-0.5\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "0.5\n", + "\n", + "\n", + "1.0\n", + "\n", + "\n", + "-1.0\n", + "\n", + "\n", + "-0.5\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "0.5\n", + "\n", + "\n", + "1.0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plt = plot(xlim=(-1, 1), ylim=(-1, 1), legend=nothing)\n", + "\n", + "x = range(-1, stop=1, length=50)\n", + "y = range(-1, stop=1, length=50)\n", + "contour!(plt, x, y, (x, y) -> evaluate(adf, SVector(x, y)), fill=true)\n", + "\n", + "for leaf in allleaves(adf)\n", + " v = hcat(collect(vertices(leaf.boundary))...)\n", + " plot!(plt, v[1,[1,2,4,3,1]], v[2,[1,2,4,3,1]], color=:white)\n", + "end\n", + "\n", + "\n", + "plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.0.0", + "language": "julia", + "name": "julia-1.0" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.0.0" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/examples/adaptive_distances.ipynb b/examples/adaptive_distances.ipynb deleted file mode 100644 index 1d9661e..0000000 --- a/examples/adaptive_distances.ipynb +++ /dev/null @@ -1,1416 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import StaticArrays: SVector\n", - "using RegionTrees" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "include(\"adaptive_distance_fields.jl\")\n", - "import AdaptivelySampledDistanceFields: ASDF, evaluate" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "Cell: RegionTrees.HyperRectangle{2,Float64}([-1.0,-1.0],[2.0,2.0])" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s = x -> sqrt(sum((x - SVector(0, 0)).^2))\n", - "adf = ASDF(s, SVector(-1., -1), SVector(2., 2))" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "using Plots" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "-1.0\n", - "\n", - "\n", - "-0.5\n", - "\n", - "\n", - "0.0\n", - "\n", - "\n", - "0.5\n", - "\n", - "\n", - "1.0\n", - "\n", - "\n", - "-1.0\n", - "\n", - "\n", - "-0.5\n", - "\n", - "\n", - "0.0\n", - "\n", - "\n", - "0.5\n", - "\n", - "\n", - "1.0\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "plt = plot(xlim=(-1, 1), ylim=(-1, 1), legend=nothing)\n", - "\n", - "x = linspace(-1, 1)\n", - "y = linspace(-1, 1)\n", - "contour!(plt, x, y, (x, y) -> evaluate(adf, SVector(x, y)), fill=true)\n", - "\n", - "for leaf in allleaves(adf)\n", - " v = hcat(collect(vertices(leaf.boundary))...)\n", - " plot!(plt, v[1,[1,2,4,3,1]], v[2,[1,2,4,3,1]], color=:white)\n", - "end\n", - "\n", - "\n", - "plt" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Julia 0.5.0", - "language": "julia", - "name": "julia-0.5" - }, - "language_info": { - "file_extension": ".jl", - "mimetype": "application/julia", - "name": "julia", - "version": "0.5.0" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/examples/adaptive_mpc.ipynb b/examples/adaptive_mpc.ipynb deleted file mode 100644 index 14d31a6..0000000 --- a/examples/adaptive_mpc.ipynb +++ /dev/null @@ -1,285 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Adaptively Sampled MPC\n", - "\n", - "This is a simple demonstration of an adaptively sampled region quadtree used to approximate the solutions to a model-predictive control problem. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "using RegionTrees\n", - "import StaticArrays: SVector\n", - "using Plots\n", - "Plots.gr()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# This module implements our MPC code, which consists of a 1-dimensional\n", - "# double-integrator system, forward-euler time-stepping dynamics, and a \n", - "# 10 step prediction window. \n", - "\n", - "module mpc\n", - "\n", - "using JuMP\n", - "using Gurobi\n", - "using StaticArrays\n", - "using Interpolations\n", - "using RegionTrees\n", - "import RegionTrees: AbstractRefinery, needs_refinement, refine_data\n", - "\n", - "# Solve the MPC problem from a given initial position and velocity\n", - "function run_mpc(q0, v0)\n", - " model = Model(solver=GurobiSolver(OutputFlag=0))\n", - " num_time_steps = 10\n", - " dt = 0.1\n", - " u_limit = 3\n", - " C_q = 100\n", - " c_vfinal = 100\n", - " C_u = 1\n", - "\n", - " @variable model q[1:num_time_steps]\n", - " @variable model v[1:num_time_steps]\n", - " @variable model u[1:num_time_steps]\n", - "\n", - " @constraint model [i=2:num_time_steps] q[i] == q[i-1] + v[i-1] * dt\n", - " @constraint model [i=2:num_time_steps] v[i] == v[i-1] + u[i-1] * dt\n", - " @constraint model u .<= u_limit\n", - " @constraint model u .>= -u_limit\n", - " @constraint model q[1] == q0\n", - " @constraint model v[1] == v0\n", - "\n", - " @objective model Min C_q * sum{q[i]^2, i=1:num_time_steps} + c_vfinal * v[end]^2 + C_u * sum{u[i]^2, i=1:num_time_steps}\n", - " solve(model)\n", - "\n", - " getvalue(q), getvalue(v), getvalue(u)\n", - "end\n", - "\n", - "# The MPCRefinery provides enough behavior to implement the \n", - "# RegionTrees AdaptiveSampling interface, which lets us generate\n", - "# a quadtree of initial states and their corresponding MPC solutions.\n", - "struct MPCRefinery <: AbstractRefinery\n", - "end\n", - "\n", - "function evaluate(cell, point)\n", - " p = (point - cell.boundary.origin) ./ cell.boundary.widths\n", - " cell.data[p[1] + 1, p[2] + 1]\n", - "end\n", - "\n", - "# A cell in the quadtree needs refinement if its interpolated solution\n", - "# derived from its vertices is not a good fit for the true MPC solution\n", - "# at its center and the center of each of its faces\n", - "function needs_refinement(::MPCRefinery, cell)\n", - " for x in body_and_face_centers(cell.boundary)\n", - " value_interp = evaluate(cell, x)\n", - " value_true = run_mpc(x[1], x[2])[3]\n", - " if !isapprox(value_interp[1], value_true[1], rtol=1e-1, atol=1e-1)\n", - " return true\n", - " end\n", - " end\n", - " false\n", - "end\n", - "\n", - "# The data element associated with a cell is a bilinear interpolation\n", - "# of the MPC function evaluated at the vertices of the cell.\n", - "function refine_data(r::MPCRefinery, cell::Cell, indices)\n", - " refine_data(r, child_boundary(cell, indices))\n", - "end\n", - "\n", - "function refine_data(::MPCRefinery, boundary::HyperRectangle)\n", - " f = v -> run_mpc(v[1], v[2])[3]\n", - " interpolate(f.(vertices(boundary)),\n", - " BSpline(Linear()), OnGrid())\n", - "end\n", - "\n", - "# Needed to let us interpolate directly on arrays of control inputs\n", - "Base.one{T, N}(::Type{Array{T, N}}) = one(T)\n", - "\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Simulate a given control function for the double integerator\n", - "# model.\n", - "function simulate(controller, q0, v0, dt, timespan)\n", - " num_time_steps = timespan / dt\n", - " qs = [q0]\n", - " vs = [v0]\n", - " ts = [0.0]\n", - " q = q0\n", - " v = v0\n", - " for t in 0:dt:(timespan)\n", - " u = controller(t, q, v)\n", - " q += v * dt\n", - " v += u * dt\n", - " push!(qs, q)\n", - " push!(vs, v)\n", - " push!(ts, t)\n", - " end\n", - " ts, qs, vs\n", - "end\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "controller = (t, q, v) -> begin\n", - " q, v, u = mpc.run_mpc(q, v)\n", - " u[1]\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "t, q, v = simulate(controller, 10.0, 0.0, 0.1, 10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# State space portrait of the solution, starting from q=10, v=0\n", - "plot(q, v, xlim=(-10, 10), ylim=(-10, 10), xlabel=\"q\", ylabel=\"v\", legend=nothing)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "plot(t, q, xlabel=\"t\", ylabel=\"q\", legend=nothing)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "plot(t, v, xlabel=\"t\", ylabel=\"v\", legend=nothing)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Approximating the solutions space\n", - "Now that we've written down and tested the true MPC solution, we can try to approximate it. The AdaptiveSampling() function will generate a quadtree by iteratively refining each cell in the space until the solutions to the MPC problem within that cell are well-approximated by the interpolation. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "boundary = RegionTrees.HyperRectangle(SVector(-10., -10), SVector(20., 20))\n", - "refinery = mpc.MPCRefinery()\n", - "root = RegionTrees.Cell(boundary, mpc.refine_data(refinery, boundary))\n", - "adaptivesampling!(root, refinery)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Now we can plot each region in the quadtree. Note that we end up with\n", - "# a lot of detail along the switching surface from maximum acceleration\n", - "# to maximum deceleration\n", - "plt = plot(xlim=(-10, 10), ylim=(-10, 10), legend=nothing, grid=false)\n", - "for cell in RegionTrees.allleaves(root)\n", - " v = hcat(collect(RegionTrees.vertices(cell.boundary))...)\n", - " plot!(v[1,[1,2,4,3,1]], v[2,[1,2,4,3,1]])\n", - "end\n", - "plt" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Using the Approximate Solution\n", - "We can use the quadtree to produce an approximate controller for our system. Given the current state, we can look up the cell in the quadtree which encompasses that state, then use that cell's interpolation to find our control tape. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "approx_controller = (t, q, v) -> begin\n", - " x = [q, v]\n", - " leaf = RegionTrees.findleaf(root, x)\n", - " u = mpc.evaluate(leaf, x)\n", - " u[1]\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "t, q, v = simulate(approx_controller, 10.0, 0.0, 0.1, 10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# The results are similar to, but not quite as good as, the \n", - "# values obtained from the exact MPC solution. \n", - "plot(q, v, xlim=(-10, 10), ylim=(-10, 10), xlabel=\"q\", ylabel=\"v\", legend=nothing)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Julia 1.0.1", - "language": "julia", - "name": "julia-1.0" - }, - "language_info": { - "file_extension": ".jl", - "mimetype": "application/julia", - "name": "julia", - "version": "1.0.1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/adaptive_mpc/Manifest.toml b/examples/adaptive_mpc/Manifest.toml new file mode 100644 index 0000000..473b440 --- /dev/null +++ b/examples/adaptive_mpc/Manifest.toml @@ -0,0 +1,350 @@ +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "9930c1a6cd49d9fcd7218df6be417e6ae4f1468a" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.2" + +[[Calculus]] +deps = ["Compat"] +git-tree-sha1 = "f60954495a7afcee4136f78d1d60350abd37a409" +uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" +version = "0.4.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "2d9e14d19bad3f9ad5cc5e4cffabc3cfa59de825" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.3.0" + +[[Contour]] +deps = ["LinearAlgebra", "StaticArrays", "Test"] +git-tree-sha1 = "b974e164358fea753ef853ce7bad97afec15bb80" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.5.1" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "8fc6e166e24fda04b2b648d4260cdad241788c54" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.14.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "c49ec69428ffea0c1d1bbdc63d1a70f5df5860ad" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.7" + +[[Distributed]] +deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "8425a7d4e060bc2ded32d090bce910a187d6cce7" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.9.0" + +[[GR]] +deps = ["Base64", "DelimitedFiles", "Pkg", "Random", "Serialization", "Sockets", "Test"] +git-tree-sha1 = "18e3aa0f988f6e94c90394deaa76cb095bf87469" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.35.0" + +[[Gurobi]] +deps = ["Compat", "Libdl", "LinQuadOptInterface", "MathProgBase"] +git-tree-sha1 = "417fe26b36445e5bf6c027c6a14fbf4ea2b7c705" +uuid = "2e9cd046-0924-5485-92f1-d5272153d98b" +version = "0.5.4" + +[[InteractiveUtils]] +deps = ["LinearAlgebra", "Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "56691033f157dd1ee1d2aa042114caeefefa897b" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.10.5" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "fec8e4d433072731466d37ed0061b3ba7f70eeb9" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.19.0" + +[[JuMP]] +deps = ["Calculus", "Compat", "ForwardDiff", "MathProgBase", "Pkg", "ReverseDiffSparse"] +git-tree-sha1 = "3716c8cae07d5056e7b9981d2d4dde239bd9c1d1" +uuid = "4076af6c-e467-56ae-b986-b466b2749572" +version = "0.18.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinQuadOptInterface]] +deps = ["Compat", "MathOptInterface"] +git-tree-sha1 = "c246e73894d2063ab0697be54ecbb122e604df19" +uuid = "f8899e07-120b-5979-ab1d-7b97bb9e1a48" +version = "0.4.1" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[MathOptInterface]] +deps = ["Compat", "Unicode"] +git-tree-sha1 = "d7427366a571b41214fa51e2e33b7a64c8950e5f" +uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +version = "0.6.2" + +[[MathProgBase]] +deps = ["Compat"] +git-tree-sha1 = "3bf2e534e635df810e5f4b4f1a8b6de9004a0d53" +uuid = "fdba3010-5040-5b88-9595-932c9decdf73" +version = "0.7.7" + +[[Measures]] +deps = ["Test"] +git-tree-sha1 = "ddfd6d13e330beacdde2c80de27c1c671945e7d9" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "adc26d2ee85a49c413464110d922cf21efc9d233" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.3.1" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "f8cd140824f74f2948ff8660bc2292e16d29c1b7" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.8.1" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[PlotThemes]] +deps = ["PlotUtils", "Requires", "Test"] +git-tree-sha1 = "f3afd2d58e1f6ac9be2cea46e4a9083ccc1d990b" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "0.3.0" + +[[PlotUtils]] +deps = ["Colors", "Dates", "Printf", "Random", "Reexport", "Test"] +git-tree-sha1 = "fd28f30a294a38ec847de95d8ac7ac916ccd7c06" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "0.5.5" + +[[Plots]] +deps = ["Base64", "Contour", "Dates", "FixedPointNumbers", "GR", "JSON", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "Random", "RecipesBase", "Reexport", "Requires", "Showoff", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "UUIDs"] +git-tree-sha1 = "a36cbf119f1605268d0457e04e717901ae88b68c" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "0.21.0" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[RecipesBase]] +deps = ["Random", "Test"] +git-tree-sha1 = "0b3cb370ee4dc00f47f1193101600949f3dcf884" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "0.6.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[RegionTrees]] +deps = ["IterTools", "LinearAlgebra", "StaticArrays", "Test"] +path = "../.." +uuid = "dee08c22-ab7f-5625-9660-a9af2021b33f" +version = "0.2.0+" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[ReverseDiffSparse]] +deps = ["Calculus", "Compat", "DataStructures", "ForwardDiff", "MathProgBase", "NaNMath"] +git-tree-sha1 = "2c445d3c0a519376c950023ac67079bb71418f9b" +uuid = "89212889-6d3f-5f97-b412-7825138f6c9c" +version = "0.8.4" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Showoff]] +deps = ["Compat"] +git-tree-sha1 = "276b24f3ace98bec911be7ff2928d497dc759085" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "0.2.1" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "ebc5c2a27d91d5ec611a9861168182e2168effd3" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.9.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "723193a13e8078cec6dcd0b8fe245c8bfd81690e" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.25.0" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" diff --git a/examples/adaptive_mpc/Project.toml b/examples/adaptive_mpc/Project.toml new file mode 100644 index 0000000..b4977f6 --- /dev/null +++ b/examples/adaptive_mpc/Project.toml @@ -0,0 +1,7 @@ +[deps] +Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b" +Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/examples/adaptive_mpc/adaptive_mpc.ipynb b/examples/adaptive_mpc/adaptive_mpc.ipynb new file mode 100644 index 0000000..211e659 --- /dev/null +++ b/examples/adaptive_mpc/adaptive_mpc.ipynb @@ -0,0 +1,5403 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Adaptively Sampled MPC\n", + "\n", + "This is a simple demonstration of an adaptively sampled region quadtree used to approximate the solutions to a model-predictive control problem. " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "using Pkg\n", + "pkg\"activate .\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "using RegionTrees\n", + "using StaticArrays: SVector\n", + "using Plots" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Academic license - for non-commercial use only\n" + ] + }, + { + "data": { + "text/plain": [ + "Main.mpc" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# This module implements our MPC code, which consists of a 1-dimensional\n", + "# double-integrator system, forward-euler time-stepping dynamics, and a \n", + "# 10 step prediction window. \n", + "\n", + "module mpc\n", + "\n", + "using JuMP\n", + "using Gurobi\n", + "using StaticArrays\n", + "using Interpolations\n", + "using RegionTrees\n", + "import RegionTrees: AbstractRefinery, needs_refinement, refine_data\n", + "\n", + "const env = Gurobi.Env()\n", + "\n", + "# Solve the MPC problem from a given initial position and velocity\n", + "function run_mpc(q0, v0)\n", + " model = Model(solver=GurobiSolver(env, OutputFlag=0))\n", + " num_time_steps = 10\n", + " dt = 0.1\n", + " u_limit = 3\n", + " C_q = 100\n", + " c_vfinal = 100\n", + " C_u = 1\n", + "\n", + " @variable model q[1:num_time_steps]\n", + " @variable model v[1:num_time_steps]\n", + " @variable model u[1:num_time_steps]\n", + "\n", + " @constraint model [i=2:num_time_steps] q[i] == q[i-1] + v[i-1] * dt\n", + " @constraint model [i=2:num_time_steps] v[i] == v[i-1] + u[i-1] * dt\n", + " @constraint model u .<= u_limit\n", + " @constraint model u .>= -u_limit\n", + " @constraint model q[1] == q0\n", + " @constraint model v[1] == v0\n", + "\n", + " @objective model Min C_q * sum{q[i]^2, i=1:num_time_steps} + c_vfinal * v[end]^2 + C_u * sum{u[i]^2, i=1:num_time_steps}\n", + " solve(model)\n", + "\n", + " getvalue(q), getvalue(v), getvalue(u)\n", + "end\n", + "\n", + "# The MPCRefinery provides enough behavior to implement the \n", + "# RegionTrees AdaptiveSampling interface, which lets us generate\n", + "# a quadtree of initial states and their corresponding MPC solutions.\n", + "struct MPCRefinery <: AbstractRefinery\n", + "end\n", + "\n", + "function evaluate(cell, point)\n", + " p = (point - cell.boundary.origin) ./ cell.boundary.widths\n", + " cell.data(p[1] + 1, p[2] + 1)\n", + "end\n", + "\n", + "# A cell in the quadtree needs refinement if its interpolated solution\n", + "# derived from its vertices is not a good fit for the true MPC solution\n", + "# at its center and the center of each of its faces\n", + "function needs_refinement(::MPCRefinery, cell)\n", + " for x in body_and_face_centers(cell.boundary)\n", + " value_interp = evaluate(cell, x)\n", + " value_true = run_mpc(x[1], x[2])[3]\n", + " if !isapprox(value_interp[1], value_true[1], rtol=1e-1, atol=1e-1)\n", + " return true\n", + " end\n", + " end\n", + " false\n", + "end\n", + "\n", + "# The data element associated with a cell is a bilinear interpolation\n", + "# of the MPC function evaluated at the vertices of the cell.\n", + "function refine_data(r::MPCRefinery, cell::Cell, indices)\n", + " refine_data(r, child_boundary(cell, indices))\n", + "end\n", + "\n", + "function refine_data(::MPCRefinery, boundary::HyperRectangle)\n", + " f = v -> run_mpc(v[1], v[2])[3]\n", + " interpolate(f.(vertices(boundary)),\n", + " BSpline(Linear()))\n", + "end\n", + "\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "simulate (generic function with 1 method)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Simulate a given control function for the double integerator\n", + "# model.\n", + "function simulate(controller, q0, v0, dt, timespan)\n", + " num_time_steps = timespan / dt\n", + " qs = [q0]\n", + " vs = [v0]\n", + " ts = [0.0]\n", + " q = q0\n", + " v = v0\n", + " for t in 0:dt:(timespan)\n", + " u = controller(t, q, v)\n", + " q += v * dt\n", + " v += u * dt\n", + " push!(qs, q)\n", + " push!(vs, v)\n", + " push!(ts, t)\n", + " end\n", + " ts, qs, vs\n", + "end\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "#3 (generic function with 1 method)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "controller = (t, q, v) -> begin\n", + " q, v, u = mpc.run_mpc(q, v)\n", + " u[1]\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "([0.0, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 … 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10.0], [10.0, 10.0, 9.97, 9.91, 9.82, 9.7, 9.55, 9.37, 9.16, 8.92 … 8.59724e-5, 5.36258e-5, 2.83979e-5, 9.84092e-6, -2.88847e-6, -1.08171e-5, -1.50039e-5, -1.64406e-5, -1.59925e-5, -1.43722e-5], [0.0, -0.3, -0.6, -0.9, -1.2, -1.5, -1.8, -2.1, -2.4, -2.7 … -0.000323466, -0.000252279, -0.00018557, -0.000127294, -7.9286e-5, -4.18688e-5, -1.43665e-5, 4.48084e-6, 1.6203e-5, 2.23757e-5])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "t, q, v = simulate(controller, 10.0, 0.0, 0.1, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "-10\n", + "\n", + "\n", + "-5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "5\n", + "\n", + "\n", + "10\n", + "\n", + "\n", + "-10\n", + "\n", + "\n", + "-5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "5\n", + "\n", + "\n", + "10\n", + "\n", + "\n", + "q\n", + "\n", + "\n", + "v\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# State space portrait of the solution, starting from q=10, v=0\n", + "plot(q, v, xlim=(-10, 10), ylim=(-10, 10), xlabel=\"q\", ylabel=\"v\", legend=nothing)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "2.5\n", + "\n", + "\n", + "5.0\n", + "\n", + "\n", + "7.5\n", + "\n", + "\n", + "10.0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "3\n", + "\n", + "\n", + "6\n", + "\n", + "\n", + "9\n", + "\n", + "\n", + "t\n", + "\n", + "\n", + "q\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot(t, q, xlabel=\"t\", ylabel=\"q\", legend=nothing)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0.0\n", + "\n", + "\n", + "2.5\n", + "\n", + "\n", + "5.0\n", + "\n", + "\n", + "7.5\n", + "\n", + "\n", + "10.0\n", + "\n", + "\n", + "-6\n", + "\n", + "\n", + "-4\n", + "\n", + "\n", + "-2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "2\n", + "\n", + "\n", + "t\n", + "\n", + "\n", + "v\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot(t, v, xlabel=\"t\", ylabel=\"v\", legend=nothing)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Approximating the solutions space\n", + "Now that we've written down and tested the true MPC solution, we can try to approximate it. The AdaptiveSampling() function will generate a quadtree by iteratively refining each cell in the space until the solutions to the MPC problem within that cell are well-approximated by the interpolation. " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Cell: HyperRectangle{2,Float64}([-10.0, -10.0], [20.0, 20.0])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "boundary = RegionTrees.HyperRectangle(SVector(-10., -10), SVector(20., 20))\n", + "refinery = mpc.MPCRefinery()\n", + "root = RegionTrees.Cell(boundary, mpc.refine_data(refinery, boundary))\n", + "adaptivesampling!(root, refinery)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "-10\n", + "\n", + "\n", + "-5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "5\n", + "\n", + "\n", + "10\n", + "\n", + "\n", + "-10\n", + "\n", + "\n", + "-5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "5\n", + "\n", + "\n", + "10\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Now we can plot each region in the quadtree. Note that we end up with\n", + "# a lot of detail along the switching surface from maximum acceleration\n", + "# to maximum deceleration\n", + "plt = plot(xlim=(-10, 10), ylim=(-10, 10), legend=nothing, grid=false)\n", + "for cell in RegionTrees.allleaves(root)\n", + " v = hcat(collect(RegionTrees.vertices(cell.boundary))...)\n", + " plot!(v[1,[1,2,4,3,1]], v[2,[1,2,4,3,1]])\n", + "end\n", + "plt" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Using the Approximate Solution\n", + "We can use the quadtree to produce an approximate controller for our system. Given the current state, we can look up the cell in the quadtree which encompasses that state, then use that cell's interpolation to find our control tape. " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "#5 (generic function with 1 method)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "approx_controller = (t, q, v) -> begin\n", + " x = [q, v]\n", + " leaf = RegionTrees.findleaf(root, x)\n", + " u = mpc.evaluate(leaf, x)\n", + " u[1]\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "([0.0, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 … 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10.0], [10.0, 10.0, 9.97, 9.91, 9.82, 9.7, 9.55, 9.37, 9.16, 8.92 … 9.99227e-5, 6.22194e-5, 3.28375e-5, 1.12446e-5, -3.55003e-6, -1.27489e-5, -1.75901e-5, -1.92311e-5, -1.86816e-5, -1.67721e-5], [0.0, -0.3, -0.6, -0.9, -1.2, -1.5, -1.8, -2.1, -2.4, -2.7 … -0.000377034, -0.000293819, -0.000215929, -0.000147947, -9.1989e-5, -4.84113e-5, -1.64101e-5, 5.49477e-6, 1.90947e-5, 2.62314e-5])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "t, q, v = simulate(approx_controller, 10.0, 0.0, 0.1, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "-10\n", + "\n", + "\n", + "-5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "5\n", + "\n", + "\n", + "10\n", + "\n", + "\n", + "-10\n", + "\n", + "\n", + "-5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "5\n", + "\n", + "\n", + "10\n", + "\n", + "\n", + "q\n", + "\n", + "\n", + "v\n", + "\n", + "\n", + "\n" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# The results are similar to, but not quite as good as, the \n", + "# values obtained from the exact MPC solution. \n", + "plot(q, v, xlim=(-10, 10), ylim=(-10, 10), xlabel=\"q\", ylabel=\"v\", legend=nothing)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.0.0", + "language": "julia", + "name": "julia-1.0" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.0.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/demo/Manifest.toml b/examples/demo/Manifest.toml new file mode 100644 index 0000000..3309834 --- /dev/null +++ b/examples/demo/Manifest.toml @@ -0,0 +1,230 @@ +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "2d9e14d19bad3f9ad5cc5e4cffabc3cfa59de825" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.3.0" + +[[Contour]] +deps = ["LinearAlgebra", "StaticArrays", "Test"] +git-tree-sha1 = "b974e164358fea753ef853ce7bad97afec15bb80" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.5.1" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "8fc6e166e24fda04b2b648d4260cdad241788c54" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.14.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[GR]] +deps = ["Base64", "DelimitedFiles", "Pkg", "Random", "Serialization", "Sockets", "Test"] +git-tree-sha1 = "18e3aa0f988f6e94c90394deaa76cb095bf87469" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.35.0" + +[[InteractiveUtils]] +deps = ["LinearAlgebra", "Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "fec8e4d433072731466d37ed0061b3ba7f70eeb9" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.19.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Measures]] +deps = ["Test"] +git-tree-sha1 = "ddfd6d13e330beacdde2c80de27c1c671945e7d9" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "adc26d2ee85a49c413464110d922cf21efc9d233" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.3.1" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[PlotThemes]] +deps = ["PlotUtils", "Requires", "Test"] +git-tree-sha1 = "f3afd2d58e1f6ac9be2cea46e4a9083ccc1d990b" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "0.3.0" + +[[PlotUtils]] +deps = ["Colors", "Dates", "Printf", "Random", "Reexport", "Test"] +git-tree-sha1 = "fd28f30a294a38ec847de95d8ac7ac916ccd7c06" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "0.5.5" + +[[Plots]] +deps = ["Base64", "Contour", "Dates", "FixedPointNumbers", "GR", "JSON", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "Random", "RecipesBase", "Reexport", "Requires", "Showoff", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "UUIDs"] +git-tree-sha1 = "a36cbf119f1605268d0457e04e717901ae88b68c" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "0.21.0" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RecipesBase]] +deps = ["Random", "Test"] +git-tree-sha1 = "0b3cb370ee4dc00f47f1193101600949f3dcf884" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "0.6.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[RegionTrees]] +deps = ["IterTools", "LinearAlgebra", "StaticArrays", "Test"] +path = "../.." +uuid = "dee08c22-ab7f-5625-9660-a9af2021b33f" +version = "0.2.0+" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Showoff]] +deps = ["Compat"] +git-tree-sha1 = "276b24f3ace98bec911be7ff2928d497dc759085" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "0.2.1" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "ebc5c2a27d91d5ec611a9861168182e2168effd3" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.9.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "723193a13e8078cec6dcd0b8fe245c8bfd81690e" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.25.0" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/examples/demo/Project.toml b/examples/demo/Project.toml new file mode 100644 index 0000000..1b081e3 --- /dev/null +++ b/examples/demo/Project.toml @@ -0,0 +1,4 @@ +[deps] +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/examples/demo.ipynb b/examples/demo/demo.ipynb similarity index 73% rename from examples/demo.ipynb rename to examples/demo/demo.ipynb index 6e7d7f0..738db58 100644 --- a/examples/demo.ipynb +++ b/examples/demo/demo.ipynb @@ -2,18 +2,28 @@ "cells": [ { "cell_type": "code", - "execution_count": 33, + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "using Pkg\n", + "pkg\"activate .\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "using RegionTrees\n", - "import StaticArrays: SVector\n", + "using StaticArrays: SVector\n", "using Plots" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -22,7 +32,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 34, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -37,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -46,7 +56,7 @@ "true" ] }, - "execution_count": 35, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -59,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -68,7 +78,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 36, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -80,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -89,7 +99,7 @@ "false" ] }, - "execution_count": 37, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -101,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -110,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -119,7 +129,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.5, 0.5])" ] }, - "execution_count": 39, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -133,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -142,7 +152,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.5, 0.5])" ] }, - "execution_count": 40, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -154,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -163,7 +173,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.5, 0.5])" ] }, - "execution_count": 41, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -175,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -184,7 +194,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [0.25, 0.25])" ] }, - "execution_count": 42, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -196,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -205,7 +215,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.25], [0.25, 0.25])" ] }, - "execution_count": 43, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -216,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -225,170 +235,170 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "0.0\n", + "\n", + "0.0\n", "\n", - "\n", - "0.2\n", + "\n", + "0.2\n", "\n", - "\n", - "0.4\n", + "\n", + "0.4\n", "\n", - "\n", - "0.6\n", + "\n", + "0.6\n", "\n", - "\n", - "0.8\n", + "\n", + "0.8\n", "\n", - "\n", - "1.0\n", + "\n", + "1.0\n", "\n", - "\n", - "0.0\n", + "\n", + "0.0\n", "\n", - "\n", - "0.2\n", + "\n", + "0.2\n", "\n", - "\n", - "0.4\n", + "\n", + "0.4\n", "\n", - "\n", - "0.6\n", + "\n", + "0.6\n", "\n", - "\n", - "0.8\n", + "\n", + "0.8\n", "\n", - "\n", - "1.0\n", + "\n", + "1.0\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", "\n" ] }, - "execution_count": 44, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -405,7 +415,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -415,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -424,7 +434,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 46, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -435,7 +445,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -444,7 +454,7 @@ "\"A\"" ] }, - "execution_count": 47, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -457,7 +467,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -466,7 +476,7 @@ "Cell{String,2,Float64,4}" ] }, - "execution_count": 48, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -479,7 +489,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -488,7 +498,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 49, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -503,7 +513,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -512,7 +522,7 @@ "\"B\"" ] }, - "execution_count": 50, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -523,7 +533,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -532,7 +542,7 @@ "\"C\"" ] }, - "execution_count": 51, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -543,7 +553,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -552,7 +562,7 @@ "Cell: HyperRectangle{2,Float64}([0.25, 0.75], [0.25, 0.25])" ] }, - "execution_count": 52, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -579,7 +589,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -588,7 +598,7 @@ "\"root child (1, 2) child (2, 2) child (1, 1)\"" ] }, - "execution_count": 53, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -599,7 +609,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -608,7 +618,7 @@ "Cell: HyperRectangle{2,Float64}([0.0, 0.0], [1.0, 1.0])" ] }, - "execution_count": 54, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -658,7 +668,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -667,7 +677,7 @@ "\"child with widths: [0.03125, 0.03125]\"" ] }, - "execution_count": 55, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -678,7 +688,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -687,3221 +697,3221 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "0.0\n", + "\n", + "0.0\n", "\n", - "\n", - "0.2\n", + "\n", + "0.2\n", "\n", - "\n", - "0.4\n", + "\n", + "0.4\n", "\n", - "\n", - "0.6\n", + "\n", + "0.6\n", "\n", - "\n", - "0.8\n", + "\n", + "0.8\n", "\n", - "\n", - "1.0\n", + "\n", + "1.0\n", "\n", - "\n", - "0.0\n", + "\n", + "0.0\n", "\n", - "\n", - "0.2\n", + "\n", + "0.2\n", "\n", - "\n", - "0.4\n", + "\n", + "0.4\n", "\n", - "\n", - "0.6\n", + "\n", + "0.6\n", "\n", - "\n", - "0.8\n", + "\n", + "0.8\n", "\n", - "\n", - "1.0\n", + "\n", + "1.0\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", "\n" ] }, - "execution_count": 56, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -3918,7 +3928,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Julia 1.0.1", + "display_name": "Julia 1.0.0", "language": "julia", "name": "julia-1.0" }, @@ -3926,7 +3936,7 @@ "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "1.0.1" + "version": "1.0.0" } }, "nbformat": 4, diff --git a/test/REQUIRE b/test/REQUIRE index 3613e3e..41eab80 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1,2 @@ -Interpolations 0.8 +Interpolations 0.9 NBInclude 2.0 diff --git a/test/asdfs.jl b/test/asdfs.jl index 6d4cf86..a757772 100644 --- a/test/asdfs.jl +++ b/test/asdfs.jl @@ -1,5 +1,5 @@ @testset "adaptively sampled distance fields" begin - include("../examples/adaptive_distance_fields.jl") + include("../examples/adaptive_distance_fields/adaptive_distance_fields.jl") import .AdaptivelySampledDistanceFields: ASDF, evaluate import StaticArrays: SVector From d3acadd9378df3504cf0c53f9c21fb105a9924e6 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 7 Nov 2018 08:23:08 -0500 Subject: [PATCH 4/9] test notebooks in their own projects --- test/REQUIRE | 2 +- test/runtests.jl | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/test/REQUIRE b/test/REQUIRE index 41eab80..bbbd182 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1,2 @@ Interpolations 0.9 -NBInclude 2.0 +IJulia diff --git a/test/runtests.jl b/test/runtests.jl index 1b1e0a1..7c10aa2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,7 @@ using Test using RegionTrees using StaticArrays -using NBInclude +using IJulia using LinearAlgebra include("hyperrectangle.jl") @@ -9,6 +9,13 @@ include("cell.jl") include("twosarray.jl") include("asdfs.jl") -# const notebooks_dir = joinpath(dirname(@__FILE__), "..", "examples") -# @nbinclude(joinpath(notebooks_dir, "demo.ipynb")) -# @nbinclude(joinpath(notebooks_dir, "adaptive_distances.ipynb")) +const notebooks_dir = joinpath(dirname(@__FILE__), "..", "examples") + +function execute_notebook(path) + mktempdir() do dir + run(`$(IJulia.jupyter) nbconvert --execute $path --output-dir=$dir`) + end +end + +execute_notebook(joinpath(notebooks_dir, "demo", "demo.ipynb")) +execute_notebook(joinpath(notebooks_dir, "adaptive_distance_fields", "adaptive_distances.ipynb")) From 1468339728d0020042565ac7f5f8ec9e90935a25 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Thu, 8 Nov 2018 08:12:58 -0500 Subject: [PATCH 5/9] fix tests --- test/REQUIRE | 2 +- test/runtests.jl | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/test/REQUIRE b/test/REQUIRE index bbbd182..6859e51 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1,2 @@ Interpolations 0.9 -IJulia +NBInclude diff --git a/test/runtests.jl b/test/runtests.jl index 7c10aa2..252b91a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,19 +1,26 @@ using Test using RegionTrees using StaticArrays -using IJulia using LinearAlgebra +using NBInclude include("hyperrectangle.jl") include("cell.jl") include("twosarray.jl") include("asdfs.jl") -const notebooks_dir = joinpath(dirname(@__FILE__), "..", "examples") +const notebooks_dir = joinpath(@__DIR__, "..", "examples") +# """ +# Run a jupyter notebook (.ipynb) file using NBInclude. Spawns a +# new Julia session so that notebooks that use a different project +# directory still work. +# """ function execute_notebook(path) - mktempdir() do dir - run(`$(IJulia.jupyter) nbconvert --execute $path --output-dir=$dir`) + # julia = joinpath(Sys.BINDIR, "julia") + # run(`$julia --project=$(dirname(path)) -e "using NBInclude; @nbinclude(\"$path\")"`) + cd(dirname(path)) do + @nbinclude(path) end end From 2fac3a3d5c2f66e6eacd94443aa9cd231030ee49 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Thu, 8 Nov 2018 16:47:58 -0500 Subject: [PATCH 6/9] test notebooks in separate session with cd --- test/runtests.jl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 252b91a..87ee2b2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,16 +11,15 @@ include("asdfs.jl") const notebooks_dir = joinpath(@__DIR__, "..", "examples") -# """ -# Run a jupyter notebook (.ipynb) file using NBInclude. Spawns a -# new Julia session so that notebooks that use a different project -# directory still work. -# """ +""" +Run a jupyter notebook (.ipynb) file using NBInclude. Spawns a +new Julia session so that notebooks that use a different project +directory work reliably. +""" function execute_notebook(path) - # julia = joinpath(Sys.BINDIR, "julia") - # run(`$julia --project=$(dirname(path)) -e "using NBInclude; @nbinclude(\"$path\")"`) + julia = joinpath(Sys.BINDIR, "julia") cd(dirname(path)) do - @nbinclude(path) + run(`$julia --project=$(dirname(path)) -e "using NBInclude; @nbinclude(\"$path\")"`) end end From 477d78c0e4749800a8c8c2c52e6b3c82f092521b Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Thu, 8 Nov 2018 16:58:55 -0500 Subject: [PATCH 7/9] add Pkg to demo projects --- .../adaptive_distance_fields/Manifest.toml | 12 +++++++++++ .../adaptive_distance_fields/Project.toml | 2 ++ examples/adaptive_mpc/Manifest.toml | 20 +++++++++++++++---- examples/adaptive_mpc/Project.toml | 2 ++ examples/demo/Manifest.toml | 12 +++++++++++ examples/demo/Project.toml | 2 ++ test/runtests.jl | 8 +------- 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/examples/adaptive_distance_fields/Manifest.toml b/examples/adaptive_distance_fields/Manifest.toml index 7d214de..a2fb3e8 100644 --- a/examples/adaptive_distance_fields/Manifest.toml +++ b/examples/adaptive_distance_fields/Manifest.toml @@ -115,6 +115,12 @@ version = "0.3.1" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" +[[NBInclude]] +deps = ["Compat", "JSON", "SoftGlobalScope"] +git-tree-sha1 = "9881dd75c83eba704798dfd7185770c29ac720f8" +uuid = "0db19996-df87-5ea3-a455-e3a50d440464" +version = "2.1.0" + [[NaNMath]] deps = ["Compat"] git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" @@ -216,6 +222,12 @@ version = "0.2.1" [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" +[[SoftGlobalScope]] +deps = ["Test"] +git-tree-sha1 = "97f6dfcf612b9a7260fde44170725d9ea34b1431" +uuid = "b85f4697-e234-5449-a836-ec8e2f98b302" +version = "1.0.7" + [[SortingAlgorithms]] deps = ["DataStructures", "Random", "Test"] git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" diff --git a/examples/adaptive_distance_fields/Project.toml b/examples/adaptive_distance_fields/Project.toml index bbf2d18..b66268f 100644 --- a/examples/adaptive_distance_fields/Project.toml +++ b/examples/adaptive_distance_fields/Project.toml @@ -1,5 +1,7 @@ [deps] Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/examples/adaptive_mpc/Manifest.toml b/examples/adaptive_mpc/Manifest.toml index 473b440..1061daa 100644 --- a/examples/adaptive_mpc/Manifest.toml +++ b/examples/adaptive_mpc/Manifest.toml @@ -105,9 +105,9 @@ version = "0.35.0" [[Gurobi]] deps = ["Compat", "Libdl", "LinQuadOptInterface", "MathProgBase"] -git-tree-sha1 = "417fe26b36445e5bf6c027c6a14fbf4ea2b7c705" +git-tree-sha1 = "2e6c179def1b5f121ab21852b2c36e81c9f005db" uuid = "2e9cd046-0924-5485-92f1-d5272153d98b" -version = "0.5.4" +version = "0.5.5" [[InteractiveUtils]] deps = ["LinearAlgebra", "Markdown"] @@ -145,9 +145,9 @@ uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" [[LinQuadOptInterface]] deps = ["Compat", "MathOptInterface"] -git-tree-sha1 = "c246e73894d2063ab0697be54ecbb122e604df19" +git-tree-sha1 = "7baadee415b6fc86519152fdfafb1d3526488171" uuid = "f8899e07-120b-5979-ab1d-7b97bb9e1a48" -version = "0.4.1" +version = "0.4.2" [[LinearAlgebra]] deps = ["Libdl"] @@ -187,6 +187,12 @@ version = "0.3.1" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" +[[NBInclude]] +deps = ["Compat", "JSON", "SoftGlobalScope"] +git-tree-sha1 = "9881dd75c83eba704798dfd7185770c29ac720f8" +uuid = "0db19996-df87-5ea3-a455-e3a50d440464" +version = "2.1.0" + [[NaNMath]] deps = ["Compat"] git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" @@ -294,6 +300,12 @@ version = "0.2.1" [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" +[[SoftGlobalScope]] +deps = ["Test"] +git-tree-sha1 = "97f6dfcf612b9a7260fde44170725d9ea34b1431" +uuid = "b85f4697-e234-5449-a836-ec8e2f98b302" +version = "1.0.7" + [[SortingAlgorithms]] deps = ["DataStructures", "Random", "Test"] git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" diff --git a/examples/adaptive_mpc/Project.toml b/examples/adaptive_mpc/Project.toml index b4977f6..67d0e6d 100644 --- a/examples/adaptive_mpc/Project.toml +++ b/examples/adaptive_mpc/Project.toml @@ -2,6 +2,8 @@ Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b" Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/examples/demo/Manifest.toml b/examples/demo/Manifest.toml index 3309834..2483c73 100644 --- a/examples/demo/Manifest.toml +++ b/examples/demo/Manifest.toml @@ -103,6 +103,12 @@ version = "0.3.1" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" +[[NBInclude]] +deps = ["Compat", "JSON", "SoftGlobalScope"] +git-tree-sha1 = "9881dd75c83eba704798dfd7185770c29ac720f8" +uuid = "0db19996-df87-5ea3-a455-e3a50d440464" +version = "2.1.0" + [[NaNMath]] deps = ["Compat"] git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" @@ -192,6 +198,12 @@ version = "0.2.1" [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" +[[SoftGlobalScope]] +deps = ["Test"] +git-tree-sha1 = "97f6dfcf612b9a7260fde44170725d9ea34b1431" +uuid = "b85f4697-e234-5449-a836-ec8e2f98b302" +version = "1.0.7" + [[SortingAlgorithms]] deps = ["DataStructures", "Random", "Test"] git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" diff --git a/examples/demo/Project.toml b/examples/demo/Project.toml index 1b081e3..8294996 100644 --- a/examples/demo/Project.toml +++ b/examples/demo/Project.toml @@ -1,4 +1,6 @@ [deps] +NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/test/runtests.jl b/test/runtests.jl index 87ee2b2..a4171de 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,15 +11,9 @@ include("asdfs.jl") const notebooks_dir = joinpath(@__DIR__, "..", "examples") -""" -Run a jupyter notebook (.ipynb) file using NBInclude. Spawns a -new Julia session so that notebooks that use a different project -directory work reliably. -""" function execute_notebook(path) - julia = joinpath(Sys.BINDIR, "julia") cd(dirname(path)) do - run(`$julia --project=$(dirname(path)) -e "using NBInclude; @nbinclude(\"$path\")"`) + @nbinclude(path) end end From 04fa05c6e45c046fd202455e7758066b84617fe7 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Thu, 8 Nov 2018 17:05:54 -0500 Subject: [PATCH 8/9] another try --- test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index a4171de..4c67561 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,8 +12,9 @@ include("asdfs.jl") const notebooks_dir = joinpath(@__DIR__, "..", "examples") function execute_notebook(path) + julia = joinpath(Sys.BINDIR, "julia") cd(dirname(path)) do - @nbinclude(path) + run(`$julia --project=$(dirname(path)) -e "using NBInclude; @nbinclude(\"$path\")"`) end end From 45db0838a98bc36ae1b7bebba4e3f474b44732cc Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Sun, 11 Nov 2018 11:30:19 -0500 Subject: [PATCH 9/9] don't worry about notebook tests --- test/REQUIRE | 1 - test/runtests.jl | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/test/REQUIRE b/test/REQUIRE index 6859e51..3a81753 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1 @@ Interpolations 0.9 -NBInclude diff --git a/test/runtests.jl b/test/runtests.jl index 4c67561..6987c25 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,21 +2,8 @@ using Test using RegionTrees using StaticArrays using LinearAlgebra -using NBInclude include("hyperrectangle.jl") include("cell.jl") include("twosarray.jl") include("asdfs.jl") - -const notebooks_dir = joinpath(@__DIR__, "..", "examples") - -function execute_notebook(path) - julia = joinpath(Sys.BINDIR, "julia") - cd(dirname(path)) do - run(`$julia --project=$(dirname(path)) -e "using NBInclude; @nbinclude(\"$path\")"`) - end -end - -execute_notebook(joinpath(notebooks_dir, "demo", "demo.ipynb")) -execute_notebook(joinpath(notebooks_dir, "adaptive_distance_fields", "adaptive_distances.ipynb"))