层次分析法C#代码_第1页
层次分析法C#代码_第2页
层次分析法C#代码_第3页
层次分析法C#代码_第4页
层次分析法C#代码_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上层次分析法Analitic Hierachy Process (AHP)一、需求分析问题举例    1. 在海尔、新飞、容声和雪花四个牌号的电冰箱中选购一种。要考虑品牌的信誉、冰箱的功能、价格和耗电量。    2. 在泰山、杭州和承德三处选择一个旅游点。要考虑景点的景色、居住的环境、饮食的特色、交通便利和旅游的费用。    3. 在基础研究、应用研究和数学教育中选择一个领域申报科研课题。要考虑成果的贡献(实用价值、科学意义),可行性(难度、周期和经费)和人才培养。模型和方法  1. 层次结构模型的构

2、造步骤一:确定层次结构,将决策的目标、考虑的因素(决策准则)和决策对象按它们之间的相互关系分为最高层、中间层和最低层,绘出层次结构图。      最高层:决策的目的、要解决的问题。      最低层:决策时的备选方案。      中间层:考虑的因素、决策的准则。        对于相邻的两层,称高层为目标层,低层为因素层。步骤二: 通过相互比较,确定下一层各因素对上一层目标的影响的权重,将定性的判断定量化,即构造因素判断矩阵。步骤三:由矩阵的特征值确定判别的一致性;

3、由相应的特征向量表示各因素的影响权重,计算权向量。步骤四: 通过综合计算给出最底层(各方案)对最高层(总目标)影响的权重,权重最大的方案即为实现目标的最由选择。2. 因素判断矩阵比较n个因素y=(y1,y2,yn)对目标 z 的影响.采用两两成对比较,用aij表示因素 yi与因素yj对目标z的影响程度之比。 通常用数字 1 9及其倒数作为程度比较的标度, 即九级标度法xi/xj  相当    较重要    重要    很重要  绝对重要aij          &#

4、160; 1              3        5        7        9  2, 4, 6, 8  居于上述两个相邻判断之间。当aij > 1时,对目标 Z来说 xi 比 xj重要, 其数值大小表示重要的程度。同时必有 aji = 1/ aij 1,对目标 Z来说 xj比 xi 不重要,其数值大小表示不重要的程度。称矩阵 A = (

5、aij )为因素判断矩阵。因为  aij >0 且 aji =1/ aij  故称A = (aij )为正互反矩阵。例. 选择旅游景点  Z:目标,选择景点  y:因素,决策准则  y1 费用,y2 景色,y3 居住,y4 饮食,y5 交通3. 一致性与权向量如果  aij ajk =aik  i, j, k=1,2,n, 则称正互反矩阵A具有一致性.  这表明对各个因素所作的两两比较是可传递的。 一致性互正反矩阵A=( aij )具有性质:A的每一行(列)均为任意指定行(列)的正数倍数,因此 rank(A)

6、=1.A有特征值=n,  其余特征值均为零.记A的对应特征值=n的特征向量为w=(w1 w2 , wn)    则  aij =wi wj-1如果在目标z中n个因素y=(y1,y2,yn)所占比重分别为w=(w1 w2 , wn),  则 iwi =1, 且因素判断矩阵为  A=(wi wj-1) 。因此,称一致性正互反矩阵A相应于特征值n的归一化特征向量为因素y=(y1,y2,yn)对目标z的权向量  4. 一致性检验与因素排序定理1: n阶正互反矩阵

7、A是一致性的当且仅当其最大特征值为 n.定理2: 正互反矩阵具有模最大的正实数特征值1, 其重数为1, 且相应特征向量为正向量.为刻画n阶正互反矩阵A=( aij )与一致性接近的程度, 定义一致性指标(Consensus index) :               CI=(1-n)/(n-1)CI = 0,  A 有完全的一致性。CI  接近于 0,  A  有满意的一致性 。 Saaty又引入平均随机一致性指标RTn  &

8、#160; 1    2    3      4      5      6      7      8      9RI    0    0    0.58    0.90    1.12    1.24    1.32  &#

9、160; 1.41    1.45当CR = CI / RI < 0.1 时,  认为A 有满意的一致性。此时取A 的相应于&#61548;1 的归一化特征向量w=(w1 w2 , wn)为因素y=(y1,y2,yn)对目标z的权向量。由w=( w2 , wn)分量wi的大小可以对因素的重要性排序。 择校排名二、使用的知识要点  1.动态生成控件三、主程序界面四、主要程序段动态生本控件,并加上相应所需要的方法:        /初始化文本框        pri

10、vate void Initextbox(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+)/生成标签                            Label mylabel = new Label();        &#

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

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

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

