1: /*
2: * Copyright (C) 2013 changedi
3: *
4: * Licensed under the Apache License, Version 2.0 (the "License");
5: * you may not use this file except in compliance with the License.
6: * You may obtain a copy of the License at
7: *
8: * http://www.apache.org/licenses/LICENSE-2.0
9: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package com.jybat.dp;
17:
18: //Discounted Profits Problem
19: //A discounted DP problem from Winston/Venkataramanan
20: //pp.779--780
21: //Used a reproductionFactor of 2 instead of 1.2 so number of
22: //fish takes on integral values, without the need to use a
23: //round or a floor function.
24: public class DPP {
25: private static int T = 2; // planning horizon T=2 years
26: private static double interestRate = 0.05; // assume 5% interest rate
27: private static int initialFishAmount = 10; // initially 10,000 fish in lake
28: private static int reproductionFactor = 2; // in 1 year 100% more fish
29:
30: private static double revenue(int xt) {
31: // simply assume that the sale price is $3 per fish, no matter what
32: return 3.0 * xt;
33: }
34:
35: private static double cost(int xt, int b) {
36: // simply assume that it costs $2 to catch (and process) a fish, no
37: // matter what
38: return 2.0 * xt;
39: }
40:
41: // t is stage number, each stage represents one year
42: // b is current number of fish in lake (scaled to thousands)
43: public static double f(int t, int b) {
44: if (t == T + 1)// T+1 is outside planning horizon
45: return 0.0;
46: // xt is the number of fish to catch and sell
47: // during year t
48: int xt;
49: double max = Double.MIN_VALUE;
50: for (xt = 0; xt <= b; xt++) {
51: double earn = revenue(xt) - cost(xt, b) + 1 / (1 + interestRate)
52: * f(t + 1, reproductionFactor * (b - xt));
53: if (earn > max)
54: max = earn;
55: }
56: return max;
57: }
58:
59: /**
60: * @param args
61: */
62: public static void main(String[] args) {
63: System.out.println(f(1, initialFishAmount));
64: }
65:
66: }