text:
"""
     S = mdsspec(sysR::MDFilterIF, freq; cdinp = false, MDGainTol = 0.01,
                 atol, atol1 = atol, atol2 = atol, rtol = 0, fast = true)

Compute, for a given set of real frequencies `freq`, the strong binary structure matrix `S`
of a collection of model detection filters
using the model detection filter internal form object `sysR::MDFilterIF`.

`freq` must contain a real frequency value or a vector of `nf` real frequencies
which characterize the classes of persistent control and disturbance signals
(default: `freq = 0`, i.e., characterizing constant signals) and defines
the set `Ω` of complex frequencies which characterize the classes of persistent signals
as follows:
if `f` is a real frequency in `freq`, then the corresponding complex frequency `λ` in `Ω`
is `λ := im*f`, for a continuous-time system,
or `λ := exp(im*f*abs(Ts))`, for a discrete-time system with sampling-time `Ts`.

For an `M × N` array of filters `sysR`, `S` is an `M × N` binary array determined as follows.
Let the `(i,j)`-th component filter `sysR.sys[i,j]` have the input-output form

     rij = Ruij(λ)*u + Rdij(λ)*dj + Rwij(λ)*wj + Rvij(λ)*vj ,

with the Laplace- or Z-transformed residual output `rij`, control inputs `u`,
disturbance inputs `dj`, noise inputs `wj`, and auxiliary inputs `vj`,
and with `Ruij(λ)`, `Rdij(λ)`, `Rwij(λ)` and `Rvij(λ)`, the corresponding transfer function matrices.
Then, `S[i,j] = 1` if `Ruij(λs)` is nonzero for all `λs ∈ Ω` and `cdinp = false` (default), or
if `[Ruij(λs) Rdij(λs)]` is nonzero for all `λs ∈ Ω` and `cdinp = true`. Otherwise, `S[i,j] = 0`.

`MDGainTol = tol` specifies an absolute  threshold `tol` for the nonzero magnitudes of
the frequency response gains (default: `tol = 0.01`).

The computation of minimal realizations of individual input-output channels relies on pencil manipulation algorithms,
which employ rank determinations based on either the use of
rank revealing QR-decomposition with column pivoting, if `fast = true` (default) or
the more reliable SVD-decompositions if `fast = false`.

If `(Arij-λErij,Brij,Crij,Drij)` is the descriptor realization of `sysR.sys[i,j]`, then
the keyword arguments `atol1`, `atol2`, and `rtol`, specify, respectively, the absolute tolerance for the
nonzero elements of matrices `Arij`, `Brij`, `Crij`, `Drij`, the absolute tolerance for the nonzero elements of `Erij`,
and the relative tolerance for the nonzero elements of `Arij`, `Brij`, `Crij`, `Drij` and `Eirj`.
The default relative tolerance is `nij*ϵ`, where `ϵ` is the working _machine epsilon_
and `nij` is the order of the system `sysR.sys[i,j]`.
The keyword argument `atol` can be used to simultaneously set `atol1 = atol` and `atol2 = atol`.
"""
function mdsspec(sysR::MDFilterIF{T}, freq::Union{AbstractVector{<:Real},Real} = 0;  cdinp::Bool = false,
                  MDGainTol::Real = 0.01, atol::Real = zero(float(real(T))), atol1::Real = atol, atol2::Real = atol,
                  rtol::Real = 0, fast::Bool = true) where T
    isa(freq,Vector) ? tfreq = freq : tfreq = [freq]
    lfreq = length(tfreq);
    M, N = size(sysR.sys)
    S = trues(M,N)
    mu = sysR.mu
    cdinp && (md = sysR.md)
    for j = 1:N
        for i = 1:M
            if cdinp
               Sc = fdisspec_(sysR.sys[i,j][:,1:mu+md[j]], tfreq; FDGainTol = MDGainTol, block = true, atol1, atol2, rtol, fast)[1]
            else
               Sc = fdisspec_(sysR.sys[i,j][:,1:mu], tfreq; FDGainTol = MDGainTol, block = true, atol1, atol2, rtol, fast)[1]
            end
            S[i,j] = lfreq == 1 ? any(Sc) : all([any(view(Sc,:,:,k)) for k = 1:lfreq])
        end
    end
    return S
