text:
### A Pluto.jl notebook ###
# v0.19.6

using Markdown
using InteractiveUtils

# ╔═╡ 7c904df4-8434-11ec-119d-0117ccc4d0ae
# hideall
let
    docs_dir = dirname(dirname(@__DIR__))
    pkg_dir = dirname(docs_dir)

    using Pkg: Pkg
    Pkg.activate(docs_dir)
    Pkg.develop(; path=pkg_dir)
    Pkg.instantiate()
end

# ╔═╡ 29dd924c-8f29-422f-84cf-ddb393e01fb2
# hideall
try using Revise; catch end # For development purposes.

# ╔═╡ bc9d5fb8-2f76-4b09-b770-29a95ad4dabe
begin
    using CairoMakie
    using DataFrames
    using Resample
    using StableRNGs: StableRNG
end

# ╔═╡ 62e550fe-aa36-4f11-ade8-d7262cbb228f
md"""
# SMOTE

This is a tutorial walking through the basic functionality of the `smote` function of this package which implements the Synthetic Minority Over-sampling TEchnique (SMOTE) (Chawla et al., [2002](https://doi.org/10.1613/jair.953)).

This technique is useful when the accuracy of a statistical model is low due to class imbalances.
For example, when fitting a model on an outcome variable with 2 classes and one class has 10 items and the other 90 items, then a model can score very well by always predicting a sample to be in the biggest class.
These biggest and smallest classes are respectively known as the majority and minority class.

The idea of SMOTE is to fix the class imbalance by generating random points in between points in the minority group.
This will be shown below in more detail.

## In between

In the first part of this tutorial, a few random points in a minority class are generated.
Next, we plot these points, generate a few synthetic (new) points and show that the synthetic points lay between the original points.
"""

# ╔═╡ c35d1118-9caf-469a-a437-ab3436d89bb6
md"Let's start by generating some random data:"

# ╔═╡ 566a54ec-3731-4b1b-be80-ce3a814202f4
df = let
    rng = StableRNG(2)
    DataFrame(; A=rand(rng, 4), B=rand(rng, 4))
end

# ╔═╡ 3ee34b73-8394-4f0e-ad93-4f8f20ced692
md"Which looks as follows when plotted:"

# ╔═╡ 8398cc7a-d927-4beb-8f5b-0b342f1a59e6
# hideall
resolution = (1000, 800);

# ╔═╡ 7b36f122-a63d-43f7-9861-73c6b65da5fa
# hideall
let
    fig = Figure(; resolution)
    ax = Axis(fig[1, 1])
    scatter!(ax, df.A, df.B; label="Minority")
    Legend(fig[1, 2], ax)
    fig
end

# ╔═╡ f643a1a0-0683-4051-8f88-427ef5cfa3e7
md"To generate new synthetic points (`new_points`), we use the `smote` function from this package:"

# ╔═╡ 8349ef02-26c7-4e22-a146-2528b6bc5d88
new_data = let
    rng = StableRNG(1)
    new_points = smote(rng, df, 4)
    DataFrame(new_points)
end

# ╔═╡ 336c44ef-5248-4588-8db4-4fcee24cdfcc
md"
Plotting these 2-dimensional points with the synthetic points looks as follows:
"

# ╔═╡ e617e094-567b-4425-8409-d8513902ad92
# hideall
let
    fig = Figure(; resolution)
    ax = Axis(fig[1, 1])

    scatter!(ax, df.A, df.B; label="Minority")
    scatter!(ax, new_data.A, new_data.B; label="Synthetic")

    for i in 1:nrow(df)
        for j in 1:nrow(df)
            if i < j
                kwargs = (; color=:black, linestyle=:dash, linewidth=1)
                lines!(ax, [df.A[i], df.A[j]], [df.B[i], df.B[j]]; kwargs...)
            end
        end
    end

    Legend(fig[1, 2], ax)
    fig
end

# ╔═╡ 2934cfb2-36fa-4969-9bc8-007ee24274aa
md"
where the dashed lines are straight lines in between all the points.
As expected, the synthetic points lay in between the minority points.

Next, we do this for a point cloud.
"

# ╔═╡ 1edf932f-61b8-411e-812d-ef455b3b0d28
md"""
## Cloud

When doing this for many points, we will see that the cloud of points gets thicker due when the synthetic points are added.
In the first part of this tutorial, we passed the data as a DataFrame (or any other `Tables.istable` object), but we can also pass a matrix:
"""

# ╔═╡ c102759b-40f1-45a0-ab04-99ccd28cabf5
mat = randn(2, 400) .* 100

# ╔═╡ fdd2f703-45c7-4867-b248-7639cdb69119
md"which looks as follows when plotted:"

# ╔═╡ c4dc370b-98db-412c-8d9f-c181d4ad623e
# hideall
let
    fig = Figure(; resolution)
    ax = Axis(fig[1, 1])
    scatter!(ax, mat[1, :], mat[2, :]; label="Minority")
    Legend(fig[1, 2], ax)
    fig
end

# ╔═╡ d3259ee5-34ab-4f94-a7ea-e6a590f51cb5
md"Now, we can generate a bunch of synthetic data:"

# ╔═╡ a451ea0f-8118-4865-b058-da14a394f23e
new_mat = smote(mat, 300)

# ╔═╡ 15d68355-0a57-48ef-91d8-e2644eaf6d4b
md"which looks as follows:"

# ╔═╡ 5678cc5f-00ac-4425-af1f-2174da9ba1f3
# hideall
let
    fig = Figure(; resolution)
    ax = Axis(fig[1, 1])
    scatter!(ax, mat[1, :], mat[2, :]; label="Minority")
    scatter!(ax, new_mat[1, :], new_mat[2, :]; label="Synthetic")
    Legend(fig[1, 2], ax)
    fig
end

# ╔═╡ Cell order:
# ╠═7c904df4-8434-11ec-119d-0117ccc4d0ae
# ╠═29dd924c-8f29-422f-84cf-ddb393e01fb2
# ╠═62e550fe-aa36-4f11-ade8-d7262cbb228f
# ╠═bc9d5fb8-2f76-4b09-b770-29a95ad4dabe
# ╠═c35d1118-9caf-469a-a437-ab3436d89bb6
# ╠═566a54ec-3731-4b1b-be80-ce3a814202f4
# ╠═3ee34b73-8394-4f0e-ad93-4f8f20ced692
# ╠═8398cc7a-d927-4beb-8f5b-0b342f1a59e6
# ╠═7b36f122-a63d-43f7-9861-73c6b65da5fa
# ╠═f643a1a0-0683-4051-8f88-427ef5cfa3e7
# ╠═8349ef02-26c7-4e22-a146-2528b6bc5d88
# ╠═336c44ef-5248-4588-8db4-4fcee24cdfcc
# ╠═e617e094-567b-4425-8409-d8513902ad92
# ╠═2934cfb2-36fa-4969-9bc8-007ee24274aa
# ╠═1edf932f-61b8-411e-812d-ef455b3b0d28
# ╠═c102759b-40f1-45a0-ab04-99ccd28cabf5
# ╠═fdd2f703-45c7-4867-b248-7639cdb69119
# ╠═c4dc370b-98db-412c-8d9f-c181d4ad623e
# ╠═d3259ee5-34ab-4f94-a7ea-e6a590f51cb5
# ╠═a451ea0f-8118-4865-b058-da14a394f23e
# ╠═15d68355-0a57-48ef-91d8-e2644eaf6d4b
# ╠═5678cc5f-00ac-4425-af1f-2174da9ba1f3


text:
module HFMod
using  DataFrames, Distributions, StatsBase, GZip, JLD#, ArrayFire (Needs to be updated to 0.6)

if !isdefined(:constDef)
  const constDef = true
  #other constants here

  const debugHFMod = true #switch for performance impairing checks
  const dataPath = pwd() * "\\data"
  const dataFileName = "HFPerformance_2015-2017"

end

function PreProcessHFData()

  #this makes sure we have a binary of the data (Improves load times 3-4x)
  if !isfile("$dataPath\\$dataFileName.jls")
    #extract from the zip file
    gHandle::GZipStream = GZip.open("$dataPath\\$dataFileName.gz")
    write("$dataPath\\$dataFileName.csv", readlines(gHandle,chomp=false))
    close(gHandle)

    #write the binary
    oStream::IOStream = open("$dataPath\\$dataFileName.jls","w+")
    serialize(oStream, readtable("$dataPath\\$dataFileName.csv"))
    close(oStream)
  end

  #load the binary
  iStream::IOStream = open("$dataPath\\$dataFileName.jls")
  HFData::DataFrame = deserialize(iStream)
  close(iStream)

  #type conversions here
  #=for i = 1:size(HFData,1)
    HFData[i,[:]:date] = Date("$(HFData[i,:date])",Dates.DateFormat("yyyymmdd"))
  end=#
  rename!(HFData,:date,:date_old)
  HFData[:,:date] = map((x::Int)->Date("$x",Dates.DateFormat("yyyymmdd")),HFData[:,:date_old])

  println(HFData[1:3,:])

  #save the binary
  oStream = open("$dataPath\\$(dataFileName)_clean.jls","w+")
  serialize(oStream, HFData)
  close(oStream)

  #println(HFData[])

end

@time PreProcessHFData()

end

ext: jl

max_stars_repo_path: Old/Scraper3/Ref- Data Functions.jl

max_stars_repo_name: clintonTE/CCA

max_issues_repo_path: Old/Scraper3/Ref- Data Functions.jl

max_issues_repo_name: clintonTE/CCA

max_forks_repo_path: Old/Scraper3/Ref- Data Functions.jl

max_forks_repo_name: clintonTE/CCA


text:
using aoc2019.computer: load_program, io, run
using Match

input = joinpath(@__DIR__, "input")
p = load_program(input)

affected = 0

function scan(i, j)
    stdin, stdout = io()
    @async run(copy(p), stdin, stdout)
    put!(stdin, i)
    put!(stdin, j)
    res = take!(stdout)
    close(stdin)
    close(stdout)
    return res == 1 ? true : false
end

for i in 0:49
    for j in 0:49
        if scan(i, j)
            global affected += 1
        end
    end
end

i = 0
j = 99
n = nothing

while true
    # scan until beam found
    while !scan(i, j)
        global i += 1
    end
    # check box
    if scan(i + 99, j - 99)
        global n = i * 10000 + j - 99
        break
    end
    global j += 1
end

p1 = affected
@assert p1 == 206
p2 = n
@assert p2 == 6190948

print("-----------------------------------------------------------------------\n")
print("tractor beam -- part one\n    affected : $p1\n")
print("tractor beam -- part two\n    distance : $p2\n")
print("-----------------------------------------------------------------------\n")


text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:2] <= 1)

                     @variable(m, -47.02611826463841 <= q <= 46.175694332378946)

                     add_NL_constraint(m, :(swish(0.14172886209520552 + -0.7326244672203441*swish(-0.9862473619768446 + 0.12598046880516867*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.9857820194451663*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3507087497777257*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.16930171271231975*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + 0.6188053648075824*swish(-0.8901994655270467 + 0.3517572387180481*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5057680398491988*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15346000401268212*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.000907155550359029*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + 0.748255673773524*swish(0.9418689270026719 + 0.23440750676702393*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.9578891219409944*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4332120963929875*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15216088947964046*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.19681615050825796*swish(-0.3160427191298667 + -0.1453900085539872*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3370407689400481*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5646332930109117*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4312398718758548*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + swish(0.7126847484534728 + 0.5521736820641339*swish(-0.9862473619768446 + 0.12598046880516867*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.9857820194451663*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3507087497777257*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.16930171271231975*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.5863621462894022*swish(-0.8901994655270467 + 0.3517572387180481*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5057680398491988*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15346000401268212*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.000907155550359029*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.2365722039484086*swish(0.9418689270026719 + 0.23440750676702393*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.9578891219409944*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4332120963929875*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15216088947964046*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.47134077688752996*swish(-0.3160427191298667 + -0.1453900085539872*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3370407689400481*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5646332930109117*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4312398718758548*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + swish(0.3678622626620536 + -0.645924933237755*swish(-0.9862473619768446 + 0.12598046880516867*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.9857820194451663*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3507087497777257*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.16930171271231975*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + 0.23980134898526861*swish(-0.8901994655270467 + 0.3517572387180481*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5057680398491988*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15346000401268212*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.000907155550359029*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + 0.5641271464877478*swish(0.9418689270026719 + 0.23440750676702393*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.9578891219409944*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4332120963929875*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15216088947964046*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.22456183587218126*swish(-0.3160427191298667 + -0.1453900085539872*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3370407689400481*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5646332930109117*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4312398718758548*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + swish(-0.9861590919257504 + -0.9031060096581198*swish(-0.9862473619768446 + 0.12598046880516867*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.9857820194451663*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3507087497777257*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.16930171271231975*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.6492392304855641*swish(-0.8901994655270467 + 0.3517572387180481*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5057680398491988*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15346000401268212*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.000907155550359029*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + 0.1540584284169868*swish(0.9418689270026719 + 0.23440750676702393*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.9578891219409944*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4332120963929875*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.15216088947964046*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2])))) + -0.8682585596517867*swish(-0.3160427191298667 + -0.1453900085539872*swish(-0.32432918385015697 + -0.6977940842525037*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.476420397288412*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.5549201217740469*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.4315951265237059*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.3370407689400481*swish(0.2633379906083797 + 0.3509284626355762*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.5977055959243147*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.642253969451728*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.10048605306401859*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + 0.5646332930109117*swish(-0.34549165187553976 + 0.5367448324029058*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.7077894233575681*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + -0.4911236080946888*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + -0.5306931393323575*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))) + -0.4312398718758548*swish(0.538919292477293 + 0.8088100362525972*swish(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2])) + -0.4318478690072691*swish(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2])) + 0.8077402924106214*swish(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2])) + 0.12603114956525063*swish(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
module Day15

export get_inputs, get_solution1, get_solution2

## Input getting
function get_inputs()
    test_input1 = test_input2 = read_csv(IOBuffer("0,3,6"))
    test_output1 = 436
    test_output2 = 175594
    data = read_csv(joinpath(@__DIR__, "input.txt"))
    return (; test_input1, test_input2, test_output1, test_output2, data)
end

read_csv(io) = parse.(Int, split(read(io, String), r",|\n|\r\n"; keepempty=false))

## Solution functions
# Part 1
function get_solution1(data, n=2020)
    called_nums = Dict(num => turn for (turn, num) in enumerate(data))
    last_num = last(data)

    for i in (length(data)+1):n
        num = haskey(called_nums, last_num) ? i-1 - called_nums[last_num] : 0
        called_nums[last_num] = i-1
        last_num = num
    end

    return last_num
end

# Part 2
get_solution2(data) = get_solution1(data, 30000000)

end


text:
"""
    couple_models(aero::Wagner, stru::LiftingLineSection)

Create an aerostructural model using an unsteady aerodynamic model based
on Wagner's function and a lifting line section model.  The existence of this
coupling allows [`Wagner`](@ref) to be used with [`LiftingLine`](@ref).  This
model introduces the freestream air density ``\\rho`` as an additional parameter.
"""
couple_models(aero::Wagner, stru::LiftingLineSection) = (aero, stru)

# --- Traits --- #

number_of_additional_parameters(::Type{<:Wagner}, ::Type{LiftingLineSection}) = 1

coupling_inplaceness(::Type{<:Wagner}, ::Type{LiftingLineSection}) = OutOfPlace()

coupling_rate_jacobian_type(::Type{<:Wagner}, ::Type{LiftingLineSection}) = Linear()
coupling_state_jacobian_type(::Type{<:Wagner}, ::Type{LiftingLineSection}) = Nonlinear()
coupling_parameter_jacobian_type(::Type{<:Wagner}, ::Type{LiftingLineSection}) = Nonlinear()
coupling_time_gradient_type(::Type{<:Wagner}, ::Type{LiftingLineSection}) = Zeros()

# --- Methods --- #

function get_coupling_inputs(aero::Wagner, stru::LiftingLineSection, dx, x, p, t)
    # extract rate variables
    dλ1, dλ2, dvx, dvy, dvz, dωx, dωy, dωz = dx
    # extract state variables
    λ1, λ2, vx, vy, vz, ωx, ωy, ωz = x
    # extract parameters
    a, b, a0, α0, cd0, cm0, ρ = p
    # extract model constants
    C1 = aero.C1
    C2 = aero.C2
    # freestream velocity components
    u, v, ω = liftingline_velocities(vx, vz, ωy)
    udot, vdot, ωdot = liftingline_accelerations(dvx, dvz, dωy)
    # aerodynamic loads
    N, A, M = wagner_loads(a, b, ρ, a0, α0, cd0, cm0, C1, C2, u, v, ω, vdot, ωdot, λ1, λ2)
    # forces and moments per unit span
    f = SVector(A, 0, N)
    m = SVector(0, M, 0)
    # return portion of inputs that is not dependent on the state rates
    return vcat(u, v, ω, f, m)
end

# --- Performance Overloads --- #

# TODO: State rate, state, and parameter jacobians

# --- Convenience Methods --- #

function set_additional_parameters!(padd, aero::Wagner, stru::LiftingLineSection; rho)

    padd[1] = rho

    return padd
end

function separate_additional_parameters(aero::Wagner, stru::LiftingLineSection, padd)

    return (rho = padd[1],)
end


text:
import StringUtils

function main()
    if length(ARGS) > 0
        filename = ARGS[1]
        a = readlines(filename)
        m = StringUtils.grid_to_matrix(a)
        l = length(m)
        for row in 2:l
            ncols = length(m[row])
            for col in 1:ncols
                left = col == 1 ? 0 : m[row-1][col-1]
                right = col == ncols ? 0 : m[row-1][col]
                m[row][col] += max(left, right)
            end
        end
        @printf("The maximum total has value %d\n",maximum(m[l]))
    else
        error("this program needs a single numeric argument")
    end
end

main()


text:
using DynamicEnergyBudgets, Unitful, Test
using DynamicEnergyBudgets: non_growth_flux

@testset "Half saturation curve" begin
    mx = 10.0
    half = 5.0
    x = 5.0
    @test half_saturation(mx, half, x) == 5.0

    # Maximum
    x = 100000000000000000000000000.0
    @test half_saturation(mx, half, x) == 10.0

    # Minimum
    x = 0.0
    @test half_saturation(mx, half, x) == 0.0
end

@testset "Flux" begin
    (a, b, c) = non_growth_flux.((0.1,0.2,0.3), (0.2,0.3,0.4), 0.1)
    @test a ≈ 0.01
    @test b ≈ 0.04
    @test c ≈ 0.09
end

@testset "Rate" begin
    j_E_mai    = 0.003
    y_E_CH_NO  = 1.0/1.5
    y_E_EN     = 1.0/0.7
    y_V_E      = 0.7
    kap_soma   = 0.6
    r          = 0.001
    reserve    = (1.0, 1.0, 1.0)
    turnover   = ((0.2, 0.2, 0.2) .* 0.05)
    su = ParallelComplementarySU()

    # rate_formula(r, su, rel_reserve::NTuple{3}, turnover::NTuple{3}, j_E_mai, y_E_Ea, y_E_Eb, y_V_E, κsoma) = begin
    rf = rate_formula(r, su, reserve, turnover, j_E_mai, y_E_CH_NO, y_E_EN, y_V_E, kap_soma)

    @test rf == 0.002874195250659631

    @testset "test rate with units" begin
        j_E_mai   = 0.003u"mol/mol*d^-1"
        turnover = ((0.2u"mol/mol*d^-1", 0.2u"mol/mol*d^-1", 0.2u"mol/mol*d^-1") .* 0.05)
        mass = (1.0u"mol/mol", 1.0u"mol/mol", 1.0u"mol/mol")
        r = 0.001u"mol/mol*d^-1"
        @test_nowarn non_growth_flux.(mass, turnover, r)
        rf = rate_formula(r, su, reserve, turnover, j_E_mai, y_E_CH_NO, y_E_EN, y_V_E, kap_soma)
        @test rf == 0.002874195250659631u"mol/mol*d^-1"
    end

end

nothing


text:
@testset "marking missings in image" begin
    for i in 1:10
        x = rand(1:30)
        y = rand(1:30)
        image = rand(1:10.0, x, y)
        clouds = rand(0:5, x, y)
        @test size(mark_missing(image, clouds)) == size(image)
    end
end

@testset "marking missings in datacube" begin
    for i in 1:10
        x = rand(1:30)
        y = rand(1:30)
        z = rand(1:30)
        datacube = rand(1:10.0, x, y, z)
        clouds = rand(0:5, x, y, z)
        @test size(mark_missing(datacube, clouds)) == size(datacube)
    end
end


text:
"""
    BIDSDataset

"""
 struct BIDSDataset
    "`name`: Name of the dataset (required)"
    name::String
    "`BIDSVersion`: The version of the BIDS standard that was used. (required)"
    BIDSVersion::VersionNumber
    "`License`: What license is this dataset distributed under? (recommended)"
    license::String
    "`authors`: List of individuals who contributed to the creation/curation of the dataset (optional)."
    authors::Vector{String}
    "`acknowledgements`: Text acknowledging contributions of individuals or institutions beyond those listed in Authors or Funding (optional)."
    acknowledgements::String
    "`howtoacknowledge`: Instructions how researchers using this dataset should acknowledge the original authors. This field can also be used to define a publication that should be cited in publications that use the dataset (optional)."
    howtoacknowledge::String
    "`funding`: List of sources of funding (grant numbers) (optional)"
    funding::String
    "`referencesandlinks`: List of references to publication that contain information on the dataset, or links (optional)."
    referencesandlinks::Vector{String}
    "`datasetdoi`:The Document Object Identifier of the dataset (not the corresponding paper) (optional)."
    datasetdoi::String
end


text:
module FakePackageNoReTest
using Test

@testset "FakePackageNoReTest" begin
    @test true
end
end

max_issues_repo_name: rfourquet/InlineTest

max_forks_repo_name: rfourquet/InlineTest


text:
using WeavePynb
using Mustache

mmd(fname) = mmd_to_html(fname, BRAND_HREF="../toc.html", BRAND_NAME="Calculus with Julia")


text:
"""
    Kucoin.place_limit_order(api_data[; <keyword arguments>]) -> JSON3.Object

Place a limit order. See Kucoin official [docs](https://docs.kucoin.com/#place-a-new-order)
for more details.

# Arguments
- `api_data::UserApiData`: holds user API data susch as api key, secret, passphrase, etc.

# Keywords
- `price::String`: price per base currency in quote cuurency
- `size::String`: amount of base currency to buy or sell
- `time_in_force::String`: [Optional] `"GTC"`, `"GTT"`, `"IOC"`, or `"FOK"` (default is
`"GTC"`), read [Time In Force](https://docs.kucoin.com/#time-in-force)
- `cancel_after::Int64`: [Optional] cancel after `n` seconds, requires `time_in_force` to
be `"GTT"`
- `post_only::Bool`: [Optional] post only flag, invalid when `time_in_force` is
`"IOC"` or `"FOK"`, read [Post Only](https://docs.kucoin.com/#post-only)
- `hidden::Bool`: [Optional] order will not be displayed in the order book
- `iceberg::Bool`: [Optional] only aportion of the order is displayed in the order book
- `visible_size::String`: [Optional] the maximum visible size of an iceberg order
- `client_order_id::String`: unique order id created by users to identify their orders,
e.g. UUID
- `side::String`: `"buy"` or `"sell"`
- `symbol::String`: a valid trading symbol code. e.g. `"ETH-BTC"`
- `remark::String`: [Optional] remark for the order, length cannot exceed 100 utf-8
characters
- `stp::String`: [Optional] self trade prevention, valid values: `"CN"`, `"CO"`, `"CB"`
or `"DC"`, read [Self-Trade Prevention](https://docs.kucoin.com/#self-trade-prevention)
- `trade_type::String`: [Optional] the type of trading `TRADE` (Spot Trade), `MARGIN_TRADE`
(Margin Trade). Default is `TRADE`

# Returns
- `JSON3.Object`
```json
{
  "orderId": "5bd6e9286d99522a52e458de"
}
```
"""
function place_limit_order(
    api_data::ApiData;
    price::String,
    size::String,
    time_in_force::Union{String,Nothing}=nothing,
    cancel_after::Union{Int64,Nothing}=nothing,
    post_only::Union{Bool,Nothing}=nothing,
    hidden::Union{Bool,Nothing}=nothing,
    iceberg::Union{Bool,Nothing}=nothing,
    visible_size::Union{String,Nothing}=nothing,
    client_order_id::String,
    side::String,
    symbol::String,
    remark::Union{String,Nothing}=nothing,
    stp::Union{String,Nothing}=nothing,
    trade_type::Union{String,Nothing}=nothing,
)::JSON3.Object
    return _handle(
        _kucoin_request(
            api_data,
            _HTTP_METHOD_POST,
            "/api/v1/orders";
            price=price,
            size=size,
            timeInForce=time_in_force,
            cancelAfter=cancel_after,
            postOnly=post_only,
            hidden=hidden,
            iceberg=iceberg,
            visibleSize=visible_size,
            clientOid=client_order_id,
            side=side,
            symbol=symbol,
            type="limit",
            remark=remark,
            stp=stp,
            tradeType=trade_type,
        ),
    )
end

"""
    Kucoin.place_market_order(api_data[; <keyword arguments>]]) -> JSON3.Object

Place a market order. See Kucoin official [docs](https://docs.kucoin.com/#place-a-new-order)
 for more details.

# Arguments
- `api_data::UserApiData`: holds user API data susch as api key, secret, passphrase, etc.

# Keywords
- `size::String`: [Optional] desired amount in base currency. It is required that you use
one of the two parameters, `size` or `funds`.
- `funds::String`: [Optional] the desired amount of quote currency to use. It is required
that you use one of the two parameters, `size` or `funds`.
- `client_order_id::String`: unique order id created by users to identify their orders,
e.g. UUID
- `side::String`: `"buy"` or `"sell"`
- `symbol::String`: a valid trading symbol code. e.g. `"ETH-BTC"`
- `remark::String`: [Optional] remark for the order, length cannot exceed 100 utf-8
characters
- `stp::String`: [Optional] self trade prevention, valid values: `"CN"`, `"CO"`, `"CB"`
or `"DC"`, read [Self-Trade Prevention](https://docs.kucoin.com/#self-trade-prevention)

# Returns
- `JSON3.Object`
```json
{
  "orderId": "5bd6e9286d99522a52e458de"
}
```
"""
function place_market_order(
    api_data::ApiData;
    size::Union{String,Nothing}=nothing,
    funds::Union{String,Nothing}=nothing,
    client_order_id::String,
    side::String,
    symbol::String,
    remark::Union{String,Nothing}=nothing,
    stp::Union{String,Nothing}=nothing,
)::JSON3.Object
    return _handle(
        _kucoin_request(
            api_data,
            _HTTP_METHOD_POST,
            "/api/v1/orders";
            size=size,
            funds=funds,
            clientOid=client_order_id,
            side=side,
            symbol=symbol,
            type="market",
            remark=remark,
            stp=stp,
        ),
    )
end

"""
    Kucoin.cancel_all_orders(api_data[; symbol[, trade_type]]]) -> Union{JSON3.Array{String},JSON3.Array{Union{}}}

Cancel all open orders. See Kucoin official
[docs](https://docs.kucoin.com/#cancel-all-orders) for more details.

# Arguments
- `api_data::UserApiData`: holds user API data susch as api key, secret, passphrase, etc.

# Keywords
- `symbol::String`: [Optional] a valid symbol code for the trading pair
- `trade_type::String`: [Optional] the type of trading, cancel the orders for the specified
trading type, and the default is to cancel the spot trading order (`TRADE`)

# Returns
- `Union{JSON3.Array{String},JSON3.Array{Union{}}}`: a list of ids of the canceled orders
```json
[
  "5c52e11203aa677f33e493fb",  //orderId
  "5c52e12103aa677f33e493fe",
  "5c52e12a03aa677f33e49401",
  "5c626b0803aa676fee8412a2"
]
```
"""
function cancel_all_orders(
    api_data::ApiData;
    symbol::Union{String,Nothing}=nothing,
    trade_type::Union{String,Nothing}=nothing,
)::Union{JSON3.Array{String},JSON3.Array{Union{}}}
    return _handle(
        _kucoin_request(
            api_data,
            _HTTP_METHOD_DELETE,
            "/api/v1/orders";
            symbol=symbol,
            tradeType=trade_type,
        ),
    )["cancelledOrderIds"]
end


text:
# This file is auto-generated by AWSMetadata.jl
using AWS
using AWS.AWSServices: honeycode
using AWS.Compat
using AWS.UUIDs

"""
    batch_create_table_rows(rows_to_create, table_id, workbook_id)
    batch_create_table_rows(rows_to_create, table_id, workbook_id, params::Dict{String,<:Any})

 The BatchCreateTableRows API allows you to create one or more rows at the end of a table
in a workbook. The API allows you to specify the values to set in some or all of the
columns in the new rows.   If a column is not explicitly set in a specific row, then the
column level formula specified in the table will be applied to the new row. If there is no
column level formula but the last row of the table has a formula, then that formula will be
copied down to the new row. If there is no column level formula and no formula in the last
row of the table, then that column will be left blank for the new rows.

# Arguments
- `rows_to_create`:  The list of rows to create at the end of the table. Each item in this
  list needs to have a batch item id to uniquely identify the element in the request and the
  cells to create for that row. You need to specify at least one item in this list.   Note
  that if one of the column ids in any of the rows in the request does not exist in the
  table, then the request fails and no updates are made to the table.
- `table_id`: The ID of the table where the new rows are being added.  If a table with the
  specified ID could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook where the new rows are being added.  If a workbook
  with the specified ID could not be found, this API throws ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"clientRequestToken"`:  The request token for performing the batch create operation.
  Request tokens help to identify duplicate requests. If a call times out or fails due to a
  transient error like a failed network connection, you can retry the call with the same
  request token. The service ensures that if the first call using that request token is
  successfully performed, the second call will not perform the operation again.   Note that
  request tokens are valid only for a few minutes. You cannot use request tokens to dedupe
  requests spanning hours or days.
"""
batch_create_table_rows(rowsToCreate, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchcreate", Dict{String, Any}("rowsToCreate"=>rowsToCreate); aws_config=aws_config)
batch_create_table_rows(rowsToCreate, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchcreate", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("rowsToCreate"=>rowsToCreate), params)); aws_config=aws_config)

"""
    batch_delete_table_rows(row_ids, table_id, workbook_id)
    batch_delete_table_rows(row_ids, table_id, workbook_id, params::Dict{String,<:Any})

 The BatchDeleteTableRows API allows you to delete one or more rows from a table in a
workbook. You need to specify the ids of the rows that you want to delete from the table.

# Arguments
- `row_ids`:  The list of row ids to delete from the table. You need to specify at least
  one row id in this list.   Note that if one of the row ids provided in the request does not
  exist in the table, then the request fails and no rows are deleted from the table.
- `table_id`: The ID of the table where the rows are being deleted.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook where the rows are being deleted.  If a workbook
  with the specified id could not be found, this API throws ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"clientRequestToken"`:  The request token for performing the delete action. Request
  tokens help to identify duplicate requests. If a call times out or fails due to a transient
  error like a failed network connection, you can retry the call with the same request token.
  The service ensures that if the first call using that request token is successfully
  performed, the second call will not perform the action again.   Note that request tokens
  are valid only for a few minutes. You cannot use request tokens to dedupe requests spanning
  hours or days.
"""
batch_delete_table_rows(rowIds, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchdelete", Dict{String, Any}("rowIds"=>rowIds); aws_config=aws_config)
batch_delete_table_rows(rowIds, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchdelete", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("rowIds"=>rowIds), params)); aws_config=aws_config)

"""
    batch_update_table_rows(rows_to_update, table_id, workbook_id)
    batch_update_table_rows(rows_to_update, table_id, workbook_id, params::Dict{String,<:Any})

 The BatchUpdateTableRows API allows you to update one or more rows in a table in a
workbook.   You can specify the values to set in some or all of the columns in the table
for the specified rows. If a column is not explicitly specified in a particular row, then
that column will not be updated for that row. To clear out the data in a specific cell, you
need to set the value as an empty string (\"\").

# Arguments
- `rows_to_update`:  The list of rows to update in the table. Each item in this list needs
  to contain the row id to update along with the map of column id to cell values for each
  column in that row that needs to be updated. You need to specify at least one row in this
  list, and for each row, you need to specify at least one column to update.   Note that if
  one of the row or column ids in the request does not exist in the table, then the request
  fails and no updates are made to the table.
- `table_id`: The ID of the table where the rows are being updated.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook where the rows are being updated.  If a workbook
  with the specified id could not be found, this API throws ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"clientRequestToken"`:  The request token for performing the update action. Request
  tokens help to identify duplicate requests. If a call times out or fails due to a transient
  error like a failed network connection, you can retry the call with the same request token.
  The service ensures that if the first call using that request token is successfully
  performed, the second call will not perform the action again.   Note that request tokens
  are valid only for a few minutes. You cannot use request tokens to dedupe requests spanning
  hours or days.
"""
batch_update_table_rows(rowsToUpdate, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchupdate", Dict{String, Any}("rowsToUpdate"=>rowsToUpdate); aws_config=aws_config)
batch_update_table_rows(rowsToUpdate, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchupdate", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("rowsToUpdate"=>rowsToUpdate), params)); aws_config=aws_config)

"""
    batch_upsert_table_rows(rows_to_upsert, table_id, workbook_id)
    batch_upsert_table_rows(rows_to_upsert, table_id, workbook_id, params::Dict{String,<:Any})

 The BatchUpsertTableRows API allows you to upsert one or more rows in a table. The upsert
operation takes a filter expression as input and evaluates it to find matching rows on the
destination table. If matching rows are found, it will update the cells in the matching
rows to new values specified in the request. If no matching rows are found, a new row is
added at the end of the table and the cells in that row are set to the new values specified
in the request.   You can specify the values to set in some or all of the columns in the
table for the matching or newly appended rows. If a column is not explicitly specified for
a particular row, then that column will not be updated for that row. To clear out the data
in a specific cell, you need to set the value as an empty string (\"\").

# Arguments
- `rows_to_upsert`:  The list of rows to upsert in the table. Each item in this list needs
  to have a batch item id to uniquely identify the element in the request, a filter
  expression to find the rows to update for that element and the cell values to set for each
  column in the upserted rows. You need to specify at least one item in this list.   Note
  that if one of the filter formulas in the request fails to evaluate because of an error or
  one of the column ids in any of the rows does not exist in the table, then the request
  fails and no updates are made to the table.
- `table_id`: The ID of the table where the rows are being upserted.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook where the rows are being upserted.  If a workbook
  with the specified id could not be found, this API throws ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"clientRequestToken"`:  The request token for performing the update action. Request
  tokens help to identify duplicate requests. If a call times out or fails due to a transient
  error like a failed network connection, you can retry the call with the same request token.
  The service ensures that if the first call using that request token is successfully
  performed, the second call will not perform the action again.   Note that request tokens
  are valid only for a few minutes. You cannot use request tokens to dedupe requests spanning
  hours or days.
"""
batch_upsert_table_rows(rowsToUpsert, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchupsert", Dict{String, Any}("rowsToUpsert"=>rowsToUpsert); aws_config=aws_config)
batch_upsert_table_rows(rowsToUpsert, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/batchupsert", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("rowsToUpsert"=>rowsToUpsert), params)); aws_config=aws_config)

"""
    describe_table_data_import_job(job_id, table_id, workbook_id)
    describe_table_data_import_job(job_id, table_id, workbook_id, params::Dict{String,<:Any})

 The DescribeTableDataImportJob API allows you to retrieve the status and details of a
table data import job.

# Arguments
- `job_id`: The ID of the job that was returned by the StartTableDataImportJob request.  If
  a job with the specified id could not be found, this API throws ResourceNotFoundException.
- `table_id`: The ID of the table into which data was imported.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook into which data was imported.  If a workbook with
  the specified id could not be found, this API throws ResourceNotFoundException.

"""
describe_table_data_import_job(jobId, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("GET", "/workbooks/$(workbookId)/tables/$(tableId)/import/$(jobId)"; aws_config=aws_config)
describe_table_data_import_job(jobId, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("GET", "/workbooks/$(workbookId)/tables/$(tableId)/import/$(jobId)", params; aws_config=aws_config)

"""
    get_screen_data(app_id, screen_id, workbook_id)
    get_screen_data(app_id, screen_id, workbook_id, params::Dict{String,<:Any})

 The GetScreenData API allows retrieval of data from a screen in a Honeycode app. The API
allows setting local variables in the screen to filter, sort or otherwise affect what will
be displayed on the screen.

# Arguments
- `app_id`: The ID of the app that contains the screem.
- `screen_id`: The ID of the screen.
- `workbook_id`: The ID of the workbook that contains the screen.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"maxResults"`:  The number of results to be returned on a single page. Specify a number
  between 1 and 100. The maximum value is 100.   This parameter is optional. If you don't
  specify this parameter, the default page size is 100.
- `"nextToken"`:  This parameter is optional. If a nextToken is not specified, the API
  returns the first page of data.   Pagination tokens expire after 1 hour. If you use a token
  that was returned more than an hour back, the API will throw ValidationException.
- `"variables"`:  Variables are optional and are needed only if the screen requires them to
  render correctly. Variables are specified as a map where the key is the name of the
  variable as defined on the screen. The value is an object which currently has only one
  property, rawValue, which holds the value of the variable to be passed to the screen.
"""
get_screen_data(appId, screenId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/screendata", Dict{String, Any}("appId"=>appId, "screenId"=>screenId, "workbookId"=>workbookId); aws_config=aws_config)
get_screen_data(appId, screenId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/screendata", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("appId"=>appId, "screenId"=>screenId, "workbookId"=>workbookId), params)); aws_config=aws_config)

"""
    invoke_screen_automation(app_id, automation_id, screen_id, workbook_id)
    invoke_screen_automation(app_id, automation_id, screen_id, workbook_id, params::Dict{String,<:Any})

 The InvokeScreenAutomation API allows invoking an action defined in a screen in a
Honeycode app. The API allows setting local variables, which can then be used in the
automation being invoked. This allows automating the Honeycode app interactions to write,
update or delete data in the workbook.

# Arguments
- `app_id`: The ID of the app that contains the screen automation.
- `automation_id`: The ID of the automation action to be performed.
- `screen_id`: The ID of the screen that contains the screen automation.
- `workbook_id`: The ID of the workbook that contains the screen automation.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"clientRequestToken"`:  The request token for performing the automation action. Request
  tokens help to identify duplicate requests. If a call times out or fails due to a transient
  error like a failed network connection, you can retry the call with the same request token.
  The service ensures that if the first call using that request token is successfully
  performed, the second call will return the response of the previous call rather than
  performing the action again.   Note that request tokens are valid only for a few minutes.
  You cannot use request tokens to dedupe requests spanning hours or days.
- `"rowId"`:  The row ID for the automation if the automation is defined inside a block
  with source or list.
- `"variables"`:  Variables are specified as a map where the key is the name of the
  variable as defined on the screen. The value is an object which currently has only one
  property, rawValue, which holds the value of the variable to be passed to the screen. Any
  variables defined in a screen are required to be passed in the call.
"""
invoke_screen_automation(appId, automationId, screenId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/apps/$(appId)/screens/$(screenId)/automations/$(automationId)"; aws_config=aws_config)
invoke_screen_automation(appId, automationId, screenId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/apps/$(appId)/screens/$(screenId)/automations/$(automationId)", params; aws_config=aws_config)

"""
    list_table_columns(table_id, workbook_id)
    list_table_columns(table_id, workbook_id, params::Dict{String,<:Any})

 The ListTableColumns API allows you to retrieve a list of all the columns in a table in a
workbook.

# Arguments
- `table_id`: The ID of the table whose columns are being retrieved.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook that contains the table whose columns are being
  retrieved.  If a workbook with the specified id could not be found, this API throws
  ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"nextToken"`:  This parameter is optional. If a nextToken is not specified, the API
  returns the first page of data.   Pagination tokens expire after 1 hour. If you use a token
  that was returned more than an hour back, the API will throw ValidationException.
"""
list_table_columns(tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("GET", "/workbooks/$(workbookId)/tables/$(tableId)/columns"; aws_config=aws_config)
list_table_columns(tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("GET", "/workbooks/$(workbookId)/tables/$(tableId)/columns", params; aws_config=aws_config)

"""
    list_table_rows(table_id, workbook_id)
    list_table_rows(table_id, workbook_id, params::Dict{String,<:Any})

 The ListTableRows API allows you to retrieve a list of all the rows in a table in a
workbook.

# Arguments
- `table_id`: The ID of the table whose rows are being retrieved.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook that contains the table whose rows are being
  retrieved.  If a workbook with the specified id could not be found, this API throws
  ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"maxResults"`: The maximum number of rows to return in each page of the results.
- `"nextToken"`:  This parameter is optional. If a nextToken is not specified, the API
  returns the first page of data.   Pagination tokens expire after 1 hour. If you use a token
  that was returned more than an hour back, the API will throw ValidationException.
- `"rowIds"`:  This parameter is optional. If one or more row ids are specified in this
  list, then only the specified row ids are returned in the result. If no row ids are
  specified here, then all the rows in the table are returned.
"""
list_table_rows(tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/list"; aws_config=aws_config)
list_table_rows(tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/list", params; aws_config=aws_config)

"""
    list_tables(workbook_id)
    list_tables(workbook_id, params::Dict{String,<:Any})

 The ListTables API allows you to retrieve a list of all the tables in a workbook.

# Arguments
- `workbook_id`: The ID of the workbook whose tables are being retrieved.  If a workbook
  with the specified id could not be found, this API throws ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"maxResults"`: The maximum number of tables to return in each page of the results.
- `"nextToken"`:  This parameter is optional. If a nextToken is not specified, the API
  returns the first page of data.   Pagination tokens expire after 1 hour. If you use a token
  that was returned more than an hour back, the API will throw ValidationException.
"""
list_tables(workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("GET", "/workbooks/$(workbookId)/tables"; aws_config=aws_config)
list_tables(workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("GET", "/workbooks/$(workbookId)/tables", params; aws_config=aws_config)

"""
    query_table_rows(filter_formula, table_id, workbook_id)
    query_table_rows(filter_formula, table_id, workbook_id, params::Dict{String,<:Any})

 The QueryTableRows API allows you to use a filter formula to query for specific rows in a
table.

# Arguments
- `filter_formula`: An object that represents a filter formula along with the id of the
  context row under which the filter function needs to evaluate.
- `table_id`: The ID of the table whose rows are being queried.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook whose table rows are being queried.  If a workbook
  with the specified id could not be found, this API throws ResourceNotFoundException.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"maxResults"`: The maximum number of rows to return in each page of the results.
- `"nextToken"`:  This parameter is optional. If a nextToken is not specified, the API
  returns the first page of data.   Pagination tokens expire after 1 hour. If you use a token
  that was returned more than an hour back, the API will throw ValidationException.
"""
query_table_rows(filterFormula, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/query", Dict{String, Any}("filterFormula"=>filterFormula); aws_config=aws_config)
query_table_rows(filterFormula, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/rows/query", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("filterFormula"=>filterFormula), params)); aws_config=aws_config)

"""
    start_table_data_import_job(client_request_token, data_format, data_source, import_options, table_id, workbook_id)
    start_table_data_import_job(client_request_token, data_format, data_source, import_options, table_id, workbook_id, params::Dict{String,<:Any})

 The StartTableDataImportJob API allows you to start an import job on a table. This API
will only return the id of the job that was started. To find out the status of the import
request, you need to call the DescribeTableDataImportJob API.

# Arguments
- `client_request_token`:  The request token for performing the update action. Request
  tokens help to identify duplicate requests. If a call times out or fails due to a transient
  error like a failed network connection, you can retry the call with the same request token.
  The service ensures that if the first call using that request token is successfully
  performed, the second call will not perform the action again.   Note that request tokens
  are valid only for a few minutes. You cannot use request tokens to dedupe requests spanning
  hours or days.
- `data_format`:  The format of the data that is being imported. Currently the only option
  supported is \"DELIMITED_TEXT\".
- `data_source`:  The source of the data that is being imported. The size of source must be
  no larger than 100 MB. Source must have no more than 100,000 cells and no more than 1,000
  rows.
- `import_options`:  The options for customizing this import request.
- `table_id`: The ID of the table where the rows are being imported.  If a table with the
  specified id could not be found, this API throws ResourceNotFoundException.
- `workbook_id`: The ID of the workbook where the rows are being imported.  If a workbook
  with the specified id could not be found, this API throws ResourceNotFoundException.

"""
start_table_data_import_job(clientRequestToken, dataFormat, dataSource, importOptions, tableId, workbookId; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/import", Dict{String, Any}("clientRequestToken"=>clientRequestToken, "dataFormat"=>dataFormat, "dataSource"=>dataSource, "importOptions"=>importOptions); aws_config=aws_config)
start_table_data_import_job(clientRequestToken, dataFormat, dataSource, importOptions, tableId, workbookId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = honeycode("POST", "/workbooks/$(workbookId)/tables/$(tableId)/import", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("clientRequestToken"=>clientRequestToken, "dataFormat"=>dataFormat, "dataSource"=>dataSource, "importOptions"=>importOptions), params)); aws_config=aws_config)


text:
#
# Hybrid A* path planning for trailer
#
# author: Atsushi Sakai(@Atsushi_twi)
#

module trailer_hybrid_a_star

using PyPlot
using DataFrames
using NearestNeighbors
using DataStructures

include("rs_path.jl")
include("grid_a_star.jl")
include("trailerlib.jl")

const XY_GRID_RESOLUTION = 2.0 #[m]
const YAW_GRID_RESOLUTION = deg2rad(15.0) #[rad]
const GOAL_TYAW_TH = deg2rad(5.0) #[rad]
const MOTION_RESOLUTION = 0.1 #[m] path interporate resolution
const N_STEER = 20.0 # number of steer command
const EXTEND_AREA= 5.0 #[m] map extend length
const SKIP_COLLISION_CHECK= 4 # skip number for collision check

const SB_COST = 100.0 # switch back penalty cost
const BACK_COST = 5.0 # backward penalty cost
const STEER_CHANGE_COST = 5.0 # steer angle change penalty cost
const STEER_COST = 1.0 # steer angle change penalty cost
const JACKKNIF_COST= 200.0 # Jackknif cost
const H_COST = 5.0 # Heuristic cost

const WB = trailerlib.WB #[m] Wheel base
const LT = trailerlib.LT #[m] length of trailer
const MAX_STEER = trailerlib.MAX_STEER #[rad] maximum steering angle

struct Node
    xind::Int64 #x index
    yind::Int64 #y index
    yawind::Int64 #yaw index
    direction::Bool # moving direction forword:true, backword:false
    x::Array{Float64} # x position [m]
    y::Array{Float64} # y position [m]
    yaw::Array{Float64} # yaw angle [rad]
    yaw1::Array{Float64} # trailer yaw angle [rad]
    directions::Array{Bool} # directions of each points forward: true, backward:false
    steer::Float64 # steer input
    cost::Float64 # cost
    pind::Int64 # parent index
end

struct Config # config struct for hybrid A* DB
    minx::Int64
    miny::Int64
    minyaw::Int64
    minyawt::Int64
    maxx::Int64
    maxy::Int64
    maxyaw::Int64
    maxyawt::Int64
    xw::Int64
    yw::Int64
    yaww::Int64
    yawtw::Int64
    xyreso::Float64
    yawreso::Float64
end

mutable struct Path
    x::Array{Float64} # x position [m]
    y::Array{Float64} # y position [m]
    yaw::Array{Float64} # yaw angle [rad]
    yaw1::Array{Float64} # trailer angle [rad]
    direction::Array{Bool} # direction forward: true, back false
    cost::Float64 # cost
end

function calc_hybrid_astar_path(sx::Float64, sy::Float64, syaw::Float64, syaw1::Float64,
                                gx::Float64, gy::Float64, gyaw::Float64, gyaw1::Float64,
                                ox::Array{Float64}, oy::Array{Float64},
                                xyreso::Float64, yawreso::Float64,
                                )
    """
    sx: start x position [m]
    sy: start y position [m]
    gx: goal x position [m]
    gx: goal x position [m]
    ox: x position list of Obstacles [m]
    oy: y position list of Obstacles [m]
    xyreso: grid resolution [m]
    yawreso: yaw angle resolution [rad]
    """

    syaw, gyaw = rs_path.pi_2_pi(syaw), rs_path.pi_2_pi(gyaw)
    ox, oy = ox[:], oy[:]

    kdtree = KDTree(hcat(ox, oy)')

    const c = calc_config(ox, oy, xyreso, yawreso)
    nstart = Node(round(Int64,sx/xyreso), round(Int64,sy/xyreso), round(Int64, syaw/yawreso),true,[sx],[sy],[syaw],[syaw1],[true],0.0,0.0, -1)
    ngoal = Node(round(Int64,gx/xyreso), round(Int64,gy/xyreso), round(Int64,gyaw/yawreso),true,[gx],[gy],[gyaw],[gyaw1],[true],0.0,0.0, -1)

    h_dp = calc_holonomic_with_obstacle_heuristic(ngoal, ox, oy, xyreso)

    open, closed = Dict{Int64, Node}(), Dict{Int64, Node}()
    fnode = nothing
    open[calc_index(nstart, c)] = nstart
    pq = PriorityQueue{Int64,Float64}()
    enqueue!(pq, calc_index(nstart, c), calc_cost(nstart, h_dp, ngoal, c))

    u, d = calc_motion_inputs()
    nmotion = length(u)

    while true
        if length(open) == 0
            println("Error: Cannot find path, No open set")
            return []
        end

        c_id = dequeue!(pq)
        current = open[c_id]

        #move current node from open to closed
        delete!(open, c_id)
        closed[c_id] = current

        isupdated, fpath = update_node_with_analystic_expantion(current, ngoal, c, ox, oy, kdtree, gyaw1)
        if isupdated # found
            fnode = fpath
            break
        end

        inityaw1 = current.yaw1[1]

        for i in 1:nmotion
            node = calc_next_node(current, c_id, u[i], d[i], c)

            if !verify_index(node, c, ox, oy, inityaw1, kdtree) continue end

            node_ind = calc_index(node, c)

            # If it is already in the closed set, skip it
            if haskey(closed, node_ind)  continue end

            if !haskey(open, node_ind)
                open[node_ind] = node
                enqueue!(pq, node_ind, calc_cost(node, h_dp, ngoal, c))
            else
                if open[node_ind].cost > node.cost
                    # If so, update the node to have a new parent
                    open[node_ind] = node
                end
            end
        end
    end

    println("final expand node:", length(open) + length(closed))

    path = get_final_path(closed, fnode, nstart, c)

    return path
end

function update_node_with_analystic_expantion(current::Node,
                                             ngoal::Node,
                                             c::Config,
                                             ox,
                                             oy,
                                             kdtree,
                                             gyaw1::Float64
                                            )

    apath = analystic_expantion(current, ngoal, c, ox, oy, kdtree)
    if apath != nothing
        fx = apath.x[2:end]
        fy = apath.y[2:end]
        fyaw =  apath.yaw[2:end]
        steps = MOTION_RESOLUTION*apath.directions
        yaw1 = trailerlib.calc_trailer_yaw_from_xyyaw(apath.x, apath.y, apath.yaw, current.yaw1[end], steps)
        if abs(rs_path.pi_2_pi(yaw1[end] - gyaw1)) >= GOAL_TYAW_TH
            return false, nothing #no update
        end
        fcost = current.cost + calc_rs_path_cost(apath, yaw1)
        fyaw1 = yaw1[2:end]
        fpind = calc_index(current, c)

        fd = Bool[]
        for d in apath.directions[2:end]
            if d >= 0
                push!(fd, true)
            else
                push!(fd, false)
            end
        end

        fsteer = 0.0

        fpath = Node(current.xind, current.yind, current.yawind, current.direction, fx, fy, fyaw, fyaw1, fd, fsteer, fcost, fpind)

        return true, fpath
    end

    return false, nothing #no update
end

function calc_rs_path_cost(rspath::rs_path.Path, yaw1)

    cost = 0.0
    for l in rspath.lengths
        if l >= 0 # forward
            cost += l
        else # back
            cost += abs(l) * BACK_COST
        end
    end

    # swich back penalty
    for i in 1:length(rspath.lengths) - 1
        if rspath.lengths[i] * rspath.lengths[i+1] < 0.0 # switch back
            cost += SB_COST
        end
    end

    # steer penalyty
    for ctype in rspath.ctypes
        if ctype != "S" # curve
            cost += STEER_COST*abs(MAX_STEER)
        end
    end

    # ==steer change penalty
    # calc steer profile
    nctypes = length(rspath.ctypes)
    ulist = fill(0.0, nctypes)
    for i in 1:nctypes
        if rspath.ctypes[i] == "R"
            ulist[i] = - MAX_STEER
        elseif rspath.ctypes[i] == "L"
            ulist[i] = MAX_STEER
        end
    end

    for i in 1:length(rspath.ctypes) - 1
        cost += STEER_CHANGE_COST*abs(ulist[i+1] - ulist[i])
    end

    cost += JACKKNIF_COST * sum(abs.(rs_path.pi_2_pi.(rspath.yaw-yaw1)))

    return cost
end

function analystic_expantion(n::Node, ngoal::Node, c::Config, ox, oy, kdtree)

    sx = n.x[end]
    sy = n.y[end]
    syaw = n.yaw[end]

    max_curvature = tan(MAX_STEER)/WB
    paths = rs_path.calc_paths(sx,sy,syaw,ngoal.x[end], ngoal.y[end], ngoal.yaw[end],
                                   max_curvature, step_size=MOTION_RESOLUTION)

    if length(paths) == 0
        return nothing
    end

    pathqueue = PriorityQueue{rs_path.Path, Float64}()
    for path in paths
        steps = MOTION_RESOLUTION*path.directions
        yaw1 = trailerlib.calc_trailer_yaw_from_xyyaw(path.x, path.y, path.yaw, n.yaw1[end], steps)
        enqueue!(pathqueue, path, calc_rs_path_cost(path, yaw1))
    end

    for i in length(pathqueue)
        path = dequeue!(pathqueue)

        steps = MOTION_RESOLUTION*path.directions
        yaw1 = trailerlib.calc_trailer_yaw_from_xyyaw(path.x, path.y, path.yaw, n.yaw1[end], steps)
        ind = 1:SKIP_COLLISION_CHECK:length(path.x)
        if trailerlib.check_trailer_collision(ox, oy, path.x[ind], path.y[ind], path.yaw[ind], yaw1[ind], kdtree = kdtree)
            # plot(path.x, path.y, "-^b")
            return path # path is ok
        end
    end

    return nothing
end

function calc_motion_inputs()

    up = [i for i in MAX_STEER/N_STEER:MAX_STEER/N_STEER:MAX_STEER]
    u = vcat([0.0], [i for i in up], [-i for i in up])
    d = vcat([1.0 for i in 1:length(u)], [-1.0 for i in 1:length(u)])
    u = vcat(u,u)

    return u, d
end

function verify_index(node::Node, c::Config, ox, oy, inityaw1, kdtree)

    # overflow map
    if (node.xind - c.minx) >= c.xw
        return false
    elseif (node.xind - c.minx) <= 0
        return false
    end
    if (node.yind - c.miny) >= c.yw
        return false
    elseif (node.yind - c.miny) <= 0
        return false
    end

    # check collisiton
    steps = MOTION_RESOLUTION*node.directions
    yaw1 = trailerlib.calc_trailer_yaw_from_xyyaw(node.x, node.y, node.yaw, inityaw1, steps)
    ind = 1:SKIP_COLLISION_CHECK:length(node.x)
    if !trailerlib.check_trailer_collision(ox, oy, node.x[ind], node.y[ind], node.yaw[ind], yaw1[ind], kdtree = kdtree)
        return false
    end

    return true #index is ok"
end

function calc_next_node(current::Node, c_id::Int64,
                        u::Float64, d::Float64,
                        c::Config,
                        )

    arc_l = XY_GRID_RESOLUTION*1.5

    nlist = floor(Int64, arc_l/MOTION_RESOLUTION)+1
    xlist = fill(0.0, nlist)
    ylist = fill(0.0, nlist)
    yawlist = fill(0.0, nlist)
    yaw1list = fill(0.0, nlist)

    xlist[1] = current.x[end] + d * MOTION_RESOLUTION*cos(current.yaw[end])
    ylist[1] = current.y[end] + d * MOTION_RESOLUTION*sin(current.yaw[end])
    yawlist[1] = rs_path.pi_2_pi(current.yaw[end] + d*MOTION_RESOLUTION/WB * tan(u))
    yaw1list[1] = rs_path.pi_2_pi(current.yaw1[end] + d*MOTION_RESOLUTION/LT*sin(current.yaw[end]-current.yaw1[end]))

    for i in 1:(nlist-1)
        xlist[i+1] = xlist[i] + d * MOTION_RESOLUTION*cos(yawlist[i])
        ylist[i+1] = ylist[i] + d * MOTION_RESOLUTION*sin(yawlist[i])
        yawlist[i+1] = rs_path.pi_2_pi(yawlist[i] + d*MOTION_RESOLUTION/WB * tan(u))
        yaw1list[i+1] = rs_path.pi_2_pi(yaw1list[i] + d*MOTION_RESOLUTION/LT*sin(yawlist[i]-yaw1list[i]))
    end

    xind = round(Int64, xlist[end]/c.xyreso)
    yind = round(Int64, ylist[end]/c.xyreso)
    yawind = round(Int64, yawlist[end]/c.yawreso)

    addedcost = 0.0
    if d > 0
        direction = true
        addedcost += abs(arc_l)
    else
        direction = false
        addedcost += abs(arc_l) * BACK_COST
    end

    # swich back penalty
    if direction != current.direction # switch back penalty
        addedcost += SB_COST
    end

    # steer penalyty
    addedcost += STEER_COST*abs(u)

    # steer change penalty
    addedcost += STEER_CHANGE_COST*abs(current.steer - u)

    # jacknif cost
    addedcost += JACKKNIF_COST * sum(abs.(rs_path.pi_2_pi.(yawlist-yaw1list)))

    cost = current.cost + addedcost

    directions = [direction for i in 1:length(xlist)]
    node = Node(xind, yind, yawind, direction, xlist, ylist, yawlist, yaw1list, directions, u, cost, c_id)

    return node
end

function is_same_grid(node1::Node,node2::Node)

    if node1.xind != node2.xind
        return false
    end
    if node1.yind != node2.yind
        return false
    end
    if node1.yawind != node2.yawind
        return false
    end

    return true

end

function calc_index(node::Node, c::Config)
    ind = (node.yawind - c.minyaw)*c.xw*c.yw+(node.yind - c.miny)*c.xw + (node.xind - c.minx)

    # 4D grid
    yaw1ind = round(Int64, node.yaw1[end]/c.yawreso)
    ind += (yaw1ind - c.minyawt) *c.xw*c.yw*c.yaww

    if ind <= 0
        println("Error(calc_index):", ind)
    end
    return ind
end

function calc_holonomic_with_obstacle_heuristic(gnode::Node, ox::Array{Float64}, oy::Array{Float64}, xyreso::Float64)
    h_dp = grid_a_star.calc_dist_policy(gnode.x[end], gnode.y[end], ox, oy, xyreso, 1.0)
    return h_dp
end

function calc_config(ox::Array{Float64}, oy::Array{Float64},
                     xyreso::Float64, yawreso::Float64
                     )

    min_x_m = minimum(ox) - EXTEND_AREA
    min_y_m = minimum(oy) - EXTEND_AREA
    max_x_m = maximum(ox) + EXTEND_AREA
    max_y_m = maximum(oy) + EXTEND_AREA

    push!(ox, min_x_m)
    push!(oy, min_y_m)
    push!(ox, max_x_m)
    push!(oy, max_y_m)

    minx = round(Int64, min_x_m/xyreso)
    miny = round(Int64, min_y_m/xyreso)
    maxx = round(Int64, max_x_m/xyreso)
    maxy = round(Int64, max_y_m/xyreso)

    xw = round(Int64,(maxx - minx))
    yw = round(Int64,(maxy - miny))

    minyaw = round(Int64, - pi/yawreso) - 1
    maxyaw = round(Int64, pi/yawreso)
    yaww = round(Int64,(maxyaw - minyaw))

    minyawt = minyaw
    maxyawt = maxyaw
    yawtw = yaww

    config = Config(minx, miny, minyaw, minyawt, maxx, maxy, maxyaw, maxyawt, xw, yw, yaww, yawtw,
                    xyreso, yawreso)

    return config
end

function get_final_path(closed::Dict{Int64, Node},
                        ngoal::Node,
                        nstart::Node,
                        c::Config)

    rx, ry, ryaw = Array{Float64}(reverse(ngoal.x)),Array{Float64}(reverse(ngoal.y)),Array{Float64}(reverse(ngoal.yaw))
    ryaw1 = Array{Float64}(reverse(ngoal.yaw1))
    direction = Array{Float64}(reverse(ngoal.directions))
    nid = ngoal.pind
    finalcost = ngoal.cost

    while true
        n = closed[nid]
        rx = vcat(rx, reverse(n.x))
        ry = vcat(ry, reverse(n.y))
        ryaw = vcat(ryaw, reverse(n.yaw))
        ryaw1 = vcat(ryaw1, reverse(n.yaw1))
        direction = vcat(direction, reverse(n.directions))
        nid = n.pind
        if is_same_grid(n, nstart)
            break
        end
    end

    rx = reverse(rx)
    ry = reverse(ry)
    ryaw = reverse(ryaw)
    ryaw1 = reverse(ryaw1)
    direction = reverse(direction)

    # adjuct first direction
    direction[1] = direction[2]

    path = Path(rx, ry, ryaw, ryaw1, direction, finalcost)

    return path
end

function calc_cost(n::Node, h_dp::Array{Float64}, ngoal::Node, c::Config)

   return (n.cost + H_COST*h_dp[n.xind - c.minx, n.yind - c.miny])

end

function main()
    println(PROGRAM_FILE," start!!")

    sx = 14.0  # [m]
    sy = 10.0  # [m]
    syaw0 = deg2rad(00.0)
    syaw1 = deg2rad(00.0)

    gx = 0.0  # [m]
    gy = 0.0  # [m]
    gyaw0 = deg2rad(90.0)
    gyaw1 = deg2rad(90.0)

    ox = Float64[]
    oy = Float64[]

    for i in -25:25
        push!(ox, Float64(i))
        push!(oy, 15.0)
    end
    for i in -25:-4
        push!(ox, Float64(i))
        push!(oy, 4.0)
    end
    for i in -15:4
        push!(ox, -4.0)
        push!(oy, Float64(i))
    end
    for i in -15:4
        push!(ox, 4.0)
        push!(oy, Float64(i))
    end
    for i in 4:25
        push!(ox, Float64(i))
        push!(oy, 4.0)
    end
    for i in -4:4
        push!(ox, Float64(i))
        push!(oy, -15.0)
    end

    oox = ox[:]
    ooy = oy[:]

    @time path = calc_hybrid_astar_path(sx, sy, syaw0, syaw1, gx, gy, gyaw0, gyaw1, ox, oy, XY_GRID_RESOLUTION, YAW_GRID_RESOLUTION)

    plot(oox, ooy, ".k")
    trailerlib.plot_trailer(sx, sy, syaw0, syaw1, 0.0)
    trailerlib.plot_trailer(gx, gy, gyaw0, gyaw1, 0.0)
    x = path.x
    y = path.y
    yaw = path.yaw
    yaw1 = path.yaw1
    direction = path.direction

    steer = 0.0
    for ii in 1:length(x)
        cla()
        plot(oox, ooy, ".k")
        plot(x, y, "-r", label="Hybrid A* path")

        if ii < length(x)-1
            k = (yaw[ii+1] - yaw[ii])/MOTION_RESOLUTION
            if !direction[ii]
                k *= -1
            end
            steer = atan2(WB*k, 1.0)
        else
            steer = 0.0
        end
        trailerlib.plot_trailer.(x[ii], y[ii], yaw[ii], yaw1[ii], steer)
        grid(true)
        axis("equal")
        pause(0.0001)
    end
    println("Done")
    axis("equal")
    show()

    println(PROGRAM_FILE," Done!!")
end

end #module

max_stars_repo_name: Oasis-Guo/HybridAStarTrailer

max_issues_repo_name: Oasis-Guo/HybridAStarTrailer

max_forks_repo_name: Oasis-Guo/HybridAStarTrailer


text:
# Types for use in the rest of the package

using DataStructures: OrderedDict
using JSON

const EPS = sqrt(eps())

Dim = UInt

struct Intersect2D
    p1d1::Float64
    p1d2::Float64
    p2d1::Float64
    p2d2::Float64
end

function Base.isapprox(x::Intersect2D, y::Intersect2D; atol::Real=0, rtol::Real=rtoldefault(x, y, atol), nans::Bool=false)
  # FIXME: easy to break
    isapprox(x.p1d1, y.p1d1, atol, rtol, nans) &&
  isapprox(x.p1d2, y.p1d2, atol, rtol, nans) &&
  isapprox(x.p2d1, y.p2d1, atol, rtol, nans) &&
  isapprox(x.p2d2, y.p2d2, atol, rtol, nans)
end

PointND = Vector{Float64}
LambdaND = Vector{Float64}

Simplex = Array{Float64}

ProblemSpec = OrderedDict{String,Tuple{Float64,Float64}}

struct SliceplorerPoint
  pt :: Tuple{Float64,Float64}
end
struct SliceplorerDimSample
  sample :: Array{SliceplorerPoint} # a single slice
end
struct SliceplorerDim
  dim :: Array{SliceplorerDimSample} # each element is one 'line' in the plot
end
struct SliceplorerSamples
  samples :: OrderedDict{String,SliceplorerDim}
end

struct SliceSet1D
  problemSpec::ProblemSpec
  focusPoints::Array{PointND}
  samples::SliceplorerSamples
end


text:
using Test

function fizzbuzz(number::Int)
    if number < 1
        throw(DomainError(number, "number needs to be 1 or higher"))
    elseif number % 15 == 0
        return "FizzBuzz"
    elseif number % 3 == 0
        return "Fizz"
    elseif number % 5 == 0
        return "Buzz"
    else
        return number
    end
end

@testset begin
    expected_result = [1, 2, "Fizz", 4, "Buzz", "Fizz",
                       7, 8, "Fizz", "Buzz", 11, "Fizz",
                       13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz"]
    obtained_result = [fizzbuzz(i) for i in 1:20]

    @test obtained_result == expected_result

    @test_throws MethodError fizzbuzz(1.5)
    @test_throws DomainError fizzbuzz(0)
    @test_throws DomainError fizzbuzz(-5)

end

for i in 1:20
    println(fizzbuzz(i))
end


text:
"""
    parbond(yield,term; par = 100)
The `times` and `cfs` in a named tuple for a bond paying semi-annual coupons with the given `yield` (assume annual effective if not specified) and `par` over the `term` (in integer years).
"""
function parbond(yield::Yields.Rate, term; par=100.)
    r = convert(Yields.Periodic(2), yield)
    coupon = Yields.rate(r) / 2
    times = 0.5:0.5:term
    cfs = map(times) do t
        if t == term
            return par + par * coupon
        else
            return par * coupon
        end
    end

    (; times, cfs)
end

function parbond(yield::T,term; par=100.) where {T<:Real}
    y = Yields.Periodic(yield,1)
    return parbond(y,term;par)
end

max_stars_repo_name: alecloudenback/ActuaryUtilities

max_issues_repo_name: alecloudenback/ActuaryUtilities

max_forks_repo_name: alecloudenback/ActuaryUtilities


text:
using TupleTools

diff(v::AbstractVector) = Base.diff(v)
diff(v::Tuple) = TupleTools.diff(v)