From b1223b1e2e9546d609388f3970375054350bfda6 Mon Sep 17 00:00:00 2001 From: thorek1 Date: Fri, 10 Nov 2023 19:01:39 +0100 Subject: [PATCH] add max_obc_shift --- src/get_functions.jl | 8 +++----- src/macros.jl | 5 ++++- src/plotting.jl | 8 +++----- src/structures.jl | 1 + 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/get_functions.jl b/src/get_functions.jl index 3be52f00..34f17d53 100644 --- a/src/get_functions.jl +++ b/src/get_functions.jl @@ -903,11 +903,9 @@ function get_irf(𝓂::ℳ; obc_shock_idx = contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ") - obc_inequalities_idx = findall(x->contains(string(x), "Χᵒᵇᶜ") , 𝓂.var) - - periods_per_shock = sum(obc_shock_idx)÷length(obc_inequalities_idx) - - num_shocks = length(obc_inequalities_idx) + periods_per_shock = 𝓂.max_obc_shift + 1 + + num_shocks = sum(obc_shock_idx)÷periods_per_shock # Find shocks fulfilling constraint # model = JuMP.Model(MadNLP.Optimizer) diff --git a/src/macros.jl b/src/macros.jl index d07236c2..babc4d25 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -107,7 +107,9 @@ macro model(𝓂,ex...) model_ex = parse_for_loops(ex[end]) - model_ex = parse_occasionally_binding_constraints(model_ex) + max_obc_shift = 40 + + model_ex = parse_occasionally_binding_constraints(model_ex, max_obc_shift = max_obc_shift) obc_shock_bounds = Tuple{Symbol, Bool, Float64}[] @@ -853,6 +855,7 @@ macro model(𝓂,ex...) Expr[], $obc_shock_bounds, + $max_obc_shift, x->x, solution( diff --git a/src/plotting.jl b/src/plotting.jl index c9620b93..4234c31d 100644 --- a/src/plotting.jl +++ b/src/plotting.jl @@ -464,11 +464,9 @@ function plot_irf(𝓂::ℳ; obc_shock_idx = contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ") - obc_inequalities_idx = findall(x->contains(string(x), "Χᵒᵇᶜ") , 𝓂.var) - - periods_per_shock = sum(obc_shock_idx)÷length(obc_inequalities_idx) - - num_shocks = length(obc_inequalities_idx) + periods_per_shock = 𝓂.max_obc_shift + 1 + + num_shocks = sum(obc_shock_idx)÷periods_per_shock # Find shocks fulfilling constraint # model = JuMP.Model(MadNLP.Optimizer) diff --git a/src/structures.jl b/src/structures.jl index aad539ca..eff85295 100644 --- a/src/structures.jl +++ b/src/structures.jl @@ -352,6 +352,7 @@ mutable struct ℳ obc_violation_equations::Vector{Expr} obc_shock_bounds::Vector{Tuple{Symbol, Bool, Float64}} + max_obc_shift::Int obc_violation_function::Function solution::solution