end
"""
     mdperf(sysR::MDFilterIF; MDfreq, cdinp = false, rtolinf = 0.00001,
            offset, atol, atol1 = atol, atol2 = atol, rtol = 0, fast = true) -> (mdgain, fpeak)

Compute the distance-mapping performance of a collection of model detection filters
using the model detection filter internal form object `sysR::MDFilterIF`.
For an `M × N` array of filters `sysR`, the `M × N` arrays of model detection performance gains
`mdgain` and the corresponding peak frequencies `fpeak` are determined as follows.
Let the `(i,j)`-th component filter `sysR.sys[i,j]` have the input-output form

     rij = Ruij(λ)*u + Rdij(λ)*dj + Rwij(λ)*wj + Rvij(λ)*vj ,

with the Laplace- or Z-transformed residual output `rij`, control inputs `u`,
disturbance inputs `dj`, noise inputs `wj`, and auxiliary inputs `vj`,
and with `Ruij(λ)`, `Rdij(λ)`, `Rwij(λ)` and `Rvij(λ)`, the corresponding transfer function matrices.
Then, the `(i,j)`-th performance gain is evaluated as
`mdgain[i,j] = ||Ruij(λ)||∞` if `cdinp = false` (default) or `mdgain[i,j] = ||[Ruij(λ) Rdij(λ)]||∞` if `cdinp = true`
and `fpeak[i,j]` contains the corresponding peak frequency.

If `MDfreq = ω`, where `ω` is a given vector of real frequency values, then each gain `mdgain[i,j]` represents
the maximum of 2-norm pointwise gains evaluated for all frequencies in `ω` and
`fpeak[i,j]` is the corresponding peak frequency.

The stability boundary offset, `β`, to be used to assess the finite poles which belong to the
boundary of the stability domain can be specified via the keyword parameter `offset = β`.
Accordingly, for a continuous-time system, these are the finite poles having
real parts within the interval `[-β,β]`, while for a discrete-time system,
these are the finite pole having moduli within the interval `[1-β,1+β]`.
The default value used for `β` is `sqrt(ϵ)`, where `ϵ` is the working machine precision.

Pencil reduction algorithms are employed to compute the H∞-norms.
These algorithms perform rank decisions based on rank
revealing QR-decompositions with column pivoting
if `fast = true` (default) or the more reliable SVD-decompositions if `fast = false`.

If `(Arij-λErij,Brij,Crij,Drij)` is the descriptor realization of `sysR.sys[i,j]`, then
the keyword arguments `atol1`, `atol2`, and `rtol`, specify, respectively, the absolute tolerance for the
nonzero elements of matrices `Arij`, `Brij`, `Crij`, `Drij`, the absolute tolerance for the nonzero elements of `Erij`,
and the relative tolerance for the nonzero elements of `Arij`, `Brij`, `Crij`, `Drij` and `Eirj`.
The default relative tolerance is `nij*ϵ`, where `ϵ` is the working _machine epsilon_
and `nij` is the order of the system `sysR.sys[i,j]`.
The keyword argument `atol` can be used to simultaneously set `atol1 = atol` and `atol2 = atol`.

The keyword argument `rtolinf = tol` specifies the relative accuracy `tol` to be used
to compute the infinity norms. The default value used is `tol = 0.00001`.
"""
function mdperf(sysR::MDFilterIF{T}; MDfreq::Union{AbstractVector{<:Real},Real,Missing} = missing,
                cdinp::Bool = false, rtolinf::Real = 0.00001, atol::Real = zero(float(real(T))),
                atol1::Real = atol, atol2::Real = atol, rtol::Real = 0, fast::Bool = true) where T
    if ismissing(MDfreq)
       lfreq = 0
    else
       isa(MDfreq,Vector) || (MDfreq = [MDfreq])
       lfreq = length(MDfreq);
    end
    M, N = size(sysR.sys)
    mdgain = similar(Matrix{T}, M, N)
    fpeak = similar(Matrix{T}, M, N)
    inpud = 1:sysR.mu
    for j = 1:N
        cdinp && (inpud = 1:sysR.mu+sysR.md[j])
        for i = 1:M
            if lfreq == 0
                mdgain[i,j], fpeak[i,j] = ghinfnorm(sysR.sys[i,j][:,inpud]; rtolinf, atol1, atol2, rtol, fast, offset)
            else
                gmax = zero(T)
                fmax = MDfreq[1]
                for k = 1:lfreq
                    tval = opnorm(evalfr(sysR.sys[i,j][:,inpud]; fval = MDfreq[k], atol1, atol2, rtol, fast))
                    gmax > tval && (gmax = tval; fmax = tfreq)
                end
                mdgain[i,j] = gmax
                fpeak[i,j] = fmax
            end
        end
    end
    return mdgain, fpeak
