function [distance_val, zdatapiecewise_, zdatass_,check]=...
    distance_function_rules2(distance_param,distance_param_fixed,rule_param_names,...
    M00_,M10_,M01_,M11_,oo00_,...
    options00_,constraint1, constraint2,...
    constraint_relax1, constraint_relax2)


global overwrite overwrite_param_names


overwrite_param_names = rule_param_names;
overwrite = [distance_param; distance_param_fixed'];
%-13.405549864040225 with 0
%-16.108827005385145

%overwrite_param_names = char('tau_gammap','gammap_increment');


    nperiods_shocks=5000;
    nperiods = 25;
    maxiter = 20;
    irf_shock = char('eps_a','eps_isp','eps_tau');
    nshocks = size(irf_shock,1);
    randn('seed',1);
    shockssequence = randn(nperiods_shocks,nshocks);

    [zdatapiecewise_, zdatass_, ~, ~, ~, check] = ...
        solve_two_constraints_add_violvecbool_no_parse_short(M00_,M10_,M01_,M11_,oo00_,...
        options00_,constraint1, constraint2,...
        constraint_relax1, constraint_relax2,...
        shockssequence,irf_shock,nperiods,0,maxiter);


    if check==0

        distance_val = -mean(zdatapiecewise_(:,strcmp('welf',M00_.endo_names))+...
                                 zdatass_(strcmp('welf',M00_.endo_names)));

    else
        distance_val = 10000000;
        zdatapiecewise_ = nan;
        zdatass_ = nan;
    end



