<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Change Dir

    先知cd——熱愛生活是一切藝術的開始

    統計

    留言簿(18)

    積分與排名

    “牛”們的博客

    各個公司技術

    我的鏈接

    淘寶技術

    閱讀排行榜

    評論排行榜

    深入理解動態規劃的一系列問題(11)

    動態規劃本質上的問題基本就如之前所述,之前的問題也都比較簡單。復雜的動態規劃問題有幾種表現,其中之一就是成本函數計算復雜,狀態轉移過程需要考慮的細節比較多。今天講的這個問題就滿足這個條件:DPP問題(Discounted Profits Problem)

    問題是這樣的:假設有一個湖,湖里有一些魚,在第一年有b1條魚,之后在第t年開始有bt條魚。漁民靠捕魚賣魚為生,在第t年賣掉xt條魚的話,可以有r(xt)的收益。當然捕獲這些魚也會造成c(xt,bt)的成本。魚群每年會自然繁殖,假定繁殖規律是固定的,每年以s的比例自然增長。同樣漁民手里的錢存在銀行每年也會有固定利息y。請問從第一年開始到第T年,每年應該怎么捕魚才能使利益最大化,不能竭澤而漁,當然也不能等著餓死。

    乍一看這個描述,目標很明確——最大化利益,但是條件N多,在DP求解時,要仔細考慮清楚狀態轉移方程中核心的優化條件。首先我們定義狀態,年份t是個天然的stage維度,那么要知道利益,已知條件有收益函數、成本函數、增長比例和固定利息,共同的需求就是魚的數量b,于是狀態就是(t,b),因為t在1~T之間(這本身也是遞歸收斂條件),所以DPFE方程為分段方程:f(t,b)=0當且僅當t>T,當t≤T時,f(t,b)=max xt∈{0,…,b} {r(xt)-c(xt,b)+1/(1+y) * f(t+1,s(b-xt)} 。具體解釋一下,就是我們算t年b條魚時的利益時,假設捕xt條魚,那么利益等價于賣魚收益r(xt)減去捕魚成本c(xt,b),再加上明年收益及利息。

    看起來蠻復雜的問題,其實核心的狀態定義清楚后,邏輯理清,條件雖然多,但是復雜度只增加在了目標計算上,這樣的問題對于DP里來說個人認為算是不太復雜的。

    實際例子,我們假設T=2,y=0.05,s=2,初始b1=10(單位是千條),收益函數也線性化表示為3xt,成本函數簡化為2xt,這樣收益我們實際是在求f(1,10),答案輸出是19.05,其最優化決策是x1=0,x2=20,即第一年不捕魚,第二年捕完所有魚~~(這個變態的決策,有點。。。。。。)

    源碼:

       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: }

    posted on 2014-05-19 13:57 changedi 閱讀(1853) 評論(0)  編輯  收藏 所屬分類: 算法

    主站蜘蛛池模板: eeuss草民免费| 九九免费精品视频在这里| 无码AV片在线观看免费| 丁香五月亚洲综合深深爱| GOGOGO高清免费看韩国| 亚洲人成色7777在线观看不卡| 国产精品亚洲综合网站| 亚洲区小说区图片区| av网站免费线看| 亚洲AV永久精品爱情岛论坛| 日韩精品无码专区免费播放| 亚洲欧洲视频在线观看| 国产免费av片在线看| 老司机午夜免费视频| 久久亚洲高清综合| 国产成人免费视频| 中文字幕 亚洲 有码 在线| 国产精品免费视频播放器| 羞羞视频在线观看免费| 久久噜噜噜久久亚洲va久| 日产国产精品亚洲系列| yellow免费网站| 亚洲成A∨人片在线观看不卡| 日韩精品久久久久久免费| 亚洲中文字幕一区精品自拍| 亚洲成av人片一区二区三区| 久久久久久国产精品免费免费男同 | 花蝴蝶免费视频在线观看高清版 | 亚洲AV综合色区无码二区偷拍| 日韩免费一级毛片| 三年片免费观看大全国语| 亚洲无砖砖区免费| 国色精品va在线观看免费视频| 亚洲码在线中文在线观看| 国产美女精品久久久久久久免费| 精品国产免费一区二区三区| 亚洲综合无码一区二区三区| 免费一级毛片清高播放| 97在线视频免费公开观看| 国产成人高清亚洲一区91 | 亚洲AV成人无码天堂|