end
"""
    mdmatch(sysQ::MDFilter, sysc::MDModel; MDfreq, minimal = false, rtolinf, offset, atol, atol1 = atol, atol2 = atol, rtol, fast = true) -> (mdgain,fpeak,mind)

Compute the distance-mapping performance vector `mdgain` achieved using the model detection filter object `sysQ::MDFilter`
applied to a component model `sysc::MDModel`, the corresponding vector of peak frequencies `fpeak`,
and the index `mind` of the component of `mdgain` for which the minimum gain value is achieved.

If the `i`-th filter `sysQ.sys[i]` has the transfer function matrix `Qi(λ)` and
the component model `sysc::MDModel` has the partitioned transfer function matrix
`G(λ) = [Gu(λ)  Gd(λ) Gw(λ) Gv(λ)]` in accordance with
the partitioned system inputs as `controls`, `disturbances`, `noise` and `auxiliary` inputs, respectively,
then the distance-mapping performance of the `i`-th filter applied to the given component model
is computed as  `mdgain[i] = || Ri(λ) ||∞`, where `Ri(λ)`
is the corresponding internal form

     Ri(λ) = Qi(λ) * | Gu(λ)  Gd(λ) Gw(λ) Gv(λ) | .
                     |  I     0     0     0     |

Minimal descriptor realizations are computed for `Ri(λ)` if `minimal = true` and a (possibly) non-minimal
realization is determined if `minimal = false` (default).

The computation of minimal realizations of individual input-output channels relies on pencil manipulation algorithms,
which employ rank determinations based on either the use of
rank revealing QR-decomposition with column pivoting, if `fast = true` (default) or
the more reliable SVD-decompositions if `fast = false`.

If `(Ari-λEri,Bri,Cri,Dri)` is the full order descriptor realization of `Ri(λ)`, then
the keyword arguments `atol1`, `atol2`, and `rtol`, specify, respectively, the absolute tolerance for the
nonzero elements of matrices `Ari`, `Bri`, `Cri`, `Dri`, the absolute tolerance for the nonzero elements of `Eri`,
and the relative tolerance for the nonzero elements of `Ari`, `Bri`, `Cri`, `Dri` and `Eir`.
The default relative tolerance is `ni*ϵ`, where `ϵ` is the working _machine epsilon_
and `ni` is the order of the realitation of `Ri(λ)`.
The keyword argument `atol` can be used to simultaneously set `atol1 = atol` and `atol2 = atol`.

"""
function mdmatch(Q::MDFilter{T}, sysc::MDModel; minimal::Bool = false, MDfreq::Union{AbstractVector{<:Real},Real,Missing} = missing,
                 offset::Real = sqrt(eps(T)), rtolinf::Real = 0.00001,
                 atol::Real = 0., atol1::Real = atol, atol2::Real = atol, rtol::Real = 0., fast::Bool = true) where T
   # compute the internal form as
   #   R[i,j] = Q[i] * [ Gu[j] Gd[j] Gw[j] Gaux[j]]
   #                   [ I     0     0     0      ]
   if ismissing(MDfreq)
      lfreq = 0
   else
      isa(MDfreq,Vector) || (MDfreq = [MDfreq])
      lfreq = length(MDfreq);
   end
   N = length(Q.sys)
   p, m = size(sysc.sys)
   mu = sysc.mu
   (Q.ny == p && Q.mu == mu) || error("filter Q is incompatible with the given component model")
   syse = [sysc.sys;  I zeros(mu,m-mu)]
   mdgain = similar(Vector{T}, N)
   fpeak = similar(Vector{T}, N)
   N == 0 && (return mdgain, fpeak, nothing)
   tmin = Inf
   mind = 0
   for i = 1:N
       sysRi = minimal ? gminreal(Q.sys[i]*syse; atol1, atol2, rtol, fast) : Q.sys[i]*syse
       if lfreq == 0
          mdgain[i], fpeak[i] = ghinfnorm(sysRi; rtolinf, atol1, atol2, rtol, fast, offset)
       else
          gmax = zero(T)
          fmax = MDfreq[1]
          for k = 1:lfreq
              tval = opnorm(evalfr(sysRi; fval = MDfreq[k], atol1, atol2, rtol, fast))
              gmax > tval || (gmax = tval; fmax = MDfreq[k])
          end
          mdgain[i] = gmax
          fpeak[i] = fmax
       end
       tmin <= mdgain[i] || (tmin = mdgain[i]; mind = i)
   end
   return mdgain, fpeak, mind
