Message Boards Message Boards

0
|
304 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Issue with solving an optimization model using FindMaximum and mismatch the result from a paper

Posted 12 days ago

Hello, I’m trying to solve an optimization model for growing items based on a paper that uses Excel Solver to obtain the optimal solution. The model has two decision variables: n (frequency of shipments) and T (retailer's replenishment cycle). The paper provides the following equations and parameter values: Equation of Total profit Parameter Value Parameter value Cont.

The optimal values from the paper are: - n(shipment frequency) = 20 - T(retailer's replenishment cycle) = 1.62 days - Total profit = 421.14 ($/day)

Right now, I am attempting to solve the same problem in Mathematica, but I’m encountering an issue when using FindMaximum to determine the optimal values for both n and T. Here is the code I am using to find the optimal solution of both n and T

Clear["Global`*"]
    L = 4;
    w = 0.064;
    ww = 2;
    R = 250;
    Kf = 750;
    cf = 0.1;
    m = 0.2;
    Kp = 500;
    hp = 0.05;
    Kd = 100;
    h = 0.1;
    g = 6.87;
    q = 0.12;
    a = 80;
    b = 0.2;
    pv = 1;
    pf = 2;
    pr = 5;
    z = 120;
    x = 0.9;
    s = 0.2;
    Tf = - (Log[1/z (k/ww - 1)]/q);
    F[d_, n_] = 
      pr/d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - (pv w)/(
        d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - Kd/d - 
       Kp/(n d) - Kf/(
       n d) - (h a (1 - b))/(
        2 L d) (d + (((1 - b)/(
              2 - b)) (2^(1/(1 - b)) L^(1/(1 - b)) d^((2 - b)/(1 - b))) + 
            d^((3 - b)/(1 - b)))) - 
       hp/(2 R d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(1 - b)) - (
        hp (n - 1))/(2 d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(
        1 - b)) (d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - 1/
          R) - (cf x + m s)/(d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(
        1/(1 - b)) (g  Tf + g/q (Log[1 + z E^(-q n Tf)] - Log[1 + z]));
    FindMaximum[{F[d, n], d > 0}, {d, n}]

However, I encounter an error in my code:

FindMaximum::nrnum: The function value 598.228 +11.0638 (57.25 (-Log[121]+Log[1+Times[<<2>>]])-57.25 Log[1/120 (-1+Times[<<2>>])]) is not a real number at {d,n} = {0.999994,1.}.

FindMaximum::grad: Evaluation of the gradient of function Experimental`NumericalFunction[{Hold[-(-(100/d)+(66.7933 (Times[<<2>>]+<<1>>)^1.25)/d-(0.0181019 (<<1>><<1>>^2.5)/d-(0.8 <<1>>)/d-(<<18>> <<1>> <<1>> (-1+n))/d-1250/(d n)-(0.971703 (<<1>>)^1.25 (57.25 Plus[<<2>>]-57.25 Log[<<1>>]))/d)],Block},<<4>>,{<<1>>}] failed at {1.,1.}.

After that, I try to just find the optimal solution of T only by setting the n value with the optimal value from the paper which is 20. However, the total profit and the value of T I obtain are different from the results in the paper. Here is the code I use for this :

Clear["Global`*"]
    L = 4;
    w = 0.064;
    ww = 2;
    R = 250;
    Kf = 750;
    cf = 0.1;
    m = 0.2;
    Kp = 500;
    hp = 0.05;
    Kd = 100;
    h = 0.1;
    g = 6.87;
    q = 0.12;
    a = 80;
    b = 0.2;
    pv = 1;
    pf = 2;
    pr = 5;
    z = 120;
    n = 20;
    x = 0.9;
    s = 0.2;
    Tf = - (Log[1/z (g/ww - 1)]/q);

    F[d_] = pr/d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - (pv w)/(
        d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - Kd/d - 
       Kp/(n d) - Kf/(
       n d) - (h a (1 - b))/(
        2 L d) (d + (((1 - b)/(
              2 - b)) (2^(1/(1 - b)) L^(1/(1 - b)) d^((2 - b)/(1 - b))) + 
            d^((3 - b)/(1 - b)))) - 
       hp/(2 R d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(1 - b)) - (
        hp (n - 1))/(2 d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(
        1 - b)) (d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - 1/
          R) - (cf x + m s)/(d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(
        1/(1 - b)) (g n Tf + g/q (Log[1 + z E^(-q n Tf)] - Log[1 + z]));
    FindMaximum[{F[d], d > 0}, d]

The result I obtained are : Total profit = -27730 and T = 0.029

Could anyone help me understand why I am getting different results in Mathematica compared to the paper, even after using the same parameter values and the optimal value for n from the paper? Are there any potential issues with the way I’m using FindMaximum or something I might be overlooking in the optimization setup?

In case it was needed, here is the link of the paper : https://www.sciencedirect.com/science/article/abs/pii/S0307904X20306120 (I also attached the paper below)

Any insights would be greatly appreciated! Thank you!

POSTED BY: Shafa Hananta
3 Replies

After some plotting, like

Plot3D[F[d, n], {d, 0, 8}, {n, 0, 1/2},
 PlotRange -> {-1, 2500000}]

I come to suspect that the maximum is attained near d=4 and n=1/100. Using these values as starting points I get

In[172]:= FindMaximum[F[d, n], {{d, 4}, {n, 1/100}}]

Out[172]= {1.94398*10^6, {d -> 4.00704, n -> 0.0125096}}

I don't know if these are sensible values for your problem.

POSTED BY: Gianluca Gorni
Posted 12 days ago

I run your first block of code and I get the error that you get. But it doesn't really clearly show me why something is not numeric. So I try

F[0.999994,1] // InputForm

and I get

Out[8]//InputForm= -598.2275653440438 - 11.063835115005528*(57.25000000000001*
  (-Log[121] + Log[1 + 1.*(-1 + k/2)^1.]) - 57.25000000000001*Log[(-1 + k/2)/120])

and it is clear that the error message is correct, that is not a real number because k has not been assigned any numeric value. I look at all your variable assignments and see that is correct.

I have no idea what k should be so I try a few simple ideas. I try including k=2 and restart and it fails because the value for F[0.999994,1] is -infinity. I try k=1 and it fails. I try k=4 and it fails.

If you know what value k should have to give a real numeric value for F then this might let you find the maximum.

POSTED BY: Bill Nelson
Posted 12 days ago

Hi, thank you for your help!

After reviewing my work, I realized I made a mistake in the equation for Tf, which includes K. I had written it as:

Tf = - (Log[1/z (k/ww - 1)]/q);

But it should actually be:

Tf = - (Log[1/z (g/ww - 1)]/q);

Where g has a value of 6.87. According to the paper, the equation looks like this:

enter image description here

But after correcting the equation, I’m still encountering the following error:

FindMaximum::nrnum: The function value -2.5726110^29 + 2.5726110^29 I is not a real number at {d,n} = {985.615,-217184.}.

General::stop: Further output of FindMaximum::nrnum will be suppressed during this calculation.

IPOPTMinimize::badobj: Invalid objective function. The objective function doesn't evaluate to a real-valued numeric result at the initial point.

FindMaximum::nrgnum: The gradient is not a vector of real numbers at {d,n} = {985.5,-217184.}.

FindMaximum::conv: Interior point method fails to converge.

Do you have any suggestions on how I can fix this issue? It seems that the function is still returning non-real values, and the method fails to converge.

POSTED BY: Shafa Hananta
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract