home Forums # Technical Support Error in fuzzylite 5.x C++

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1899
    Unknown
    Member

    Hi, when I run my code it throws a instance of fl::Exception:

    terminate called after throwing an instance of 'fl::Exception'
      what():  [syntax error] antecedent expected variable or logical operator, but found <d3>
    {at /src/rule/Antecedent.cpp::load() [line:261]}

    Here my code:

    #ifdef _WIN32
    	#include "fl/Headers.h"
    #else
    	#include <fl/Headers.h>
    #endif
    #include <cmath>
    #include <vector>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <time.h>
    
    using namespace fl;
    using namespace std;
    
    #ifdef _WIN32
    	#undef main
    #endif
    
    struct Soma
    {
    	Soma()
    	{
    		id = 0;
    		soma = 0;
    	}
    	
    	int id;
    	int soma;
    };
    
    struct Result
    {
    	Result (  )
    	{
    		id = 0;
    		soma = 0;
    		Xmosca = 0;
    		Xmenos = 0;
    		Xmais = 0;
    		
    		mosca = 0;
    		mais = 0;
    		menos = 0;
    	}
    	
    	Result ( int i, int s, bool X, bool me, bool ma, int Xmo, int Xme, int Xma )
    	{
    		id = i;
    		soma = s;
    		Xmosca = Xmo;
    		Xmenos = Xme;
    		Xmais = Xma;
    		
    		mosca = X;
    		mais = ma;
    		menos = me;
    	}
    	
    	int id;
    	int soma;
    	
    	int Xmosca; // valor de na mosca
    	int Xmenos; // valor de um a menos
    	int Xmais; // valor de um a mais
    	bool mosca; // acertou na mosca
    	bool mais; // uma a mais
    	bool menos; // uma a menos
    };
    
    vector <Result> sugeno_BOLA1 ( int argc, char argv[100][64] );
    
    int main(int argc, char* argv[])
    {
    	char args[100][64];
    	
    	for (int i = 0; i < argc; i++)
    		for (int j = 0; argv[i][j] != ''; j++)
    			args[i][j] = argv[i][j];
    	try
    	{
    		vector <Result> bola[25];
    		
    		bola[0] = sugeno_BOLA1(argc, args);
    	}
    	catch (const char * e)
    	{
    		cout << e << endl;
    	}
    	
    	return 0;
    }
    
    vector <Result> sugeno_BOLA1 ( int argc, char argv[100][64] )
    {
    	Engine* engine = new Engine("TakagiSugeno");
    	Term * low, * high;
    	low = new Triangle("LOW", 0, 0.38, 1);
    	high = new Triangle("HIGH", 0, 0.61, 1);
    
    	InputVariable* d1 = new InputVariable;
    	d1->setInputValue(0.0);
    	d1->setName("d1");
    	d1->setRange(0.0, 1.0);
    	d1->addTerm(low);
    	d1->addTerm(high);
    	engine->addInputVariable(d1);
    	
    	InputVariable* d2 = new InputVariable;
    	d2->setInputValue(0.0);
    	d2->setName("d2");
    	d2->setRange(0.0, 1.0);
    	d2->addTerm(low);
    	d2->addTerm(high);
    	engine->addInputVariable(d2);
    	
    	InputVariable* d3 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d3");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d3);
    	
    	InputVariable* d4 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d4");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d4);
    	
    	InputVariable* d5 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d5");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d5);
    	
    	InputVariable* d6 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d6");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d6);
    	
    	InputVariable* d7 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d7");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d7);
    	
    	InputVariable* d8 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d8");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d8);
    	
    	InputVariable* d9 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d9");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d9);
    	
    	InputVariable* d10 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d10");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d10);
    	
    	OutputVariable* soma = new OutputVariable;
    	soma->setName("soma");
    	
    	soma->setRange(0.0, 1.0);
    	soma->setDefaultValue(0.0);
    	soma->addTerm(new Constant("LOW", 0.0));
    	soma->addTerm(new Constant("MEDIUM",0.50));
    	soma->addTerm(new Constant("HIGH", 1.0));
    
    	soma->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
    
    	engine->addOutputVariable(soma);
    	RuleBlock* ruleblock = new RuleBlock;
    
    	ruleblock->setEnabled(true);
    	ruleblock->setConjunction(0);
    	ruleblock->setActivation(0);
    	
    
    	// low
    	ruleblock->addRule(Rule::parse("if d1 is LOW then soma is LOW", engine));
    	ruleblock->addRule(Rule::parse("if d2 is LOW then soma is MEDIUM", engine));
    	ruleblock->addRule(Rule::parse("if d3 is LOW then soma is HIGH", engine));
    	ruleblock->addRule(Rule::parse("if d4 is LOW then soma is LOW", engine));
    	ruleblock->addRule(Rule::parse("if d5 is LOW then soma is MEDIUM", engine));
    	ruleblock->addRule(Rule::parse("if d6 is LOW then soma is HIGH", engine));
    	ruleblock->addRule(Rule::parse("if d7 is LOW then soma is LOW", engine));
    	ruleblock->addRule(Rule::parse("if d8 is LOW then soma is MEDIUM", engine));
    	ruleblock->addRule(Rule::parse("if d9 is LOW then soma is HIGH", engine));
    	ruleblock->addRule(Rule::parse("if d10 is LOW then soma is HIGH", engine));
    	
    	// high
    	ruleblock->addRule(Rule::parse("if d1 is HIGH then soma is LOW", engine));
    	ruleblock->addRule(Rule::parse("if d2 is HIGH then soma is MEDIUM", engine));
    	ruleblock->addRule(Rule::parse("if d3 is HIGH then soma is HIGH", engine));
    	ruleblock->addRule(Rule::parse("if d4 is HIGH then soma is LOW", engine));
    	ruleblock->addRule(Rule::parse("if d5 is HIGH then soma is MEDIUM", engine));
    	ruleblock->addRule(Rule::parse("if d6 is HIGH then soma is HIGH", engine));
    	ruleblock->addRule(Rule::parse("if d7 is HIGH then soma is LOW", engine));
    	ruleblock->addRule(Rule::parse("if d8 is HIGH then soma is MEDIUM", engine));
    	ruleblock->addRule(Rule::parse("if d9 is HIGH then soma is HIGH", engine));
    	ruleblock->addRule(Rule::parse("if d10 is HIGH then soma is HIGH", engine));
    	
    	engine->addRuleBlock(ruleblock);
    
    	std::string status;
    	if (not engine->isReady(&status))
    		throw Exception("Engine not ready. "
    				"The following errors were encountered:\n" + status, FL_AT);
    
    	vector <Result> ret;
    	
    	vector <Soma> sum;
    	int sort1 = 3;
    	
    	int cmd = 0;
    	for (int i = 1; i < argc; i++)
    		if (strtok(argv[i], "sort1="))
    		{
    			sscanf(argv[i], "sort1=%d", &sort1);
    			if (sort1 < 3)
    				sort1 = 3;
    			cmd = 1;
    		}
    	
    	if (!cmd)
    	{
    		cout << "previsão de BOLA1\n" << "sugeno_BOLA1\n" << "Digite o primeiro sorteio: (tem que ser maior que 500): ";
    		cin >> sort1;
    	}
    
    	Soma aux;
    	char str[256];
    	
    	FILE * file = fopen("txts/sugenoBOLA1LF.txt", "r");
    	if (!file)
    	{
    		perror("File error: txts/sugenoBOLA1LF.txt");
    		throw "Error txts/sugenoBOLA1LF.txt";
    	}
    
    	int o = 0;
    	for (;;)
    	{
    		memset(str, 0x0, sizeof(str));
    		fgets(str, 256, file);
    		if (feof(file))
    			break;
    	
    		sscanf(str, "%d teve %d BOLA1", &aux.id, &aux.soma);
    		if (aux.id >= sort1)
    		{
    			sum.push_back(aux);
    		}
    		o++;
    	}
    	fclose(file);
    	
    	cout << "Sorteios = de " << sort1 << " até " << o << endl;
    	
    	int result[4][100];
    	memset(result, 0x0, sizeof(result));
    	int vezes[100];
    	memset(vezes, 0x0, sizeof(vezes));
    	
    	srand(time(NULL));
    	
    	int j = 0, k = 0, l, n = 0, m = 0, p = 0;
    	for (int i = 10; i < sum.size() - 1; i++)
    	{
    		
    		d1->setInputValue(sum[i - 9].soma);
    		d2->setInputValue(sum[i - 8].soma);
    		d3->setInputValue(sum[i - 7].soma);
    		d4->setInputValue(sum[i - 6].soma);
    		d5->setInputValue(sum[i - 5].soma);
    		d6->setInputValue(sum[i - 4].soma);
    		d7->setInputValue(sum[i - 3].soma);
    		d8->setInputValue(sum[i - 2].soma);
    		d9->setInputValue(sum[i - 1].soma);
    		d10->setInputValue(sum[i   ].soma);
    		
    		engine->process();
    		double d = soma->getOutputValue();
    
    		double a = floor(d);
    		double b = sum[i + 1].soma;
    		
    		
    		
    		int r = (int)(2.0 * (rand() / (RAND_MAX + 1.0)));
    		if (r == sum[i + 1].soma)
    		{
    			m++;
    		}
    
    		ret.push_back(Result(sum[i + 1].id, sum[i + 1].soma, a == b, b == a - 1.0, b == a + 1.0, a, a - 1.0, a + 1.0));
    		vezes[int(a)]++;
    	}
    	
    	return ret;
    }
    

    `

    #1900

    Hi,

    your problem is you copied and pasted without modifying variables. Check InputVariables d4-d10 utilise d3 instead of their respective variable.

    For example:

    
            InputVariable* d9 = new InputVariable;
    	d3->setInputValue(0.0);
    	d3->setName("d9");
    	d3->setRange(0.0, 1.0);
    	d3->addTerm(low);
    	d3->addTerm(high);
    	engine->addInputVariable(d9);
    
    #1901
    Unknown
    Member

    Ops! Thank you! The error was because use of Ctrl+c/v hehehe Sorry for this.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.