end

max_stars_repo_name: andreasvarga/FaultDetectionTools

max_issues_repo_name: andreasvarga/FaultDetectionTools

max_forks_repo_name: andreasvarga/FaultDetectionTools


text:
push!(LOAD_PATH, "../src/")

using Documenter, Dojo

# copy animations to docs/src/assets/animations
path_assets_animations = joinpath(@__DIR__, "src/assets/animations")
!isdir(path_assets_animations) && mkdir(path_assets_animations)
path_animations = joinpath(@__DIR__, "../examples/animations")
files = readdir(path_animations)
filter!(x -> endswith(x, ".gif"), files)
for file in files
    cp(joinpath(path_animations, file), joinpath(path_assets_animations, file), force=true)
end

makedocs(
    modules = [Dojo],
    format = Documenter.HTML(prettyurls=false),
    sitename = "Dojo",
    pages = [
        ##############################################
        ## MAKE SURE TO SYNC WITH docs/src/index.md ##
        ##############################################
        "index.md",

        "Creating a Mechanism" => [
            "define_mechanism.md",
            "load_mechanism.md",
           ],

        "Creating a Simulation" => [
            "define_simulation.md",
            "define_controller.md",
            "simulation_with_gradients.md",
           ],

        "Environments" => [
            "load_environment.md",
            "define_environment.md",
            "environment_simulation_gradients.md",
        ],

        "Gradients from Simulator" => [
            "simulation_with_gradients.md",
            "gradients.md",
           ],

        "Examples" => [
            "simulation.md",
            "trajectory_optimization.md",
            "reinforcement_learning.md",
            "system_identification.md",
           ],

        "State Representations" => [
            "maximal_representation.md",
            "minimal_representation.md",
        ],

        "Contact Models" => [
            "contact_models.md",
            "impact.md",
            "nonlinear_friction.md",
            "linearized_friction.md",
            "collisions.md",
        ],

        "Interior-Point Solver" => [
            "interior_point.md",
            "solver_options.md",
        ],

        "faq.md",
        "api.md",
        "contributing.md",
        "citing.md"
    ]
)

deploydocs(
    repo = "github.com/dojo-sim/Dojo.jl.git",
)

ext: jl


text:
using Pkg
using CSV
using DataFrames
using Distributions
using Random
using StatsBase
using NamedArrays

# Pkg.installed()

# ##Zmienne
# #Menu z cenami

# menu = Dict("BigMac"=>20, "Drwal"=>30, "McNuggets"=>23, "McChicken" => 25, "Wege" => 18)
# prices = [20, 30, 23, 25, 18]
# #Produkty i ich data waznosci
# #val = Dict("BigMac"=>20, "Drwal"=>20, "McNuggets"=>15, "McChicken" => 25, "Wege" => 15)
# val = [10, 10, 7, 12, 7]
# start_val = [20, 20, 15, 25, 15]
# #Początkowy stan produktów
# #start = Dict("BigMac"=>20, "Drwal"=>20, "McNuggets"=>20, "McChicken" => 20, "Wege" => 20)
# start_i = [20, 20, 20, 20, 20]
# start = [20, 20, 20, 20, 20]

# #score = DataFrame(Profit = 0, Thrown_out = 0, Unfulfilled = 0, Fulfilled = 0)
# score = [0.0, 0, 0, 0]

# ##Rozkłady
# #Ilość samochodów na minutę tworzymy rozkład zeby uzyc sample w funkcji
# cars = [1, 2, 3, 4, 5]
# prob = [0.15, 0.25, 0.2, 0.2, 0.1]
# w = Weights(prob)

cars_num = sample(cars, w)
    #wylosować ilość osób w kazdym samochodzie, 1 samochod = jedna zmienna?
    num_ppl = Dict(i => rand(1:cars_num) for i in 1:cars_num)
    # wylosować zamówienia dla kazdego samochodu, zapisujemy je jako data DataFrame
    #gdzie kolumny to produkty zamowione a rzedy to nr samochodu
    orders = DataFrame(BigMac = zeros(cars_num), Drwal = zeros(cars_num),
    McNuggets = zeros(cars_num), McChicken = zeros(cars_num), Wege = zeros(cars_num))

    #losujemy zamowienia dla kazdego samochodu
    for i in 1:nrow(orders)
        for j in 1:length(num_ppl)
                prod = rand(1:ncol(orders))
                orders[i, prod] += 1
        end
    end

    sum_order = sum.(eachcol(orders))
    println("Sum order", sum_order)
    #start -= sum_order
    end_inv = start - sum_order
    println("INV = ", end_inv)
    unfulfilled = zeros(5)

    for i in 1:length(end_inv)
        if(end_inv[i] < 0)
            unfulfilled[i] -= end_inv[i]
            end_inv[i] = 0
        end
    end
    println("Unfulfilled = ", unfulfilled)

    fulfilled = sum_order - unfulfilled
    println("Fulfilled = ", fulfilled)

    gain = fulfilled .* prices
    penalty = unfulfilled .* (0.25*prices)
    val .-= 1
    thrown_out = zeros(5)
    for i in 1:length(val)
        if(val[i] <= 0)
            thrown_out[i] = end_inv[i]
            end_inv[i] = start_i[i]
            val[i] = start_val[i]
        end
    end
    loss = thrown_out.* (0.25*prices)

    profit = gain - penalty - loss

    score[1] += sum(profit)
    score[2] += sum(thrown_out)
    score[3] += abs(sum(unfulfilled))
    score[4] += sum(fulfilled)

    start = end_inv

mean(final_summed[:,2:end], dims = 2)

max_stars_repo_name: myrchas/food-orders-simulation

max_issues_repo_name: myrchas/food-orders-simulation

max_forks_repo_name: myrchas/food-orders-simulation


text:
# ---
# title: 767. Reorganize String
# id: problem767
# author: AquaIndigo
# date: 2020-11-30
# difficulty: Medium
# categories: String, Heap, Greedy, Sort
# link: <https://leetcode.com/problems/reorganize-string/description/>
# hidden: true
# ---
#
# Given a string `S`, check if the letters can be rearranged so that two
# characters that are adjacent to each other are not the same.
#
# If possible, output any possible result.  If not possible, return the empty
# string.
#
# **Example 1:**
#
#
#
#     Input: S = "aab"
#     Output: "aba"
#
#
# **Example 2:**
#
#
#
#     Input: S = "aaab"
#     Output: ""
#
#
# **Note:**
#
#   * `S` will consist of lowercase letters and have length in range `[1, 500]`.
#
#
#
#
## @lc code=start
using LeetCode

