📄 fc.h
字号:
#include "fuzzy.h"
#include <fstream>
fuzzy f1; // global fuzzy-system
int read_fuzzy(const char* fname)
{
ifstream f(fname);
if(!f){
cerr << " can not open input file: " << fname << endl;
exit(1);
}
string buf,name,art;
float a,b,c,d,cf;
int anz;
int line=0;
int ninputs=0;
int x,y,z,o;
input *ip;
output *op;
rule *rp;
f >> buf >> name >> anz;
//cerr << buf << " " << name << " " << anz << endl;
line++;
if(buf != "input"){
cerr << "error in inputfile at line: " << line
<< " first name must be input" << endl;
exit(1);
}
__inputs:
// new input
ip = new input();
ip->set_name(name);
ninputs++;
// new membership
for(int i=0; i<anz; i++){
f >> buf >> name >> art;
line++;
//cerr << buf << " " << name << " " << art << endl;
if(buf != "member"){
cerr << "error in inputfile at line: " << line
<< " first name must be member" << endl;
exit(1);
}
if(art != "trapeze" && art != "triangular"){
cerr << "error in inputfile at line: " << line
<< " type must be triangel or trapeze" << endl;
exit(1);
}
if(art == "triangular"){
f >> a >> b >> c;
//cerr << a << " " << b << " " << c << endl;
ip->set_member(name,a,b,c);
line++;
}
else{
f >> a >> b >> c >> d;
//cerr << a << " " << b << " " << c << " " << d << endl;
ip->set_member(name,a,b,c,d);
line++;
}
}
f1.add_input(ip); // add new input in fuzzy
f >> buf >> name >> anz;
line++;
//cerr << buf << " " << name << " " << anz << endl;
if(buf == "input") goto __inputs;
for(int i=0; i<anz; i++){
f >> buf >> name >> a;
op = new output(a); // make new output
op->set_name(name); // add name to output
f1.add_output(op); // add output in fuzzy
line++;
//cerr << buf << " " << name << " " << a << endl;
}
f >> buf >> anz;
line++;
//cerr << buf << " " << anz << endl;
if(buf != "rules"){
cerr << "error in inputfile at line: " << line
<< " name must be rules" << endl;
exit(1);
}
for(int i=0; i<anz; i++){
if(ninputs==1){
f >> x >> o >> cf ;
rp = new rule(x,0,0,o,cf); // rule x _ _ y cf
f1.add_rule(rp);
line++;
//cerr << x << " " << o << " " << cf << endl;
}
if(ninputs==2){
f >> x >> y >> o >> cf ;
rp = new rule(x,y,0,o,cf); // rule x x1 _ y cf
f1.add_rule(rp);
line++;
//cerr << x << " " << y << " " << o << " " << cf << endl;
}
if(ninputs==3){
f >> x >> y >> z >> o >> cf ;
rp = new rule(x,y,z,o,cf); // rule x x1 x2 y cf
f1.add_rule(rp);
line++;
//cerr << x << " " << y << " " << z << " "
// << o << " " << cf << endl;
}
}
f.close();
return(ninputs);
}
/*
int main(int argc, char** argv)
{
float val;
float x,y,z;
int count=0;
int nofi;
if(argc!=3){
cerr << "usage fuzzy with fis-file, value-file"
<< endl;
exit(1);
}
nofi=read_fuzzy(argv[1]);
ifstream f(argv[2]);
if(!f){
cerr << " can not open input file: " << argv[2] << endl;
exit(1);
}
while(!f.eof()){
if(nofi==1){
f >> x;
val = f1.calc(x,MIN);
}
if(nofi==2){
f >> x >> y;
val = f1.calc(x,y,MIN);
}
if(nofi==3){
f >> x >> y >> z;
val = f1.calc(x,y,z,MIN);
}
cout << x << " " << val << endl;
count++;
}
f.close();
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -