⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dim_eva.cpp

📁 dim_eva.rar
💻 CPP
字号:
#include<stdio.h>
#include<math.h>
#include<iostream.h>
float max(float *t,int n)
{
	int i;
	float max;
	max=t[0];
	for(i=1;i<n;i++)
	{
		if(t[i]>max) max=t[i];
	}
	return max;
}
float min(float x,float y)
{
	return x<y? x:y;
}
float *inner_mul(float *w,float** R,int m,int n)
{
	float *t,*p;
	int i,j;
	p=new float[m];
	t=new float[n];//用于临时存放w[i]与R[i][j]中较小的
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			t[j]=min(w[j],R[j][i]);
		p[i]=max(t,m);
	}
	delete[] t;
	return p;

}
float dim_evaluation()
{
	float **R;
	float *w,*B;//w[n] is a weigh vector,B is a evaluation vector=w.R
	int *v;
	int m,n;//m is the number of element of w,n is m is the number of element of v
	//that is w[m],v[n] R[m][n]
	float s=0,t=0;
	int i,j;
    cout<<"input m=";
	cin>>m;
	cout<<"input n=";
	cin>>n;
	R=new float*[m];
	for(i=0;i<m;i++)
		R[i]=new float[n];
	w=new float[m];
	B=new float[n];
	v=new int[n];
	cout<<"input the elements of R[m][n]:\n";
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			cin>>R[i][j];
    cout<<"intput the elements of w[m]:\n";
	for(i=0;i<m;i++)
		cin>>w[i];
	cout<<"input the elements of v[n]:\n";
	for(i=0;i<n;i++)
		cin>>v[i];
	B=inner_mul(w,R,m,n);//求内积
	//下面做归一化处理
	for(i=0;i<n;i++)
		t+=B[i];
	for(i=0;i<n;i++)
		B[i]=B[i]/t;
	for(i=0;i<n;i++)
		s+=B[i]*v[i];
	return s;
}

void main()
{
	float s;
	s=dim_evaluation();
	cout<<"the result is:"<<s<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -