#include <stdio.h>
#include <math.h>
//全局变量定义
#define d1 0.61
#define d2 0.93
#define d3 1.4
#define d4 2.55
#define vp 1.4
#define vpMAX 2.9
#define f1=100
#define f2=115
/*
构建前方步行区域结构体
*/
struct Front
{
float velocity;//跟随状态前方步行者步行速度
int type;//0为跟随状态,1为非跟随状态
int distance_range;//距离范围
int rel_v_range;//相对速度范围
float PPSgranularity;//倾向性粒度
}frt;
float pedestrian_velocity;//目标步行者当前速度
float Reldistance;//相对距离
float Relvelocity;//相对速度
int pedestrian_velocity_range;//目标步行者速度范围
int frequency;//非跟随状态目标步行者步频
int c1, c2, c3;
int PPStype;//倾向性类型
int JudgeVelocityRange(float a);//速度范围判断
int JudgefrequencyRange(float a);//步频范围判断
int JudgedistanceRange(float a);//距离范围判断
int JudgeRelVelocityRange(float a);//相对速度范围判断
float propensity_quantification(int a, int b, int c);//倾向性量化
void Input(void);//输入
void Judge(void);//判断
void IdentifyPropensity(void);//倾向性判断
int main()
{
Input();
Judge();
IdentifyPropensity();
return 0;
}
void Input(void)
{
printf("目标步行者是否处于跟随状态:(0:处于跟随状态,1:处于非跟随状态)\n");
scanf("%d",&frt.type);
pedestrian_velocity_range = JudgeVelocityRange(pedestrian_velocity);
if (frt.type == 0)
{
printf("目标步行者的步行速度为: m/s\n");
scanf("%f",&pedestrian_velocity);
printf("与前方步行者的间距为: m\n");
scanf("%f",&Reldistance);
printf("前方步行者的步行速度为: m/s\n");
scanf("%f",&frt.velocity);
}
else if (frt.type == 1)
{
printf("目标步行者的步频为 步/min\n");
scanf("%d",&frequency);
}
}
void Judge(void)
{
if (frt.type == 0)
{
JudgedistanceRange(Reldistance);
Relvelocity = pedestrian_velocity - frt.velocity;
JudgeRelVelocityRange(Relvelocity);
c1 = frt.distance_range;
c2 = frt.rel_v_range;
c3 = pedestrian_velocity_range;
frt.PPSgranularity = propensity_quantification(c1, c2, c3);
}
else
JudgefrequencyRange(frequency);
}
/*
整数代表速度范围
0----慢
1----居中
2----快
*/
int JudgeVelocityRange(float a)
{
if (a < vp / 2)
return 0;
else if (a < (vp + vpMAX) / 2)
return 1;
else
return 2;
}
/*
以整数代表距离范围
0----危险
1----近
2----中
3----远
*/
int JudgedistanceRange(float a)
{
float a1,a2,a3;
a1 = (d1 + d2) / 2;
a2 = (d2 + d3) / 2;
a3 = (d3 + d4) / 2;
if (Reldistance < a1)
a = 0;
else if (Reldistance < a2)
a = 1;
else if (Reldistance < a3)
a = 2;
else
a = 3;
}
/*
以整数代表相对速度范围
0----负
1----零
2----正
*/
int JudgeRelVelocityRange(float a)
{
if (a < 0)
return 0;
else if (a == 0)
return 1;
else
return 2;
}
/*
用3维数组存储评分表并打分
*/
float Judgepropensity_granularity(int a, int b, int c)
{
float table[4][3][3] =
{
{{0.0, 0.0, 0.0}, {0.0, 0.0, 0.1}, {0.1, 0.1, 0.2}},
{{0.1, 0.1, 0.2}, {0.2, 0.3, 0.4}, {0.4, 0.5, 0.6}},
{{0.4, 0.5, 0.6}, {0.5, 0.6, 0.7}, {0.8, 0.9, 1.0}},
{{0.9, 0.9, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}}
};
return table[a][b][c];
}
/*
以整数代表倾向性类型
0----保守型
1----普通型
2----激进型
*/
void IdentifyPropensity(void)
{
}