層次分析法C#代碼(共22頁(yè))_第1頁(yè)
層次分析法C#代碼(共22頁(yè))_第2頁(yè)
層次分析法C#代碼(共22頁(yè))_第3頁(yè)
層次分析法C#代碼(共22頁(yè))_第4頁(yè)
層次分析法C#代碼(共22頁(yè))_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、層次分析法Analitic Hierachy Process (AHP)一、需求分析問(wèn)題舉例    1. 在海爾、新飛、容聲和雪花四個(gè)牌號(hào)的電冰箱中選購(gòu)一種。要考慮品牌的信譽(yù)、冰箱的功能、價(jià)格和耗電量。    2. 在泰山、杭州和承德三處選擇一個(gè)旅游點(diǎn)。要考慮景點(diǎn)的景色、居住的環(huán)境、飲食的特色、交通便利和旅游的費(fèi)用。    3. 在基礎(chǔ)研究、應(yīng)用研究和數(shù)學(xué)教育中選擇一個(gè)領(lǐng)域申報(bào)科研課題。要考慮成果的貢獻(xiàn)(實(shí)用價(jià)值、科學(xué)意義),可行性(難度、周期和經(jīng)費(fèi))和人才培養(yǎng)。模型和方法  1. 層次結(jié)構(gòu)模型的構(gòu)造步驟一:確定層次結(jié)構(gòu),將

2、決策的目標(biāo)、考慮的因素(決策準(zhǔn)則)和決策對(duì)象按它們之間的相互關(guān)系分為最高層、中間層和最低層,繪出層次結(jié)構(gòu)圖。      最高層:決策的目的、要解決的問(wèn)題。      最低層:決策時(shí)的備選方案。      中間層:考慮的因素、決策的準(zhǔn)則。        對(duì)于相鄰的兩層,稱高層為目標(biāo)層,低層為因素層。步驟二: 通過(guò)相互比較,確定下一層各因素對(duì)上一層目標(biāo)的影響的權(quán)重,將定性的判斷定量化,即構(gòu)造因素判斷矩陣。步驟三:由矩陣的特征值確定判別的一致性;由相應(yīng)的特征向量表示各因素

3、的影響權(quán)重,計(jì)算權(quán)向量。步驟四: 通過(guò)綜合計(jì)算給出最底層(各方案)對(duì)最高層(總目標(biāo))影響的權(quán)重,權(quán)重最大的方案即為實(shí)現(xiàn)目標(biāo)的最由選擇。2. 因素判斷矩陣比較n個(gè)因素y=(y1,y2,yn)對(duì)目標(biāo) z 的影響.采用兩兩成對(duì)比較,用aij表示因素 yi與因素yj對(duì)目標(biāo)z的影響程度之比。 通常用數(shù)字 1 9及其倒數(shù)作為程度比較的標(biāo)度, 即九級(jí)標(biāo)度法xi/xj  相當(dāng)    較重要    重要    很重要  絕對(duì)重要aij            1 

4、            3        5        7        9  2, 4, 6, 8  居于上述兩個(gè)相鄰判斷之間。當(dāng)aij > 1時(shí),對(duì)目標(biāo) Z來(lái)說(shuō) xi 比 xj重要, 其數(shù)值大小表示重要的程度。同時(shí)必有 aji = 1/ aij 1,對(duì)目標(biāo) Z來(lái)說(shuō) xj比 xi 不重要,其數(shù)值大小表示不重要的程度。稱矩陣 A = ( aij )為因素判斷矩陣。

5、因?yàn)?#160; aij >0 且 aji =1/ aij  故稱A = (aij )為正互反矩陣。例. 選擇旅游景點(diǎn)  Z:目標(biāo),選擇景點(diǎn)  y:因素,決策準(zhǔn)則  y1 費(fèi)用,y2 景色,y3 居住,y4 飲食,y5 交通3. 一致性與權(quán)向量如果  aij ajk =aik  i, j, k=1,2,n, 則稱正互反矩陣A具有一致性.  這表明對(duì)各個(gè)因素所作的兩兩比較是可傳遞的。 一致性互正反矩陣A=( aij )具有性質(zhì):A的每一行(列)均為任意指定行(列)的正數(shù)倍數(shù),因此 rank(A)=1.A有特征值&

6、#61548;=n,  其余特征值均為零.記A的對(duì)應(yīng)特征值=n的特征向量為w=(w1 w2 , wn)    則  aij =wi wj-1如果在目標(biāo)z中n個(gè)因素y=(y1,y2,yn)所占比重分別為w=(w1 w2 , wn),  則 iwi =1, 且因素判斷矩陣為  A=(wi wj-1) 。因此,稱一致性正互反矩陣A相應(yīng)于特征值n的歸一化特征向量為因素y=(y1,y2,yn)對(duì)目標(biāo)z的權(quán)向量  4. 一致性檢驗(yàn)與因素排序定理1: n階正互反矩陣A是一致性的當(dāng)且僅當(dāng)其最大

7、特征值為 n.定理2: 正互反矩陣具有模最大的正實(shí)數(shù)特征值1, 其重?cái)?shù)為1, 且相應(yīng)特征向量為正向量.為刻畫n階正互反矩陣A=( aij )與一致性接近的程度, 定義一致性指標(biāo)(Consensus index) :               CI=(1-n)/(n-1)CI = 0,  A 有完全的一致性。CI  接近于 0,  A  有滿意的一致性 。 Saaty又引入平均隨機(jī)一致性指標(biāo)RTn    1 

8、   2    3      4      5      6      7      8      9RI    0    0    0.58    0.90    1.12    1.24    1.32    1.41

9、0;   1.45當(dāng)CR = CI / RI < 0.1 時(shí),  認(rèn)為A 有滿意的一致性。此時(shí)取A 的相應(yīng)于&#61548;1 的歸一化特征向量w=(w1 w2 , wn)為因素y=(y1,y2,yn)對(duì)目標(biāo)z的權(quán)向量。由w=( w2 , wn)分量wi的大小可以對(duì)因素的重要性排序。 擇校排名二、使用的知識(shí)要點(diǎn)  1.動(dòng)態(tài)生成控件三、主程序界面四、主要程序段動(dòng)態(tài)生本控件,并加上相應(yīng)所需要的方法:        /初始化文本框        private void Ini

10、textbox(int len,string str)                    this.groupBox1.Controls.Clear();/清空不用的控件            TextBox mytextbox;/定義文本框            int x=this.groupBox1.Location.X+10;     

11、       int y=this.groupBox1.Location.Y+40;            for(int i = 0; i<len;i+)/生成標(biāo)簽                            Label mylabel = new Label();            &

12、#160;   mylabel.Text = stri.ToString();                mylabel.Location = new Point(x+i*60,y-40);                mylabel.AutoSize = true;                this.groupBox1.Control

13、s.Add(mylabel);                        for(int i=0;i<len;i+)/生成文本框                            for(int j=0;j<len;j+)             

14、                      mytextbox = new TextBox();                    mytextbox.Size = new System.Drawing.Size(60,20);                    mytextbox

15、.BackColor = Color.LightGoldenrodYellow;                    mytextbox.Name = "mytextbox"+i+j;                    mytextbox.Leave += new System.EventHandler(this.textBox_mouseover);   &#

16、160;                 mytextbox.Location = new Point(x,y);                    if(i=j)                                    

17、         mytextbox.BackColor = Color.Wheat;                        mytextbox.Text = "1"                        mytextbox.Enabled = false;   

18、                                     if(i<j)                                            mytextbox

19、.BackColor = SystemColors.ActiveBorder;                        mytextbox.Enabled = false;                                        this.groupB

20、ox1.Controls.Add(mytextbox);                    x+=60;                                x=this.groupBox1.Location.X+10;              

21、0; y+=20;                    相應(yīng)的方法:        /控制文本框        private void textBox_mouseover(object sender,System.EventArgs e)                    TextBox temptextbox

