层次分析报告法C#代码.docx

上传人:b****7 文档编号:11224879 上传时间:2023-02-25 格式:DOCX 页数:25 大小:22.04KB
下载 相关 举报
层次分析报告法C#代码.docx_第1页
第1页 / 共25页
层次分析报告法C#代码.docx_第2页
第2页 / 共25页
层次分析报告法C#代码.docx_第3页
第3页 / 共25页
层次分析报告法C#代码.docx_第4页
第4页 / 共25页
层次分析报告法C#代码.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

层次分析报告法C#代码.docx

《层次分析报告法C#代码.docx》由会员分享,可在线阅读,更多相关《层次分析报告法C#代码.docx(25页珍藏版)》请在冰豆网上搜索。

层次分析报告法C#代码.docx

层次分析报告法C#代码

层次分析法AnaliticHierachyProcess(AHP)

一、需求分析

问题举例

  1.在海尔、新飞、容声和雪花四个牌号的电冰箱中选购一种。

要考虑品牌的信誉、冰箱的功能、价格和耗电量。

  2.在泰山、杭州和承德三处选择一个旅游点。

要考虑景点的景色、居住的环境、饮食的特色、交通便利和旅游的费用。

  3.在基础研究、应用研究和数学教育中选择一个领域申报科研课题。

要考虑成果的贡献(实用价值、科学意义),可行性(难度、周期和经费)和人才培养。

模型和方法

 1.层次结构模型的构造

步骤一:

确定层次结构,将决策的目标、考虑的因素(决策准则)和决策对象按它们之间的相互关系分为最高层、中间层和最低层,绘出层次结构图。

   最高层:

决策的目的、要解决的问题。

   最低层:

决策时的备选方案。

   中间层:

考虑的因素、决策的准则。

    对于相邻的两层,称高层为目标层,低层为因素层。

步骤二:

通过相互比较,确定下一层各因素对上一层目标的影响的权重,将定性的判断定量化,即构造因素判断矩阵。

步骤三:

由矩阵的特征值确定判别的一致性;由相应的特征向量表示各因素的影响权重,计算权向量。

步骤四:

通过综合计算给出最底层(各方案)对最高层(总目标)影响的权重,权重最大的方案即为实现目标的最由选择。

2.因素判断矩阵

比较n个因素y=(y1,y2,…,yn)对目标z的影响.

采用两两成对比较,用aij表示因素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:

因素,决策准则

 y1费用,y2景色,y3居住,y4饮食,y5交通

3.一致性与权向量

如果 aijajk=aik i,j,k=1,2,…,n,则称正互反矩阵A具有一致性. 这表明对各个因素所作的两两比较是可传递的。

一致性互正反矩阵A=(aij)具有性质:

A的每一行(列)均为任意指定行(列)的正数倍数,因此rank(A)=1.

A有特征值=n, 其余特征值均为零.

记A的对应特征值=n的特征向量为w=(w1w2,…,wn)  则 aij=wiwj-1

如果在目标z中n个因素y=(y1,y2,…,yn)所占比重分别为w=(w1w2,…,wn), 

则iwi=1,且因素判断矩阵为 A=(wiwj-1)。

因此,称一致性正互反矩阵A相应于特征值n的归一化特征向量为因素y=(y1,y2,…,yn)对目标z的权向量 

4.一致性检验与因素排序

定理1:

n阶正互反矩阵A是一致性的当且仅当其最大特征值为n.

定理2:

正互反矩阵具有模最大的正实数特征值1,其重数为1,且相应特征向量为正向量.

为刻画n阶正互反矩阵A=(aij)与一致性接近的程度,定义一致性指标(Consensusindex):

       CI=(1-n)/(n-1)

CI=0, A有完全的一致性。

CI 接近于0, A 有满意的一致性。

Saaty又引入平均随机一致性指标RT

n  1  2  3   4   5   6   7   8   9

RI  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=(w1w2,…,wn)为因素y=(y1,y2,…,yn)对目标z的权向量。

由w=(w2,…,wn)分量wi的大小可以对因素的重要性排序。

择校排名

二、使用的知识要点

 1.动态生成控件

三、主程序界面

四、主要程序段