function reorganize_string(S::String)
    char_arr = codeunits(S)
    ascii_a, len = Int('a'), length(S)
    mp = fill(0, 26)
    for ch in char_arr
        mp[ch - ascii_a + 1] += 1
    end
    max_freq = argmax(mp)
    if mp[max_freq] > (len + 1) ÷ 2
        return ""
    end
    res = fill('a', len)
    idx = 1
    for i in 1:mp[max_freq]
        res[idx] = Char(max_freq + ascii_a - 1)
        idx += 2
    end
    mp[max_freq] = 0
    for i in 1:26
        for j in 1:mp[i]
            (idx > len) && (idx = 2)
            res[idx] = Char(i + ascii_a - 1)
            idx += 2
        end
    end
    ## println(res)
    return String(res)
end
## @lc code=end


text:
# noise processes definition
sigma = 0.001
σ = 200*sigma
noisemix1 = MixtureModel([Normal(0, 0.001), Normal(0, σ)], [0.9, 0.1])
noisemixdensity1(x) = pdf.(noisemix1, x)

sigma_param = sqrt(0.002)
paramnoise = Normal(0, sigma_param)
parametricnoisedensity(x) = pdf(Normal(0, sigma_param), x)

sigma23 = sqrt(4*1e-2)
sigma33 = sqrt(1*1e-4)
noisemix2 = MixtureModel(Normal[Normal(0, sigma23), Normal(0, sigma33)], [1.0/3, 2.0/3])
noisemixdensity2(x) = pdf.(noisemix2, x)

max_stars_repo_name: cmerkatas/GSBR

max_issues_repo_name: cmerkatas/GSBR

max_forks_repo_name: cmerkatas/GSBR


text:
# AUTO GENERATED FILE - DO NOT EDIT

export tabs

"""
    tabs(;kwargs...)
    tabs(children::Any;kwargs...)
    tabs(children_maker::Function;kwargs...)

A Tabs component.
Tabs
Keyword arguments:
- `children` (Array of a list of or a singular dash component, string or numbers | a list of or a singular dash component, string or number; optional): Pass in a collection of <Tab> children to be rendered depending on the
currently selected tab
- `ariaLabel` (String; optional): Specify the text to be read by screen-readers when visiting the <Tabs>
component
- `style` (Dict; optional): Specify the inline style
- `className` (String; optional): Provide a className that is applied to the root <nav> component for the
<Tabs>
- `hidden` (Bool; optional): Specify whether the Tab content is hidden
- `role` (String; optional): By default, this value is "navigation". You can also provide an alternate
role if it makes sense from the accessibility-side
- `triggerHref` (String; optional): Provide a string that represents the `href` for the triggered <Tab>
- `selected` (Real; optional): Optionally provide an index for the currently selected <Tab>
- `iconDescription` (String; optional): Provide a description that is read out when a user visits the caret icon
for the dropdown menu of items
- `tabContentClassName` (String; optional): Provide a className that is applied to the <TabContent> components
- `id` (String; optional): The ID of this component, used to identify dash components
in callbacks. The ID needs to be unique across all of the
components in an app.
- `headerOffsets` (Array of Strings; optional): Number of columns of left offset the header will have
- `headerSizes` (Array of Strings; optional): Number of columns the header will have
- `value` (String; optional): Value of the selected tab
"""
function tabs(; kwargs...)
        available_props = Symbol[:children, :ariaLabel, :style, :className, :hidden, :role, :triggerHref, :selected, :iconDescription, :tabContentClassName, :id, :headerOffsets, :headerSizes, :value]
        wild_props = Symbol[]
        return Component("tabs", "Tabs", "dash_carbon_components", available_props, wild_props; kwargs...)
end

tabs(children::Any; kwargs...) = tabs(;kwargs..., children = children)
tabs(children_maker::Function; kwargs...) = tabs(children_maker(); kwargs...)

max_stars_repo_name: Matheus-Rangel/dash-carbon-components

max_issues_repo_name: Matheus-Rangel/dash-carbon-components

max_forks_repo_name: Matheus-Rangel/dash-carbon-components