I am trying to call an optimization function for a set of operations where the object function contains integrals. i get this error when i try to do the optimization, i actually want to optimize a cost function, this is the error i get: *Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got 1. = 4 .. 7*

here is my work:

a2 := 18;

b2 := 5;

a1 := 3;

b1 := 2.5;

ci := 0.05;

cr := 1;

cf := 10;

p := 0.1;

L := 0.5;

S := 3;

T := 10;

cud := 50;

co := 0.02;

tr := 0.006;

ti := 0.0014;

tf := 0.014;

K := 2;

A := 2;

M := 7;

f01 := x -> b1*(x/a1)^(b1 - 1)*exp(-(x/a1)^b1)/a1;

f02 := x -> b2*(x/a2)^(b2 - 1)*exp(-(x/a2)^b2)/a2;

fx := x -> p*f01(x) + (1 - p)*f02(x);

fh := h -> L*exp(-L*h);

Fh := h -> 1 - exp(-L*h);

P1_1 := (K, A, M) -> sum(int(fx(x)*(1 - Fh(i*A - x)), x = (i - 1)*A .. i*A), i = 1 .. K);

L1_1 := (K, A, M) -> sum((i*A + tr + i*ti)*P1_1(K, A, M), i = 1 .. K);

C1_1 := (K, A, M) -> sum((ci*i + cr)*P1_1(K, A, M), i = 1 .. K);

NULL;

P2_1 := (K, A, M) -> sum(int(fh(h)*fx(x), [h = 0 .. i*A - x, x = (i - 1)*A .. i*A]), i = 1 .. K);

L2_1 := (K, A, M) -> sum((tf + (i - 1)*ti)*int((x + h)*fh(h)*fx(x), [h = 0 .. i*A - x, x = (i - 1)*A .. i*A]), i = 1 .. K);

C2_1 := (K, A, M) -> sum(((i - 1)*ci + cf)*P2_1(K, A, M), i = 1 .. K);

P3_1 := (K, A, M) -> int(fh(h)*fx(x), [h = 0 .. M - x, x = A*K .. M]);

L3_1 := (K, A, M) -> (K*ti + tf)*int((x + h)*fh(h)*fx(x), [h = 0 .. M - x, x = A*K .. M]);

C3_1 := (K, A, M) -> (K*ci + cf)*P3_1(K, A, M);

P4_1 := (K, A, M) -> int(fx(x)*(1 - Fh(M - x)), x = A*K .. M);

L4_1 := (K, A, M) -> (K*ti + tr + M)*int(fx(x)*(1 - Fh(M - x)), x = A*K .. M);

C4_1 := (K, A, M) -> (K*ci + cr)*int(fx(x)*(1 - Fh(M - x)), x = A*K .. M);

P5_1 := (K, A, M) -> int(fx(x), x = M .. infinity);

L5_1 := (K, A, M) -> (K*ti + tr + M)*int(fx(x), x = M .. infinity);

C5_1 := (K, A, M) -> (K*ci + cr)*int(fx(x), x = M .. infinity);

Ptotal_1 := (K, A, M) -> P1_1(K, A, M) + P2_1(K, A, M) + P3_1(K, A, M) + P4_1(K, A, M) + P5_1(K, A, M);

Ptotal_1(K, A, M);

evalf(Ptotal_1(K, A, M));

Ltotal_1 := (K, A, M) -> L1_1(K, A, M) + L2_1(K, A, M) + L3_1(K, A, M) + L4_1(K, A, M) + L5_1(K, A, M);

evalf(Ltotal_1(K, A, M));

Ctotal_1 := (K, A, M) -> C1_1(K, A, M) + C2_1(K, A, M) + C3_1(K, A, M) + C4_1(K, A, M) + C5_1(K, A, M);

Cost_rate_1 := (K, A, M) -> Ctotal_1(K, A, M)/Ltotal_1(K, A, M);

integralOF := int(Cost_rate_1(K, A, M), x = 1 .. 2);

evalf(integralOF);

0.2759938793

MTBOF := Ltotal_1(K, A, M)/(P2_1(K, A, M) + P3_1(K, A, M));

evalf(MTBOF);

159.4642167

rd := 1/MTBOF;

ro := 1/M + rd;

const1 := 0 <= K;

const2 := K*A <= M;

const3 := M <= 20;

const4 := 0 <= A;

const5 := 0 <= M;

totalconstr := {const1, const2, const3, const4, const5};

optimized_cost := Optimization:-Minimize(integralOF, totalconstr);

Error, (in Optimization:-NLPSolve) integration range or variable must be specified in the second argument, got 1. = 4 .. 7

NULL;

please, i need assitance urgently.. thanks