diff --git a/examples/Computing controlled invariant sets.ipynb b/examples/Computing controlled invariant sets.ipynb index f7e523b2..ccba0318 100644 --- a/examples/Computing controlled invariant sets.ipynb +++ b/examples/Computing controlled invariant sets.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "collapsed": true }, @@ -39,20 +39,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "@_time (macro with 1 method)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "macro _time(x)\n", " quote\n", @@ -66,20 +55,21 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "using Gurobi\n", + "lpsolver = GurobiSolver(OutputFlag=0);" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "iterate! (generic function with 1 method)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "function liftu(S, sys::HybridSystems.DiscreteLinearControlSystem)\n", " [sys.A sys.B] \\ S\n", @@ -95,7 +85,8 @@ " map(t -> new_constraint(hs, S, q, t), out_transitions(hs, q))\n", "end\n", "function add_hrep!(S, h::HalfSpace)\n", - " if S ⊆ h # If S ⊆ h, then adding h will not change affect S\n", + " # I was using LP cycling errors when using CDD's LP solver\n", + " if issubset(S, h) # If S ⊆ h, then adding h will not change affect S\n", " false\n", " else\n", " push!(S, SimpleHRepresentation(reshape(h.a, 1, length(h.a)), [h.β]))\n", @@ -104,7 +95,7 @@ "end\n", "function add_constraint!(S, P)\n", " added = count(map(h -> add_hrep!(S, h), ineqs(P))) + count(map(h -> add_hrep!(S, h), eqs(P)))\n", - " removehredundancy!(S)\n", + " removehredundancy!(S) # CDD throws LP cycling error\n", " added\n", "end\n", "function add_constraints!(S::Polyhedron, Ps::Vector{<:Polyhedron})\n", @@ -116,46 +107,18 @@ " @show added\n", "end\n", "function iterate!(hs, S, nit)\n", - " map(i -> (@_time set_iteration!(hs, S)), 1:nit)\n", + " map(i -> (gc(); @_time set_iteration!(hs, S)), 1:nit)\n", "end" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "nineqs(I0[1]) = 8\n", - "m = 1\n", - "added = [6, 8, 8, 8, 8, 8, 8, 8, 8, 8]\n", - "added = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n", - "added = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12]\n", - "added = [14, 14, 14, 14, 14, 14, 14, 14, 14, 14]\n", - "added = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n", - "added = [26, 26, 26, 26, 26, 26, 26, 26, 26, 26]\n", - "added = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\n", - "t[m, :] = [0.138743, 0.275568, 0.753732, 1.98394, 5.05119, 12.3602, 27.083]\n" - ] - }, - { - "data": { - "text/plain": [ - "1×7 Array{Float64,2}:\n", - " 0.138743 0.275568 0.753732 1.98394 5.05119 12.3602 27.083" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "Mmax = 1\n", - "nit = 7\n", + "nit = 2\n", "t = zeros(Mmax, nit)\n", "Hs = Vector{HybridSystem}(Mmax)\n", "CIS = Vector{Vector{Polyhedron}}(Mmax)\n", @@ -173,20 +136,27 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Mmax = size(t, 1)\n", + "nit = 1\n", + "previt = size(t, 2)\n", + "t = [t zeros(Mmax, nit)]\n", + "totit = size(t, 2)\n", + "for m in 1:Mmax\n", + " t[m, previt+(1:nit)] = iterate!(Hs[m], CIS[m], nit)\n", + " @show t[m, :]\n", + "end\n", + "t" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Plots.PyPlotBackend()" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import Plots\n", "Plots.pyplot()" @@ -194,20 +164,9 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "D = [1, 2]\n", "Plots.plot(project(Hs[1].invariants[1], D))\n", @@ -216,13 +175,26 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, + "execution_count": null, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "Plots.savefig(\"dist_trailerspeed.png\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "t" + ] + }, { "cell_type": "code", "execution_count": null, @@ -243,7 +215,7 @@ "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.6.1" + "version": "0.6.2" } }, "nbformat": 4,