15、60; mytextbox.BackColor = Color.LightGoldenrodYellow;                    mytextbox.Name = "mytextbox"+i+j;                    mytextbox.Leave += new System.EventHandler(this.textBox_mouseove

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

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

18、                                        if(i<j)                                          

19、60; mytextbox.BackColor = SystemColors.ActiveBorder;                        mytextbox.Enabled = false;                                       

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

21、;     y+=20;                    相应的方法:        /控制文本框        private void textBox_mouseover(object sender,System.EventArgs e)                    TextBo

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

23、60; MessageBox.Show("没有输入数字");            /    temptextbox.Focus();                        else                          

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

25、0;                           if(tempC is TextBox)                                            if(tempC.Name.ToString() = "

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

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

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

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

30、#160;                               /textBox_mouseover获取第个文本框的值:        private void getdata(double, matrix)                    foreach(Control tempC in th

31、is.groupBox1.Controls)                            try                                    if(tempC is TextBox)        

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

33、                                              MessageBox.Show("有文本框没有填数据!");                            r

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

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

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

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

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

39、err.ToString();                                    五、所有程序代码using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace 经济管理模型    / <s

40、ummary>    / ccfx2 的摘要说明。    / </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;/准则数  &#

41、160;     private System.Int32 LenB;/方案数        private double, zhuzematrix;/准则数方阵        private double, fanganmatrix;/方案阵        private string zhuze;/准则字符串        private string fangan;/方案字符串    

42、60;   private int Stepcount=0;/录入矩阵的步骤        private double W;/单序w        private double, TW;/总序w        private double Torder;/总的方案排名        private double lamda;/单序最大lamda        private doubl

43、e Tlamda;/总序lamda        private System.Windows.Forms.GroupBox groupBox1;        private System.Windows.Forms.Label label5;        private System.Windows.Forms.Button button1;        private System.Windows.Forms.Label la

44、bel1;        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、;       / <summary>        / 必需的设计器变量。        / </summary>        private System.ComponentModel.Container components = null;        public ccfx2()             

46、;       /            / Windows 窗体设计器支持所必需的            /            InitializeComponent();            /            / TODO: 在 InitializeC

47、omponent 调用后添加任何构造函数代码            /                / <summary>        / 清理所有正在使用的资源。        / </summary>        protected override void Dispose( bool disposin

48、g )                    if( disposing )                            if(components != null)                          &

49、#160;         components.Dispose();                                        base.Dispose( disposing );                #region Windows 窗体设计器生成

50、的代码        / <summary>        / 设计器支持所需的方法 - 不要使用代码编辑器修改        / 此方法的内容。        / </summary>        private void InitializeComponent()              

51、0;     this.groupBox1 = new System.Windows.Forms.GroupBox();            this.textBox2 = new System.Windows.Forms.TextBox();            this.textBox1 = new System.Windows.Forms.TextBox();            th

52、is.label2 = new System.Windows.Forms.Label();            this.label1 = new System.Windows.Forms.Label();            this.label5 = new System.Windows.Forms.Label();            this.button1 = new System.Windows.F

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

54、#160;       / 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.group

56、Box1.Controls.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.g

58、roupBox1.TabStop = false;            /             / textBox2            /             this.textBox2.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.

59、Top | System.Windows.Forms.AnchorStyles.Left)                 | System.Windows.Forms.AnchorStyles.Right);            this.textBox2.BackColor = System.Drawing.Color.Ivory;            this.textBox2.Loca

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

61、0;         this.textBox2.Text = ""            /             / textBox1            /             this.textBox1.Anchor = (System.Windows.Forms.AnchorSty

62、les)(System.Windows.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);           

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

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

66、ex = 1;            this.label2.Text = "方案:"            /             / label1            /             this.label1.Location = new System.Dra

67、wing.Point(24, 48);            this.label1.Name = "label1"            this.label1.TabIndex = 0;            this.label1.Text = "准则:"            /     &

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

69、0;     | System.Windows.Forms.AnchorStyles.Right);            this.label5.AutoSize = true;            this.label5.ForeColor = System.Drawing.Color.Red;            this.label5.Location = new System.Dra

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

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

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

73、;下一步"            this.button1.Click += new System.EventHandler(this.button1_Click);            /             / button2            /             t

74、his.button2.Anchor = (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.Nam

75、e = "button2"            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(61

77、6, 421);            this.Controls.Add(this.button2);            this.Controls.Add(this.button1);            this.Controls.Add(this.label5);            this.Controls.Add(this.groupB

78、ox1);            this.Name = "ccfx2"            this.Text = "层次分析法"            this.Load += new System.EventHandler(this.ccfx2_Load);            this.groupBox1.

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

80、;       /初始化变量        private void InitValue()/                    /录入准则字符串            this.zhuze = this.textBox1.Text.ToString().Trim().Split(',');        &

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

82、button2.Visible = false;            /=实例化各变量            this.zhuzematrix = new doublethis.LenA,this.LenA;            this.fanganmatrix = new doublethis.LenA,;            for(int i

83、= 0;i<LenA;i+)                this.fanganmatrixi = new doubleLenB,LenB;            this.W = new doubleLenA;            this.TW = new doubleLenA,LenB;            this.T

84、order = new doubleLenB;            this.Tlamda = new doubleLenA;            /=            this.groupBox1.Controls.Clear();            this.label5.Text="请输入准则层相对目标的判别矩阵"&#

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

86、x;/定义文本框            int x=this.groupBox1.Location.X+10;            int y=this.groupBox1.Location.Y+40;            for(int i = 0; i<len;i+)/生成标签                  &

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

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

89、60;         for(int j=0;j<len;j+)                                    mytextbox = new TextBox();                    mytextbox.Size = new S

90、ystem.Drawing.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、;                   mytextbox.Enabled = false;                                        if(i<j)                

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

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

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

97、ntArgs e)                    TextBox temptextbox = (TextBox) sender;            string tempstr = temptextbox.Name.ToString();            if(temptextbox.Text.Trim() = "")   

98、60;                     /    MessageBox.Show("没有输入数字");            /    temptextbox.Focus();                        else  

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

100、60; foreach(Control tempC in this.groupBox1.Controls)                                    if(tempC is TextBox)                                            if(tempC.Name.ToString() = "mytextbox"+j+i)                                              &#

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论