22、 = (TextBox) sender;            string tempstr = temptextbox.Name.ToString();            if(temptextbox.Text.Trim() = "")                         /    MessageBo

23、x.Show("沒(méi)有輸入數(shù)字");            /    temptextbox.Focus();                        else                            string i =

24、 tempstr.Substring(tempstr.Length-2,1);                string j =  tempstr.Substring(tempstr.Length-1,1);                foreach(Control tempC in this.groupBox1.Controls)            

25、60;                       if(tempC is TextBox)                                            if(tempC.Name.ToString() = "mytextbox&qu

26、ot;+j+i)                                                    if(temptextbox.Text.ToString().Trim().IndexOf("/")>0)            &#

27、160;                   tempC.Text = temptextbox.Text.ToString().Substring(temptextbox.Text.ToString().Trim().Length-1,1);                            else if(temptextbox.Text.ToString().

28、Trim()="1")                                tempC.Text = "1"                            else          

29、0;                     tempC.Text = "1/"+temptextbox.Text;                                                   

30、                            /textBox_mouseover獲取第個(gè)文本框的值:        private void getdata(double, matrix)                    foreach(Control tempC in this.groupBox1.

31、Controls)                            try                                    if(tempC is TextBox)            &#

32、160;                               string tempstr = tempC.Text.ToString().Trim();                        if(tempstr = "")         

33、                                           MessageBox.Show("有文本框沒(méi)有填數(shù)據(jù)!");                            return; 

34、                                              int i = Convert.ToInt32(tempC.Name.ToString().Substring(tempC.Name.ToString().Length-2,1);             

35、          int j = Convert.ToInt32(tempC.Name.ToString().Substring(tempC.Name.ToString().Length-1,1);                        if(tempstr.IndexOf("/")>0)              

36、60;                                     matrixi,j = Convert.ToDouble(tempstr.Substring(0,1)/Convert.ToDouble(tempstr.Substring(tempstr.Length-1,1);                 

37、                              else                            matrixi,j=Convert.ToDouble(tempstr);                &

38、#160;                                   catch(Exception err)                                    MessageBox.Show(err.ToString(

39、);                                    五、所有程序代碼using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace 經(jīng)濟(jì)管理模型    / <summary>

40、60;   / ccfx2 的摘要說(shuō)明。    / </summary>    public class ccfx2 : System.Windows.Forms.Form            private static double RI = 0,0,0,0.58,0.90,1.12,1.24,1.32,1.41,1.45;        private Int32 LenA;/準(zhǔn)則數(shù)      &

41、#160; private System.Int32 LenB;/方案數(shù)        private double, zhuzematrix;/準(zhǔn)則數(shù)方陣        private double, fanganmatrix;/方案陣        private string zhuze;/準(zhǔn)則字符串        private string fangan;/方案字符串        pr

42、ivate int Stepcount=0;/錄入矩陣的步驟        private double W;/單序w        private double, TW;/總序w        private double Torder;/總的方案排名        private double lamda;/單序最大lamda        private double Tlamda;/總序l

43、amda        private System.Windows.Forms.GroupBox groupBox1;        private System.Windows.Forms.Label label5;        private System.Windows.Forms.Button button1;        private System.Windows.Forms.Label label1;  &

44、#160;     private System.Windows.Forms.Label label2;        private System.Windows.Forms.TextBox textBox1;        private System.Windows.Forms.TextBox textBox2;        private System.Windows.Forms.Button button2;    

45、0;   / <summary>        / 必需的設(shè)計(jì)器變量。        / </summary>        private System.ComponentModel.Container components = null;        public ccfx2()                

46、0;   /            / Windows 窗體設(shè)計(jì)器支持所必需的            /            InitializeComponent();            /            / TODO: 在 InitializeComponent 調(diào)用后添

47、加任何構(gòu)造函數(shù)代碼            /                / <summary>        / 清理所有正在使用的資源。        / </summary>        protected override void Dispose( bool disposing )  

48、60;                 if( disposing )                            if(components != null)                             

49、      components.Dispose();                                        base.Dispose( disposing );                #region Windows 窗體設(shè)計(jì)器生成的代碼  

50、60;     / <summary>        / 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改        / 此方法的內(nèi)容。        / </summary>        private void InitializeComponent()                  

51、60; this.groupBox1 = new System.Windows.Forms.GroupBox();            this.textBox2 = new System.Windows.Forms.TextBox();            this.textBox1 = new System.Windows.Forms.TextBox();            this.label2 = n

52、ew System.Windows.Forms.Label();            this.label1 = new System.Windows.Forms.Label();            this.label5 = new System.Windows.Forms.Label();            this.button1 = new System.Windows.Forms.Button()

53、;            this.button2 = new System.Windows.Forms.Button();            this.groupBox1.SuspendLayout();            this.SuspendLayout();            /        

54、    / groupBox1            /             this.groupBox1.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)              

55、;   | System.Windows.Forms.AnchorStyles.Left)                 | System.Windows.Forms.AnchorStyles.Right);            this.groupBox1.Controls.Add(this.textBox2);            this.groupBox1.Controls

56、.Add(this.textBox1);            this.groupBox1.Controls.Add(this.label2);            this.groupBox1.Controls.Add(this.label1);            this.groupBox1.Location = new System.Drawing.Point(0, 8);    &

57、#160;       this.groupBox1.Name = "groupBox1"            this.groupBox1.Size = new System.Drawing.Size(616, 360);            this.groupBox1.TabIndex = 15;            this.groupBox1.TabS

58、top = false;            /             / textBox2            /             this.textBox2.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.

59、Windows.Forms.AnchorStyles.Left)                 | System.Windows.Forms.AnchorStyles.Right);            this.textBox2.BackColor = System.Drawing.Color.Ivory;            this.textBox2.Location = new Sy

60、stem.Drawing.Point(128, 80);            this.textBox2.Name = "textBox2"            this.textBox2.Size = new System.Drawing.Size(472, 20);            this.textBox2.TabIndex = 3;      

61、60;     this.textBox2.Text = ""            /             / textBox1            /             this.textBox1.Anchor = (System.Windows.Forms.AnchorStyles)(System.W

62、indows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)                 | System.Windows.Forms.AnchorStyles.Right);            this.textBox1.BackColor = System.Drawing.Color.Ivory;         

63、   this.textBox1.Location = new System.Drawing.Point(128, 48);            this.textBox1.Name = "textBox1"            this.textBox1.Size = new System.Drawing.Size(472, 20);            this.textBox

64、1.TabIndex = 2;            this.textBox1.Text = ""            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);            /             /

65、label2            /             this.label2.Location = new System.Drawing.Point(24, 80);            this.label2.Name = "label2"            this.label2.TabIndex = 1; 

66、           this.label2.Text = "方案:"            /             / label1            /             this.label1.Location = new System.Drawing.Point(24

67、, 48);            this.label1.Name = "label1"            this.label1.TabIndex = 0;            this.label1.Text = "準(zhǔn)則:"            /        

68、    / label5            /             this.label5.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)               

69、60; | System.Windows.Forms.AnchorStyles.Right);            this.label5.AutoSize = true;            this.label5.ForeColor = System.Drawing.Color.Red;            this.label5.Location = new System.Drawing.Point(16

70、, 384);            this.label5.Name = "label5"            this.label5.Size = new System.Drawing.Size(0, 16);            this.label5.TabIndex = 16;            /   

71、60;         / button1            /             this.button1.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);        

72、60;   this.button1.Location = new System.Drawing.Point(456, 384);            this.button1.Name = "button1"            this.button1.TabIndex = 17;            this.button1.Text = "下一步"

73、60;           this.button1.Click += new System.EventHandler(this.button1_Click);            /             / button2            /             this.button2.A

74、nchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);            this.button2.Location = new System.Drawing.Point(536, 384);            this.button2.Name = "but

75、ton2"            this.button2.TabIndex = 21;            this.button2.Text = "從例子獲取"            this.button2.Click += new System.EventHandler(this.button2_Click);         

