Off[FindMinimum::"fmmp"];
dataPminPmax = {{100, 625}, {80, 500}, {75, 400}, {30, 
            300}};
dataCinCout = {{3000, 1500}, {3000, 1500}, {2000, 1000}, {1000, 
            800}};
dataAcka = {{500, 8, 0.004}, {400, 6.4, 0.0048}, {600, 7.9, 
            0.005}, {400, 7.5, 0.0055}};
n = Length[dataAcka];
datazatizeni = {600, 800, 1100, 1400, 1000, 1200, 1000, 1400, 1600, 
          1600, 1400, 800};
tauP = 1. ;
penale1[P_, Pmin_, Pmax_] = 
        Exp[((P - Pmax)/tauP)] + 
          Exp[((Pmin - P)/tauP)];
podminkyMinMax = 
        Table[penale1[(Subscript[P, i]), dataPminPmax[[i, 1]], 
            dataPminPmax[[i, 2]]], {i, 
            Length[dataPminPmax]}];
celkemMinmax = 
        Sum[podminkyMinMax[[i]], {i, 
            Length[dataPminPmax]}];

vlastninaklady // 
        ClearAll;
  

    nasazeni = {a1, a2, a3, a4};

    vlastninaklady[a1_, a2_, a3_, a4_] = 
        Table[dataAcka[[i, 1]] + dataAcka[[i, 2]]*(Subscript[P, i]) + 
              dataAcka[[i, 3]]*((Subscript[P, i])^2), {i, n}] . 
          nasazeni;

    podminkyvhodine // ClearAll; ClearAll[pomsum];

    dosacka = 
        Table[(Subscript[P, i]) -> (Subscript[P, i])*nasazeni[[i]], {i, 
            n}];

    sp = Sum[(Subscript[P, i]), {i, n}];

    pomsum[a1_, a2_, a3_, a4_] = sp /. dosacka;

    podminkyvhodine[a1_, a2_, a3_, a4_, hodina_Integer] := 
        pomsum[a1, a2, a3, a4] - 
          datazatizeni[[hodina]];

    ClearAll[pokus];

    vahasplnenivykonu = (10^6);

    pokus[a1_, a2_, a3_, a4_, hodina_Integer] := 
        vlastninaklady[a1, a2, a3, a4] + celkemMinmax + 
          vahasplnenivykonu*
            podminkyvhodine[a1, a2, a3, a4, hodina]^2;

    promenne = 
        Table[{(Subscript[P, i]), dataPminPmax[[i, 1]], dataPminPmax[[i, 2]]}, {i, 
            n}];

    minimum[{a1_, a2_, a3_, a4_}, hodina_Integer] := 
      FindMinimum[pokus[a1, a2, a3, a4, hodina], promenne]

nk = (2^n) - 1;
komb = ((Take[#, -4] &) /@ (IntegerDigits[Range[nk], 
                  2] /. {q__Integer} -> {0, 0, 0, q})) // 
        Union

minzkombinaci[
        hodina_Integer] := Union[
          Table[{minimum[komb[[i]], 
                  hodina][[1]], (((minimum[komb[[i]], 
                            hodina][[2]]) . komb[[i]]) /. 
                  Plus -> List), komb[[i]]}, {i, 
              nk}]][[1]]

cenaprepnuti[v1_, v2_] := 
        Sum[If[Sign[(v1 - v2)][[i]] < 0, dataCinCout[[i, 1]], 
            If[Sign[(v1 - v2)][[i]] > 0, dataCinCout[[i, 2]], 
              0]], {i, n}];
minimumkrok[v1_, {a1_, a2_, a3_, a4_}, hodina_Integer] := 
        FindMinimum[
          pokus[a1, a2, a3, a4, hodina] + cenaprepnuti[v1, {a1, a2, a3, a4}], 
          promenne];
ClearAll[okrok];
okrok[
        listik_List] := {First[
          Union[Table[{minimumkrok[listik[[1, 3]], komb[[i]], 
                    listik[[2]] - 
                      1][[1]], (((minimumkrok[
                              listik[[1, 3]], komb[[i]], 
                              listik[[2]] - 1][[2]]) . 
                        komb[[i]]) /. Plus -> List), 
                komb[[i]]}, {i, nk}]]], listik[[2]] - 1}

start = {minzkombinaci[12], 12};
vysledek = NestList[okrok, start, 11]

(sp /. Plus -> List) . vysledek[[1, 1, 3]] /. 
      vysledek[[1, 1, 2]]

vlastninaklady[Sequence @@ vysledek[[1, 1, 3]]]

penale1[P_, Pmin_, Pmax_] = 
        Exp[((P - Pmax)/tauP)] + 
          Exp[((Pmin - P)/tauP)];
Plot[penale1[P, 100, 500], {P, 0, 600}, 
      PlotRange -> All]

prechod[odkud_, kam_, kde_, rychlost_] := 
      Module[{res, a, b}, 
        res = Solve[{odkud == -a + b, kam == a + b}, {a, 
                b}][[1]]; 
        a*Tanh[rychlost*(P - kde)] + b /. res]
Plot[prechod[-1, 1, 2, 60], {P, -5, 5}]