Example #1
0
TEST(FuzzySet, fuzzyset) {
  	FuzzySet* velocidadeBaixa = new FuzzySet(0.0, 0.0, 30, 60);

  	float pertinance = velocidadeBaixa->getPertinance();

  	EXPECT_EQ(0, pertinance);
}
Example #2
0
TEST(FuzzySet, fuzzyset_isvalid) {
  	FuzzySet* velocidadeBaixa = new FuzzySet(0.0, 0.0, 30, 60);

  	bool isValid = velocidadeBaixa->isValid();

  	EXPECT_TRUE(isValid);
}
Example #3
0
TEST(FuzzySet, setPertinenceAndgetPertinence){
  FuzzySet* fuzzySet = new FuzzySet(0, 10, 10, 20);

  fuzzySet->setPertinence(0.5);

  float result = fuzzySet->getPertinence();

  EXPECT_EQ(result, 0.5);
}
Example #4
0
TEST(Fuzzy, setInputAndFuzzifyAndDefuzzify08){
  Fuzzy* fuzzy = new Fuzzy();

  FuzzyInput* age = new FuzzyInput(1);

  FuzzySet* months = new FuzzySet(-360, -6, 5, 1200);
  age->addFuzzySet(months);

  fuzzy->addFuzzyInput(age);

  FuzzyOutput* quality = new FuzzyOutput(1);

  FuzzySet* avaliation = new FuzzySet(0, 1, 1, 1);
  quality->addFuzzySet(avaliation);

  fuzzy->addFuzzyOutput(quality);

  //-------------------- Montando as regras Fuzzy
  FuzzyRuleAntecedent* ifMonths = new FuzzyRuleAntecedent();
  ifMonths->joinSingle(months);

  FuzzyRuleConsequent* thenAvaliation = new FuzzyRuleConsequent();
  thenAvaliation->addOutput(avaliation);
  
  // Instanciando um objeto FuzzyRule
  FuzzyRule* fuzzyRule01 = new FuzzyRule(1, ifMonths, thenAvaliation);
  fuzzy->addFuzzyRule(fuzzyRule01);

  fuzzy->setInput(1, 50);

  fuzzy->fuzzify();
  // cout << "Pertinência (months): " << months->getPertinence() << endl;

  // cout << "Pertinência (avaliation): " << avaliation->getPertinence() << endl;

  float fuzzyAntecedentEvaluate = ifMonths->evaluate();

  // cout << "Entrada: " << dist << ", Saida: " << output << endl;

  EXPECT_EQ(months->getPertinence(), fuzzyAntecedentEvaluate);
}
Example #5
0
TEST(Fuzzy, addFuzzyRule){
  Fuzzy* fuzzy = new Fuzzy();

  FuzzyRuleAntecedent* seTemperatureLowOrpressureSmall = new FuzzyRuleAntecedent();
  FuzzySet* temperatureLow = new FuzzySet(0, 10, 10, 20);
  temperatureLow->setPertinence(0.5);
  FuzzySet* pressureSmall = new FuzzySet(0, 10, 10, 20);
  pressureSmall->setPertinence(0.5);
  seTemperatureLowOrpressureSmall->joinWithOR(temperatureLow, pressureSmall);

  FuzzyRuleAntecedent* andRiskMinimum = new FuzzyRuleAntecedent();
  FuzzySet* riskMinimum = new FuzzySet(0, 10, 10, 20);
  riskMinimum->setPertinence(0.7);
  andRiskMinimum->joinSingle(riskMinimum);

  FuzzyRuleAntecedent* seTemperatureLowOrpressureSmallandRiskMinimum = new FuzzyRuleAntecedent();
  seTemperatureLowOrpressureSmallandRiskMinimum->joinWithAND(seTemperatureLowOrpressureSmall, andRiskMinimum);

  FuzzyRuleConsequent* thenDangerLow = new FuzzyRuleConsequent();

  FuzzySet* dangerLow = new FuzzySet(0, 10, 10, 20);

  thenDangerLow->addOutput(dangerLow);

  FuzzyRule* fuzzyRule = new FuzzyRule(1, seTemperatureLowOrpressureSmallandRiskMinimum, thenDangerLow);
  
  bool result = fuzzy->addFuzzyRule(fuzzyRule);

  EXPECT_TRUE(result);
}
Example #6
0
TEST(FuzzyRule, evaluateExpressionAndIsFired){
  FuzzyRuleAntecedent* fuzzyRuleAntecedent2 = new FuzzyRuleAntecedent();
  FuzzySet* temperatureLow = new FuzzySet(0, 10, 10, 20);
  temperatureLow->setPertinence(0.5);
  FuzzySet* pressureSmall = new FuzzySet(0, 10, 10, 20);
  pressureSmall->setPertinence(0.5);
  fuzzyRuleAntecedent2->joinWithOR(temperatureLow, pressureSmall);

  FuzzyRuleAntecedent* fuzzyRuleAntecedent1 = new FuzzyRuleAntecedent();
  FuzzySet* riskMinimum = new FuzzySet(0, 10, 10, 20);
  riskMinimum->setPertinence(0.7);
  fuzzyRuleAntecedent1->joinSingle(riskMinimum);

  FuzzyRuleAntecedent* fuzzyRuleAntecedent3 = new FuzzyRuleAntecedent();
  fuzzyRuleAntecedent3->joinWithAND(fuzzyRuleAntecedent2, fuzzyRuleAntecedent1);

  FuzzyRuleConsequent* fuzzyRuleConsequent = new FuzzyRuleConsequent();

  FuzzySet* dangerLow = new FuzzySet(0, 10, 10, 20);

  fuzzyRuleConsequent->addOutput(dangerLow);

  FuzzyRule* fuzzyRule = new FuzzyRule(1, fuzzyRuleAntecedent3, fuzzyRuleConsequent);
  
  bool result1 = fuzzyRule->evaluateExpression();

  bool result2 = fuzzyRule->isFired();

  EXPECT_TRUE(result1);
  EXPECT_TRUE(result2);
}
Example #7
0
TEST(FuzzyRuleAntecedent, evaluate){
  FuzzyRuleAntecedent* fuzzyRuleAntecedent1 = new FuzzyRuleAntecedent();

  FuzzySet* riskMinimum = new FuzzySet(0, 10, 10, 20);
  riskMinimum->setPertinence(0.5);
  fuzzyRuleAntecedent1->joinSingle(riskMinimum);

  FuzzyRuleAntecedent* fuzzyRuleAntecedent2 = new FuzzyRuleAntecedent();
  FuzzySet* temperatureLow = new FuzzySet(0, 10, 10, 20);
  temperatureLow->setPertinence(0.0);
  FuzzySet* pressureSmall = new FuzzySet(0, 10, 10, 20);
  pressureSmall->setPertinence(0.5);
  fuzzyRuleAntecedent2->joinWithOR(temperatureLow, pressureSmall);

  FuzzyRuleAntecedent* fuzzyRuleAntecedent3 = new FuzzyRuleAntecedent();
  fuzzyRuleAntecedent3->joinWithAND(fuzzyRuleAntecedent1, fuzzyRuleAntecedent2);

  float result = fuzzyRuleAntecedent3->evaluate();

  EXPECT_GT(result, 0.0);
}
int main(int argc, char *argv[]) {
	Fuzzy* fuzzy = new Fuzzy();

	// FuzzyInput
	FuzzyInput* distance = new FuzzyInput(1);

	FuzzySet* close = new FuzzySet(0, 20, 20, 40);
	distance->addFuzzySet(close);
	FuzzySet* safe = new FuzzySet(30, 50, 50, 70);
	distance->addFuzzySet(safe);
	FuzzySet* distante = new FuzzySet(60, 80, 100, 100);
	distance->addFuzzySet(distante);

	fuzzy->addFuzzyInput(distance);

	// FuzzyInput
	FuzzyInput* inputSpeed = new FuzzyInput(2);

	FuzzySet* stoped = new FuzzySet(0, 0, 0, 0);
	inputSpeed->addFuzzySet(stoped);
	FuzzySet* slow = new FuzzySet(1, 10, 10, 20);
	inputSpeed->addFuzzySet(slow);
	FuzzySet* normal = new FuzzySet(15, 30, 30, 50);
	inputSpeed->addFuzzySet(normal);
	FuzzySet* quick = new FuzzySet(45, 60, 70, 70);
	inputSpeed->addFuzzySet(quick);

	fuzzy->addFuzzyInput(inputSpeed);

	// FuzzyInput
	FuzzyInput* temperature = new FuzzyInput(3);

	FuzzySet* cold = new FuzzySet(-30, -30, -20, -10);
	temperature->addFuzzySet(cold);
	FuzzySet* good = new FuzzySet(-15, 0, 0, 15);
	temperature->addFuzzySet(good);
	FuzzySet* hot = new FuzzySet(10, 20, 30, 30);
	temperature->addFuzzySet(hot);

	fuzzy->addFuzzyInput(temperature);

	// FuzzyOutput
	FuzzyOutput* risk = new FuzzyOutput(1);

	FuzzySet* minimum = new FuzzySet(0, 20, 20, 40);
	risk->addFuzzySet(minimum);
	FuzzySet* average = new FuzzySet(30, 50, 50, 70);
	risk->addFuzzySet(average);
	FuzzySet* maximum = new FuzzySet(60, 80, 80, 100);
	risk->addFuzzySet(maximum);

	fuzzy->addFuzzyOutput(risk);

	// FuzzyOutput
	// adicionando speed como output também
	FuzzyOutput* outputSpeed = new FuzzyOutput(2);

	FuzzySet* stopedOut = new FuzzySet(0, 0, 0, 0);
	outputSpeed->addFuzzySet(stopedOut);
	FuzzySet* slowOut = new FuzzySet(1, 10, 10, 20);
	outputSpeed->addFuzzySet(slowOut);
	FuzzySet* normalOut = new FuzzySet(15, 30, 30, 50);
	outputSpeed->addFuzzySet(normalOut);
	FuzzySet* quickOut = new FuzzySet(45, 60, 70, 70);
	outputSpeed->addFuzzySet(quickOut);

	fuzzy->addFuzzyOutput(outputSpeed);

	// Building FuzzyRule
	FuzzyRuleAntecedent* distanceCloseAndSpeedQuick = new FuzzyRuleAntecedent();
	distanceCloseAndSpeedQuick->joinWithAND(close, quick);
	FuzzyRuleAntecedent* temperatureCold = new FuzzyRuleAntecedent();
	temperatureCold->joinSingle(cold);
	FuzzyRuleAntecedent* ifDistanceCloseAndSpeedQuickOrTemperatureCold = new FuzzyRuleAntecedent();
	ifDistanceCloseAndSpeedQuickOrTemperatureCold->joinWithOR(distanceCloseAndSpeedQuick, temperatureCold);

	FuzzyRuleConsequent* thenRisMaximumAndSpeedSlow = new FuzzyRuleConsequent();
	thenRisMaximumAndSpeedSlow->addOutput(maximum);
	thenRisMaximumAndSpeedSlow->addOutput(slowOut);

	FuzzyRule* fuzzyRule1 = new FuzzyRule(1, ifDistanceCloseAndSpeedQuickOrTemperatureCold, thenRisMaximumAndSpeedSlow);
	fuzzy->addFuzzyRule(fuzzyRule1);

	// Building FuzzyRule
	FuzzyRuleAntecedent* distanceSafeAndSpeedNormal = new FuzzyRuleAntecedent();
	distanceSafeAndSpeedNormal->joinWithAND(safe, normal);
	FuzzyRuleAntecedent* ifDistanceSafeAndSpeedNormalOrTemperatureGood = new FuzzyRuleAntecedent();
	ifDistanceSafeAndSpeedNormalOrTemperatureGood->joinWithOR(distanceSafeAndSpeedNormal, good);

	FuzzyRuleConsequent* thenRiskAverageAndSpeedNormal = new FuzzyRuleConsequent();
	thenRiskAverageAndSpeedNormal->addOutput(average);
	thenRiskAverageAndSpeedNormal->addOutput(normalOut);

	FuzzyRule* fuzzyRule2 = new FuzzyRule(2, ifDistanceSafeAndSpeedNormalOrTemperatureGood, thenRiskAverageAndSpeedNormal);
	fuzzy->addFuzzyRule(fuzzyRule2);

	// Building FuzzyRule
	FuzzyRuleAntecedent* distanceDistanteAndSpeedSlow = new FuzzyRuleAntecedent();
	distanceDistanteAndSpeedSlow->joinWithAND(distante, slow);
	FuzzyRuleAntecedent* ifDistanceDistanteAndSpeedSlowOrTemperatureHot = new FuzzyRuleAntecedent();
	ifDistanceDistanteAndSpeedSlowOrTemperatureHot->joinWithOR(distanceDistanteAndSpeedSlow, hot);

	FuzzyRuleConsequent* thenRiskMinimumSpeedQuick = new FuzzyRuleConsequent();
	thenRiskMinimumSpeedQuick->addOutput(minimum);
	thenRiskMinimumSpeedQuick->addOutput(quickOut);

	FuzzyRule* fuzzyRule3 = new FuzzyRule(3, ifDistanceDistanteAndSpeedSlowOrTemperatureHot, thenRiskMinimumSpeedQuick);
	fuzzy->addFuzzyRule(fuzzyRule3);

	fuzzy->setInput(1, 10);
	fuzzy->setInput(2, 30);
	fuzzy->setInput(3, -15);

	fuzzy->fuzzify();

	pwOut << "Distância: " << close->getPertinence() << ", " << safe->getPertinence() << ", " << distante->getPertinence() << '\n';
	pwOut << "Velocidade: " << stoped->getPertinence() << ", " << slow->getPertinence() << ", " << normal->getPertinence() << ", " << quick->getPertinence() << '\n';
	pwOut << "Temperatura: " << cold->getPertinence() << ", " << good->getPertinence() << ", " << hot->getPertinence() << '\n';

	pwOut << "regra1: " << fuzzyRule1->isFired() << ", regra2: " << fuzzyRule2->isFired() << ", regra3: " << fuzzyRule3->isFired() << '\n';

	float output1 = fuzzy->defuzzify(1);
	float output2 = fuzzy->defuzzify(2);

	pwOut << "Saída Risco: " << output1 << ", Saída Velocidade: " << output2 << '\n';

	return 0;
}
Example #9
0
int main(int argc, char *argv[]) {
	Fuzzy* fuzzy = new Fuzzy();

    FuzzySet* t1 = new FuzzySet(0, 0, 0, 2);
    // FuzzySet* t2 = new FuzzySet(-1.5, 7.5, 7.5, 16.5);  // Antes
    FuzzySet* t2 = new FuzzySet(1.5, 7.5, 7.5, 16.5);  // después
    FuzzySet* t3 = new FuzzySet(3.5, 12.5, 12.5, 21.5);
    FuzzySet* t4 = new FuzzySet(9.5, 18.5, 18.5, 27.5);
    FuzzySet* t5 = new FuzzySet(14.5, 23.5, 23.5, 32.5);
    // FuzzySet* t6 = new FuzzySet(24.5, 37, 37, 37); // Antes
    FuzzySet* t6 = new FuzzySet(24.5, 37, 39, 39); // después - La temperatura puedes ser major que 37 grados

    FuzzySet* mbaja = new FuzzySet(0, 0, 0, 212);
    FuzzySet* baja = new FuzzySet(0, 212, 212, 425);
    FuzzySet* media = new FuzzySet(212, 425, 425, 638);
    FuzzySet* alta = new FuzzySet(425, 637, 637, 850);
    // FuzzySet* malta = new FuzzySet(637, 850, 850, 850); // Antes
    FuzzySet* malta = new FuzzySet(637, 850, 900, 900); // después - Las puertas analogicas de Arduino varian de 0 a 1024

    FuzzySet* v10 = new FuzzySet(0, 0, 0, 10);
    FuzzySet* v9 = new FuzzySet(0, 10, 10, 20);
    FuzzySet* v8 = new FuzzySet(10, 20, 20, 30);
    FuzzySet* v7 = new FuzzySet(20, 30, 30, 40);
    FuzzySet* v6 = new FuzzySet(30, 40, 40, 50);
    FuzzySet* v5 = new FuzzySet(40, 50, 50, 60); 
    FuzzySet* v4 = new FuzzySet(50, 60, 60, 70); 
    FuzzySet* v3 = new FuzzySet(60, 70, 70, 80);
    FuzzySet* v2 = new FuzzySet(70, 80, 80, 90);
    FuzzySet* v1 = new FuzzySet(80, 90, 90, 100);
    FuzzySet* v0 = new FuzzySet(90, 100, 100, 100);

    // FuzzyInput
    FuzzyInput* temperatura = new FuzzyInput(1);
    temperatura->addFuzzySet(t1);
    temperatura->addFuzzySet(t2);
    temperatura->addFuzzySet(t3);
    temperatura->addFuzzySet(t4);
    temperatura->addFuzzySet(t5);
    temperatura->addFuzzySet(t6);
    fuzzy->addFuzzyInput(temperatura);

    // FuzzyInput
    FuzzyInput* luminosidad = new FuzzyInput(2);
    luminosidad->addFuzzySet(mbaja);
    luminosidad->addFuzzySet(baja);
    luminosidad->addFuzzySet(media);
    luminosidad->addFuzzySet(alta);
    luminosidad->addFuzzySet(malta);
    fuzzy->addFuzzyInput(luminosidad);

    // FuzzyOutput
    FuzzyOutput* voltaje = new FuzzyOutput(1);
    voltaje->addFuzzySet(v10);  
    voltaje->addFuzzySet(v9);  
    voltaje->addFuzzySet(v8);  
    voltaje->addFuzzySet(v7); 
    voltaje->addFuzzySet(v6);  
    voltaje->addFuzzySet(v5);  
    voltaje->addFuzzySet(v4);  
    voltaje->addFuzzySet(v3); 
    voltaje->addFuzzySet(v2);  
    voltaje->addFuzzySet(v1);  
    voltaje->addFuzzySet(v0);
    fuzzy->addFuzzyOutput(voltaje);

    // Building FuzzyRule1
    FuzzyRuleAntecedent* iftemperaturat1Andluminosidadmbaja = new FuzzyRuleAntecedent();
    iftemperaturat1Andluminosidadmbaja->joinWithAND(t1, mbaja);
    FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule1 = new FuzzyRule(1, iftemperaturat1Andluminosidadmbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule1);

    // Building FuzzyRule2
    FuzzyRuleAntecedent* iftemperaturat1Andluminosidadbaja = new FuzzyRuleAntecedent();
    iftemperaturat1Andluminosidadbaja->joinWithAND(t1, baja);
    // FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule2 = new FuzzyRule(2, iftemperaturat1Andluminosidadbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule2);

    // Building FuzzyRule3
    FuzzyRuleAntecedent* iftemperaturat1Andluminosidadmedia = new FuzzyRuleAntecedent();
    iftemperaturat1Andluminosidadmedia->joinWithAND(t1, media);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule3 = new FuzzyRule(3, iftemperaturat1Andluminosidadmedia, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule3);

    // Building FuzzyRule4
    FuzzyRuleAntecedent* iftemperaturat1Andluminosidadalta = new FuzzyRuleAntecedent();
    iftemperaturat1Andluminosidadalta->joinWithAND(t1, alta);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule4 = new FuzzyRule(4, iftemperaturat1Andluminosidadalta, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule4);

    // Building FuzzyRule5
    FuzzyRuleAntecedent* iftemperaturat1Andluminosidadmalta = new FuzzyRuleAntecedent();
    iftemperaturat1Andluminosidadmalta->joinWithAND(t1, malta);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule5 = new FuzzyRule(5, iftemperaturat1Andluminosidadmalta, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule5);

    // Building FuzzyRule6
    FuzzyRuleAntecedent* iftemperaturat2Andluminosidadmbaja = new FuzzyRuleAntecedent();
    iftemperaturat2Andluminosidadmbaja->joinWithAND(t2, mbaja);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule6 = new FuzzyRule(6, iftemperaturat2Andluminosidadmbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule6);

    // Building FuzzyRule7
    FuzzyRuleAntecedent* iftemperaturat2Andluminosidadbaja = new FuzzyRuleAntecedent();
    iftemperaturat2Andluminosidadbaja->joinWithAND(t2, baja);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule7 = new FuzzyRule(7, iftemperaturat2Andluminosidadbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule7);

    // Building FuzzyRule8
    FuzzyRuleAntecedent* iftemperaturat2Andluminosidadmedia = new FuzzyRuleAntecedent();
    iftemperaturat2Andluminosidadmedia->joinWithAND(t2, media);
    FuzzyRuleConsequent* thenvoltajev1 = new FuzzyRuleConsequent();
    thenvoltajev1->addOutput(v1);
    FuzzyRule* fuzzyRule8 = new FuzzyRule(8, iftemperaturat2Andluminosidadmedia, thenvoltajev1);
    fuzzy->addFuzzyRule(fuzzyRule8);

    // Building FuzzyRule9
    FuzzyRuleAntecedent* iftemperaturat2Andluminosidadalta = new FuzzyRuleAntecedent();
    iftemperaturat2Andluminosidadalta->joinWithAND(t2, alta);
    FuzzyRuleConsequent* thenvoltajev2 = new FuzzyRuleConsequent();
    thenvoltajev2->addOutput(v2);
    FuzzyRule* fuzzyRule9 = new FuzzyRule(9, iftemperaturat2Andluminosidadalta, thenvoltajev2);
    fuzzy->addFuzzyRule(fuzzyRule9);

    // Building FuzzyRule10
    FuzzyRuleAntecedent* iftemperaturat2Andluminosidadmalta = new FuzzyRuleAntecedent();
    iftemperaturat2Andluminosidadmalta->joinWithAND(t2, malta);
    FuzzyRuleConsequent* thenvoltajev3 = new FuzzyRuleConsequent();
    thenvoltajev3->addOutput(v3);
    FuzzyRule* fuzzyRule10 = new FuzzyRule(10, iftemperaturat2Andluminosidadmalta, thenvoltajev3);
    fuzzy->addFuzzyRule(fuzzyRule10);

    // Building FuzzyRule11
    FuzzyRuleAntecedent* iftemperaturat3Andluminosidadmbaja = new FuzzyRuleAntecedent();
    iftemperaturat3Andluminosidadmbaja->joinWithAND(t3, mbaja);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule11 = new FuzzyRule(11, iftemperaturat3Andluminosidadmbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule11);

    // Building FuzzyRule12
    FuzzyRuleAntecedent* iftemperaturat3Andluminosidadbaja = new FuzzyRuleAntecedent();
    iftemperaturat3Andluminosidadbaja->joinWithAND(t3, baja);
    //FuzzyRuleConsequent* thenvoltajev1 = new FuzzyRuleConsequent();
    //thenvoltajev1->addOutput(v1);
    FuzzyRule* fuzzyRule12 = new FuzzyRule(12, iftemperaturat3Andluminosidadbaja, thenvoltajev1);
    fuzzy->addFuzzyRule(fuzzyRule12);

    // Building FuzzyRule13
    FuzzyRuleAntecedent* iftemperaturat3Andluminosidadmedia = new FuzzyRuleAntecedent();
    iftemperaturat3Andluminosidadmedia->joinWithAND(t3, media);
    //FuzzyRuleConsequent* thenvoltajev2 = new FuzzyRuleConsequent();
    //thenvoltajev2->addOutput(v2);
    FuzzyRule* fuzzyRule13 = new FuzzyRule(13, iftemperaturat3Andluminosidadmedia, thenvoltajev2);
    fuzzy->addFuzzyRule(fuzzyRule13);

    // Building FuzzyRule14
    FuzzyRuleAntecedent* iftemperaturat3Andluminosidadalta = new FuzzyRuleAntecedent();
    iftemperaturat3Andluminosidadalta->joinWithAND(t3, alta);
    FuzzyRuleConsequent* thenvoltajev4 = new FuzzyRuleConsequent();
    thenvoltajev4->addOutput(v4);
    FuzzyRule* fuzzyRule14 = new FuzzyRule(14, iftemperaturat3Andluminosidadalta, thenvoltajev4);
    fuzzy->addFuzzyRule(fuzzyRule14);

    // Building FuzzyRule15
    FuzzyRuleAntecedent* iftemperaturat3Andluminosidadmalta = new FuzzyRuleAntecedent();
    iftemperaturat3Andluminosidadmalta->joinWithAND(t3, malta);
    FuzzyRuleConsequent* thenvoltajev6 = new FuzzyRuleConsequent();
    thenvoltajev6->addOutput(v6);
    FuzzyRule* fuzzyRule15 = new FuzzyRule(15, iftemperaturat3Andluminosidadmalta, thenvoltajev6);
    fuzzy->addFuzzyRule(fuzzyRule15);

    // Building FuzzyRule16
    FuzzyRuleAntecedent* iftemperaturat4Andluminosidadmbaja = new FuzzyRuleAntecedent();
    iftemperaturat4Andluminosidadmbaja->joinWithAND(t4, mbaja);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule16 = new FuzzyRule(16, iftemperaturat4Andluminosidadmbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule16);

    // Building FuzzyRule17
    FuzzyRuleAntecedent* iftemperaturat4Andluminosidadbaja = new FuzzyRuleAntecedent();
    iftemperaturat4Andluminosidadbaja->joinWithAND(t4, baja);
    //FuzzyRuleConsequent* thenvoltajev2 = new FuzzyRuleConsequent();
    //thenvoltajev2->addOutput(v2);
    FuzzyRule* fuzzyRule17 = new FuzzyRule(17, iftemperaturat4Andluminosidadbaja, thenvoltajev2);
    fuzzy->addFuzzyRule(fuzzyRule17);

    // Building FuzzyRule18
    FuzzyRuleAntecedent* iftemperaturat4Andluminosidadmedia = new FuzzyRuleAntecedent();
    iftemperaturat4Andluminosidadmedia->joinWithAND(t4, media);
    FuzzyRuleConsequent* thenvoltajev5 = new FuzzyRuleConsequent();
    thenvoltajev5->addOutput(v5);
    FuzzyRule* fuzzyRule18 = new FuzzyRule(18, iftemperaturat4Andluminosidadmedia, thenvoltajev5);
    fuzzy->addFuzzyRule(fuzzyRule18);

    // Building FuzzyRule19
    FuzzyRuleAntecedent* iftemperaturat4Andluminosidadalta = new FuzzyRuleAntecedent();
    iftemperaturat4Andluminosidadalta->joinWithAND(t4, alta);
    FuzzyRuleConsequent* thenvoltajev7 = new FuzzyRuleConsequent();
    thenvoltajev7->addOutput(v7);
    FuzzyRule* fuzzyRule19 = new FuzzyRule(19, iftemperaturat4Andluminosidadalta, thenvoltajev7);
    fuzzy->addFuzzyRule(fuzzyRule19);

    // Building FuzzyRule20
    FuzzyRuleAntecedent* iftemperaturat4Andluminosidadmalta = new FuzzyRuleAntecedent();
    iftemperaturat4Andluminosidadmalta->joinWithAND(t4, malta);
    FuzzyRuleConsequent* thenvoltajev9 = new FuzzyRuleConsequent();
    thenvoltajev9->addOutput(v9);
    FuzzyRule* fuzzyRule20 = new FuzzyRule(20, iftemperaturat4Andluminosidadmalta, thenvoltajev9);
    fuzzy->addFuzzyRule(fuzzyRule20);

    // Building FuzzyRule21
    FuzzyRuleAntecedent* iftemperaturat5Andluminosidadmbaja = new FuzzyRuleAntecedent();
    iftemperaturat5Andluminosidadmbaja->joinWithAND(t5, mbaja);
    //FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    //thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule21 = new FuzzyRule(21, iftemperaturat5Andluminosidadmbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule21);

    // Building FuzzyRule22
    FuzzyRuleAntecedent* iftemperaturat5Andluminosidadbaja = new FuzzyRuleAntecedent();
    iftemperaturat5Andluminosidadbaja->joinWithAND(t5, baja);
    // FuzzyRuleConsequent* thenvoltajev3 = new FuzzyRuleConsequent();
    //thenvoltajev3->addOutput(v3);
    FuzzyRule* fuzzyRule22 = new FuzzyRule(22, iftemperaturat5Andluminosidadbaja, thenvoltajev3);
    fuzzy->addFuzzyRule(fuzzyRule22);

    // Building FuzzyRule23
    FuzzyRuleAntecedent* iftemperaturat5Andluminosidadmedia = new FuzzyRuleAntecedent();
    iftemperaturat5Andluminosidadmedia->joinWithAND(t5, media);
    // FuzzyRuleConsequent* thenvoltajev6 = new FuzzyRuleConsequent();
    // thenvoltajev6->addOutput(v6);
    FuzzyRule* fuzzyRule23 = new FuzzyRule(23, iftemperaturat5Andluminosidadmedia, thenvoltajev6);
    fuzzy->addFuzzyRule(fuzzyRule23);

    // Building FuzzyRule24
    FuzzyRuleAntecedent* iftemperaturat5Andluminosidadalta = new FuzzyRuleAntecedent();
    iftemperaturat5Andluminosidadalta->joinWithAND(t5, alta);
    FuzzyRuleConsequent* thenvoltajev8 = new FuzzyRuleConsequent();
    thenvoltajev8->addOutput(v8);
    FuzzyRule* fuzzyRule24 = new FuzzyRule(24, iftemperaturat5Andluminosidadalta, thenvoltajev8);
    fuzzy->addFuzzyRule(fuzzyRule24);

    // Building FuzzyRule25
    FuzzyRuleAntecedent* iftemperaturat5Andluminosidadmalta = new FuzzyRuleAntecedent();
    iftemperaturat5Andluminosidadmalta->joinWithAND(t5, malta);
    FuzzyRuleConsequent* thenvoltajev10 = new FuzzyRuleConsequent();
    thenvoltajev10->addOutput(v10);
    FuzzyRule* fuzzyRule25 = new FuzzyRule(25, iftemperaturat5Andluminosidadmalta, thenvoltajev10);
    fuzzy->addFuzzyRule(fuzzyRule25);

    // Building FuzzyRule26
    FuzzyRuleAntecedent* iftemperaturat6Andluminosidadmbaja = new FuzzyRuleAntecedent();
    iftemperaturat6Andluminosidadmbaja->joinWithAND(t6, mbaja);
    // FuzzyRuleConsequent* thenvoltajev0 = new FuzzyRuleConsequent();
    // thenvoltajev0->addOutput(v0);
    FuzzyRule* fuzzyRule26 = new FuzzyRule(26, iftemperaturat6Andluminosidadmbaja, thenvoltajev0);
    fuzzy->addFuzzyRule(fuzzyRule26);

    // Building FuzzyRule27
    FuzzyRuleAntecedent* iftemperaturat6Andluminosidadbaja = new FuzzyRuleAntecedent();
    iftemperaturat6Andluminosidadbaja->joinWithAND(t6, baja);
    //FuzzyRuleConsequent* thenvoltajev4 = new FuzzyRuleConsequent();
    // thenvoltajev4->addOutput(v4);
    FuzzyRule* fuzzyRule27 = new FuzzyRule(27, iftemperaturat6Andluminosidadbaja, thenvoltajev4);
    fuzzy->addFuzzyRule(fuzzyRule27);

    // Building FuzzyRule28
    FuzzyRuleAntecedent* iftemperaturat6Andluminosidadmedia = new FuzzyRuleAntecedent();
    iftemperaturat6Andluminosidadmedia->joinWithAND(t6, media);
    //FuzzyRuleConsequent* thenvoltajev7 = new FuzzyRuleConsequent();
    //thenvoltajev7->addOutput(v7);
    FuzzyRule* fuzzyRule28 = new FuzzyRule(28, iftemperaturat6Andluminosidadmbaja, thenvoltajev7);
    fuzzy->addFuzzyRule(fuzzyRule28);

    // Building FuzzyRule29
    FuzzyRuleAntecedent* iftemperaturat6Andluminosidadalta = new FuzzyRuleAntecedent();
    iftemperaturat6Andluminosidadalta->joinWithAND(t6, alta);
    //FuzzyRuleConsequent* thenvoltajev9 = new FuzzyRuleConsequent();
    //thenvoltajev9->addOutput(v9);
    FuzzyRule* fuzzyRule29 = new FuzzyRule(29, iftemperaturat6Andluminosidadalta, thenvoltajev9);
    fuzzy->addFuzzyRule(fuzzyRule29);

    // Building FuzzyRule30
    FuzzyRuleAntecedent* iftemperaturat6Andluminosidadmalta = new FuzzyRuleAntecedent();
    iftemperaturat6Andluminosidadmalta->joinWithAND(t6, malta);
    //FuzzyRuleConsequent* thenvoltajev10 = new FuzzyRuleConsequent();
    //thenvoltajev10->addOutput(v10);
    FuzzyRule* fuzzyRule30 = new FuzzyRule(30, iftemperaturat6Andluminosidadmalta, thenvoltajev10);
    fuzzy->addFuzzyRule(fuzzyRule30);

    int lm35Values[10] = {200, 25, 60, 17, 9, 10, 37, 34, 40, 74};
    int ldrValues[10] = {1000, 100, 376, 34, 198, 276, 200, 250, 600, 177};

    for(int i=0; i < 1; i++){
        std::cout << "\nIteracion " << i << std::endl;

        int celsius = lm35Values[i];
        int grados = (5.0 * celsius * 100) / 1024.0;

        fuzzy->setInput(1, grados);
        fuzzy->setInput(2, ldrValues[i]);

        fuzzy->fuzzify();
        float output = fuzzy->defuzzify(1);

        std::cout << "temperatura: " << t1->getPertinence() << ", " << t2->getPertinence() << ", " << t3->getPertinence() << ", " << t4->getPertinence() << ", " << t5->getPertinence() << ", " << t6->getPertinence() << std::endl;

        std::cout << "luminosidad: " << mbaja->getPertinence() << ", " << baja->getPertinence() << ", " << media->getPertinence() << ", " << alta->getPertinence() << ", " << malta->getPertinence() << std::endl;

        std::cout << "voltaje V10-V0: " << v10->getPertinence() << ", " << v9->getPertinence() << ", " << v8->getPertinence() << ", " << v7->getPertinence() << ", " << v6->getPertinence() << ", " << v5->getPertinence() << ", " << v4->getPertinence() << ", " << v3->getPertinence() << ", " << v4->getPertinence() << ", " << v1->getPertinence() << ", " << v0->getPertinence() << std::endl;

        std::cout << "Output: " << output << std::endl;

        std::cout << "reglas 1-15 :  " << fuzzy->isFiredRule(1) << ", " << fuzzy->isFiredRule(2) << ", " << fuzzy->isFiredRule(3) << ", " << fuzzy->isFiredRule(4) << ", " << fuzzy->isFiredRule(5) << ", " << fuzzy->isFiredRule(6) << ", " << fuzzy->isFiredRule(7) << ", " << fuzzy->isFiredRule(8) << ", " << fuzzy->isFiredRule(9) << ", " << fuzzy->isFiredRule(10) << ", " << fuzzy->isFiredRule(11) << ", " << fuzzy->isFiredRule(12) << ", " << fuzzy->isFiredRule(13) << ", " << fuzzy->isFiredRule(14) << ", " << fuzzy->isFiredRule(15) << std::endl;

        std::cout << "reglas 16-30 :  " << fuzzy->isFiredRule(16) << ", " << fuzzy->isFiredRule(17) << ", " << fuzzy->isFiredRule(18) << ", " << fuzzy->isFiredRule(19) << ", " << fuzzy->isFiredRule(20) << ", " << fuzzy->isFiredRule(21) << ", " << fuzzy->isFiredRule(22) << ", " << fuzzy->isFiredRule(23) << ", " << fuzzy->isFiredRule(24) << ", " << fuzzy->isFiredRule(25) << ", " << fuzzy->isFiredRule(26) << ", " << fuzzy->isFiredRule(27) << ", " << fuzzy->isFiredRule(28) << ", " << fuzzy->isFiredRule(29) << ", " << fuzzy->isFiredRule(30) << std::endl;
    }

	return 0;
}
Example #10
0
int main(int argc, char *argv[]) {
    Fuzzy* fuzzy = new Fuzzy();

    ///////////////////////////////////////////////////////////////////////////////
    FuzzySet* ErroAltoNegativo = new FuzzySet(-101.0, -101.0, -100.0, -50.0);
    FuzzySet* ErroMedioNegativo = new FuzzySet(-100.0, -50.0, -50.0, 0.0);
    FuzzySet* ErroBaixonegativo = new FuzzySet(-50.0, 0.0, 0.0, 0.0);
    FuzzySet* ErroBaixoPositivo = new FuzzySet(0.0, 0.0, 0.0, 50.0);
    FuzzySet* ErroMedioPositivo = new FuzzySet(0.0, 50.0, 50.0, 100.0);
    FuzzySet* ErroAltoPositivo = new FuzzySet(50.0, 100.0, 101.0, 101.0);

    // Criando o FuzzyInput Erro
    FuzzyInput* Erro = new FuzzyInput(1);
    // Criando os FuzzySet que compoem o FuzzyInput distancia 
    Erro->addFuzzySet(ErroAltoNegativo); // Adicionando o FuzzySet small em Erro
    Erro->addFuzzySet(ErroMedioNegativo); // Adicionando o FuzzySet small em Erro
    Erro->addFuzzySet(ErroBaixonegativo); // Adicionando o FuzzySet small em Erro
    Erro->addFuzzySet(ErroBaixoPositivo); // Adicionando o FuzzySet small em Erro
    Erro->addFuzzySet(ErroMedioPositivo); // Adicionando o FuzzySet small em Erro
    Erro->addFuzzySet(ErroAltoPositivo); // Adicionando o FuzzySet small em Erro

    fuzzy->addFuzzyInput(Erro); // Adicionando o FuzzyInput no objeto Fuzzy  
    ///////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////

    FuzzySet* DerroAltoNegativo = new FuzzySet(-101.0, -101.0, -100.0, -50.0);
    FuzzySet* DerroMedioNegativo = new FuzzySet(-100.0, -50.0, -50.0, 0.0);
    FuzzySet* DerroBaixonegativo = new FuzzySet(-50.0, 0.0, 0.0, 0.0);
    FuzzySet* DerroBaixoPositivo = new FuzzySet(0.0, 0.0, 0.0, 50.0);
    FuzzySet* DerroMedioPositivo = new FuzzySet(0.0, 50.0, 50.0, 100.0);
    FuzzySet* DerroAltoPositivo = new FuzzySet(50.0, 100.0, 101.0, 101.0);

    // Criando o FuzzyInput Derivada do Erro
    FuzzyInput* DErro = new FuzzyInput(2);
    // Criando os FuzzySet que compoem o FuzzyInput distancia 
    DErro->addFuzzySet(DerroAltoNegativo); // Adicionando o FuzzySet small em DErro
    DErro->addFuzzySet(DerroMedioNegativo); // Adicionando o FuzzySet small em DErro
    DErro->addFuzzySet(DerroBaixonegativo); // Adicionando o FuzzySet small em DErro
    DErro->addFuzzySet(DerroBaixoPositivo); // Adicionando o FuzzySet small em DErro
    DErro->addFuzzySet(DerroMedioPositivo); // Adicionando o FuzzySet small em DErro
    DErro->addFuzzySet(DerroAltoPositivo); // Adicionando o FuzzySet small em DErro

    fuzzy->addFuzzyInput(DErro); // Adicionando o FuzzyInput no objeto Fuzzy 
    //////////////////////////////////////////////////////////////////////////////////


    //////////////////////////////////////////////////////////////////////////////////    
    // Criando o FuzzyOutput Velocidade
    FuzzyOutput* Velocidade = new FuzzyOutput(1);

    FuzzySet* OutAltoNegativo = new FuzzySet(-101.0, -101.0, -100.0, -50.0);
    FuzzySet* OutMedioNegativo = new FuzzySet(-100.0, -50.0, -50.0, 0.0);
    FuzzySet* OutBaixonegativo = new FuzzySet(-50.0, 0.0, 0.0, 0.0);
    FuzzySet* OutBaixoPositivo = new FuzzySet(0.0, 0.0, 0.0, 50.0);
    FuzzySet* OutMedioPositivo = new FuzzySet(0.0, 50.0, 50.0, 100.0);
    FuzzySet* OutAltoPositivo = new FuzzySet(50.0, 100.0, 101.0, 101.0);


    // Criando os FuzzySet que compoem o FuzzyOutput velocidade 
    Velocidade->addFuzzySet(OutAltoNegativo);  // Adicionando o FuzzySet slow em velocity
    Velocidade->addFuzzySet(OutMedioNegativo);  // Adicionando o FuzzySet slow em velocity
    Velocidade->addFuzzySet(OutBaixonegativo);  // Adicionando o FuzzySet slow em velocity
    Velocidade->addFuzzySet(OutBaixoPositivo);  // Adicionando o FuzzySet slow em velocity
    Velocidade->addFuzzySet(OutMedioPositivo);  // Adicionando o FuzzySet slow em velocity
    Velocidade->addFuzzySet(OutAltoPositivo);  // Adicionando o FuzzySet slow em velocity

    fuzzy->addFuzzyOutput(Velocidade); // Adicionando o FuzzyOutput no objeto Fuzzy   
    //////////////////////////////////////////////////////////////////////////////////

    FuzzyRuleAntecedent* IfErroAltoNegativoAndDerroAltoNegativo = new FuzzyRuleAntecedent();
    IfErroAltoNegativoAndDerroAltoNegativo->joinWithAND(ErroAltoNegativo,DerroAltoNegativo);

    FuzzyRuleAntecedent* IfErroAltoNegativoAndDerroMedioNegativo = new FuzzyRuleAntecedent();
    IfErroAltoNegativoAndDerroMedioNegativo->joinWithAND(ErroAltoNegativo,DerroMedioNegativo);

    FuzzyRuleAntecedent* IfErroAltoNegativoAndDerroBaixonegativo = new FuzzyRuleAntecedent();
    IfErroAltoNegativoAndDerroBaixonegativo->joinWithAND(ErroAltoNegativo,DerroBaixonegativo);

    FuzzyRuleAntecedent* IfErroAltoNegativoAndDerroBaixoPositivo = new FuzzyRuleAntecedent();
    IfErroAltoNegativoAndDerroBaixoPositivo->joinWithAND(ErroAltoNegativo,DerroBaixoPositivo);

    FuzzyRuleAntecedent* IfErroAltoNegativoAndDerroMedioPositivo = new FuzzyRuleAntecedent(); 
    IfErroAltoNegativoAndDerroMedioPositivo->joinWithAND(ErroAltoNegativo,DerroMedioPositivo);

    FuzzyRuleAntecedent* IfErroAltoNegativoAndDerroAltoPositivo = new FuzzyRuleAntecedent(); 
    IfErroAltoNegativoAndDerroAltoPositivo->joinWithAND(ErroAltoNegativo,DerroAltoPositivo);

    FuzzyRuleAntecedent* IfErroMedioNegativoAndDerroAltoNegativo = new FuzzyRuleAntecedent(); 
    IfErroMedioNegativoAndDerroAltoNegativo->joinWithAND(ErroMedioNegativo,DerroAltoNegativo);

    FuzzyRuleAntecedent* IfErroMedioNegativoAndDerroMedioNegativo = new FuzzyRuleAntecedent(); 
    IfErroMedioNegativoAndDerroMedioNegativo->joinWithAND(ErroMedioNegativo,DerroMedioNegativo);

    FuzzyRuleAntecedent* IfErroMedioNegativoAndDerroBaixonegativo = new FuzzyRuleAntecedent(); 
    IfErroMedioNegativoAndDerroBaixonegativo->joinWithAND(ErroMedioNegativo,DerroBaixonegativo);

    FuzzyRuleAntecedent* IfErroMedioNegativoAndDerroBaixoPositivo = new FuzzyRuleAntecedent(); 
    IfErroMedioNegativoAndDerroBaixoPositivo->joinWithAND(ErroMedioNegativo,DerroBaixoPositivo);

    FuzzyRuleAntecedent* IfErroMedioNegativoAndDerroMedioPositivo = new FuzzyRuleAntecedent(); 
    IfErroMedioNegativoAndDerroMedioPositivo->joinWithAND(ErroMedioNegativo,DerroMedioPositivo);

    FuzzyRuleAntecedent* IfErroMedioNegativoAndDerroAltoPositivo = new FuzzyRuleAntecedent(); 
    IfErroMedioNegativoAndDerroAltoPositivo->joinWithAND(ErroMedioNegativo,DerroAltoPositivo);

    FuzzyRuleAntecedent* IfErroBaixonegativoAndDerroAltoNegativo = new FuzzyRuleAntecedent(); 
    IfErroBaixonegativoAndDerroAltoNegativo->joinWithAND(ErroBaixonegativo,DerroAltoNegativo);

    FuzzyRuleAntecedent* IfErroBaixonegativoAndDerroMedioNegativo = new FuzzyRuleAntecedent();
    IfErroBaixonegativoAndDerroMedioNegativo->joinWithAND(ErroBaixonegativo,DerroMedioNegativo);

    FuzzyRuleAntecedent* IfErroBaixonegativoAndDerroBaixonegativo = new FuzzyRuleAntecedent(); 
    IfErroBaixonegativoAndDerroBaixonegativo->joinWithAND(ErroBaixonegativo,DerroBaixonegativo);

    FuzzyRuleAntecedent* IfErroBaixonegativoAndDerroBaixoPositivo = new FuzzyRuleAntecedent(); 
    IfErroBaixonegativoAndDerroBaixoPositivo->joinWithAND(ErroBaixonegativo,DerroBaixoPositivo);

    FuzzyRuleAntecedent* IfErroBaixonegativoAndDerroMedioPositivo = new FuzzyRuleAntecedent(); 
    IfErroBaixonegativoAndDerroMedioPositivo->joinWithAND(ErroBaixonegativo,DerroMedioPositivo);

    FuzzyRuleAntecedent* IfErroBaixonegativoAndDerroAltoPositivo = new FuzzyRuleAntecedent(); 
    IfErroBaixonegativoAndDerroAltoPositivo->joinWithAND(ErroBaixonegativo,DerroAltoPositivo);

    FuzzyRuleAntecedent* IfErroBaixoPositivoAndDerroAltoNegativo = new FuzzyRuleAntecedent(); 
    IfErroBaixoPositivoAndDerroAltoNegativo->joinWithAND(ErroBaixoPositivo,DerroAltoNegativo);

    FuzzyRuleAntecedent* IfErroBaixoPositivoAndDerroMedioNegativo = new FuzzyRuleAntecedent(); 
    IfErroBaixoPositivoAndDerroMedioNegativo->joinWithAND(ErroBaixoPositivo,DerroMedioNegativo);

    FuzzyRuleAntecedent* IfErroBaixoPositivoAndDerroBaixonegativo = new FuzzyRuleAntecedent(); 
    IfErroBaixoPositivoAndDerroBaixonegativo->joinWithAND(ErroBaixoPositivo,DerroBaixonegativo);

    FuzzyRuleAntecedent* IfErroBaixoPositivoAndDerroBaixoPositivo = new FuzzyRuleAntecedent(); 
    IfErroBaixoPositivoAndDerroBaixoPositivo->joinWithAND(ErroBaixoPositivo,DerroBaixoPositivo);

    FuzzyRuleAntecedent* IfErroBaixoPositivoAndDerroMedioPositivo = new FuzzyRuleAntecedent();
    IfErroBaixoPositivoAndDerroMedioPositivo->joinWithAND(ErroBaixoPositivo,DerroMedioPositivo);

    FuzzyRuleAntecedent* IfErroBaixoPositivoAndDerroAltoPositivo = new FuzzyRuleAntecedent(); 
    IfErroBaixoPositivoAndDerroAltoPositivo->joinWithAND(ErroBaixoPositivo,DerroAltoPositivo);

    FuzzyRuleAntecedent* IfErroMedioPositivoAndDerroAltoNegativo = new FuzzyRuleAntecedent(); 
    IfErroMedioPositivoAndDerroAltoNegativo->joinWithAND(ErroMedioPositivo,DerroAltoNegativo);

    FuzzyRuleAntecedent* IfErroMedioPositivoAndDerroMedioNegativo = new FuzzyRuleAntecedent(); 
    IfErroMedioPositivoAndDerroMedioNegativo->joinWithAND(ErroMedioPositivo,DerroMedioNegativo);

    FuzzyRuleAntecedent* IfErroMedioPositivoAndDerroBaixonegativo = new FuzzyRuleAntecedent();
    IfErroMedioPositivoAndDerroBaixonegativo->joinWithAND(ErroMedioPositivo,DerroBaixonegativo);

    FuzzyRuleAntecedent* IfErroMedioPositivoAndDerroBaixoPositivo = new FuzzyRuleAntecedent(); 
    IfErroMedioPositivoAndDerroBaixoPositivo->joinWithAND(ErroMedioPositivo,DerroBaixoPositivo);

    FuzzyRuleAntecedent* IfErroMedioPositivoAndDerroMedioPositivo = new FuzzyRuleAntecedent();
    IfErroMedioPositivoAndDerroMedioPositivo->joinWithAND(ErroMedioPositivo,DerroMedioPositivo);

    FuzzyRuleAntecedent* IfErroMedioPositivoAndDerroAltoPositivo = new FuzzyRuleAntecedent(); 
    IfErroMedioPositivoAndDerroAltoPositivo->joinWithAND(ErroMedioPositivo,DerroAltoPositivo);

    FuzzyRuleAntecedent* IfErroAltoPositivoAndDerroAltoNegativo = new FuzzyRuleAntecedent(); 
    IfErroAltoPositivoAndDerroAltoNegativo->joinWithAND(ErroAltoPositivo,DerroAltoNegativo);

    FuzzyRuleAntecedent* IfErroAltoPositivoAndDerroMedioNegativo = new FuzzyRuleAntecedent();
    IfErroAltoPositivoAndDerroMedioNegativo->joinWithAND(ErroAltoPositivo,DerroMedioNegativo);

    FuzzyRuleAntecedent* IfErroAltoPositivoAndDerroBaixonegativo = new FuzzyRuleAntecedent(); 
    IfErroAltoPositivoAndDerroBaixonegativo->joinWithAND(ErroAltoPositivo,DerroBaixonegativo);

    FuzzyRuleAntecedent* IfErroAltoPositivoAndDerroBaixoPositivo = new FuzzyRuleAntecedent();
    IfErroAltoPositivoAndDerroBaixoPositivo->joinWithAND(ErroAltoPositivo,DerroBaixoPositivo);

    FuzzyRuleAntecedent* IfErroAltoPositivoAndDerroMedioPositivo = new FuzzyRuleAntecedent();
    IfErroAltoPositivoAndDerroMedioPositivo->joinWithAND(ErroAltoPositivo,DerroMedioPositivo);

    FuzzyRuleAntecedent* IfErroAltoPositivoAndDerroAltoPositivo = new FuzzyRuleAntecedent(); 
    IfErroAltoPositivoAndDerroAltoPositivo->joinWithAND(ErroAltoPositivo,DerroAltoPositivo);


    FuzzyRuleConsequent* ThenOutAltoPositivo = new FuzzyRuleConsequent(); 
    ThenOutAltoPositivo->addOutput(OutAltoPositivo);

    FuzzyRuleConsequent* ThenOutMedioPositivo = new FuzzyRuleConsequent();
    ThenOutMedioPositivo->addOutput(OutMedioPositivo);

    FuzzyRuleConsequent* ThenOutBaixoPositivo = new FuzzyRuleConsequent();
    ThenOutBaixoPositivo->addOutput(OutBaixoPositivo);

    FuzzyRuleConsequent* ThenOutBaixonegativo = new FuzzyRuleConsequent();
    ThenOutBaixonegativo->addOutput(OutBaixonegativo);

    FuzzyRuleConsequent* ThenOutMedioNegativo = new FuzzyRuleConsequent();
    ThenOutMedioNegativo->addOutput(OutMedioNegativo);

    FuzzyRuleConsequent* ThenOutAltoNegativo = new FuzzyRuleConsequent();
    ThenOutAltoNegativo->addOutput(OutAltoNegativo);


    FuzzyRule* fuzzyRule01 = new FuzzyRule(1, IfErroAltoNegativoAndDerroAltoNegativo, ThenOutAltoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule01);

    FuzzyRule* fuzzyRule02 = new FuzzyRule(2, IfErroAltoNegativoAndDerroMedioNegativo, ThenOutAltoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule02);

    FuzzyRule* fuzzyRule03 = new FuzzyRule(3, IfErroAltoNegativoAndDerroBaixonegativo, ThenOutAltoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule03);

    FuzzyRule* fuzzyRule04 = new FuzzyRule(4, IfErroAltoNegativoAndDerroBaixoPositivo, ThenOutMedioPositivo);
    fuzzy->addFuzzyRule(fuzzyRule04);

    FuzzyRule* fuzzyRule05 = new FuzzyRule(5, IfErroAltoNegativoAndDerroMedioPositivo, ThenOutMedioPositivo);
    fuzzy->addFuzzyRule(fuzzyRule05);

    FuzzyRule* fuzzyRule06 = new FuzzyRule(6, IfErroAltoNegativoAndDerroAltoPositivo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule06);

    FuzzyRule* fuzzyRule07 = new FuzzyRule(7, IfErroMedioNegativoAndDerroAltoNegativo, ThenOutAltoPositivo); 
    fuzzy->addFuzzyRule(fuzzyRule07);

    FuzzyRule* fuzzyRule08 = new FuzzyRule(8, IfErroMedioNegativoAndDerroMedioNegativo, ThenOutAltoPositivo); //++++
    fuzzy->addFuzzyRule(fuzzyRule08);

    FuzzyRule* fuzzyRule09 = new FuzzyRule(9, IfErroMedioNegativoAndDerroBaixonegativo, ThenOutMedioPositivo); //++++
    fuzzy->addFuzzyRule(fuzzyRule09);

    FuzzyRule* fuzzyRule10 = new FuzzyRule(10, IfErroMedioNegativoAndDerroBaixoPositivo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule10);

    FuzzyRule* fuzzyRule11 = new FuzzyRule(11, IfErroMedioNegativoAndDerroMedioPositivo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule11);

    FuzzyRule* fuzzyRule12 = new FuzzyRule(12, IfErroMedioNegativoAndDerroAltoPositivo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule12);

    FuzzyRule* fuzzyRule13 = new FuzzyRule(13, IfErroBaixonegativoAndDerroAltoNegativo, ThenOutMedioPositivo);
    fuzzy->addFuzzyRule(fuzzyRule13);

    FuzzyRule* fuzzyRule14 = new FuzzyRule(14, IfErroBaixonegativoAndDerroMedioNegativo, ThenOutMedioPositivo); //++++
    fuzzy->addFuzzyRule(fuzzyRule14);

    FuzzyRule* fuzzyRule15 = new FuzzyRule(15, IfErroBaixonegativoAndDerroBaixonegativo, ThenOutBaixoPositivo); //++++
    fuzzy->addFuzzyRule(fuzzyRule15);

    FuzzyRule* fuzzyRule16 = new FuzzyRule(16, IfErroBaixonegativoAndDerroBaixoPositivo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule16);

    FuzzyRule* fuzzyRule17 = new FuzzyRule(17, IfErroBaixonegativoAndDerroMedioPositivo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule17);

    FuzzyRule* fuzzyRule18 = new FuzzyRule(18, IfErroBaixonegativoAndDerroAltoPositivo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule18);

    FuzzyRule* fuzzyRule19 = new FuzzyRule(19, IfErroBaixoPositivoAndDerroAltoNegativo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule19);

    FuzzyRule* fuzzyRule20 = new FuzzyRule(20, IfErroBaixoPositivoAndDerroMedioNegativo, ThenOutBaixoPositivo);
    fuzzy->addFuzzyRule(fuzzyRule20);

    FuzzyRule* fuzzyRule21 = new FuzzyRule(21, IfErroBaixoPositivoAndDerroBaixonegativo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule21);

    FuzzyRule* fuzzyRule22 = new FuzzyRule(22, IfErroBaixoPositivoAndDerroBaixoPositivo, ThenOutBaixonegativo); //----
    fuzzy->addFuzzyRule(fuzzyRule22);

    FuzzyRule* fuzzyRule23 = new FuzzyRule(23, IfErroBaixoPositivoAndDerroMedioPositivo, ThenOutMedioNegativo); //----
    fuzzy->addFuzzyRule(fuzzyRule23);

    FuzzyRule* fuzzyRule24 = new FuzzyRule(24, IfErroBaixoPositivoAndDerroAltoPositivo, ThenOutMedioNegativo);
    fuzzy->addFuzzyRule(fuzzyRule24);

    FuzzyRule* fuzzyRule25 = new FuzzyRule(25, IfErroMedioPositivoAndDerroAltoNegativo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule25);

    FuzzyRule* fuzzyRule26 = new FuzzyRule(26, IfErroMedioPositivoAndDerroMedioNegativo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule26);

    FuzzyRule* fuzzyRule27 = new FuzzyRule(27, IfErroMedioPositivoAndDerroBaixonegativo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule27);

    FuzzyRule* fuzzyRule28 = new FuzzyRule(28, IfErroMedioPositivoAndDerroBaixoPositivo, ThenOutMedioNegativo); //----
    fuzzy->addFuzzyRule(fuzzyRule28);

    FuzzyRule* fuzzyRule29 = new FuzzyRule(29, IfErroMedioPositivoAndDerroMedioPositivo, ThenOutAltoNegativo); //----
    fuzzy->addFuzzyRule(fuzzyRule29);

    FuzzyRule* fuzzyRule30 = new FuzzyRule(30, IfErroMedioPositivoAndDerroAltoPositivo, ThenOutAltoNegativo);
    fuzzy->addFuzzyRule(fuzzyRule30);

    FuzzyRule* fuzzyRule31 = new FuzzyRule(31, IfErroAltoPositivoAndDerroAltoNegativo, ThenOutBaixonegativo);
    fuzzy->addFuzzyRule(fuzzyRule31);

    FuzzyRule* fuzzyRule32 = new FuzzyRule(32, IfErroAltoPositivoAndDerroMedioNegativo, ThenOutMedioNegativo);
    fuzzy->addFuzzyRule(fuzzyRule32);

    FuzzyRule* fuzzyRule33 = new FuzzyRule(33, IfErroAltoPositivoAndDerroBaixonegativo, ThenOutMedioNegativo);
    fuzzy->addFuzzyRule(fuzzyRule33);

    FuzzyRule* fuzzyRule34 = new FuzzyRule(34, IfErroAltoPositivoAndDerroBaixoPositivo, ThenOutAltoNegativo); 
    fuzzy->addFuzzyRule(fuzzyRule34);

    FuzzyRule* fuzzyRule35 = new FuzzyRule(35, IfErroAltoPositivoAndDerroMedioPositivo, ThenOutAltoNegativo); 
    fuzzy->addFuzzyRule(fuzzyRule35);

    FuzzyRule* fuzzyRule36 = new FuzzyRule(36, IfErroAltoPositivoAndDerroAltoPositivo, ThenOutAltoNegativo); 
    fuzzy->addFuzzyRule(fuzzyRule36);

    fuzzy->setInput(1, 0);
    fuzzy->setInput(2, 0);
    fuzzy->fuzzify();
    
    float outputPitch = fuzzy->defuzzify(1);
    
    std::cout << "Erro: " << ErroAltoNegativo->getPertinence() << ", " << ErroMedioNegativo->getPertinence() << ", " << ErroBaixonegativo->getPertinence() << ", " << ErroBaixoPositivo->getPertinence() << ", " << ErroMedioPositivo->getPertinence() << ", " << ErroAltoPositivo->getPertinence() << std::endl;
    std::cout << "DErro: " << DerroAltoNegativo->getPertinence() << ", " << DerroMedioNegativo->getPertinence() << ", " << DerroBaixonegativo->getPertinence() << ", " << DerroBaixoPositivo->getPertinence() << ", " << DerroMedioPositivo->getPertinence() << ", " << DerroAltoPositivo->getPertinence() << std::endl;
    std::cout << "velocidade: " << OutAltoNegativo->getPertinence() << ", " << OutMedioNegativo->getPertinence() << ", " << OutBaixonegativo->getPertinence() << ", " << OutBaixoPositivo->getPertinence() << ", " << OutMedioPositivo->getPertinence() << ", " << OutAltoPositivo->getPertinence() << std::endl;

    std::cout << "Output: " << outputPitch << std::endl;

    std::cout << "regras 1-15 : " << fuzzy->isFiredRule(1) << ", " << fuzzy->isFiredRule(2) << ", " << fuzzy->isFiredRule(3) << ", " << fuzzy->isFiredRule(4) << ", " << fuzzy->isFiredRule(5) << ", " << fuzzy->isFiredRule(6) << ", " << fuzzy->isFiredRule(7) << ", " << fuzzy->isFiredRule(8) << ", " << fuzzy->isFiredRule(9) << ", " << fuzzy->isFiredRule(10) << ", " << fuzzy->isFiredRule(11) << ", " << fuzzy->isFiredRule(12) << ", " << fuzzy->isFiredRule(13) << ", " << fuzzy->isFiredRule(14) << ", " << fuzzy->isFiredRule(15) << std::endl;
    std::cout << "regras 16-30 : " << fuzzy->isFiredRule(16) << ", " << fuzzy->isFiredRule(17) << ", " << fuzzy->isFiredRule(18) << ", " << fuzzy->isFiredRule(19) << ", " << fuzzy->isFiredRule(20) << ", " << fuzzy->isFiredRule(21) << ", " << fuzzy->isFiredRule(22) << ", " << fuzzy->isFiredRule(23) << ", " << fuzzy->isFiredRule(24) << ", " << fuzzy->isFiredRule(25) << ", " << fuzzy->isFiredRule(26) << ", " << fuzzy->isFiredRule(27) << ", " << fuzzy->isFiredRule(28) << ", " << fuzzy->isFiredRule(29) << ", " << fuzzy->isFiredRule(30) << std::endl;
    std::cout << "regras 31-36 : " << fuzzy->isFiredRule(31) << ", " << fuzzy->isFiredRule(32) << ", " << fuzzy->isFiredRule(33) << ", " << fuzzy->isFiredRule(34) << ", " << fuzzy->isFiredRule(35) << ", " << fuzzy->isFiredRule(36) << std::endl;

    std::cout << "\n" << std::endl;

    fuzzy->setInput(1, -100);
    fuzzy->setInput(2, -100);
    fuzzy->fuzzify();
    
    outputPitch = fuzzy->defuzzify(1);
    
    std::cout << "Erro: " << ErroAltoNegativo->getPertinence() << ", " << ErroMedioNegativo->getPertinence() << ", " << ErroBaixonegativo->getPertinence() << ", " << ErroBaixoPositivo->getPertinence() << ", " << ErroMedioPositivo->getPertinence() << ", " << ErroAltoPositivo->getPertinence() << std::endl;
    std::cout << "DErro: " << DerroAltoNegativo->getPertinence() << ", " << DerroMedioNegativo->getPertinence() << ", " << DerroBaixonegativo->getPertinence() << ", " << DerroBaixoPositivo->getPertinence() << ", " << DerroMedioPositivo->getPertinence() << ", " << DerroAltoPositivo->getPertinence() << std::endl;
    std::cout << "velocidade: " << OutAltoNegativo->getPertinence() << ", " << OutMedioNegativo->getPertinence() << ", " << OutBaixonegativo->getPertinence() << ", " << OutBaixoPositivo->getPertinence() << ", " << OutMedioPositivo->getPertinence() << ", " << OutAltoPositivo->getPertinence() << std::endl;

    std::cout << "Output: " << outputPitch << std::endl;

    std::cout << "regras 1-15 : " << fuzzy->isFiredRule(1) << ", " << fuzzy->isFiredRule(2) << ", " << fuzzy->isFiredRule(3) << ", " << fuzzy->isFiredRule(4) << ", " << fuzzy->isFiredRule(5) << ", " << fuzzy->isFiredRule(6) << ", " << fuzzy->isFiredRule(7) << ", " << fuzzy->isFiredRule(8) << ", " << fuzzy->isFiredRule(9) << ", " << fuzzy->isFiredRule(10) << ", " << fuzzy->isFiredRule(11) << ", " << fuzzy->isFiredRule(12) << ", " << fuzzy->isFiredRule(13) << ", " << fuzzy->isFiredRule(14) << ", " << fuzzy->isFiredRule(15) << std::endl;
    std::cout << "regras 16-30 : " << fuzzy->isFiredRule(16) << ", " << fuzzy->isFiredRule(17) << ", " << fuzzy->isFiredRule(18) << ", " << fuzzy->isFiredRule(19) << ", " << fuzzy->isFiredRule(20) << ", " << fuzzy->isFiredRule(21) << ", " << fuzzy->isFiredRule(22) << ", " << fuzzy->isFiredRule(23) << ", " << fuzzy->isFiredRule(24) << ", " << fuzzy->isFiredRule(25) << ", " << fuzzy->isFiredRule(26) << ", " << fuzzy->isFiredRule(27) << ", " << fuzzy->isFiredRule(28) << ", " << fuzzy->isFiredRule(29) << ", " << fuzzy->isFiredRule(30) << std::endl;
    std::cout << "regras 31-36 : " << fuzzy->isFiredRule(31) << ", " << fuzzy->isFiredRule(32) << ", " << fuzzy->isFiredRule(33) << ", " << fuzzy->isFiredRule(34) << ", " << fuzzy->isFiredRule(35) << ", " << fuzzy->isFiredRule(36) << std::endl;

    return 0;
}
Example #11
0
TEST(FuzzySet, calculatePertinenceAndgetPertinence){
  FuzzySet* fuzzySet = new FuzzySet(0, 10, 10, 20);

  // Valor 1
  fuzzySet->calculatePertinence(-5);
  float result1 = fuzzySet->getPertinence();

  // Valor 2
  fuzzySet->calculatePertinence(5);
  float result2 = fuzzySet->getPertinence();

  // Valor 3
  fuzzySet->calculatePertinence(10);
  float result3 = fuzzySet->getPertinence();

  // Valor 4
  fuzzySet->calculatePertinence(15);
  float result4 = fuzzySet->getPertinence();

  // Valor 5
  fuzzySet->calculatePertinence(25);
  float result5 = fuzzySet->getPertinence();

  EXPECT_EQ(result1, 0.0);
  EXPECT_EQ(result2, 0.5);
  EXPECT_EQ(result3, 1.0);
  EXPECT_EQ(result4, 0.5);
  EXPECT_EQ(result5, 0.0);
}