c_code/demo.c
/* compute the membership vf for a crisp input */
compute the membership vf for a crisp input
compute the membership vf for a crisp input
double compute_membership(fuzzy_in* in)
{
	double a, b, c, d, sigma, mean;
	double out = 0.0f;
	int type = in->membership_type;
	switch(type){
		case test:
			switch(in->membership_func){
				case smalld:
					out = min(max(0, -(in->crisp_val-80)/120), 1);
				break;
				case larged:
					out = 1 - min(max(0, -(in->crisp_val-80)/160), 1);
				break;
				case smallt:
					out = (-abs(in->crisp_val)+180)/180;
				break;
				case larget:
					out = 1 -  (-abs(in->crisp_val)+180)/180;
				break;
			}
		break;
		case triangle:
		   switch(in->membership_func){
			case smalld:
				        a = -80, b = 0, c = 80;
			break;
			case larged:
				         a = 0, b = 80, c = 160;
			break;
			case smallt:
					a = -180, b = 0, c = 180;
			break;	
			case larget:
					a = 0, b = 180, c = 360;
			break;	
			}
			out = max(min((in->crisp_val - a)/(b-a), (c - in->crisp_val)/(c - b)), 0);			
		break;
		case trapezoid:
		   switch(in->membership_func){
			case smalld:
				         a = -20.2, b = -1.04, c = 10, d = 80;
			break;
			case larged:
				         a = 0, b = 70, c = 69.2, d = 85.2;
			break;
			case smallt:
					 a = -60.6, b = -3.12, c = 5, d = 180;
			break;	
			case larget:
					 a = 0, b = 80, c = 208, d = 256;
			break;	
			}
			out = max(min((in->crisp_val-a)/(b-a), min(1, (d-in->crisp_val)/(d-c))), 0);
		break;
		case gauss:
		    switch(in->membership_func){
			case smalld:
				        sigma = 25, mean = 0;
			break;
			case larged:
				         sigma = 25, mean = 80;
			break;
			case smallt:
					 sigma = 60, mean = 0;
			break;	
			case larget:
					  sigma = 60, mean = 180;
			break;	
			}
			out = exp(-pow((in->crisp_val - mean),2)/(2*pow(sigma,2)));	
		break;
	}
	return out; 
}
double compute_membership ( fuzzy_in * in ) { double a , b , c , d , sigma , mean ; double out = 0.0f ; int type = in -> membership_type ; switch ( type ) { case test : switch ( in -> membership_func ) { case smalld : out = min ( max ( 0 , - ( in -> crisp_val - 80 ) / 120 ) , 1 ) ; break ; case larged : out = 1 - min ( max ( 0 , - ( in -> crisp_val - 80 ) / 160 ) , 1 ) ; break ; case smallt : out = ( - abs ( in -> crisp_val ) + 180 ) / 180 ; break ; case larget : out = 1 - ( - abs ( in -> crisp_val ) + 180 ) / 180 ; break ; } break ; case triangle : switch ( in -> membership_func ) { case smalld : a = -80 , b = 0 , c = 80 ; break ; case larged : a = 0 , b = 80 , c = 160 ; break ; case smallt : a = -180 , b = 0 , c = 180 ; break ; case larget : a = 0 , b = 180 , c = 360 ; break ; } out = max ( min ( ( in -> crisp_val - a ) / ( b - a ) , ( c - in -> crisp_val ) / ( c - b ) ) , 0 ) ; break ; case trapezoid : switch ( in -> membership_func ) { case smalld : a = -20.2 , b = -1.04 , c = 10 , d = 80 ; break ; case larged : a = 0 , b = 70 , c = 69.2 , d = 85.2 ; break ; case smallt : a = -60.6 , b = -3.12 , c = 5 , d = 180 ; break ; case larget : a = 0 , b = 80 , c = 208 , d = 256 ; break ; } out = max ( min ( ( in -> crisp_val - a ) / ( b - a ) , min ( 1 , ( d - in -> crisp_val ) / ( d - c ) ) ) , 0 ) ; break ; case gauss : switch ( in -> membership_func ) { case smalld : sigma = 25 , mean = 0 ; break ; case larged : sigma = 25 , mean = 80 ; break ; case smallt : sigma = 60 , mean = 0 ; break ; case larget : sigma = 60 , mean = 180 ; break ; } out = exp ( - pow ( ( in -> crisp_val - mean ) , 2 ) / ( 2 * pow ( sigma , 2 ) ) ) ; break ; } return out ; }
compute the membership vf for a crisp input
compute the membership vf for a crisp input
/* check the type of the membership */ /* for distance error 
			   used params: Small MF -> a = -60, b = 0, c = 60
					Large MF -> a = 0, b = 60, c = 120
			*/ /* for heading angle error 
			   used params: Small MF -> a = -180, b = 0, c = 180
					Large MF -> a = 0, b = 180, c = 360
			*/ /* for distance error 
			   used params: Small MF -> a = -20.2, b = -1.04, c = 10, d = 60
					Large MF -> a = 0, b = 50, c = 69.2, d = 85.2
			*/ /* for heading angle error 
			   used params: Small MF -> a = -60.6, b = -3.12, c = 5, d = 180
					Large MF -> a = 0, b = 60, c = 208, d = 256
			*/ /* for distance error 
			   used params: Small MF -> sigma = 25  mean = 0 
					Large MF -> sigma = 25  mean = 60
			*/ /* for heading angle error 
			   used params: Small MF -> sigma = 60  mean = 0
					Large MF -> sigma = 60  mean = 180
			*/