1、层次分析报告法C#代码层次分析法Analitic Hierachy Process (AHP)一、需求分析问题举例 1. 在海尔、新飞、容声和雪花四个牌号的电冰箱中选购一种。要考虑品牌的信誉、冰箱的功能、价格和耗电量。 2. 在泰山、杭州和承德三处选择一个旅游点。要考虑景点的景色、居住的环境、饮食的特色、交通便利和旅游的费用。 3. 在基础研究、应用研究和数学教育中选择一个领域申报科研课题。要考虑成果的贡献(实用价值、科学意义),可行性(难度、周期和经费)和人才培养。模型和方法 1. 层次结构模型的构造步骤一:确定层次结构,将决策的目标、考虑的因素(决策准则)和决策对象按它们之间的相互关系分为
2、最高层、中间层和最低层,绘出层次结构图。 最高层:决策的目的、要解决的问题。 最低层:决策时的备选方案。 中间层:考虑的因素、决策的准则。 对于相邻的两层,称高层为目标层,低层为因素层。步骤二: 通过相互比较,确定下一层各因素对上一层目标的影响的权重,将定性的判断定量化,即构造因素判断矩阵。步骤三:由矩阵的特征值确定判别的一致性;由相应的特征向量表示各因素的影响权重,计算权向量。步骤四: 通过综合计算给出最底层(各方案)对最高层(总目标)影响的权重,权重最大的方案即为实现目标的最由选择。2. 因素判断矩阵比较n个因素y=(y1,y2,yn)对目标 z 的影响.采用两两成对比较,用aij表示因素
3、 yi与因素yj对目标z的影响程度之比。 通常用数字 1 9及其倒数作为程度比较的标度, 即九级标度法xi/xj 相当 较重要 重要 很重要 绝对重要aij 1 3 5 7 9 2, 4, 6, 8 居于上述两个相邻判断之间。当aij 1时,对目标 Z来说 xi 比 xj重要, 其数值大小表示重要的程度。同时必有 aji = 1/ aij 1,对目标 Z来说 xj比 xi 不重要,其数值大小表示不重要的程度。称矩阵 A = ( aij )为因素判断矩阵。因为 aij 0 且 aji =1/ aij 故称A = (aij )为正互反矩阵。例. 选择旅游景点 Z:目标,选择景点 y
4、:因素,决策准则 y1 费用,y2 景色,y3 居住,y4 饮食,y5 交通3. 一致性与权向量如果 aij ajk =aik i, j, k=1,2,n, 则称正互反矩阵A具有一致性. 这表明对各个因素所作的两两比较是可传递的。 一致性互正反矩阵A=( aij )具有性质:A的每一行(列)均为任意指定行(列)的正数倍数,因此 rank(A)=1.A有特征值=n, 其余特征值均为零.记A的对应特征值=n的特征向量为w=(w1 w2 , wn) 则 aij =wi wj-1如果在目标z中n个因素y=(y1,y2,yn)所占比重分别为w=(w1 w2 , wn),
5、则 iwi =1, 且因素判断矩阵为 A=(wi wj-1) 。因此,称一致性正互反矩阵A相应于特征值n的归一化特征向量为因素y=(y1,y2,yn)对目标z的权向量 4. 一致性检验与因素排序定理1: n阶正互反矩阵A是一致性的当且仅当其最大特征值为 n.定理2: 正互反矩阵具有模最大的正实数特征值1, 其重数为1, 且相应特征向量为正向量.为刻画n阶正互反矩阵A=( aij )与一致性接近的程度, 定义一致性指标(Consensus index) : CI=(1-n)/(n-1)CI = 0, A 有完全的一致性。CI 接近于 0, A 有满
6、意的一致性 。 Saaty又引入平均随机一致性指标RTn 1 2 3 4 5 6 7 8 9RI 0 0 0.58 0.90 1.12 1.24 1.32 1.41 1.45当CR = CI / RI 0.1 时, 认为A 有满意的一致性。此时取A 的相应于1 的归一化特征向量w=(w1 w2 , wn)为因素y=(y1,y2,yn)对目标z的权向量。由w=( w2 , wn)分量wi的大小可以对因素的重要性排序。 择校排名二、使用的知识要点 1.动态生成控件三、主程序界面四、主要程序段动态生本控件,并加上相应所需要的方法: /初始化文本框 private void Inite
7、xtbox(int len,string str) this.groupBox1.Controls.Clear();/清空不用的控件 TextBox mytextbox;/定义文本框 int x=this.groupBox1.Location.X+10; int y=this.groupBox1.Location.Y+40; for(int i = 0; ilen;i+)/生成标签 Label mylabel = new Label(); mylabel.Text = stri.ToString(); mylabel.Location = new Point(x+i*60,y-40); myl
8、abel.AutoSize = true; this.groupBox1.Controls.Add(mylabel); for(int i=0;ilen;i+)/生成文本框 for(int j=0;jlen;j+) mytextbox = new TextBox(); mytextbox.Size = new System.Drawing.Size(60,20); mytextbox.BackColor = Color.LightGoldenrodYellow; mytextbox.Name = mytextbox+i+j; mytextbox.Leave += new System.Even
9、tHandler(this.textBox_mouseover); mytextbox.Location = new Point(x,y); if(i=j) mytextbox.BackColor = Color.Wheat; mytextbox.Text = 1; mytextbox.Enabled = false; if(i0) tempC.Text = temptextbox.Text.ToString().Substring(temptextbox.Text.ToString().Trim().Length-1,1); else if(temptextbox.Text.ToString
10、().Trim()=1) tempC.Text = 1; else tempC.Text = 1/+temptextbox.Text; /textBox_mouseover获取第个文本框的值: private void getdata(double, matrix) foreach(Control tempC in this.groupBox1.Controls) try if(tempC is TextBox) string tempstr = tempC.Text.ToString().Trim(); if(tempstr = ) MessageBox.Show(有文本框没有填数据!);
11、return; int i = Convert.ToInt32(tempC.Name.ToString().Substring(tempC.Name.ToString().Length-2,1); int j = Convert.ToInt32(tempC.Name.ToString().Substring(tempC.Name.ToString().Length-1,1); if(tempstr.IndexOf(/)0) matrixi,j = Convert.ToDouble(tempstr.Substring(0,1)/Convert.ToDouble(tempstr.Substring
12、(tempstr.Length-1,1); else matrixi,j=Convert.ToDouble(tempstr); catch(Exception err) MessageBox.Show(err.ToString(); 五、所有程序代码using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace 经济管理模型 / / ccfx2 的摘要说明。 / public class ccfx2 : Syst
13、em.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;/准则数 private System.Int32 LenB;/方案数 private double, zhuzematrix;/准则数方阵 private double, fanganmatrix;/方案阵 private string zhuze;/准则字符串 private string fangan;/方案字符串 private int Stepcount=0;/录入矩
14、阵的步骤 private double W;/单序w private double, TW;/总序w private double Torder;/总的方案排名 private double lamda;/单序最大lamda private double Tlamda;/总序lamda private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label5; private System.Windows.Forms.Button button1; private System.Wind
15、ows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button2; / / 必需的设计器变量。 / private System.ComponentModel.Container components = null; public ccfx2() / /
16、Windows 窗体设计器支持所必需的 / InitializeComponent(); / / TODO: 在 InitializeComponent 调用后添加任何构造函数代码 / / / 清理所有正在使用的资源。 / protected override void Dispose( bool disposing ) if( disposing ) if(components != null) components.Dispose(); base.Dispose( disposing ); #region Windows 窗体设计器生成的代码 / / 设计器支持所需的方法 - 不要使用代码
17、编辑器修改 / 此方法的内容。 / private void InitializeComponent() this.groupBox1 = new System.Windows.Forms.GroupBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.La
18、bel(); this.label5 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); / / groupBox1 / this.groupBox1.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.
19、Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); this.groupBox1.Controls.Add(this.textBox2); this.groupBox1.Controls.Add(this.textBox1); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Location = new System.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1