我的代码发出此错误
'Net.Kniaz.AHP.AHPModel'不包含'AddCriteria'的定义,并且没有扩展方法'AddCriteria'接受类型'Net.Kniaz.AHP.AHPModel'的第一个参数可以找到(你错过了吗?) using指令或程序集引用?)
我不知道问题是什么。我回顾了几个类似的问题,但仍然找不到解决方案。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetMatrix;
using GeneralMatrix;
using NUnit.Framework;
using Net.Kniaz.AHP;
namespace Net.Kniaz.AHP
{
public class AHPModel
{
public AHPModel(int n, int m);
private GeneralMatrix _criteria;
private GeneralMatrix _choiceMatrix;
private GeneralMatrix _orderedCriteria;
private GeneralMatrix _calculatedChoices;
private int _ncriteria;
private int _mchoice;
private int _superDim;
}
public class TestAHP
{
public void TestVacationSpotSelection()
{
double[][] criteria = new double[][]
{
new double[] {1,5,0.33333333,1},
new double[] {0,1,0.2,0.5},
new double[] {0,0,1,3},
new double[] {0,0,0,1}
};
double[][] activitiesChoices = new double[][]
{
new double[] {1,4,3},
new double[] {0,1,2},
new double[] {0,0,1}
};
double[][] nightlifeChoices = new double[][]
{
new double[] {1,0.5,0.3333333},
new double[] {0,1,0.5},
new double[] {0,0,1}
};
double[][] siteseeingChoices = new double[][]
{
new double[] {1,0.142857,0.2},
new double[] {0,1,2},
new double[] {0,0,1}
};
double[][] costChoices = new double[][]
{
new double[] {1,3,5},
new double[] {0,1,2},
new double[] {0,0,1}
};
//4 criteria, 3 choices
AHPModel model = new AHPModel(4,3);
model.AddCriteria(criteria);
model.AddCriterionRatedChoices(0,activitiesChoices);
model.AddCriterionRatedChoices(1,nightlifeChoices);
model.AddCriterionRatedChoices(2,siteseeingChoices);
model.AddCriterionRatedChoices(3,costChoices);
model.CalculateModel();
GeneralMatrix calcCriteria = model.CalculatedCriteria;
GeneralMatrix results = model.ModelResult;
GeneralMatrix choices = model.CalculatedChoices;
//choices: SF 42%, Orlando31%, NY 27%
Assert.AreEqual(31,System.Math.Round(choices.GetElement(0,0)*100,0));
Assert.AreEqual(42,System.Math.Round(choices.GetElement(1,0)*100,0));
Assert.AreEqual(27,System.Math.Round(choices.GetElement(2,0)*100,0));
错误位于距离末端(模型)的行(5到13)行中。
答案 0 :(得分:2)
您的班级AHPModel显然没有方法AddCriteria ...
答案 1 :(得分:1)
您正在尝试使用一段不存在的代码。
public class AHPModel
{
public AHPModel(int n, int m);
private GeneralMatrix _criteria;
private GeneralMatrix _choiceMatrix;
private GeneralMatrix _orderedCriteria;
private GeneralMatrix _calculatedChoices;
private int _ncriteria;
private int _mchoice;
private int _superDim;
/*private void AddCriteria(object o);*/ //<-ghost code
}