Scale [A,B] to [0,1], and buy 100% of your tank from the first station if its price is below 0.2583, then repeat for the remaining stations with limits 0.3047, 0.375, 0.5, and 1.
Solution explanation:
Here is a solution for strategies of a certain form: Before departing, declare a threshold price $T_i$ for each gas station $i \in \{1,2,3,4,5\}$. Upon arriving at station $i$, fill up 100% of the tank if the station's price is less than or equal to $T_i$. What are the optimal thresholds?
I conjecture that a strategy of this form is optimal, as the total cost we are optimizing is linear with respect to the price you end up paying. As such, I don't see any reason why you would ever do a partial fillup. If we were optimizing a nonlinear function, like the utility of your money, or the probability that you would spend less than some bound, then I could see reasons for a partial fill.
Assume each station's price $P_i$ is uniformly distributed on $[0,1]$ (for simplicity, this will be the price to fill up the entire tank, and can be scaled to $[A,B]$ at the end). We also must enforce $T_5 = 1$ to ensure that the tank is eventually full. Then, the expected cost of the fillup is
$E[Cost] = \sum_{i=1}^5E[P_i$ assuming $P_i \leq T_i]*Prob(P_i \leq T_i)*Prob(P_j > T_j$ for all $j < i)$.
Given that all prices are uniformly distributed (and assuming all thresholds are in $[0,1]$), we can write $Prob(P_i \leq T_i) = T_i$ and $E[P_i$ assuming $P_i \leq T_i]=\frac{T_i}{2}$. Then, the expected cost is
$E[Cost] = \left[T_1^2 + T_2^2(1-T_1)+T_3^2(1-T_1)(1-T_2)+T_4^2(1-T_1)(1-T_2)(1-T_3)+(1-T_1)(1-T_2)(1-T_3)(1-T_4)\right]*\frac{1}{2}.$
This is a function of four variables, and I used Wolfram Alpha to compute the local minimum. It returned
min{T_1^2 + T_2^2 (1 - T_1) + T_3^2 (1 - T_1) (1 - T_2) + T_4^2 (1 - T_1) (1 - T_2) (1 - T_3) + (1 - T_1) (1 - T_2) (1 - T_3) (1 - T_4)} = 483008799/1073741824 at (T_1, T_2, T_3, T_4) = (8463/32768, 39/128, 3/8, 1/2)
Therefore, you would expect to pay $\frac{483008799}{1073741824}*\frac{1}{2} \approx 0.2249$ on average using thresholds $(\frac{8463}{32768}, \frac{39}{128}, \frac{3}{8}, \frac{1}{2}, 1) \approx (0.2583, 0.3047, 0.375, 0.5, 1).$
To scale prices to $[A,B]$, multiply each value by $(B-A)$ and add $A$.