76、   /             / ccfx2            /             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);            this.ClientSize = new System.Drawing.Size(616, 421); 

77、;           this.Controls.Add(this.button2);            this.Controls.Add(this.button1);            this.Controls.Add(this.label5);            this.Controls.Add(this.groupBox1);  &

78、#160;         this.Name = "ccfx2"            this.Text = "層次分析法"            this.Load += new System.EventHandler(this.ccfx2_Load);            this.groupBox1.ResumeLayout(

79、false);            this.ResumeLayout(false);                #endregion        private void ccfx2_Load(object sender, System.EventArgs e)                    

80、0;   /初始化變量        private void InitValue()/                    /錄入準(zhǔn)則字符串            this.zhuze = this.textBox1.Text.ToString().Trim().Split(',');           

81、this.fangan = this.textBox2.Text.ToString().Trim().Split(',');            this.LenA = zhuze.Length;            this.LenB = fangan.Length;            if(this.LenA !=5 | this.LenB != 3) this.button2.Visib

82、le = false;            /=實(shí)例化各變量            this.zhuzematrix = new doublethis.LenA,this.LenA;            this.fanganmatrix = new doublethis.LenA,;            for(int i = 0;i<LenA

83、;i+)                this.fanganmatrixi = new doubleLenB,LenB;            this.W = new doubleLenA;            this.TW = new doubleLenA,LenB;            this.Torder = new d

84、oubleLenB;            this.Tlamda = new doubleLenA;            /=            this.groupBox1.Controls.Clear();            this.label5.Text="請(qǐng)輸入準(zhǔn)則層相對(duì)目標(biāo)的判別矩陣"    &

85、#160;           /初始化文本框        private void Initextbox(int len,string str)                    this.groupBox1.Controls.Clear();/清空不用的控件            TextBox mytextbox;/定義文本框 

86、;           int x=this.groupBox1.Location.X+10;            int y=this.groupBox1.Location.Y+40;            for(int i = 0; i<len;i+)/生成標(biāo)簽                     

87、      Label mylabel = new Label();                mylabel.Text = stri.ToString();                mylabel.Location = new Point(x+i*60,y-40);                mylabel.Au

88、toSize = true;                this.groupBox1.Controls.Add(mylabel);                        for(int i=0;i<len;i+)/生成文本框                      &#

89、160;     for(int j=0;j<len;j+)                                    mytextbox = new TextBox();                    mytextbox.Size = new System.Drawing

90、.Size(60,20);                    mytextbox.BackColor = Color.LightGoldenrodYellow;                    mytextbox.Name = "mytextbox"+i+j;               

91、     mytextbox.Leave += new System.EventHandler(this.textBox_mouseover);                    mytextbox.Location = new Point(x,y);                    if(i=j)          

92、                                   mytextbox.BackColor = Color.Wheat;                        mytextbox.Text = "1"        

93、0;               mytextbox.Enabled = false;                                        if(i<j)                    &#

94、160;                       mytextbox.BackColor = SystemColors.ActiveBorder;                        mytextbox.Enabled = false;                

95、0;                       this.groupBox1.Controls.Add(mytextbox);                    x+=60;                             

96、  x=this.groupBox1.Location.X+10;                y+=20;                            /控制文本框        private void textBox_mouseover(object sender,System.EventArgs e)

97、0;                   TextBox temptextbox = (TextBox) sender;            string tempstr = temptextbox.Name.ToString();            if(temptextbox.Text.Trim() = "")       &#

98、160;                 /    MessageBox.Show("沒(méi)有輸入數(shù)字");            /    temptextbox.Focus();                        else      &#

99、160;                     string i = tempstr.Substring(tempstr.Length-2,1);                string j =  tempstr.Substring(tempstr.Length-1,1);                foreach(C

100、ontrol tempC in this.groupBox1.Controls)                                    if(tempC is TextBox)                                            if(tempC.Name.ToString() = "mytextbox"+j+i)                                                    if(t

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論