动态生本控件,并加上相应所需要的方法:

    //初始化文本框

    privatevoidInitextbox(intlen,string[]str)

    {

      this.groupBox1.Controls.Clear();//清空不用的控件

      TextBoxmytextbox;//定义文本框

      intx=this.groupBox1.Location.X+10;

      inty=this.groupBox1.Location.Y+40;

      for(inti=0;i

      {

        Labelmylabel=newLabel();

        mylabel.Text=str[i].ToString();

        mylabel.Location=newPoint(x+i*60,y-40);

        mylabel.AutoSize=true;

        this.groupBox1.Controls.Add(mylabel);

      }

      for(inti=0;i

      {

        for(intj=0;j

        {

          mytextbox=newTextBox();

          mytextbox.Size=newSystem.Drawing.Size(60,20);

          mytextbox.BackColor=Color.LightGoldenrodYellow;

          mytextbox.Name="mytextbox"+i+j;

          mytextbox.Leave+=newSystem.EventHandler(this.textBox_mouseover);

          mytextbox.Location=newPoint(x,y);

          if(i==j)

          {

            mytextbox.BackColor=Color.Wheat;

            mytextbox.Text="1";

            mytextbox.Enabled=false;

          }

          if(i

          {

            mytextbox.BackColor=SystemColors.ActiveBorder;

            mytextbox.Enabled=false;

          }

          this.groupBox1.Controls.Add(mytextbox);

          x+=60;

        }

        x=this.groupBox1.Location.X+10;

        y+=20;

      }

    }

相应的方法:

    //控制文本框

    privatevoidtextBox_mouseover(objectsender,System.EventArgse)

    {

      TextBoxtemptextbox=(TextBox)sender;

      stringtempstr=temptextbox.Name.ToString();

      if(temptextbox.Text.Trim()=="")

      {

      //  MessageBox.Show("没有输入数字");

      //  temptextbox.Focus();

      }

      else

      {

        stringi=tempstr.Substring(tempstr.Length-2,1);

        stringj= tempstr.Substring(tempstr.Length-1,1);

        foreach(ControltempCinthis.groupBox1.Controls)

        {

          if(tempCisTextBox)

          {

            if(tempC.Name.ToString()=="mytextbox"+j+i)

            {

              if(temptextbox.Text.ToString().Trim().IndexOf("/")>0)

                tempC.Text=temptextbox.Text.ToString().Substring(temptextbox.Text.ToString().Trim().Length-1,1);

              elseif(temptextbox.Text.ToString().Trim()=="1")

                tempC.Text="1";

              else

                tempC.Text="1/"+temptextbox.Text;

            }

          }

        }

      }

    }//textBox_mouseover

获取第个文本框的值:

    privatevoidgetdata(double[,]matrix)

    {

      foreach(ControltempCinthis.groupBox1.Controls)

      {

        try

        {

          if(tempCisTextBox)

          {

            stringtempstr=tempC.Text.ToString().Trim();

            if(tempstr=="")

            {

              MessageBox.Show("有文本框没有填数据!

");

              return;

            }

            inti=Convert.ToInt32(tempC.Name.ToString().Substring(tempC.Name.ToString().Length-2,1));

            intj=Convert.ToInt32(tempC.Name.ToString().Substring(tempC.Name.ToString().Length-1,1));

            if(tempstr.IndexOf("/")>0)

            {

              matrix[i,j]=Convert.ToDouble(tempstr.Substring(0,1))/Convert.ToDouble(tempstr.Substring(tempstr.Length-1,1));

            }

            else

              matrix[i,j]=Convert.ToDouble(tempstr);

          }

        }

        catch(Exceptionerr)

        {

          MessageBox.Show(err.ToString());

        }

      }

    }

五、所有程序代码

usingSystem;

usingSystem.Drawing;

usingSystem.Collections;

usingSystem.ComponentModel;

usingSystem.Windows.Forms;

namespace经济管理模型

{

  ///

  ///ccfx2的摘要说明。

  ///

  publicclassccfx2:

System.Windows.Forms.Form

  {

    privatestaticdouble[]RI={0,0,0,0.58,0.90,1.12,1.24,1.32,1.41,1.45};

    privateInt32LenA;//准则数

    privateSystem.Int32LenB;//方案数

    privatedouble[,]zhuzematrix;//准则数方阵

    privatedouble[][,]fanganmatrix;//方案阵

    privatestring[]zhuze;//准则字符串

    privatestring[]fangan;//方案字符串

    privateintStepcount=0;//录入矩阵的步骤

    privatedouble[]W;//单序w

    privatedouble[,]TW;//总序w

    privatedouble[]Torder;//总的方案排名

    privatedoublelamda;//单序最大lamda

    privatedouble[]Tlamda;//总序lamda

    privateSystem.Windows.Forms.GroupBoxgroupBox1;

    privateSystem.Windows.Forms.Labellabel5;

    privateSystem.Windows.Forms.Buttonbutton1;

    privateSystem.Windows.Forms.Labellabel1;

    privateSystem.Windows.Forms.Labellabel2;

    privateSystem.Windows.Forms.TextBoxtextBox1;

    privateSystem.Windows.Forms.TextBoxtextBox2;

    privateSystem.Windows.Forms.Buttonbutton2;

    ///

    ///必需的设计器变量。

    ///

    privateSystem.ComponentModel.Containercomponents=null;

    publicccfx2()

    {

      //

      //Windows窗体设计器支持所必需的

      //

      InitializeComponent();

      //

      //TODO:

在InitializeComponent调用后添加任何构造函数代码

      //

    }

    ///

    ///清理所有正在使用的资源。

    ///

    protectedoverridevoidDispose(booldisposing)

    {

      if(disposing)

      {

        if(components!

=null)

        {

          components.Dispose();

        }

      }

      base.Dispose(disposing);

    }

    #regionWindows窗体设计器生成的代码

    ///

    ///设计器支持所需的方法-不要使用代码编辑器修改

    ///此方法的内容。

    ///

    privatevoidInitializeComponent()

    {

      this.groupBox1=newSystem.Windows.Forms.GroupBox();

      this.textBox2=newSystem.Windows.Forms.TextBox();

      this.textBox1=newSystem.Windows.Forms.TextBox();

      this.label2=newSystem.Windows.Forms.Label();

      this.label1=newSystem.Windows.Forms.Label();

      this.label5=newSystem.Windows.Forms.Label();

      this.button1=newSystem.Windows.Forms.Button();

      this.button2=newSystem.Windows.Forms.Button();

      this.groupBox1.SuspendLayout();

      this.SuspendLayout();

      //

      //groupBox1

      //

      this.groupBox1.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.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=newSystem.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1