/* This library is for use only in education and research. It is not for commercial use! Written permission from author is necessary for commercial use or for inclusion as a part of project or program or another library!
Programs, projects, libraries or anything consists this library or its part MUST NOT be sold without author permission!
Author: Dekovich Igor,
ph: (-61) (2) 4225 2673,
mobile: (-61) 042 189 69 84
e-mail: idekovich@yahoo.com*/
#include "fuzzy.h"
#ifdef __cplusplus
extern "C"{
#endif
extern float max_lambda=5.0; /* maximal value to be checked in calculating_lambda() and calculating_positive_lambda() (if the function doesn't changes signum from initial point (setup later as lambda) through check points (defined later with step) until the end than it is assumed that there is no solution for lambda) */
/* if all values could happen to be very close to 0.0 end could required to be increased (in the case of 27 values of 0.01 end should be 1000) */
/* setting the value here */
/* testmalloc and testfree are introduced to enable easier analysis of a problem with memory allocation occur */
/* enable (by defining TEST_MALLOC (before calling fuzzy library, for example "#define TEST_MALLOC 1") different than 0) printing history of all malloc allocations and freeding of memory */
/* all malloc calls should be replaced with testmalloc ones (instead of "malloc(XXX)" should be written "testmalloc(XXX)") */
/* all free calls should be replaced with testfree ones (instead of "free(XXX)" should be written "testfree(XXX)") */
void *testmalloc(size_t nrbytes)
{
void *p;
int i=TEST_MALLOC;
if(nrbytes>UINT_MAX) printf("\n\n WARNING: REQUIRED ALLOCATION OF %d Bytes THAT IS > MAXIMAL LONG UNSIGNED VALUE! However this allocation could proceed OK. if the system (malloc) accept it without overflow. IF PROGRAM CONTINUES NORMALLY THEN EVERYTHING SEEMS OK!\n");
p=(void*)malloc(nrbytes);
if(i!=0) printf("\n %d bytes allocated at %p", nrbytes, p);
return(p);
}
void testfree(char *p)
{
int i=TEST_MALLOC;
if(i!=0) printf("\n freed %p", p);
free(p);
}
/* void exit_handling(int number, int location) prints message and then exits execution of program; "int number" describes what caused exit and chooses message. */
void exit_handling(int number, int location)
{
switch(number)
{
case 1: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE at (%d) \n", location);
break;
case 2: printf("\n EXIT since Level's node has different number of weights than previous Level nodes ==> check=0 at neuron *create_highest_difference_from_neighborns() or neuron *create_corner_extractor( at (%d) \n", location);
break;
case 3: printf("\n EXIT since number of neurones in neuron population is different than number of objects on its input fuzzy_set **preparing_neuron_population_neuron_inputs_through_window() at (%d) \n", location);
break;
case 4: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_highest_difference_from_neighborns_descriptor() at (%d) \n", location);
break;
case 5: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_corner_extractor_descriptor() at (%d) \n", location);
break;
case 6: printf("\n EXIT since in function node_first_Level_corner_extractor() node_number is (%d) that is out of range 1 throught 8 \n",location);
break;
case 7: printf("\n EXIT since in function sum_of_2multiplications_with_maximum_of_3() number of inputs is not divisible with 5 but has remainder (%d) \n", location);
break;
case 8: printf("\n EXIT since in function sum_of_roots_of_2multiplications_with_maximum_of_3 number of inputs is not divisible with 5 but hasremainder (%d) \n", location);
break;
case 9: printf("\n EXIT since in function arithmetic_mean_of_roots_of_2multiplications_with_maximum_of_3 number of inputs is not divisible with 5 but hasremainder (%d) \n", location);
break;
case 10: printf("\n EXIT since in function highest_arithmetic_mean_of_2_with_maximum_of_3() number of inputs is not divisible with 5 but hasremainder (%d) \n", location);
break;
case 11: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_sort2_descriptor() at (%d) \n", location);
break;
case 12: if(location!=2)
printf("\n EXIT since in function corner_extractor_last_Level_output() number of inputs into the node is not 2 exactly but (%d) \n", location);
else
printf("\n EXIT since in function corner_extractor_last_Level_output() number of inputs into the node is 2 exactly but the node is not properly created since pointer from the node's first characteristic onto the following one (*follow) is different from the pointer on the node's last characteristic! ATTENTION checked condition is:>>node->first->follow==node->last<number_of_neurones!=(int)((highest_number_of_corners-lowest_number_of_corners)/step) means number of neurones in the neural population is different than the number this function should prepare inputs for. Exit has occured at the location (%d) \n", location);
break;
case 19: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_area_separator_descriptor() at (%d) \n", location);
break;
case 20: printf("\n EXIT since in function preparing_area_separator_neuron_population_neuron_inputs: np->number_of_neurones!=1 means number of neurones in the neural population is different than the number this function should prepare inputs for. Only one neuron per population is expected in the case of area separator. Exit has occured at the location (%d) \n", location);
break;
case 21: printf("\n EXIT since function area_separator_all_Levels(fuzzy_object *node, int Level_number) is called with Level_number=%d that's different from 1 or 2 that are expected! \n", location);
break;
case 22: printf("\n EXIT since in function create_area_without_edges_separator input->number_of_objects!=horisontal_resolution*vertical_resolution at the location (%d) \n", location);
break;
case 23: printf("\n EXIT since in function float *read_bitmap() at location %d in switch command non-hexadecimal character has occured! \n", location);
break;
case 24: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_descriptor() at (%d) \n", location);
break;
case 25: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_3L_descriptor() at (%d) \n", location);
break;
case 26: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_4L_descriptor() at (%d) \n", location);
break;
case 27: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_5L_descriptor() at (%d) \n", location);
break;
case 28: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_5L_W_descriptor() at (%d) \n", location);
break;
case 29: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_4L_W_descriptor() at (%d) \n", location);
break;
case 30: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_3L_W_descriptor() at (%d) \n", location);
break;
case 31: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_descriptor() at (%d) \n", location);
break;
case 32: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1_descriptor() at (%d) \n", location);
break;
case 33: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_3L_1_descriptor() at (%d) \n", location);
break;
case 34: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_4L_1_descriptor() at (%d) \n", location);
break;
case 35: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_5L_1_descriptor() at (%d) \n", location);
break;
case 36: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1_descriptor() at (%d) \n", location);
break;
case 37: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_3L_W_1_descriptor() at (%d) \n", location);
break;
case 38: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_4L_W_1_descriptor() at (%d) \n", location);
break;
case 39: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_5L_W_1_descriptor() at (%d) \n", location);
break;
case 40: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_11_descriptor() at (%d) \n", location);
break;
case 41: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_22_descriptor() at (%d) \n", location);
break;
case 42: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_21_descriptor() at (%d) \n", location);
break;
case 43: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_22_11_descriptor() at (%d) \n", location);
break;
case 44: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_21_11_descriptor() at (%d) \n", location);
break;
case 45: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_22_21_descriptor() at (%d) \n", location);
break;
case 46: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FBALL_22_21_11_descriptor() at (%d) \n", location);
break;
case 47: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_11_descriptor() at (%d) \n", location);
break;
case 48: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_22_descriptor() at (%d) \n", location);
break;
case 49: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_21_descriptor() at (%d) \n", location);
break;
case 50: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_22_11_descriptor() at (%d) \n", location);
break;
case 51: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_21_11_descriptor() at (%d) \n", location);
break;
case 52: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_22_21_descriptor() at (%d) \n", location);
break;
case 53: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FBALL_22_21_11_descriptor() at (%d) \n", location);
break;
case 54: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_11_descriptor() at (%d) \n", location);
break;
case 55: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_22_descriptor() at (%d) \n", location);
break;
case 56: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_21_descriptor() at (%d) \n", location);
break;
case 57: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_22_11_descriptor() at (%d) \n", location);
break;
case 58: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_21_11_descriptor() at (%d) \n", location);
break;
case 59: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_22_21_descriptor() at (%d) \n", location);
break;
case 60: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FBALL_22_21_11_descriptor() at (%d) \n", location);
break;
case 61: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_11_descriptor() at (%d) \n", location);
break;
case 62: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_22_descriptor() at (%d) \n", location);
break;
case 63: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_21_descriptor() at (%d) \n", location);
break;
case 64: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_22_11_descriptor() at (%d) \n", location);
break;
case 65: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_21_11_descriptor() at (%d) \n", location);
break;
case 66: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_22_21_descriptor() at (%d) \n", location);
break;
case 67: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FBALL_22_21_11_descriptor() at (%d) \n", location);
break;
case 68: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_11_descriptor() at (%d) \n", location);
break;
case 69: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_22_descriptor() at (%d) \n", location);
break;
case 70: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_21_descriptor() at (%d) \n", location);
break;
case 71: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_22_11_descriptor() at (%d) \n", location);
break;
case 72: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_21_11_descriptor() at (%d) \n", location);
break;
case 73: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_22_21_descriptor() at (%d) \n", location);
break;
case 74: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_FB1_22_21_11_descriptor() at (%d) \n", location);
break;
case 75: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_11_descriptor() at (%d) \n", location);
break;
case 76: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_22_descriptor() at (%d) \n", location);
break;
case 77: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_21_descriptor() at (%d) \n", location);
break;
case 78: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_22_11_descriptor() at (%d) \n", location);
break;
case 79: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_21_11_descriptor() at (%d) \n", location);
break;
case 80: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_22_21_descriptor() at (%d) \n", location);
break;
case 81: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_FB1_22_21_11_descriptor() at (%d) \n", location);
break;
case 82: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_11_descriptor() at (%d) \n", location);
break;
case 83: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_22_descriptor() at (%d) \n", location);
break;
case 84: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_21_descriptor() at (%d) \n", location);
break;
case 85: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_22_11_descriptor() at (%d) \n", location);
break;
case 86: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_21_11_descriptor() at (%d) \n", location);
break;
case 87: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_22_21_descriptor() at (%d) \n", location);
break;
case 88: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_1out_FB1_22_21_11_descriptor() at (%d) \n", location);
break;
case 89: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_11_descriptor() at (%d) \n", location);
break;
case 90: printf("\n EXIT since FEEDBACK IS POORLY DEFINED (Level numbers in either vector source or vector destination are out of domain) in create_recurrent_FCNN() at (%d) \n", location);
break;
case 91: printf("\n EXIT since FEEDBACK IS POORLY DEFINED (Level numbers in either vector source or vector destination are out of domain) in create_recurrent_FCNN_with_only_1_output() at (%d) \n", location);
break;
case 92: printf("\n EXIT since FEEDBACK IS POORLY DEFINED (Level numbers in either vector source or vector destination are out of domain) in create_recurrent_FCNN_FB1() at (%d) \n", location);
break;
case 93: printf("\n EXIT since FEEDBACK IS POORLY DEFINED (Level numbers in either vector source or vector destination are out of domain) in create_recurrent_FCNN_FB1_with_only_1_output() at (%d) \n", location);
break;
case 94: printf("\n EXIT since Reyni's parameter alpha (extern float Reyni_alpha) either isn't positive or is 1.0 at (%d) \n", location);
break;
case 95: if (location==1)
{
printf("\n EXIT since calculating_lambda() at (%d) can't find soultion for lambda (inside given range and with given parameters epsilon, epsilon0, and step) \n", location);
}
else
{
printf("\n EXIT since calculating_positive_lambda() at (%d) can't find a positive soultion for lambda (inside given range and with given parameters epsilon, epsilon0, and step) \n", location);
};
break;
case 100: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_22_descriptor() at (%d) \n", location);
break;
case 101: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_21_descriptor() at (%d) \n", location);
break;
case 102: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_22_11_descriptor() at (%d) \n", location);
break;
case 103: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_21_11_descriptor() at (%d) \n", location);
break;
case 104: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_22_21_descriptor() at (%d) \n", location);
break;
case 105: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_FCNN_2L_W_1out_FB1_22_21_11_descriptor() at (%d) \n", location);
break;
case 106: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_simple_neuron_descriptor() at (%d) \n", location);
break;
case 1000: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_ART2_descriptor() at (%d) \n", location);
break;
case 1001: printf("\n EXIT since INPUT VARIABLE IS OUT OF RANGE [0,1] in piecewise_linear() at (%d) \n", location);
break;
case 1002: printf("\n EXIT since INPUT VARIABLE IS OUT OF RANGE [0,1] in continuously_differentable() at (%d) \n", location);
break;
case 1003: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_convolutional_layer_neuron_descriptor() at (%d) \n", location);
break;
case 1004: printf("\n EXIT since NOT ENOUGH MEMORY IS AVAILABLE in setup_averaging_layer_neuron_descriptor() at (%d) \n", location);
break;
case 1005: printf("\n EXIT since PARAMETERS DON'T MATCH in preparing_neuron_population_input_for_convolutional_layer_neuron() at (%d) \n", location);
break;
case 1006: printf("\n EXIT since PARAMETERS DON'T MATCH in create_convolutional_layer_neuron_population_from_nucleotide_base() at (%d) \n", location);
break;
case 1007: printf("\n EXIT since there is a RECURRENT CONNECTION from root populations (if at 1), or to leaves populations (if at 2), so they must be selected on another way in filling_neural_subsystem_tree_of_neural_populations() at (%d) \n", location);
break;
case 1008: printf("\n EXIT since PARAMETERS DON'T MATCH (if at 1), can't find the related gene (if at 2), there is no written function for creating neuron population without having input fuzzy set, while input fuzzy set is undefined at the moment (if at 3), in create_neural_subsystem_from_gene_and_subsystem_tree() at (%d) \n", location);
break;
case 1009: printf("\n EXIT since required neuron population cannot be found inside its subsystem's subsystem tree (if at 1), required leaf neuron population (to be pointed) can't be found inside virtual_populations (if at 2), there is still undefined neuron population input fuzzy set and a function for treating it is not developed yet (if at 3), this system has recurrent connections to its roots so roots have to be selected manualy (if at 4), this system has recurrent connections from its leaves so leaves have to be selected manualy (if at 5), in create_neural_system() at (%d) \n", location);
break;
default: printf("\n EXIT by default at (%d) \n", location);
break;
};
exit(1); } /* ; */
/* "T"* MA"T"(int number_of_elements) where "T" means type and can be 'C'=char, 'D'=double, 'F'=float, 'I'=int, 'L'=long, 'S'=short, 'Si'=signed, 'U'=unsigned, 'Cl'=characteristic, 'FO'=fuzzy_object, 'FS'=fuzzy_set, 'CS'=crisp_set, 'EB'=enum Bool, 'ECT'= enum check_type, 'TS'=time_slice or any of previous letters with (one or more, up to 3) prefix 'p' =pointer on */
/* Returns pointer to space to be reserved (allocated)!*/
/* It deals with memory allocation (testmalloc) request for number_of_elements locations of type "T". In the case there is no available memory request is being repeated up to 101 times and if there is still lack of free memory unsucessfull end of process is caused (exit(1)). */
char* MAC(long int number_of_elements)
{
char *head;
int i=0;
do
head=(char*)testmalloc((size_t)number_of_elements*sizeof(char));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,1);
return(head);
} /* ; */
int* MAI(long int number_of_elements)
{
int *head;
int i=0;
do
head=(int*)testmalloc((size_t)number_of_elements*sizeof(int));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,2);
return(head);
} /* ; */
float* MAF(long int number_of_elements)
{
float *head;
int i=0;
do
head=(float*)testmalloc((size_t)(size_t)(number_of_elements*sizeof(float)));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,3);
return(head);
} /* ; */
double* MAD(long int number_of_elements)
{
double *head;
int i=0;
do
head=(double*)testmalloc((size_t)number_of_elements*sizeof(double));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,4);
return(head);
} /* ; */
long* MAL(long int number_of_elements)
{
long *head;
int i=0;
do
head=(long*)testmalloc((size_t)number_of_elements*sizeof(long));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,5);
return(head);
} /* ; */
short* MAS(long int number_of_elements)
{
short *head;
int i=0;
do
head=(short*)testmalloc((size_t)number_of_elements*sizeof(short));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,6);
return(head);
} /* ; */
signed* MASi(long int number_of_elements)
{
signed *head;
int i=0;
do
head=(signed*)testmalloc((size_t)number_of_elements*sizeof(signed));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,7);
return(head);
} /* ; */
unsigned int* MAU(long int number_of_elements)
{
unsigned int *head;
int i=0;
do
head=(unsigned int*)testmalloc((size_t)number_of_elements*sizeof(unsigned int));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,8);
return(head);
} /* ; */
characteristic* MACl(long int number_of_elements)
{
characteristic *head;
int i=0;
do
head=(characteristic*)testmalloc((size_t)number_of_elements*sizeof(characteristic));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,9);
return(head);
} /* ; */
fuzzy_object* MAFO(long int number_of_elements)
{
fuzzy_object *head;
int i=0;
do
head=(fuzzy_object*)testmalloc((size_t)(size_t)(number_of_elements*sizeof(fuzzy_object)));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,10);
return(head);
} /* ; */
fuzzy_set* MAFS(long int number_of_elements)
{
fuzzy_set *head;
int i=0;
do
head=(fuzzy_set*)testmalloc((size_t)number_of_elements*sizeof(fuzzy_set));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,11);
return(head);
} /* ; */
crisp_set* MACS(long int number_of_elements)
{
crisp_set *head;
int i=0;
do
head=(crisp_set*)testmalloc((size_t)number_of_elements*sizeof(crisp_set));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,12);
return(head);
} /* ; */
enum Bool* MAEB(long int number_of_elements)
{
enum Bool *head;
int i=0;
do
head=(enum Bool*)testmalloc((size_t)number_of_elements*sizeof(enum Bool));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,13);
return(head);
} /* ; */
enum check_type* MAECT(long int number_of_elements)
{
enum check_type *head;
int i=0;
do
head=(enum check_type*)testmalloc((size_t)number_of_elements*sizeof(enum check_type));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,14);
return(head);
} /* ; */
char** MApC(long int number_of_elements)
{
char **head;
int i=0;
do
head=(char**)testmalloc((size_t)number_of_elements*sizeof(char*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,21);
return(head);
} /* ; */
int** MApI(long int number_of_elements)
{
int **head;
int i=0;
do
head=(int**)testmalloc((size_t)number_of_elements*sizeof(int*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,22);
return(head);
} /* ; */
float** MApF(long int number_of_elements)
{
float **head;
int i=0;
do
head=(float**)testmalloc((size_t)(size_t)(number_of_elements*sizeof(float*)));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,23);
return(head);
} /* ; */
double** MApD(long int number_of_elements)
{
double **head;
int i=0;
do
head=(double**)testmalloc((size_t)number_of_elements*sizeof(double*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,24);
return(head);
} /* ; */
long** MApL(long int number_of_elements)
{
long **head;
int i=0;
do
head=(long**)testmalloc((size_t)number_of_elements*sizeof(long*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,25);
return(head);
} /* ; */
short** MApS(long int number_of_elements)
{
short **head;
int i=0;
do
head=(short**)testmalloc((size_t)number_of_elements*sizeof(short*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,26);
return(head);
} /* ; */
signed** MApSi(long int number_of_elements)
{
signed **head;
int i=0;
do
head=(signed**)testmalloc((size_t)number_of_elements*sizeof(signed*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,27);
return(head);
} /* ; */
unsigned int** MApU(long int number_of_elements)
{
unsigned int **head;
int i=0;
do
head=(unsigned int**)testmalloc((size_t)number_of_elements*sizeof(unsigned int*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,28);
return(head);
} /* ; */
characteristic** MApCl(long int number_of_elements)
{
characteristic **head;
int i=0;
do
head=(characteristic**)testmalloc((size_t)number_of_elements*sizeof(characteristic*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,29);
return(head);
} /* ; */
fuzzy_object** MApFO(long int number_of_elements)
{
fuzzy_object **head;
int i=0;
do
head=(fuzzy_object**)testmalloc((size_t)(size_t)(number_of_elements*sizeof(fuzzy_object*)));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,30);
return(head);
} /* ; */
fuzzy_set** MApFS(long int number_of_elements)
{
fuzzy_set **head;
int i=0;
do
head=(fuzzy_set**)testmalloc((size_t)number_of_elements*sizeof(fuzzy_set*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,31);
return(head);
} /* ; */
crisp_set** MApCS(long int number_of_elements)
{
crisp_set **head;
int i=0;
do
head=(crisp_set**)testmalloc((size_t)number_of_elements*sizeof(crisp_set*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,32);
return(head);
} /* ; */
enum Bool** MApEB(long int number_of_elements)
{
enum Bool **head;
int i=0;
do
head=(enum Bool**)testmalloc((size_t)number_of_elements*sizeof(enum Bool*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,33);
return(head);
} /* ; */
enum check_type** MApECT(long int number_of_elements)
{
enum check_type **head;
int i=0;
do
head=(enum check_type**)testmalloc((size_t)number_of_elements*sizeof(enum check_type*));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,34);
return(head);
} /* ; */
char*** MAppC(long int number_of_elements)
{
char ***head;
int i=0;
do
head=(char***)testmalloc((size_t)number_of_elements*sizeof(char**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,41);
return(head);
} /* ; */
int*** MAppI(long int number_of_elements)
{
int ***head;
int i=0;
do
head=(int***)testmalloc((size_t)number_of_elements*sizeof(int**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,42);
return(head);
} /* ; */
float*** MAppF(long int number_of_elements)
{
float ***head;
int i=0;
do
head=(float***)testmalloc((size_t)number_of_elements*sizeof(float**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,43);
return(head);
} /* ; */
double*** MAppD(long int number_of_elements)
{
double ***head;
int i=0;
do
head=(double***)testmalloc((size_t)number_of_elements*sizeof(double**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,44);
return(head);
} /* ; */
long*** MAppL(long int number_of_elements)
{
long ***head;
int i=0;
do
head=(long***)testmalloc((size_t)number_of_elements*sizeof(long**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,45);
return(head);
} /* ; */
short*** MAppS(long int number_of_elements)
{
short ***head;
int i=0;
do
head=(short***)testmalloc((size_t)number_of_elements*sizeof(short**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,46);
return(head);
} /* ; */
signed*** MAppSi(long int number_of_elements)
{
signed ***head;
int i=0;
do
head=(signed***)testmalloc((size_t)number_of_elements*sizeof(signed**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,47);
return(head);
} /* ; */
unsigned int*** MAppU(long int number_of_elements)
{
unsigned int ***head;
int i=0;
do
head=(unsigned int***)testmalloc((size_t)number_of_elements*sizeof(unsigned int**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,48);
return(head);
} /* ; */
characteristic*** MAppCl(long int number_of_elements)
{
characteristic ***head;
int i=0;
do
head=(characteristic***)testmalloc((size_t)number_of_elements*sizeof(characteristic**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,49);
return(head);
} /* ; */
fuzzy_object*** MAppFO(long int number_of_elements)
{
fuzzy_object ***head;
int i=0;
do
head=(fuzzy_object***)testmalloc((size_t)number_of_elements*sizeof(fuzzy_object**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,50);
return(head);
} /* ; */
fuzzy_set*** MAppFS(long int number_of_elements)
{
fuzzy_set ***head;
int i=0;
do
head=(fuzzy_set***)testmalloc((size_t)number_of_elements*sizeof(fuzzy_set**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,51);
return(head);
} /* ; */
crisp_set*** MAppCS(long int number_of_elements)
{
crisp_set ***head;
int i=0;
do
head=(crisp_set***)testmalloc((size_t)number_of_elements*sizeof(crisp_set**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,52);
return(head);
} /* ; */
enum Bool*** MAppEB(long int number_of_elements)
{
enum Bool ***head;
int i=0;
do
head=(enum Bool***)testmalloc((size_t)number_of_elements*sizeof(enum Bool**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,53);
return(head);
} /* ; */
enum check_type*** MAppECT(long int number_of_elements)
{
enum check_type ***head;
int i=0;
do
head=(enum check_type***)testmalloc((size_t)number_of_elements*sizeof(enum check_type**));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,54);
return(head);
} /* ; */
char**** MApppC(long int number_of_elements)
{
char ****head;
int i=0;
do
head=(char****)testmalloc((size_t)number_of_elements*sizeof(char***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,61);
return(head);
} /* ; */
int**** MApppI(long int number_of_elements)
{
int ****head;
int i=0;
do
head=(int****)testmalloc((size_t)number_of_elements*sizeof(int***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,62);
return(head);
} /* ; */
float**** MApppF(long int number_of_elements)
{
float ****head;
int i=0;
do
head=(float****)testmalloc((size_t)number_of_elements*sizeof(float***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,63);
return(head);
} /* ; */
double**** MApppD(long int number_of_elements)
{
double ****head;
int i=0;
do
head=(double****)testmalloc((size_t)number_of_elements*sizeof(double***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,64);
return(head);
} /* ; */
long**** MApppL(long int number_of_elements)
{
long ****head;
int i=0;
do
head=(long****)testmalloc((size_t)number_of_elements*sizeof(long***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,65);
return(head);
} /* ; */
short**** MApppS(long int number_of_elements)
{
short ****head;
int i=0;
do
head=(short****)testmalloc((size_t)number_of_elements*sizeof(short***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,66);
return(head);
} /* ; */
signed**** MApppSi(long int number_of_elements)
{
signed ****head;
int i=0;
do
head=(signed****)testmalloc((size_t)number_of_elements*sizeof(signed***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,67);
return(head);
} /* ; */
unsigned int**** MApppU(long int number_of_elements)
{
unsigned int ****head;
int i=0;
do
head=(unsigned int****)testmalloc((size_t)number_of_elements*sizeof(unsigned int***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,68);
return(head);
} /* ; */
characteristic**** MApppCl(long int number_of_elements)
{
characteristic ****head;
int i=0;
do
head=(characteristic****)testmalloc((size_t)number_of_elements*sizeof(characteristic***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,69);
return(head);
} /* ; */
fuzzy_object**** MApppFO(long int number_of_elements)
{
fuzzy_object ****head;
int i=0;
do
head=(fuzzy_object****)testmalloc((size_t)number_of_elements*sizeof(fuzzy_object***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,70);
return(head);
} /* ; */
fuzzy_set**** MApppFS(long int number_of_elements)
{
fuzzy_set ****head;
int i=0;
do
head=(fuzzy_set****)testmalloc((size_t)number_of_elements*sizeof(fuzzy_set***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,71);
return(head);
} /* ; */
crisp_set**** MApppCS(long int number_of_elements)
{
crisp_set ****head;
int i=0;
do
head=(crisp_set****)testmalloc((size_t)number_of_elements*sizeof(crisp_set***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,72);
return(head);
} /* ; */
enum Bool**** MApppEB(long int number_of_elements)
{
enum Bool ****head;
int i=0;
do
head=(enum Bool****)testmalloc((size_t)number_of_elements*sizeof(enum Bool***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,73);
return(head);
} /* ; */
enum check_type**** MApppECT(long int number_of_elements)
{
enum check_type ****head;
int i=0;
do
head=(enum check_type****)testmalloc((size_t)number_of_elements*sizeof(enum check_type***));
while((head==0)&&(++i<101));
if((number_of_elements>0)&&(head==0)) exit_handling(1,74);
return(head);
} /* ; */
/* *read_name() u~itaje skup karaktera koji sadr`i slova, brojeve, znakove interpunkcije; a unutar char vektora su ti skupovi odijeljeni ili jednim od prvih 40 ASCII znakova ili izme|u 59 i 63 ili 127 ASCII znakom */
char *read_name(char *read_in, char *read_from)
{
read_in--;
read_from--;
do
{
read_in++;
read_from++;
*read_in = *read_from;
} while(((*read_from > 39) && (*read_from < 59)) || ((*read_from > 63) && (*read_from < 127)));
read_in++;
return(read_in) ;
} /* ; */
/* *set_fill() je funkcija za u~itavanje fuzzy objekta preko pohranjivanja u polje pomo}u funkcije *characteristic_fill() */
characteristic *characteristic_fill(characteristic *link, fuzzy_object *head1, char *names, float *memberships)
{
characteristic *head;
head=MACl((long int)1);
head->name=MAC((long int)100);
read_name(head->name,names);
head->membership = *memberships;
head->follow=0;
head->ahead=link;
head->set=head1;
return(head);
}/* ; */
fuzzy_object *set_fill(int nmbr_characteristics, char *names, float *memberships)
{
char *name1,*name2;
int counter;
fuzzy_object *head;
name1=MAC((long int)100);
name2=names;
head=MAFO((long int)1);
head->actual=0;
head->m.name=MAC((long int)100);
read_name(head->m.name,names);
name2=read_name(name2,names);
head->number_of_characteristics = nmbr_characteristics;
names+=name2-names;
name2=name1;
head->first=characteristic_fill(head->actual,head,names,memberships);
memberships++;
names+=read_name(name2,names)-name2;
head->first->follow=0;
head->actual=head->first;
head->last=head->first; /* for the case of head->number_of_characteristics=1 */
for(counter=2; counter<=head->number_of_characteristics; counter++)
{ head->last=characteristic_fill(head->actual,head,names,memberships);
memberships++;
names+=read_name(name2,names)-name2;
name2=name1;
head->actual->follow=head->last;
head->actual=head->last;
};
testfree((char*)name1);
return(head);
}/* ; */
/* *fuzzy_set_fill() je funkcija za u~itavanje fuzzy skupa preko pohranjivanja u polje pomo}u funkcije *set_fill() */
fuzzy_set *fuzzy_set_fill(int nmbr_objects, char* f_set_name, char **names, float **memberships, int *nmbr_characteristics)
{
fuzzy_set *head;
head=MAFS((long int)1);
head->name=MAC((long int)100);
read_name(head->name, f_set_name);
head->objects=MApFO((long int)nmbr_objects);
head->number_of_objects=0;
do
*(head->objects+head->number_of_objects)=set_fill(*(nmbr_characteristics+head->number_of_objects), *(names+head->number_of_objects), *(memberships+head->number_of_objects));
while(++(head->number_of_objects)first;
do
{ act_characteristic=new_characteristic;
new_characteristic=act_characteristic->follow;
testfree((char*) act_characteristic->name);
testfree((char*) act_characteristic);
} while(new_characteristic != 0);
testfree((char*) head->m.name);
testfree((char*) head);
}/* ; */
/* delete_fuzzy_set() je funkcija za brisanje pohranjenog fuzzy seta */
void delete_fuzzy_set(fuzzy_set *head)
{
int i=0;
do
delete_fuzzy_object(*(head->objects+i));
while(++inumber_of_objects);
testfree((char*)head->name);
testfree((char*)head->objects);
testfree((char*)head);
} /* ; */
/* set_read() puni vektore names[] i memberships[] (must point to the reserved large enough location) imenima fuzzy objecta i klasa sljedno, te vrijednostima ~lanstva u pojedinoj klasi sljedno; iz zadanog fuzzy objecta */
/* ALL VECTORS M U S T BE P R E V I O U S L Y D I M E N S I O N E D */
void set_read(fuzzy_object *head, char *names, float *memberships)
{
names=read_name(names,head->m.name);
for(head->actual=head->first; head->actual!=0; head->actual=head->actual->follow, memberships++)
{ *memberships=head->actual->membership;
names=read_name(names,head->actual->name);
};
}/* ; */
/* fuzzy_set_read() puni vektore names[] i memberships[] (must point to the reserved large enough location) of each fuzzy object pointed by **names and **memberships imenima fuzzy objecta i klasa sljedno, te vrijednostima ~lanstva u pojedinoj klasi sljedno; fill address pointed by *f_set_name (enough space must be booked, Maximum enough is 100*sizeof(char)); iz zadanog fuzzy skupa */
/* ALL VECTORS M U S T BE P R E V I O U S L Y D I M E N S I O N E D */
void fuzzy_set_read(fuzzy_set *head, char **names, float **memberships, char *f_set_name)
{
int i=0;
read_name(f_set_name, head->name);
do
set_read(*(head->objects+i), *(names+i), *(memberships+i));
while(++inumber_of_objects);
} /* ; */
/* fill_set() puni fuzzy object iz vektora names[] i memberships[] */
void fill_set(fuzzy_object *head, char *names, float *memberships)
{
char *name;
name=MAC((long int)100);
read_name(head->m.name,names);
names+=read_name(name, names)- name;
for(head->actual=head->first; head->actual!=0; head->actual=head->actual->follow)
{ head->actual->membership= *(memberships++);
read_name(head->actual->name, names);
names+=read_name(name, names)- name;
};
testfree((char*)name);
}/* ; */
/* fill_fuzzy_set() fills existing fuzzy set (with the same number of objects) with new values for objects names and characteristics names and memberships */
void fill_fuzzy_set(fuzzy_set *head, char **names, float **memberships)
{
int i=0;
do
fill_set(*(head->objects+i), *(names+i), *(memberships+i));
while(++inumber_of_objects);
} /* ; */
/* fill_fuzzy_object_memberships() fills only membership values of (characteristics of) existing fuzzy object from vector *memberships */
void fill_fuzzy_object_memberships(fuzzy_object *head, float *memberships)
{
for(head->actual=head->first; head->actual!=0; head->actual=head->actual->follow)
head->actual->membership=*(memberships++);
} /* ; */
/* fill_fuzzy_set_memberships() fills only membership values of (characteristics of objects of) existing fuzzy set from vectors *memberships for each fuzzy object pointed by **memberships */
void fill_fuzzy_set_memberships(fuzzy_set *head, float **memberships)
{
int i=0;
do
fill_fuzzy_object_memberships(*(head->objects +i), *(memberships+i));
while(++inumber_of_objects);
} /* ; */
/* fuzzy_object_check() je funkcija koja provjerava da li je suma svih funkcija ~lanstva = 1+border, te da li su sve funkcije ~lanstva izmedu 0 i 1 ; vra}a vrijednosti: Y=0 - sve je u redu, S=1 - suma nije u redu, M=2 - jedna ili vi{e funkcija ~lanstva nije u redu, ALL=3 - nije u redu suma, te jedna ili vi{e funkcija ~lanstva nije u redu ; ulazna veli~ina je dozvoljeno odstupanje sume od 1 uslijed floating point ra~unanja */
/* pomo}ne funkcije su fuzzy_check_sum() koja vra}a T=1 ako je suma izmedu 1-border i 1+border, a F=0 ako nije; te fuzzy_check_membership() koja vra~a T=1 ako je svaka vrijednost funkcije ~lanstva izmedu 0 i 1, a F=0 ako nije */
enum Bool fuzzy_check_sum(fuzzy_object *head, float border)
{
float sum;
enum Bool check_sum;
for(head->actual=head->first, sum=0.0; (head->actual!=0)&&(sum<1+border); head->actual=head->actual->follow)
sum+=head->actual->membership;
check_sum=((sum < 1.0+border) && (sum > 1.0-border)) ? T : F;
return(check_sum);
}/* ; */
enum Bool fuzzy_check_membership(fuzzy_object *head)
{
enum Bool check_membership;
for(head->actual=head->first, check_membership=T; (head->actual!=0)&&(check_membership==T); head->actual=head->actual->follow)
if ((head->actual->membership<0.0)||(head->actual->membership>1.0))
check_membership=F;
return(check_membership);
}/* ; */
enum check_type fuzzy_object_check(fuzzy_object *head, float border)
{
enum check_type check;
check=(enum check_type)((1-((int)fuzzy_check_sum(head,border)))+(1-((int)fuzzy_check_membership(head)))*2);
return(check);
}/* ; */
/* fuzzy_object_normalisation() vr{i normalizaciju vrijednosti ~lanstva */
void fuzzy_object_normalisation(fuzzy_object *head)
{
characteristic *act_characteristic;
float sum;
for(act_characteristic=head->first, sum=0.0; act_characteristic!=0; act_characteristic=act_characteristic->follow)
sum+=act_characteristic->membership;
if(sum!=1.0 && sum!=0.0)
for(act_characteristic=head->first; act_characteristic!=0; act_characteristic=act_characteristic->follow)
act_characteristic->membership/=sum;
}/* ; */
/* *fill_crisp_set() puni crisp_set iz zadanih number_of_subsets koji kazuje koliko crisp_set ima podskupova, *name koji sadrzava pointer na podrucje u kojem je zapisan vektor imena (identicno kao kod *set_fill, samo sto nema imena crisp skupa), *memberships koji sadrzi pointer na podrucje gdje zapisan vektor pripadnosti subset-a crisp_set-u (0 ili 1) */
crisp_set *fill_crisp_set(int number_of_subsets, char *name, int *memberships)
{
crisp_set *crisp;
char *names, *nam, *names1;
int counter;
crisp=MACS((long int)1);
crisp->number_of_subsets=number_of_subsets;
crisp->memberships=MAEB((long int)(int)crisp->number_of_subsets);
crisp->name=MAC((long int)(int)(50*crisp->number_of_subsets));
names=crisp->name;
names1= names;
nam= name;
for(counter=0; counternumber_of_subsets; counter++)
{ names=read_name(names,nam);
nam+= names-names1;
names1= names;
*(crisp->memberships+counter)=(*(memberships+counter)>0)?T:F;
};
return(crisp);
} /* ; */
/* delete_crisp_set() je funkcija za brisanje pohranjenog crisp skupa */
void delete_crisp_set(crisp_set *head)
{
testfree((char*) head->name);
testfree((char*) head->memberships);
testfree((char*) head);
}/* ; */
/* *crisp2fuzzy(number_of_subsets, *name, *crisp_subsets) pretvara crisp skup s number_of_subsets podskupova, na kojih ukazuje *crisp_subsets i na cija imena nakon imena skupa ukazuje *name, u fuzzy */
fuzzy_object*crisp2fuzzy(char *fuzzy_object_name, int number_of_subsets, char *name, int *crisp_subsets)
{
int counter;
float *memberships;
char *names, *names1, *nam, *nam1;
names=MAC((long int)(int)(50*(number_of_subsets+1)));
names1=names;
nam=name;
names1=read_name(names,fuzzy_object_name);
nam1=names1;
memberships=MAF((long int)(int)number_of_subsets);
for(counter=0; counternumber_of_subsets+1)));
names1=names;
nam=crisp->name;
names1=read_name(names,name);
nam1=names1;
memberships=MAF((long int)(int)crisp->number_of_subsets);
for(counter=0; counternumber_of_subsets; counter++)
{ *(memberships+counter)=((*(crisp->memberships+counter))==T)? (float)1.0 : (float)0.0;
names1=read_name(names1,nam);
nam+=names1-nam1;
nam1=names1;
};
return(set_fill(crisp->number_of_subsets,names,memberships));
testfree((char*)memberships);
testfree((char*)names);
}/* ; */
/* fuzzy2crisp() je suprotna od crisp2fuzzy, a vraca strukturu crisp_set koja sadrzi number_of_subsets = broj characteristic-a fuzzy set-a, te pointere *memberships i *name usmjerava na podrucje memorije koje rezervira i puni imenima characteristic-a slijedno (u *name)(oprez - ne puni s imenom fuzzy set-a), te vrijednostima clanstva (u *memberships); ako je vrijednost clanstva pojedine characteristic-e < border tada vrijednost clanstva crisp subset-a poprima vrijednost 0, dok u ostalim slucajevima poprima vrijednost 1 */
crisp_set *fuzzy2crisp(fuzzy_object *head, float border)
{
crisp_set *crisp;
enum Bool *memberships;
char *name;
crisp=MACS((long int)1);
crisp->number_of_subsets=head->number_of_characteristics;
crisp->memberships=MAEB((long int)(int)head->number_of_characteristics);
memberships=crisp->memberships;
crisp->name=MAC((long int)(int)(50*head->number_of_characteristics));
name=crisp->name;
for(head->actual=head->first; head->actual!=0; head->actual=head->actual->follow)
{ name=read_name(name,head->actual->name);
*(memberships++)=(head->actual->membershipactual=head->first, max_membership=0.0; head->actual!=0; head->actual=head->actual->follow)
if (head->actual->membership>max_membership)
{
max_membership=head->actual->membership;
read_name(name,head->actual->name);
};
return(name);
}/* ; */
/* *fuzzy_object_defuzzyfication() je sli~na fuzzy2crisp_defuzzyfication; s tim {to vra}a pointer na po~etnu adresu vektora(char) s imenima klasa s maksimalnom vrijednosti (ako ima vi{e klasa s tom istom vrijednosti) */
char *fuzzy_object_defuzzyfication(fuzzy_object *head)
{
char *name, *name1, *name2, *name3, *name4, *name5;
float max_membership;
unsigned l=300;
name1=MAC((long int)l);
name=name1;
for(head->actual=head->first, max_membership=0.0; head->actual!=0; head->actual=head->actual->follow)
if (head->actual->membership>max_membership)
{
max_membership=head->actual->membership;
read_name(name,head->actual->name);
};
for(head->actual=head->first; head->actual!=0; head->actual=head->actual->follow)
if (head->actual->membership==max_membership)
{ if ((int)(name - name1) > (int)(l) - 100)
{ name2=name1;
name3=name;
name4=name2;
l+=100;
name1=MAC((long int)l);
name=name1;
do
{ name5=name;
name=read_name(name,name4);
name4+=name-name5;
} while(name4actual->name);
};
*name='#';
return(name1);
}/* ; */
/* check_name(*name1,*name2) vra}a T=1 ako su name1 i name2 ista imena, ina~e vra}a F=0 */
enum Bool check_name(char *name1, char *name2)
{
enum Bool check;
do
check=(*(name1++)==*(name2++))?T:F;
while((check==T)&&(((*name1>39)&&(*name1<59))||((*name1>63)&&(*name1<127))));
return(check);
}/* ; */
/* *fuzzy_AND() vra}a pointer na novi skup nastao kao presjek postoje}ih. Rezultat presjeka dvaju fuzzy skupova ne zadovoljava uvjet da je suma ~lanstava svih klasa 1. Uz pretostavku da zadani fuzzy skupovi predstavljaju distribuciju fuzzy varijable, te da je distribucija dobivena kao grafi~ki presjek zadanih distribucija dobrog oblika *fAND() vra}a kao razultat normaliziran fuzzy skup, vr{e}i normalizaciju dobivenog presjeka, u svakom slu~aju osim kada je presjek prazan skup */
fuzzy_object *fuzzy_AND(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)(head2->number_of_characteristics));
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
names=read_name(names, head1->m.name);
names--;
*(names++)='_';
*(names++)='A';
*(names++)='N';
*(names++)='D';
*(names++)='_';
names=read_name(names, head2->m.name);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=0.0;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership>head2->actual->membership)?
head2->actual->membership : head1->actual->membership;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=0.0;
/* *(set2+counter2)=T; */
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
fuzzy_object *fAND(fuzzy_object *head1, fuzzy_object *head2)
{
fuzzy_object *head;
head=fuzzy_AND(head1,head2);
fuzzy_object_normalisation(head);
return(head);
}/* ; */
/* *fuzzy_OR() vra}a pointer na novi skup nastao kao unija postoje}ih. Rezultat unije dvaju fuzzy skupova ne zadovoljava uvjet da je suma ~lanstava svih klasa 1. Uz pretostavku da zadani fuzzy skupovi predstavljaju distribuciju fuzzy varijable, te da je distribucija dobivena kao grafi~ka unija zadanih distribucija dobrog oblika *fOR() vra}a kao razultat normaliziran fuzzy skup, vr{e}i normalizaciju dobivene unije, u svakom slu~aju osim kada je unija prazan skup, a to je samo kada su oba ulazna skupa prazni skupovi */
fuzzy_object *fuzzy_OR(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)(head2->number_of_characteristics));
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
names=read_name(names, head1->m.name);
names--;
*(names++)='_';
*(names++)='O';
*(names++)='R';
*(names++)='_';
names=read_name(names, head2->m.name);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=head1->actual->membership;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membershipactual->membership)?
head2->actual->membership : head1->actual->membership;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=head2->actual->membership;
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
fuzzy_object *fOR(fuzzy_object*head1, fuzzy_object*head2)
{
fuzzy_object*head;
head=fuzzy_OR(head1,head2);
fuzzy_object_normalisation(head);
return(head);
}/* ; */
/* *fuzzy_algebraic_product() vra}a pointer na novi skup nastao kao algebarski produkt postoje}ih. Rezultat algebarskog produkta dvaju fuzzy skupova je novi fuzzy skup s clanstvom kao produktom clanstava zadanih dvaju fuzzy skupova. Vrijedi *fuzzy_algebraic_product(A,B) is subset of *fuzzy_AND(A,B). */
fuzzy_object *fuzzy_algebraic_product(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
names=read_name(names, head1->m.name);
names--;
*(names++)='_';
*(names++)='a';
*(names++)='l';
*(names++)='g';
*(names++)='e';
*(names++)='b';
*(names++)='r';
*(names++)='a';
*(names++)='i';
*(names++)='c';
*(names++)='_';
*(names++)='p';
*(names++)='r';
*(names++)='o';
*(names++)='d';
*(names++)='u';
*(names++)='c';
*(names++)='t';
*(names++)='_';
names=read_name(names, head2->m.name);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=0.0;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership*head2->actual->membership;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=0.0;
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
/* *fuzzy_bounded_product() vra}a pointer na novi skup nastao kao granicni produkt postoje}ih. Rezultat granicnog produkta dvaju fuzzy skupova je novi fuzzy skup s clanstvom = Max[0.0 , suma clanstava zadanih dvaju fuzzy skupova - 1.0]. Vrijedi *fuzzy_bounded_product(A,B) is subset of *fuzzy_algebraic_product(A,B). */
fuzzy_object *fuzzy_bounded_product(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
names=read_name(names, head1->m.name);
names--;
*(names++)='_';
*(names++)='b';
*(names++)='o';
*(names++)='u';
*(names++)='n';
*(names++)='d';
*(names++)='e';
*(names++)='d';
*(names++)='_';
*(names++)='p';
*(names++)='r';
*(names++)='o';
*(names++)='d';
*(names++)='u';
*(names++)='c';
*(names++)='t';
*(names++)='_';
names=read_name(names, head2->m.name);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=0.0;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership*head2->actual->membership)>1.0)?
head1->actual->membership*head2->actual->membership-(float)1.0 : (float)0.0;
*(set2+counter2)=T;
}; };
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=0.0;
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
/* *fuzzy_algebraic_sum() vra}a pointer na novi skup nastao kao algebarska suma postoje}ih. Rezultat algebarske sume dvaju fuzzy skupova je novi fuzzy skup s clanstvom kao sumom clanstava zadanih dvaju fuzzy skupova umanjenim za njihov umnozak. Vrijedi *fuzzy_OR(A,B) is subset of *fuzzy_algebraic_sum(A,B). */
fuzzy_object *fuzzy_algebraic_sum(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
names=read_name(names, head1->m.name);
names--;
*(names++)='_';
*(names++)='a';
*(names++)='l';
*(names++)='g';
*(names++)='e';
*(names++)='b';
*(names++)='r';
*(names++)='a';
*(names++)='i';
*(names++)='c';
*(names++)='_';
*(names++)='s';
*(names++)='u';
*(names++)='m';
*(names++)='_';
names=read_name(names, head2->m.name);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=head1->actual->membership;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership+head2->actual->membership-head1->actual->membership*head2->actual->membership;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=head2->actual->membership;
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
/* *fuzzy_bounded_sum() vra}a pointer na novi skup nastao kao granicna suma postoje}ih. Rezultat granicne sume dvaju fuzzy skupova je novi fuzzy skup s clanstvom = min[1.0 , suma clanstava zadanih dvaju fuzzy skupova]. Vrijedi *fuzzy_algebraic_sum(A,B) is subset of *fuzzy_bounded_sum(A,B). */
fuzzy_object *fuzzy_bounded_sum(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
names=read_name(names, head1->m.name);
names--;
*(names++)='_';
*(names++)='b';
*(names++)='o';
*(names++)='u';
*(names++)='n';
*(names++)='d';
*(names++)='e';
*(names++)='d';
*(names++)='_';
*(names++)='s';
*(names++)='u';
*(names++)='m';
*(names++)='_';
names=read_name(names, head2->m.name);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=head1->actual->membership;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership+head2->actual->membership)<1.0)?
head1->actual->membership+head2->actual->membership : (float)1.0 ;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=head2->actual->membership;
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
/* *fuzzy_absolute_difference() vra}a pointer na novi skup nastao kao absolutna razlika postoje}ih (C=|A-B|). Rezultat absolutne razlike dvaju fuzzy skupova je novi fuzzy skup s clanstvom kao absolutna razlika clanstava zadanih dvaju fuzzy skupova( m(C)=|m(A)-m(B)| ). */
fuzzy_object *fuzzy_absolute_difference(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
*(names++)='|';
names=read_name(names, head1->m.name);
names--;
*(names++)='-';
names=read_name(names, head2->m.name);
names--;
*(names++)='|';
*(names++)=' ';
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=head1->actual->membership;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership-head2->actual->membership)>0.0)?
head1->actual->membership-head2->actual->membership : head2->actual->membership-head1->actual->membership ;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=head2->actual->membership;
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
/* *fuzzy_convex_combination() vra}a pointer na novi skup nastao kao konveksna kombinacija postoje}ih( C=(A,B,l)=l*A+(1-l)*B). Rezultat konveksne kombinacije dvaju fuzzy skupova s faktorom l je novi fuzzy skup s clanstvom kao sumom clanstva prvog fuzzy skupa pomnozenog s l i drugog fuzzy skupa pomnozenog s komplementom od l. Faktor l (u funkciji oznacen kao lambda) je realan broj iz intervala [0.0 , 1.0]. */
fuzzy_object *fuzzy_convex_combination(fuzzy_object *head1, fuzzy_object *head2, float lambda)
{
int counter1, counter2, l;
float *membership;
enum Bool *set2;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
*(names++)='(';
names=read_name(names, head1->m.name);
names--;
*(names++)=',';
names=read_name(names, head2->m.name);
names--;
*(names++)=':';
*(names++)='l';
*(names++)=')';
*(names++)=' ';
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=head1->actual->membership*lambda;
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if(counter2number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership*lambda+head2->actual->membership*((float)1.0-lambda);
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+(counter1++))=head2->actual->membership*((float)1.0-lambda);
};
};
};
testfree((char*)set2);
return(set_fill(counter1,name,membership));
}/* ; */
/* *fuzzy_convex_set_combination() vra}a pointer na novi skup nastao kao konveksna kombinacija postoje}ih( C=(A,B,C)=C*A+(1-C)*B). Za razliku od *fuzzy_convex_combination() sada je l->C fuzzy skup. Rezultat konveksne kombinacije dvaju fuzzy skupova s fuzzy skupom l je novi fuzzy skup s clanstvom kao sumom clanstva prvog fuzzy skupa pomnozenog s clanstvom treceg fuzzy skupa i drugog fuzzy skupa pomnozenog s komplementom od clanstva treceg fuzzy skupa. */
fuzzy_object *fuzzy_convex_set_combination(fuzzy_object *head1, fuzzy_object *head2, fuzzy_object *head3)
{
int counter1, counter2, counter3,l;
float *membership;
enum Bool *set2, *set3;
char *name, *names, *name2, *name3, *name4, *name5;
membership=MAF((long int)(int)(head1->number_of_characteristics+head2->number_of_characteristics));
set2=MAEB((long int)(int)head2->number_of_characteristics);
set3=MAEB((long int)(int)head3->number_of_characteristics);
l=(head1->number_of_characteristics+head2->number_of_characteristics)*100;
name=MAC((long int)l);
names=name;
*(names++)='(';
names=read_name(names, head1->m.name);
names--;
*(names++)=',';
names=read_name(names, head2->m.name);
names--;
*(names++)=':';
names=read_name(names, head2->m.name);
names--;
*(names++)=')';
*(names++)=' ';
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter2=0; counter2<=head3->number_of_characteristics; *(set3+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ names=read_name(names,head1->actual->name);
*(membership+counter1)=0.0;
for(counter2=0, head3->actual=head3->first; (*(set3+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head3->actual=head3->actual->follow;
};
if(*(set3+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head3->actual->name)==F))
{ counter2++;
head3->actual=head3->actual->follow;
};
if((int)(counter2)number_of_characteristics)
{
*(membership+counter1)=head1->actual->membership*head3->actual->membership;
*(set3+counter2)=T;
};
};
for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if((int)(counter2)number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->membership)*head2->actual->membership;
*(set2+counter2)=T;
};
};
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
{ if(counter2<=head2->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+counter1++)=0.0;
for(counter3=0, head3->actual=head3->first; (*(set3+counter3)==T)&&(counter3number_of_characteristics); )
{ counter3++;
head3->actual=head3->actual->follow;
};
if(*(set3+counter3)==F)
{ while((counter3number_of_characteristics)&&(check_name(head2->actual->name,head3->actual->name)==F))
{ counter3++;
head3->actual=head3->actual->follow;
};
if((int)(counter3)number_of_characteristics)
{
counter1--;
*(membership+counter1++)=head2->actual->membership*((float)1.0-head3->actual->membership);
*(set3+counter3)=T;
};
};
};
};
};
for(counter2=0, head3->actual=head3->first; counter2number_of_characteristics; head3->actual=head3->actual->follow, counter2++)
{ if(*(set3+counter2)==F)
{ if(counter2<=head3->number_of_characteristics)
{ if ((int)(names - name) > (int)(l) - 100)
{ name2=name;
name3=names;
name4=name2;
l+=100;
name=MAC((long int)l);
names=name;
do
{ name5=names;
names=read_name(names,name4);
name4+=names-name5;
} while(name4actual->name);
*(membership+counter1++)=0.0;
};
};
};
testfree((char*)set2);
testfree((char*)set3);
return(set_fill(counter1,name,membership));
}/* ; */
/* fset_equall() vra}a T ako fuzzy skupovi na koje ukazuju pointeri imaju iste klase s istim nazivima (ne ispituju se vrijednosti ~lanstva, a redoslijed klasa nije bitan), a F ako nemaju */
enum Bool fset_equall_set(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2;
enum Bool *set2, equall=F;
set2=MAEB((long int)(int)head2->number_of_characteristics);
if(head1->number_of_characteristics==head2->number_of_characteristics)
{ for(counter2=0; counter2number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, equall=T, head1->actual=head1->first; (equall==T)&&(head1->actual!=0); head1->actual=head1->actual->follow, counter1++)
{ for(counter2=0, head2->actual=head2->first; (head2->actual!=0)&&(*(set2+counter2)==T); )
{ head2->actual=head2->actual->follow;
counter2++;
};
if(head2->actual==0)
equall=F;
else
{ while((check_name(head1->actual->name,head2->actual->name)==F)&&(head2->actual!=0))
do
{ head2->actual=head2->actual->follow;
counter2++;
} while((*(set2+counter2)==T)&&(head2->actual!=0));
if(head2->actual==0)
equall=F;
else
*(set2+counter2)=T;
};
};
};
testfree((char*)set2);
return(equall);
}/* ; */
/* f_equall() vra}a T ako su fuzzy skupovi na koje ukazuju pointeri jednaki (isti nazivi klasa i vrijednosti ~lanstva, a redoslijed klasa nije bitan), a F ako nisu */
enum Bool f_equall(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2;
enum Bool *set2, equall=F;
set2=MAEB((long int)(int)head2->number_of_characteristics);
if(fset_equall_set(head1,head2)==T)
{ for(counter2=0; counter2number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, equall=T, head1->actual=head1->first; (equall==T)&&(head1->actual!=0); head1->actual=head1->actual->follow, counter1++)
{ for(counter2=0, head2->actual=head2->first; *(set2+counter2)==T; )
{ head2->actual=head2->actual->follow;
counter2++;
};
while(check_name(head1->actual->name,head2->actual->name)==F)
do
{ head2->actual=head2->actual->follow;
counter2++;
} while(*(set2+counter2)==T);
if(head1->actual->membership!=head2->actual->membership)
equall=F;
else
*(set2+counter2)=T;
};
};
testfree((char*)set2);
return(equall);
}/* ; */
/* f_equall_epsilon() vra}a T ako fuzzy skupovi na koje ukazuju pointeri imaju iste nazive klasa, a vrijednosti ~lanstva istoimenih klasa se razlikuju za manje ili jednako epsilon, dok redoslijed klasa nije bitan, ina~e vra}a F */
enum Bool f_equall_epsilon(fuzzy_object *head1, fuzzy_object *head2, float epsilon)
{
int counter1, counter2;
enum Bool *set2, equall=F;
set2=MAEB((long int)(int)head2->number_of_characteristics);
if(fset_equall_set(head1,head2)==T)
{ for(counter2=0; counter2number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, equall=T, head1->actual=head1->first; (equall==T)&&(head1->actual!=0); head1->actual=head1->actual->follow, counter1++)
{ for(counter2=0, head2->actual=head2->first; *(set2+counter2)==T; )
{ head2->actual=head2->actual->follow;
counter2++;
};
while(check_name(head1->actual->name,head2->actual->name)==F)
do
{ head2->actual=head2->actual->follow;
counter2++;
} while(*(set2+counter2)==T);
if((head1->actual->membership<=head2->actual->membership+epsilon)&&(head1->actual->membership>=head2->actual->membership-epsilon))
*(set2+counter2)=T;
else
equall=F;
};
};
testfree((char*)set2);
return(equall);
}/* ; */
/* f_sum_membership() daje sumu svih vrijednosti ~lanstva fuzzy skupa */
float f_sum_membership(fuzzy_object *head)
{
float sum;
for(sum=0.0, head->actual=head->first; head->actual!=0; head->actual=head->actual->follow)
sum+=head->actual->membership;
return(sum);
}/* ; */
/* fsubsethood() vra}a vrijednost koja pokazuje koliko je 1. fuzzy skup podskup 2. po formuli S(A,B)=((~lanstva(fuzzy_AND(A,B)))/(~lanstva(A)) . Podskupnost A u B se mo`e promatrati i kao mjera uvjetovanja B od strane A. */
float fsubsethood(fuzzy_object *head1, fuzzy_object *head2)
{
float fsubsethood, fs1;
fs1=f_sum_membership(head1);
if(fs1==0.0)
fsubsethood=1.0; /* ako uzmemo da je prazan skup podskup svakog partitivnog skupa!!!!! */
else
fsubsethood=f_sum_membership(fuzzy_AND(head1, head2))/fs1;
return(fsubsethood);
}/* ; */
/* divergence() racuna divergenciju dvaju fuzzy skupova po formuli (16) iz Magisterija */
double divergence(fuzzy_object *head1, fuzzy_object *head2)
{
int counter1, counter2;
double divergence=0.0;
enum Bool *set2;
set2=MAEB((long int)(int)head2->number_of_characteristics);
for(counter2=0; counter2<=head2->number_of_characteristics; *(set2+(counter2++))=F);
for(counter1=0, head1->actual=head1->first; head1->actual!=0; head1->actual=head1->actual->follow, counter1++)
{ for(counter2=0, head2->actual=head2->first; (*(set2+counter2)==T)&&(counter2number_of_characteristics); )
{ counter2++;
head2->actual=head2->actual->follow;
};
if(*(set2+counter2)==F)
{ while((counter2number_of_characteristics)&&(check_name(head1->actual->name,head2->actual->name)==F))
{ counter2++;
head2->actual=head2->actual->follow;
};
if((int)(counter2)<(int)(head2->number_of_characteristics))
{ divergence+=((double)(head1->actual->membership-head2->actual->membership))*log((double)((1.0+head1->actual->membership)/(1.0+head2->actual->membership)))+((double)(head2->actual->membership-head1->actual->membership))*log((double)((2.0-head1->actual->membership)/(2.0-head2->actual->membership)));
*(set2+counter2)=T;
};
}
else
divergence+=((double)head1->actual->membership)*(log((double)(1.0+head1->actual->membership))-log((double)((2.0-head1->actual->membership)/2.0)));
};
for(counter2=0, head2->actual=head2->first; counter2number_of_characteristics; head2->actual=head2->actual->follow, counter2++)
{ if(*(set2+counter2)==F)
if(counter2<=head2->number_of_characteristics)
divergence+=((double)head2->actual->membership)*(log((double)(1.0+head2->actual->membership))-log((double)((2.0-head2->actual->membership)/2.0)));
};
testfree((char*)set2);
return(divergence);
}/* ; */
/* entropy_DeLuceTermini() racuna entropiju fuzzy skupa po formuli ((17) iz Magisterija) De Luce i Terminia analogno informacijskoj teoretskoj entropiji */
double entropy_DeLuceTermini(fuzzy_object *head)
{
double entropy=0.0;
for(head->actual=head->first; head->actual!=0; head->actual=head->actual->follow)
entropy+=((head->actual->membership<0.000001)||(head->actual->membership>0.999999))?(double)0.0:((double)head->actual->membership)*log((double)head->actual->membership);
entropy/=log((double)2.0)*((double)(-1.0*head->number_of_characteristics));
return(entropy);
}/* ; */
/* crisp_set *make_inverse() pravi inverzni crisp_set od zadanog crisp_set-a */
crisp_set *make_inverse(crisp_set *head)
{
int counter;
crisp_set *crisp;
char *name, *name1, *name2;
crisp=MACS((long int)1);
crisp->number_of_subsets=head->number_of_subsets;
crisp->memberships=MAEB((long int)(int)head->number_of_subsets);
crisp->name=MAC((long int)(int)(50*head->number_of_subsets));
name=crisp->name;
name1=name;
name2=head->name;
for(counter=0; counternumber_of_subsets; counter++)
{ name=read_name(name,name2);
*(crisp->memberships+counter)=(*(head->memberships+counter)==T)?F:T;
name2+=name-name1;
name1=name;
};
return(crisp);
} /* ; */
/* *inversing() pravi inverzni fuzzy_object od zadanog fuzzy_object-a */
fuzzy_object *inversing(fuzzy_object *head)
{
int counter;
char *names;
float *memberships;
names=MAC((long int)(int)(50*(head->number_of_characteristics+1)));
memberships=MAF((long int)(int)head->number_of_characteristics);
set_read(head,names,memberships);
for(counter=0; counternumber_of_characteristics; *(memberships+counter)=(float)1.0-(*(memberships+counter++)));
return(set_fill(head->number_of_characteristics,names,memberships));
testfree((char*)names);
testfree((char*)memberships);
} /* ; */
/* entropy_using_divergence() racuna entropiju fuzzy skupa preko divergencije po formuli (20) iz Magisterija */
double entropy_using_divergence(fuzzy_object *head)
{
fuzzy_object *h_n, *h_f;
crisp_set *head_near, *head_far;
char a=' ';
head_near=fuzzy2crisp(head,0.5);
head_far=make_inverse(head_near);
h_n=crisp_set2fuzzy(head_near,&a);
h_f=crisp_set2fuzzy(head_far,&a);
return(divergence(head,h_n)/divergence(head,h_f));
}/* ; */
float fuzzy_integral_Sugeno(int number_of_evaluation_items, float lambda, float **items)
/* fuzzy_integral_Sugeno returnes value of Sugeno's fuzzy integral for given number_of_evaluation_items of items stored in items[number_of_evaluation_items][2], where *(*(items+i)+j) is (j=0 ==> value; j=1 ==> confidence of that item evaluation (method)) for (i-1)-th item; lambda is Sugeno's lambda defined: g(A+B)=g(A)+g(B)+lambda*g(A)*g(B), where (A+B) means A union B, lambda>-1 and lambda<>0 */
/* lambda must satisfy lambda+1=product_over_all_items(1+lambda*item's_(evaluation_method)_confidence), lambda>-1, lambda<>0 */
/* confidences of item evaluation (method) must satisfy (Sugeno's) fuzzy measure properties */
/* values (stored in items) must satisfy the properties of fuzzy measure */
{
float *A, f_i, temp, **item_copy;
int i, j;
/* sorting items in decreasing order into item_copy */
item_copy=MApF(number_of_evaluation_items);
for(i=0; i*(*(item_copy+j)+0))
{
/* swaping values */
temp=*(*(item_copy+j)+0);
*(*(item_copy+j)+0)=*(*(item_copy+i)+0);
*(*(item_copy+i)+0)=temp;
/* swaping confidence measures */
temp=*(*(item_copy+j)+1);
*(*(item_copy+j)+1)=*(*(item_copy+i)+1);
*(*(item_copy+i)+1)=temp;
};
/* calculation of g(A) (g(A) is denoted as A) */
A=MAF(number_of_evaluation_items);
*(A+0)=*(*(item_copy+0)+1);
for(i=1; if_i) f_i=temp;
};
/* releasing reserved memory */
free((char*) A);
for(i=0; i-1 and <>0 */
/* lambda is calculated to make true lambda + 1 = product_over_all_confidences(1 + lambda * confidence) , where "=" means equal within an error < epsilon */
/* confidences must preserve the properties of fuzzy measure */
{
int i;
double lambda, end, r, r0, step, check0, check1, epsilon, epsilon0;
extern float max_lambda;
/* checking if more than one confidence value is greater than 0.0 and if not zeros are changed to 0.02 so lambda could be calculated */
for(epsilon=0.0, i=0; i0.02) epsilon+=1.0;
/* printf("%f ,", *(confidences+i)); */ };
if(epsilon<1.5)
for(i=0; i %f :", lambda, check0);
*/
do
{
/* searching for an interval where signum is changed */
if(lambda<-epsilon0)
{
for(r=lambda, check1=check0; (check0*check1>0.0)&&(!(r>-epsilon0)); )
{
r0=r;
r=(r+step>-epsilon0)? ((r0>-(epsilon0+epsilon))? epsilon0: ((-epsilon0>-1.0+epsilon0)?-epsilon0: epsilon0)): r+step;
for(check1=-1.0, i=0; i %f -> %f,", lambda, check0);
*/
for(r=lambda, check1=check0; (!(check0*check1<0.0))&&(r %f -> %f,", r, check1);
*/
};
};
/* setting new lambda as the latest r before check1 changed its signum */
lambda=r0;
/* decreasing step 10 times */
step/=10.0;
for(check0=-1.0, i=0; iepsilon)||(check0<-epsilon))&&(r {");
printf("[%f,%f,%f,%f]", lambda, check0, r, epsilon0);
printf("} ");
*/
epsilon0/=10.0;
}
while((!(r-1 and <>0 */
/* lambda is calculated to make true lambda + 1 = product_over_all_confidences(1 + lambda * confidence) , where "=" means equal within an error < epsilon */
/* lambda is forced to be positive */
/* confidences must preserve the properties of fuzzy measure */
{
int i;
double lambda, end, r, r0, step, check0, check1, epsilon, epsilon0;
extern float max_lambda;
/* checking if more than one confidence value is greater than 0.0 and if not values of zeros are changed to 0.01 so lambda could be calculated */
for(epsilon=0.0, i=0; i0.01) epsilon+=1.0;
if(epsilon<1.5)
for(i=0; iepsilon)||(check0<-epsilon))&&(rf_s=f_s;
T->o=o;
for(c=0, c1=0; co; c++)
for((*(T->f_s+c))->actual=(*(T->f_s+c))->first; (*(T->f_s+c))->actual!=0; (*(T->f_s+c))->actual=(*(T->f_s+c))->actual->follow, c1++);
T->dimension=c1;
T->nout=nout;
T->counter=0;
T->Wpast=0;
T->W=MApF((long int)1);
*(T->W)=W;
T->BPm=MApF((long int)1);
T->x=0;
T->D_w=MAF((long int)(int)(T->dimension*T->dimension));
for(c=0; cdimension*T->dimension; *(T->D_w+c++)=0.0);
return(T);
} /* ; */
/* void delete_fuzzy_batchBP(time_slice *T) delete time_slice for given system and free memory area reserved for saving F_w(i,j) for each weight. It should be run when we finish with backpropagation algorithm based learning of the neural network */
void delete_fuzzy_batchBP(time_slice *T)
{ testfree((char*)T->D_w);
testfree((char*)*(T->W));
testfree((char*)*(T->BPm));
testfree((char*)T);
} /* ; */
/* void fuzzy_system_run(time_slice *T) calculates one (iteration of) propagation of system input through system variables (over weights) to system output */
void fuzzy_system_run(time_slice *T)
{
int c1, c2, c3, c4;
characteristic *act1, *act2;
for(c1=0, c3=0, act1=(*(T->f_s+c3))->first; c1dimension; c1++, act1=(act1->follow==0)?((c3>(int)(T->o)-2)?act1:(*(T->f_s+(++c3)))->first):act1->follow)
{
for(c2=0, c4=0, act2=(*(T->f_s+c4))->first; c2<=c1; c2++, act2=(act2->follow==0)?(*(T->f_s+(++c4)))->first:act2->follow)
act1->membership+=act2->membership*(*(*(T->W)+c2+c1*T->dimension));
};
} /* ; */
/* void fuzzy_system_run_selected(time_slice *T, int n) is similar to fuzzy_system_run() with the difference that 'n' presents first object whose characteristics are calculated over influences of previous objects. For example (let o=4) n=3 means T->f_s+2 (third object) and T->f_s+3 (forth object) characteristics will be calculated over influences of previous objects. */
void fuzzy_system_run_selected(time_slice *T, int n)
{
int c1, c2, c3, c4;
characteristic *act1, *act2;
for(c1=0, c3=0, act1=(*(T->f_s+c3))->first;c3follow==0)?(*(T->f_s+(++c3)))->first:act1->follow;
c1++;
};
for(; c1dimension; c1++, act1=(act1->follow==0)?((c3>(int)(T->o)-2)?act1:(*(T->f_s+(++c3)))->first):act1->follow)
{
act1->membership=0.0;
for(c2=0, c4=0, act2=(*(T->f_s+c4))->first; c4follow==0)?(*(T->f_s+(++c4)))->first:act2->follow)
act1->membership+=act2->membership*(*(*(T->W)+c2+c1*T->dimension));
};
} /* ; */
/* void fuzzy_system_run_layers(time_slice *T, int v) is similar to fuzzy_system_run_selected() with the difference that 'v' presents number of state variables and characteristics are calculated over influences of previous levels (first level are input and state variables for the actual interval, second layer are state variables for the next interval, while third layer is output). It means output (of the next interval) is calculated only over the state variables of the next interval. */
void fuzzy_system_run_layers(time_slice *T, int v)
{
int c1, c2, c3, c4, mem1, mem2;
characteristic *act1, *act2;
for(c1=0, c3=0, act1=(*(T->f_s+c3))->first;c3o-1-2*v;)
{
act1=(act1->follow==0)?(*(T->f_s+(++c3)))->first:act1->follow;
c1++;
};
mem1=c1;
mem2=c3;
for(; c1dimension-v; c1++, act1=(act1->follow==0)?(*(T->f_s+(++c3)))->first:act1->follow)
{
act1->membership=0.0;
for(c2=0, c4=0, act2=(*(T->f_s+c4))->first; c4follow==0)?(*(T->f_s+(++c4)))->first:act2->follow)
act1->membership+=act2->membership*(*(*(T->W)+c2+c1*T->dimension));
};
for(; c1dimension; c1++, act1=(act1->follow==0)?((c3>(int)(T->o)-2)?act1:(*(T->f_s+(++c3)))->first):act1->follow)
{
act1->membership=0.0;
for(c2=mem1, c4=mem2, act2=(*(T->f_s+c4))->first; c4follow==0)?(*(T->f_s+(++c4)))->first:act2->follow)
act1->membership+=act2->membership*(*(*(T->W)+c2+c1*T->dimension));
};
} /* ; */
/* void fuzzy_batchBP(time_slice *T, float *expected_output, float *S) calculates influence corrections after each input-output observing. Influences between characteristics can be calculated for each time slice before calling function fuzzy_batchBP() and stored in vector (matrix) pointed by *(T->W) (influence from characteristic i to characteristic j is stored in location *(*(T->W)+(i-1)*T->dimension+(j-1)). It must be called after each input-output is observed. */
void fuzzy_batchBP(time_slice *T, float *expected_output, float *S)
{
int c,c2,c3,c4=1;
characteristic *act;
*(T->BPm)=MAF((long int)(int)T->dimension);
for(c=0; cdimension; *(*(T->BPm)+c++)=0.0);
act=(*(T->f_s+T->o-c4++))->last;
for(c=T->dimension-1; c>=0; c--)
{
if((T->dimension-c)<=(int)(T->nout))
{ *(*(T->BPm)+c)+=act->membership-(*(expected_output+T->nout+c-T->dimension));
act=(act->ahead==0)?(*(T->f_s+T->o-c4++))->last:act->ahead;
};
for(c2=c+1; c2dimension; *(*(T->BPm)+c)+=*(*(T->W)+c2*T->dimension+c)*(*(*(T->BPm)+c2++)));
/* limiting (*(*(T->BPm)+c) not to become to high and couse core dump */
if(*(*(T->BPm)+c)>1000.)
*(*(T->BPm)+c)=1000.;
if(*(*(T->BPm)+c)<-1000.)
*(*(T->BPm)+c)=-1000.;
for(c2=0, c3=0; c2f_s+c3))->actual=(*(T->f_s+c3))->first; ((*(T->f_s+c3))->actual!=0)&&(c2f_s+c3))->actual=(*(T->f_s+c3))->actual->follow, c2++)
*(T->D_w+c*T->dimension+c2)+=*(S+c)*(*(*(T->BPm)+c))*(*(T->f_s+c3))->actual->membership;
};
testfree((char*)*(T->BPm));
T->counter++;
} /* ; */
/* void fuzzy_batchBP_adapting_influences(time_slice *T, float correction_weight) is function, that is to be run after whole set of system observing, that corrects all influents according T->D_w. Note T->D_w is at the end reset to 0.0 so new circle of observing (the same system) can start. correction_weight is constant of correcting of influences. It should be small and made as large as possible up to 1.0, until error starts to diverge. */
void fuzzy_batchBP_adapting_influences(time_slice *T, float correction_weight)
{
int c,c2;
for(c=0; cdimension; c++)
for(c2=0; c2dimension; *(*(T->W)+c*T->dimension+c2)-=correction_weight*(*(T->D_w+c*T->dimension+c2)),
*(T->D_w+c*T->dimension+c2++)=0.0);
T->counter=0;
} /* ; */
/* void fuzzy_BP(fuzzy_object *f_s[],int o, int nout, float *expected_output, float *W, float *S, float correction_weight) changes influence (forward) between characteristics according to BackPropagation algorithm (Werbos " Propagation throught time", Proceedings of the IEEE, Vol. 78, No. 10, October 1990). Other BP variations can be used simple changing function "void fuzzy_batchBP_adapting_influences" whose main expression can be viewed as New w(i,j) = w(i,j) - correction_weight * (dE/dw(i,j)). */
void fuzzy_BP(fuzzy_object *f_s[], int o, int nout, float *expected_output, float *W, float *S, float correction_weight)
{
time_slice *T;
T=setup_fuzzy_batchBP(f_s,o,nout,W);
fuzzy_system_run(T);
fuzzy_batchBP(T,expected_output,S);
fuzzy_batchBP_adapting_influences(T,correction_weight);
delete_fuzzy_batchBP(T);
} /* ; */
/* time_slice *start_fuzzy_BP_through_time(fuzzy_object *f_s[], int o, int nout, float **W, int Wpast) reserve memory area for saving time_slice data for the system. After all patterns are presented new weight(i,j) = weight(i,j) - learning_rate * F_w(i,j). It is to be called only once for each fuzzy_BP_through_time algorithm applying and it must be called before first time calling of fuzzy_BP_through_time! */
time_slice *start_fuzzy_BP_through_time(fuzzy_object *f_s[], int o, int nout, float **W, int Wpast)
{
int c,c1;
time_slice *T;
T=MATS((long int)1);
T->f_s=f_s;
T->o=o;
T->nout=nout;
T->W=W;
T->Wpast=Wpast;
T->counter=0;
for(c=0, c1=0; cf_s+c))->actual=(*(T->f_s+c))->first; (*(T->f_s+c))->actual!=0; (*(T->f_s+c))->actual=(*(T->f_s+c))->actual->follow, c1++);
T->dimension=c1;
T->D_w=MAF((long int)(int)(T->dimension*T->dimension));
for(c=0; cdimension*T->dimension; *(T->D_w+c++)=0.0);
T->BPm=MApF((long int)(int)T->Wpast);
T->x=MApF((long int)(int)T->Wpast);
for(c=0; c<(int)(T->Wpast)-1; c++)
{
*(T->BPm+c)=MAF((long int)(int)T->dimension);
*(T->x+c)=MAF((long int)(int)(T->dimension*T->dimension));
};
return(T); } /* ; */ /* void delete_fuzzy_batchBP_through_time(time_slice *T) free memory area reserved for saving time_slice. It should be run when we finish with backpropagation through time algorithm based learning of the neural network */
void delete_fuzzy_batchBP_through_time(time_slice *T)
{ int c;
for(c=0; c<(int)(T->Wpast)-1; testfree((char*)*(T->BPm+c)), testfree((char*)*(T->x+c++))); testfree((char*)T->BPm);
testfree((char*)T->x);
testfree((char*)T->D_w);
testfree((char*)T);
} /* ; */
/* void fuzzy_BP_through_time(time_slice *T, float *expected_output, float *S) calculates influence corrections after each input-output observing. It must be called after each input-output is observed. */
void fuzzy_BP_through_time(time_slice *T, float *expected_output, float *S)
{
int c, c1,c2,c3,c4=1;
characteristic *act;
float m1, *m2, *m3;
m2=*(T->BPm+T->Wpast-1);
m3=*(T->x+T->Wpast-1);
for(c=T->Wpast-2; c>-1; *(T->BPm+c+1)=*(T->BPm+c), *(T->x+c+1)=*(T->x+c--));
*(T->BPm+0)=m2; *(T->x+0)=m3; for(c1=0, c=0; co; c++)
for((*(T->f_s+c))->actual=(*(T->f_s+c))->first; (*(T->f_s+c))->actual!=0; *(*(T->x+0)+c1++)=(*(T->f_s+c))->actual->membership, (*(T->f_s+c))->actual=(*(T->f_s+c))->actual->follow);
for(c=0; cdimension; *(*(T->BPm+0)+c++)=0.0);
act=(*(T->f_s+T->o-c4++))->last;
for(c=T->dimension-1; c>=0; c--)
{
if((T->dimension-c)<=(int)(T->nout))
{
*(*(T->BPm+0)+c)+=act->membership-(*(expected_output+T->nout+c-T->dimension));
act=(act->ahead==0)?(*(T->f_s+T->o-c4++))->last:act->ahead;
};
for(c2=c+1; c2dimension; *(*(T->BPm+0)+c)+=*(*T->W+c2*T->dimension+c)*(*(*(T->BPm+0)+c2++)));
/* limiting (*(*(T->BPm+0)+c) not to become to high and couse core dump */
if(*(*(T->BPm+0)+c)>1000.)
*(*(T->BPm+0)+c)=1000.;
if(*(*(T->BPm+0)+c)<-1000.)
*(*(T->BPm+0)+c)=-1000.;
for(c3=1; (c3Wpast+1)&&(c3counter+1); c3++)
for(c2=0; c2dimension; c2++)
{
m1=0.0;
for(c1=0; (c1Wpast+1)&&(c1counter-c3+1); m1+=*(*(T->BPm+c1+c3)+c2)*(*(*(T->x+(c1++))+c2)));
*(*(T->BPm+0)+c)+=m1*(*(*(T->BPm+c3)+c2));
};
*(*(T->BPm+0)+c)*=*(S+c);
for(c2=0, c3=0; c2f_s+c3))->actual=(*(T->f_s+c3))->first; ((*(T->f_s+c3))->actual!=0)&&(c2f_s+c3))->actual=(*(T->f_s+c3))->actual->follow, c2++)
*(T->D_w+c*T->dimension+c2)+=(*(*(T->BPm+0)+c))*(*(T->f_s+c3))->actual->membership;
};
T->counter++;
} /* ; */
/* void fuzzy_BP_through_time_adapting_influences(time_slice *T, float correction_weight) is function, that is to be run after whole set of system observing, that corrects all influents according T->D_w. Note T->D_w is at the end reset to 0.0 so new circle of observing (the same system) can start. correction_weight is constant of correcting of influences. It should be small and made as large as possible up to 1.0, until error starts to diverge. */
void fuzzy_BP_through_time_adapting_influences(time_slice *T, float correction_weight)
{
int c,c2;
for(c=0; cdimension; c++)
for(c2=0; c2dimension; (*(*(T->W+0)+c*T->dimension+c2))-=correction_weight*(*(T->D_w+c*T->dimension+c2)),
*(T->D_w+c*T->dimension+c2++)=0.0);
} /* ; */
/* float Gauss(float m, float s, float x) calculates value of Gauss function (m=average value, s=distorsion) for (input value) x */
float Gauss(float m, float s, float x)
{
return((float)((1./(s*(sqrt(2.*acos((double)-1.)))))*exp((double)(-.5*(x-m)*(x-m)/(s*s)))));
} /* ; */
#ifdef __cplusplus
}
#endif
/* All comments on this library are welcome. Feel free to contact author if there is anything you would like or you need to be added or anything you suggest to change.
This library is for use only in education and research. It is not for commercial use! Written permission from author is necessary for commercial use or for inclusion as a part of project or program or another library!
Programs, projects, libraries or anything consists this library or its part MUST NOT be sold without author permission!
Author: Dekovich Igor, 11/73 Campbell St., Wollongong, NSW 2500, Australia,
ph: xx61 (0)2 4225 2673
e-mail: idekovich@yahoo.com */
/* Split 1994 & Auckland 1995 */
/* Auckland 4/4/1995 */
/* revision 20/10/1997 */
/* last revision 10/11/2001 */