This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule_base.h
65 lines (55 loc) · 2.02 KB
/
rule_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef RULE_BASE_H
#define RULE_BASE_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "uthash.h"
#if !defined TRUE && FALSE
#define TRUE 1
#define FALSE 0
#endif
typedef struct variable_value_pair {
char *name; // variable name
char *value; // value of the variable
char *connective; // connective to the next pair AND, OR, THEN
struct variable_value_pair *next; // address of the next variable_value_pair
} var_val_pair;
typedef struct rule_node {
int num; //rule number
var_val_pair *head_of_rule; // pointer to list of variable value pair and it's connectives
var_val_pair *tail_of_rule;
struct rule_node *next; //pointer to the next rule
} rule_node;
typedef struct fuzzy_set {
char *val_name; // value name is also hash KEY
int tuple[4]; // tuple representing the set
double last_fuzzy_val; // last value after fuzzification
UT_hash_handle hh; // makes this structure hashable
} fuzzy_set;
typedef struct variable_fuzzy_sets {
// nameof the variable which has many fuzzy sets.
char *var_name; // Also it's hash KEY
int number_of_sets;
struct fuzzy_set *sets_table; // values of fuzzy sets in hash table
UT_hash_handle hh; // makes this structure hashable
} var_sets;
typedef struct rule_base {
char *name; // name of rulebase
rule_node *rule_list; // list of rules in rule base
var_sets *var_table; // hash table of variables that each has a hash table of sets
struct measurement *measurements;
} rule_base;
typedef struct measurement {
char *var_name; // name of the measured variable
double value; // value of the variable
struct measurement *next; // pointer to next measurement node
} measurement;
// function prototypes
// load rules loads rule base from a file and return pointer to it
rule_base* loadRuleBase (FILE *f_name);
var_sets* findVarSets (var_sets **var_table, char *var_name);
fuzzy_set* findFuzzySet (fuzzy_set **sets_table, char *val_name);
void copyString(char **dest, char *src);
// insert node to list
void insertMeasurement (measurement **head, char *var_name, double value);
#endif