예제 #1
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
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);
}
예제 #2
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, addFuzzyOutput){
  Fuzzy* fuzzy = new Fuzzy();

  FuzzyOutput* climate = new FuzzyOutput(1);

  FuzzySet* cold = new FuzzySet(0, 10, 10, 20);
  climate->addFuzzySet(cold);
  FuzzySet* good = new FuzzySet(10, 20, 30, 40);
  climate->addFuzzySet(good);
  FuzzySet* hot = new FuzzySet(30, 40, 40, 50);
  climate->addFuzzySet(hot);

  bool result = fuzzy->addFuzzyOutput(climate);

  EXPECT_TRUE(result);
}
예제 #3
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, addFuzzyInput){
  Fuzzy* fuzzy = new Fuzzy();

  FuzzyInput* temperature = new FuzzyInput(1);

  FuzzySet* low = new FuzzySet(0, 10, 10, 20);
  temperature->addFuzzySet(low);
  FuzzySet* mean = new FuzzySet(10, 20, 30, 40);
  temperature->addFuzzySet(mean);
  FuzzySet* high = new FuzzySet(30, 40, 40, 50);
  temperature->addFuzzySet(high);

  bool result = fuzzy->addFuzzyInput(temperature);

  EXPECT_TRUE(result);
}
예제 #4
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
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);
}
예제 #5
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;
}
예제 #6
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;
}
예제 #7
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;
}
예제 #8
0
int main(int argc, char *argv[]) {
	// Instanciando um objeto da biblioteca
	Fuzzy* fuzzy = new Fuzzy();

	// Criando o FuzzyInput distancia
	FuzzyInput* distance = new FuzzyInput(1);
	// Criando os FuzzySet que compoem o FuzzyInput distancia 
	FuzzySet* small = new FuzzySet(0, 20, 20, 40); // Distancia pequena
	distance->addFuzzySet(small); // Adicionando o FuzzySet small em distance
	FuzzySet* safe = new FuzzySet(30, 50, 50, 70); // Distancia segura
	distance->addFuzzySet(safe); // Adicionando o FuzzySet safe em distance
	FuzzySet* big = new FuzzySet(60, 80, 80, 80); // Distancia grande
	distance->addFuzzySet(big); // Adicionando o FuzzySet big em distance

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

	// Criando o FuzzyOutput velocidade
	FuzzyOutput* velocity = new FuzzyOutput(1);
	// Criando os FuzzySet que compoem o FuzzyOutput velocidade 
	FuzzySet* slow = new FuzzySet(0, 10, 10, 20); // Velocidade lenta
	velocity->addFuzzySet(slow); // Adicionando o FuzzySet slow em velocity
	FuzzySet* average = new FuzzySet(10, 20, 30, 40); // Velocidade normal
	velocity->addFuzzySet(average); // Adicionando o FuzzySet average em velocity
	FuzzySet* fast = new FuzzySet(30, 40, 40, 50); // Velocidade alta
	velocity->addFuzzySet(fast); // Adicionando o FuzzySet fast em velocity

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

	//-------------------- Montando as regras Fuzzy
	// FuzzyRule "SE distancia = pequena ENTAO velocidade = lenta"
	FuzzyRuleAntecedent* ifDistanceSmall = new FuzzyRuleAntecedent(); // Instanciando um Antecedente para a expresso
	ifDistanceSmall->joinSingle(small); // Adicionando o FuzzySet correspondente ao objeto Antecedente
	FuzzyRuleConsequent* thenVelocitySlow = new FuzzyRuleConsequent(); // Instancinado um Consequente para a expressao
	thenVelocitySlow->addOutput(slow);// Adicionando o FuzzySet correspondente ao objeto Consequente
	// Instanciando um objeto FuzzyRule
	FuzzyRule* fuzzyRule01 = new FuzzyRule(1, ifDistanceSmall, thenVelocitySlow); // Passando o Antecedente e o Consequente da expressao
	fuzzy->addFuzzyRule(fuzzyRule01); // Adicionando o FuzzyRule ao objeto Fuzzy

	// FuzzyRule "SE distancia = segura ENTAO velocidade = normal"
	FuzzyRuleAntecedent* ifDistanceSafe = new FuzzyRuleAntecedent(); // Instanciando um Antecedente para a expresso
	ifDistanceSafe->joinSingle(safe); // Adicionando o FuzzySet correspondente ao objeto Antecedente
	FuzzyRuleConsequent* thenVelocityAverage = new FuzzyRuleConsequent(); // Instancinado um Consequente para a expressao
	thenVelocityAverage->addOutput(average);// Adicionando o FuzzySet correspondente ao objeto Consequente
	// Instanciando um objeto FuzzyRule
	FuzzyRule* fuzzyRule02 = new FuzzyRule(2, ifDistanceSafe, thenVelocityAverage); // Passando o Antecedente e o Consequente da expressao
	fuzzy->addFuzzyRule(fuzzyRule02); // Adicionando o FuzzyRule ao objeto Fuzzy

	// FuzzyRule "SE distancia = grande ENTAO velocidade = alta"
	FuzzyRuleAntecedent* ifDistanceBig = new FuzzyRuleAntecedent(); // Instanciando um Antecedente para a expresso
	ifDistanceBig->joinSingle(big); // Adicionando o FuzzySet correspondente ao objeto Antecedente
	FuzzyRuleConsequent* thenVelocityFast = new FuzzyRuleConsequent(); // Instancinado um Consequente para a expressao
	thenVelocityFast->addOutput(fast);// Adicionando o FuzzySet correspondente ao objeto Consequente
	// Instanciando um objeto FuzzyRule
	FuzzyRule* fuzzyRule03 = new FuzzyRule(3, ifDistanceBig, thenVelocityFast); // Passando o Antecedente e o Consequente da expressao
	fuzzy->addFuzzyRule(fuzzyRule03); // Adicionando o FuzzyRule ao objeto Fuzzy

	for(int dist = 0; dist < 100; dist++){
		fuzzy->setInput(1, dist);

		fuzzy->fuzzify();

		float output = fuzzy->defuzzify(1);
		cout << "Entrada: " << dist << ", Saida: " << output << endl;
	}
	return 0;
}
예제 #9
0
int main(int argc, char *argv[])
{
    // Set a seed to rand
    srand((unsigned)time(0));

    // Instantiating a Fuzzy object
    Fuzzy *fuzzy = new Fuzzy();

    // Instantiating a FuzzyInput object
    FuzzyInput *distance = new FuzzyInput(1);
    // Instantiating a FuzzySet object
    FuzzySet *small = new FuzzySet(0, 20, 20, 40);
    // Including the FuzzySet into FuzzyInput
    distance->addFuzzySet(small);
    // Instantiating a FuzzySet object
    FuzzySet *safe = new FuzzySet(30, 50, 50, 70);
    // Including the FuzzySet into FuzzyInput
    distance->addFuzzySet(safe);
    // Instantiating a FuzzySet object
    FuzzySet *big = new FuzzySet(60, 80, 80, 80);
    // Including the FuzzySet into FuzzyInput
    distance->addFuzzySet(big);
    // Including the FuzzyInput into Fuzzy
    fuzzy->addFuzzyInput(distance);

    // Instantiating a FuzzyOutput objects
    FuzzyOutput *speed = new FuzzyOutput(1);
    // Instantiating a FuzzySet object
    FuzzySet *slow = new FuzzySet(0, 10, 10, 20);
    // Including the FuzzySet into FuzzyOutput
    speed->addFuzzySet(slow);
    // Instantiating a FuzzySet object
    FuzzySet *average = new FuzzySet(10, 20, 30, 40);
    // Including the FuzzySet into FuzzyOutput
    speed->addFuzzySet(average);
    // Instantiating a FuzzySet object
    FuzzySet *fast = new FuzzySet(30, 40, 40, 50);
    // Including the FuzzySet into FuzzyOutput
    speed->addFuzzySet(fast);
    // Including the FuzzyOutput into Fuzzy
    fuzzy->addFuzzyOutput(speed);

    // Building FuzzyRule "IF distance = small THEN speed = slow"
    // Instantiating a FuzzyRuleAntecedent objects
    FuzzyRuleAntecedent *ifDistanceSmall = new FuzzyRuleAntecedent();
    // Creating a FuzzyRuleAntecedent with just a single FuzzySet
    ifDistanceSmall->joinSingle(small);
    // Instantiating a FuzzyRuleConsequent objects
    FuzzyRuleConsequent *thenSpeedSlow = new FuzzyRuleConsequent();
    // Including a FuzzySet to this FuzzyRuleConsequent
    thenSpeedSlow->addOutput(slow);
    // Instantiating a FuzzyRule objects
    FuzzyRule *fuzzyRule01 = new FuzzyRule(1, ifDistanceSmall, thenSpeedSlow);
    // Including the FuzzyRule into Fuzzy
    fuzzy->addFuzzyRule(fuzzyRule01);

    // Building FuzzyRule "IF distance = safe THEN speed = average"
    // Instantiating a FuzzyRuleAntecedent objects
    FuzzyRuleAntecedent *ifDistanceSafe = new FuzzyRuleAntecedent();
    // Creating a FuzzyRuleAntecedent with just a single FuzzySet
    ifDistanceSafe->joinSingle(safe);
    // Instantiating a FuzzyRuleConsequent objects
    FuzzyRuleConsequent *thenSpeedAverage = new FuzzyRuleConsequent();
    // Including a FuzzySet to this FuzzyRuleConsequent
    thenSpeedAverage->addOutput(average);
    // Instantiating a FuzzyRule objects
    FuzzyRule *fuzzyRule02 = new FuzzyRule(2, ifDistanceSafe, thenSpeedAverage);
    // Including the FuzzyRule into Fuzzy
    fuzzy->addFuzzyRule(fuzzyRule02);

    // Building FuzzyRule "IF distance = big THEN speed = high"
    // Instantiating a FuzzyRuleAntecedent objects
    FuzzyRuleAntecedent *ifDistanceBig = new FuzzyRuleAntecedent();
    // Creating a FuzzyRuleAntecedent with just a single FuzzySet
    ifDistanceBig->joinSingle(big);
    // Instantiating a FuzzyRuleConsequent objects
    FuzzyRuleConsequent *thenSpeedFast = new FuzzyRuleConsequent();
    // Including a FuzzySet to this FuzzyRuleConsequent
    thenSpeedFast->addOutput(fast);
    // Instantiating a FuzzyRule objects
    FuzzyRule *fuzzyRule03 = new FuzzyRule(3, ifDistanceBig, thenSpeedFast);
    // Including the FuzzyRule into Fuzzy
    fuzzy->addFuzzyRule(fuzzyRule03);

    // get a random value
    int input = random(0, 100);
    // Printing something
    cout << "\n\n\nEntrance: \n\t\t\tDistance: " << input << endl;
    // Set the random value as an input
    fuzzy->setInput(1, input);
    // Running the Fuzzification
    fuzzy->fuzzify();
    // Running the Defuzzification
    float output = fuzzy->defuzzify(1);
    // Printing something
    cout << "Result: \n\t\t\tSpeed: " << output << endl;
    return 0;
}
예제 #10
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, setInputAndFuzzifyAndDefuzzify07){
  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* temperature = new FuzzyInput(2);

  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);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifDistanceCloseAndTemperatureCold = new FuzzyRuleAntecedent();
  ifDistanceCloseAndTemperatureCold->joinWithAND(close, cold);

  FuzzyRuleConsequent* thenRiskMinimum1 = new FuzzyRuleConsequent();
  thenRiskMinimum1->addOutput(minimum);

  FuzzyRule* fuzzyRule1 = new FuzzyRule(1, ifDistanceCloseAndTemperatureCold, thenRiskMinimum1);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifDistanceCloseAndTemperatureGood = new FuzzyRuleAntecedent();
  ifDistanceCloseAndTemperatureGood->joinWithAND(close, good);

  FuzzyRuleConsequent* thenRiskMinimum2 = new FuzzyRuleConsequent();
  thenRiskMinimum2->addOutput(minimum);

  FuzzyRule* fuzzyRule2 = new FuzzyRule(2, ifDistanceCloseAndTemperatureGood, thenRiskMinimum2);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifDistanceSafeAndTemperatureCold = new FuzzyRuleAntecedent();
  ifDistanceSafeAndTemperatureCold->joinWithAND(safe, cold);

  FuzzyRuleConsequent* thenRiskMinimum3 = new FuzzyRuleConsequent();
  thenRiskMinimum3->addOutput(minimum);

  FuzzyRule* fuzzyRule3 = new FuzzyRule(3, ifDistanceSafeAndTemperatureCold, thenRiskMinimum3);
  fuzzy->addFuzzyRule(fuzzyRule3);

  fuzzy->setInput(1, 10);
  fuzzy->setInput(2, -5);

  fuzzy->fuzzify();

  float output = fuzzy->defuzzify(1);

  EXPECT_EQ(20.0, output);
}
예제 #11
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, setInputAndFuzzifyAndDefuzzify06){
  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();

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

  EXPECT_EQ(80.0, output1);
  EXPECT_EQ(10.5, output2);
}
예제 #12
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, setInputAndFuzzifyAndDefuzzify05){
  Fuzzy* fuzzy = new Fuzzy();

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

  FuzzySet* low = new FuzzySet(-20, -20, -20, -20);
  temperature->addFuzzySet(low);
  FuzzySet* mean = new FuzzySet(-10, -10, -10, -10);
  temperature->addFuzzySet(mean);
  FuzzySet* high = new FuzzySet(10, 10, 10, 10);
  temperature->addFuzzySet(high);

  fuzzy->addFuzzyInput(temperature);

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

  FuzzySet* small = new FuzzySet(-20, -20, -20, -20);
  pressure->addFuzzySet(small);
  FuzzySet* normal = new FuzzySet(-10, -10, -10, -10);
  pressure->addFuzzySet(normal);
  FuzzySet* big = new FuzzySet(10, 10, 10, 10);
  pressure->addFuzzySet(big);

  fuzzy->addFuzzyInput(pressure);

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

  FuzzySet* minimum = new FuzzySet(-20, -20, -20, -20);
  risk->addFuzzySet(minimum);
  FuzzySet* average = new FuzzySet(-10, -10, -10, -10);
  risk->addFuzzySet(average);
  FuzzySet* maximum = new FuzzySet(10, 10, 10, 10);
  risk->addFuzzySet(maximum);

  fuzzy->addFuzzyOutput(risk);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifTemperatureLowAndPressureSmall = new FuzzyRuleAntecedent();
  ifTemperatureLowAndPressureSmall->joinWithAND(low, small);
  FuzzyRuleConsequent* thenRiskMinimum = new FuzzyRuleConsequent();
  thenRiskMinimum->addOutput(minimum);

  FuzzyRule* fuzzyRule1 = new FuzzyRule(1, ifTemperatureLowAndPressureSmall, thenRiskMinimum);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifTemperatureMeanAndPressureNormal = new FuzzyRuleAntecedent();
  ifTemperatureMeanAndPressureNormal->joinWithAND(mean, normal);
  FuzzyRuleConsequent* theRiskAverage = new FuzzyRuleConsequent();
  theRiskAverage->addOutput(average);

  FuzzyRule* fuzzyRule2 = new FuzzyRule(2, ifTemperatureMeanAndPressureNormal, theRiskAverage);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifTemperatureHighAndPressureBig = new FuzzyRuleAntecedent();
  ifTemperatureHighAndPressureBig->joinWithAND(high, big);
  FuzzyRuleConsequent* thenRiskMaximum = new FuzzyRuleConsequent();
  thenRiskMaximum->addOutput(maximum);

  FuzzyRule* fuzzyRule3 = new FuzzyRule(3, ifTemperatureHighAndPressureBig, thenRiskMaximum);
  fuzzy->addFuzzyRule(fuzzyRule3);

  fuzzy->setInput(1, -20);
  fuzzy->setInput(2, -15);

  fuzzy->fuzzify();

  float output = fuzzy->defuzzify(1);

  EXPECT_EQ(output, 0.0);
}
예제 #13
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, setInputAndFuzzifyAndDefuzzify01){
  Fuzzy* fuzzy = new Fuzzy();

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

  FuzzySet* low = new FuzzySet(0, 10, 10, 20);
  temperature->addFuzzySet(low);
  FuzzySet* mean = new FuzzySet(10, 20, 30, 40);
  temperature->addFuzzySet(mean);
  FuzzySet* high = new FuzzySet(30, 40, 40, 50);
  temperature->addFuzzySet(high);

  fuzzy->addFuzzyInput(temperature);

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

  FuzzySet* cold = new FuzzySet(0, 10, 10, 20);
  climate->addFuzzySet(cold);
  FuzzySet* good = new FuzzySet(10, 20, 30, 40);
  climate->addFuzzySet(good);
  FuzzySet* hot = new FuzzySet(30, 40, 40, 50);
  climate->addFuzzySet(hot);

  fuzzy->addFuzzyOutput(climate);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifTemperatureLow = new FuzzyRuleAntecedent();
  ifTemperatureLow->joinSingle(low);
  FuzzyRuleConsequent* thenClimateCold = new FuzzyRuleConsequent();
  thenClimateCold->addOutput(cold);

  FuzzyRule* fuzzyRule1 = new FuzzyRule(1, ifTemperatureLow, thenClimateCold);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifTemperatureMean = new FuzzyRuleAntecedent();
  ifTemperatureMean->joinSingle(mean);
  FuzzyRuleConsequent* thenClimateGood = new FuzzyRuleConsequent();
  thenClimateGood->addOutput(good);

  FuzzyRule* fuzzyRule2 = new FuzzyRule(2, ifTemperatureMean, thenClimateGood);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule
  FuzzyRuleAntecedent* ifTemperatureHigh = new FuzzyRuleAntecedent();
  ifTemperatureHigh->joinSingle(low);
  FuzzyRuleConsequent* thenClimateHot = new FuzzyRuleConsequent();
  thenClimateHot->addOutput(cold);

  FuzzyRule* fuzzyRule3 = new FuzzyRule(3, ifTemperatureHigh, thenClimateHot);
  fuzzy->addFuzzyRule(fuzzyRule3);

  bool result1 = fuzzy->setInput(1, 15);

  bool result2 = fuzzy->fuzzify();

  float output = fuzzy->defuzzify(1);

  EXPECT_TRUE(result1);
  EXPECT_TRUE(result2);
  EXPECT_GT(output, 0.0);
}
예제 #14
0
파일: FuzzyTest.cpp 프로젝트: CamiloJr/eFLL
TEST(Fuzzy, setInputAndFuzzifyAndDefuzzify09){
  // Instantiating an object of library
  Fuzzy* fuzzy = new Fuzzy();

  FuzzyInput* shift;
  FuzzyInput* distance;

  FuzzyOutput* steeringangle;
  FuzzyOutput* runningspeed;

  FuzzyRuleAntecedent* ifShiftS_4AndDistanceD_0;
  FuzzyRuleConsequent* thenSteeringangleAng_4AndRunningspeedSpeed_2;
  FuzzyRule* fuzzyRule1;

  FuzzyRuleAntecedent* ifShiftS_4AndDistanceD_1;
  FuzzyRuleConsequent* thenSteeringangleAng_4AndRunningspeedSpeed_1;
  FuzzyRule* fuzzyRule2;

  FuzzyRuleAntecedent* ifShiftS_4AndDistanceD_2;
  FuzzyRule* fuzzyRule3;

  FuzzyRuleAntecedent* ifShiftS_4AndDistanceD_3;
  FuzzyRuleConsequent* thenSteeringangleAng_4AndRunningspeedSpeed_0;
  FuzzyRule *fuzzyRule4;

  FuzzyRuleAntecedent* ifShiftS_4AndDistanceD_4;
  FuzzyRule* fuzzyRule5;

  FuzzyRuleAntecedent* ifShiftS_3AndDistanceD_0;
  FuzzyRuleConsequent* thenSteeringangleAng_3AndRunningspeedSpeed_3;
  FuzzyRule* fuzzyRule6;

  FuzzyRuleAntecedent* ifShiftS_3AndDistanceD_1;
  FuzzyRuleConsequent* thenSteeringangleAng_3AndRunningspeedSpeed_2;
  FuzzyRule* fuzzyRule7;

  FuzzyRuleAntecedent* ifShiftS_3AndDistanceD_2;
  FuzzyRuleConsequent* thenSteeringangleAng_3AndRunningspeedSpeed_1;
  FuzzyRule* fuzzyRule8;

  FuzzyRuleAntecedent* ifShiftS_3AndDistanceD_3;
  FuzzyRule* fuzzyRule9;

  FuzzyRuleAntecedent* ifShiftS_3AndDistanceD_4;
  FuzzyRuleConsequent* thenSteeringangleAng_3AndRunningspeedSpeed_0;
  FuzzyRule* fuzzyRule10;

  FuzzyRuleAntecedent* ifShiftS_2;
  FuzzyRuleConsequent* thenSteeringangleAng_2AndRunningspeedSpeed_4;
  FuzzyRule* fuzzyRule11;

  FuzzyRuleAntecedent* ifShiftS_1AndDistanceD_0;
  FuzzyRuleConsequent* thenSteeringangleAng_1AndRunningspeedSpeed_3;
  FuzzyRule* fuzzyRule12;

  FuzzyRuleAntecedent* ifShiftS_1AndDistanceD_1;
  FuzzyRuleConsequent* thenSteeringangleAng_1AndRunningspeedSpeed_2;
  FuzzyRule* fuzzyRule13;

  FuzzyRuleAntecedent* ifShiftS_1AndDistanceD_2;
  FuzzyRuleConsequent* thenSteeringangleAng_1AndRunningspeedSpeed_1;
  FuzzyRule* fuzzyRule14;

  FuzzyRuleAntecedent* ifShiftS_1AndDistanceD_3;
  FuzzyRule* fuzzyRule15;

  FuzzyRuleAntecedent* ifShiftS_1AndDistanceD_4;
  FuzzyRuleConsequent* thenSteeringangleAng_1AndRunningspeedSpeed_0;
  FuzzyRule* fuzzyRule16;

  FuzzyRuleAntecedent* ifShiftS_0AndDistanceD_0;
  FuzzyRuleConsequent* thenSteeringangleAng_0AndRunningspeedSpeed_2;
  FuzzyRule* fuzzyRule17;

  FuzzyRuleAntecedent* ifShiftS_0AndDistanceD_1;
  FuzzyRuleConsequent* thenSteeringangleAng_0AndRunningspeedSpeed_1;
  FuzzyRule* fuzzyRule18;

  FuzzyRuleAntecedent* ifShiftS_0AndDistanceD_2;
  FuzzyRule* fuzzyRule19;

  FuzzyRuleAntecedent* ifShiftS_0AndDistanceD_3;
  FuzzyRuleConsequent* thenSteeringangleAng_0AndRunningspeedSpeed_0;
  FuzzyRule* fuzzyRule20;

  FuzzyRuleAntecedent* ifShiftS_0AndDistanceD_4;
  FuzzyRule* fuzzyRule21;

  // Fuzzy set
  FuzzySet* s_0 = new FuzzySet (9, 21, 21, 33);        //veri left
  FuzzySet* s_1 = new FuzzySet (24, 31.5, 31.5, 39 );  //medium left
  FuzzySet* s_2 = new FuzzySet (35, 39, 39, 43);       //zero  
  FuzzySet* s_3 = new FuzzySet (39, 46.5, 46.5, 54);   //medium right
  FuzzySet* s_4 = new FuzzySet (45, 57, 57, 69);       //very right

  FuzzySet* d_0 = new FuzzySet (0, 5, 5, 10);      //farthest
  FuzzySet* d_1 = new FuzzySet (5, 10, 10, 15);      //far  
  FuzzySet* d_2 = new FuzzySet (10, 15, 15, 20);      //middle
  FuzzySet* d_3 = new FuzzySet (15, 25, 25, 35);  //near
  FuzzySet* d_4 = new FuzzySet (25, 42, 42, 59);          //nearest

  FuzzySet* ang_0 = new FuzzySet (60, 70, 70, 80);      //leftmost
  FuzzySet* ang_1 = new FuzzySet (69, 79, 79, 89);      //left
  FuzzySet* ang_2 = new FuzzySet (88, 90, 90, 92);      //middle
  FuzzySet* ang_3 = new FuzzySet (91, 101, 101, 111);    //right
  FuzzySet* ang_4 = new FuzzySet (100, 110, 110, 120);   // rightmost

  FuzzySet* speed_0 = new FuzzySet (50, 75, 75, 100);      //very slow
  FuzzySet* speed_1 = new FuzzySet (75, 110, 110, 145);    //slow
  FuzzySet* speed_2 = new FuzzySet (120, 150, 150, 180);    //middle
  FuzzySet* speed_3 = new FuzzySet (155, 190, 190, 225);    //fast
  FuzzySet* speed_4 = new FuzzySet (200, 225, 225, 250);    //veryfast

  // Fuzzy input
  shift = new FuzzyInput(1);
  shift-> addFuzzySet(s_0);
  shift-> addFuzzySet(s_1);
  shift-> addFuzzySet(s_2);
  shift-> addFuzzySet(s_3);
  shift-> addFuzzySet(s_4);
  fuzzy->addFuzzyInput(shift);

  distance = new FuzzyInput(2);
  distance-> addFuzzySet(d_0);
  distance-> addFuzzySet(d_1);
  distance-> addFuzzySet(d_2);
  distance-> addFuzzySet(d_3);
  distance-> addFuzzySet(d_4);
  fuzzy->addFuzzyInput(distance);

  // Fuzzy output
  steeringangle = new FuzzyOutput(1);
  steeringangle-> addFuzzySet(ang_0);
  steeringangle-> addFuzzySet(ang_1);
  steeringangle-> addFuzzySet(ang_2);
  steeringangle-> addFuzzySet(ang_3);
  steeringangle-> addFuzzySet(ang_4);
  fuzzy-> addFuzzyOutput(steeringangle);

  runningspeed = new FuzzyOutput(2);
  runningspeed-> addFuzzySet(speed_0);
  runningspeed-> addFuzzySet(speed_1);
  runningspeed-> addFuzzySet(speed_2);
  runningspeed-> addFuzzySet(speed_3);
  fuzzy-> addFuzzyOutput(runningspeed);

  // Fuzzy rule
  ifShiftS_4AndDistanceD_0 = new FuzzyRuleAntecedent();
  ifShiftS_4AndDistanceD_0 ->joinWithAND(s_4,d_0);
  thenSteeringangleAng_4AndRunningspeedSpeed_2 = new FuzzyRuleConsequent();
  thenSteeringangleAng_4AndRunningspeedSpeed_2->addOutput(ang_4);
  thenSteeringangleAng_4AndRunningspeedSpeed_2->addOutput(speed_2);
  fuzzyRule1 = new FuzzyRule(1, ifShiftS_4AndDistanceD_0, thenSteeringangleAng_4AndRunningspeedSpeed_2);
  fuzzy->addFuzzyRule(fuzzyRule1);

  ifShiftS_4AndDistanceD_1 = new FuzzyRuleAntecedent();
  ifShiftS_4AndDistanceD_1 ->joinWithAND(s_4,d_1);
  thenSteeringangleAng_4AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  thenSteeringangleAng_4AndRunningspeedSpeed_1->addOutput(ang_4);
  thenSteeringangleAng_4AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule2 = new FuzzyRule(2, ifShiftS_4AndDistanceD_1, thenSteeringangleAng_4AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule2);

  ifShiftS_4AndDistanceD_2 = new FuzzyRuleAntecedent();
  ifShiftS_4AndDistanceD_2->joinWithAND(s_4, d_2);
  // FuzzyRuleConsequent* thenSteeringangleAng_4AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  // thenSteeringangleAng_4AndRunningspeedSpeed_1->addOutput(ang_4);
  // thenSteeringangleAng_4AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule3 = new FuzzyRule(3, ifShiftS_4AndDistanceD_2, thenSteeringangleAng_4AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule3);

  ifShiftS_4AndDistanceD_3 = new FuzzyRuleAntecedent();
  ifShiftS_4AndDistanceD_3->joinWithAND(s_4,d_3);
  thenSteeringangleAng_4AndRunningspeedSpeed_0 = new FuzzyRuleConsequent();
  thenSteeringangleAng_4AndRunningspeedSpeed_0->addOutput(ang_4);
  thenSteeringangleAng_4AndRunningspeedSpeed_0->addOutput(speed_0);
  fuzzyRule4 = new FuzzyRule(4, ifShiftS_4AndDistanceD_3, thenSteeringangleAng_4AndRunningspeedSpeed_0);
  fuzzy->addFuzzyRule(fuzzyRule4);

  ifShiftS_4AndDistanceD_4 = new FuzzyRuleAntecedent();
  ifShiftS_4AndDistanceD_4->joinWithAND(s_4,d_4);
  // FuzzyRuleConsequent* thenSteeringangleAng_4AndRunningspeedSpeed_0 = new FuzzyRuleConsequent();
  // thenSteeringangleAng_4AndRunningspeedSpeed_0->addOutput(ang_4);
  // thenSteeringangleAng_4AndRunningspeedSpeed_0->addOutput(speed_0);
  fuzzyRule5 = new FuzzyRule(5, ifShiftS_4AndDistanceD_4, thenSteeringangleAng_4AndRunningspeedSpeed_0);
  fuzzy->addFuzzyRule(fuzzyRule5);

  ifShiftS_3AndDistanceD_0 = new FuzzyRuleAntecedent();
  ifShiftS_3AndDistanceD_0->joinWithAND(s_3,d_0);
  thenSteeringangleAng_3AndRunningspeedSpeed_3 = new FuzzyRuleConsequent();
  thenSteeringangleAng_3AndRunningspeedSpeed_3->addOutput(ang_3);
  thenSteeringangleAng_3AndRunningspeedSpeed_3->addOutput(speed_3);
  fuzzyRule6 = new FuzzyRule(6, ifShiftS_3AndDistanceD_0, thenSteeringangleAng_3AndRunningspeedSpeed_3);
  fuzzy->addFuzzyRule(fuzzyRule6);

  ifShiftS_3AndDistanceD_1 = new FuzzyRuleAntecedent();
  ifShiftS_3AndDistanceD_1->joinWithAND(s_3,d_1);
  thenSteeringangleAng_3AndRunningspeedSpeed_2 = new FuzzyRuleConsequent();
  thenSteeringangleAng_3AndRunningspeedSpeed_2->addOutput(ang_3);
  thenSteeringangleAng_3AndRunningspeedSpeed_2->addOutput(speed_2);
  fuzzyRule7 = new FuzzyRule(7, ifShiftS_3AndDistanceD_1, thenSteeringangleAng_3AndRunningspeedSpeed_2);
  fuzzy->addFuzzyRule(fuzzyRule7);

  ifShiftS_3AndDistanceD_2 = new FuzzyRuleAntecedent();
  ifShiftS_3AndDistanceD_2->joinWithAND(s_3,d_2);
  thenSteeringangleAng_3AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  thenSteeringangleAng_3AndRunningspeedSpeed_1->addOutput(ang_3);
  thenSteeringangleAng_3AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule8 = new FuzzyRule(8, ifShiftS_3AndDistanceD_2, thenSteeringangleAng_3AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule8);

  ifShiftS_3AndDistanceD_3 = new FuzzyRuleAntecedent();
  ifShiftS_3AndDistanceD_3->joinWithAND(s_3,d_3);
  // FuzzyRuleConsequent* thenSteeringangleAng_3AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  // thenSteeringangleAng_3AndRunningspeedSpeed_1->addOutput(ang_3);
  // thenSteeringangleAng_3AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule9 = new FuzzyRule(9, ifShiftS_3AndDistanceD_3, thenSteeringangleAng_3AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule9);

  ifShiftS_3AndDistanceD_4 = new FuzzyRuleAntecedent();
  ifShiftS_3AndDistanceD_4->joinWithAND(s_3,d_4);
  thenSteeringangleAng_3AndRunningspeedSpeed_0 = new FuzzyRuleConsequent();
  thenSteeringangleAng_3AndRunningspeedSpeed_0->addOutput(ang_3);
  thenSteeringangleAng_3AndRunningspeedSpeed_0->addOutput(speed_0);
  fuzzyRule10 = new FuzzyRule(10, ifShiftS_3AndDistanceD_4, thenSteeringangleAng_3AndRunningspeedSpeed_0);
  fuzzy->addFuzzyRule(fuzzyRule10);

  ifShiftS_2 = new FuzzyRuleAntecedent();
  ifShiftS_2->joinSingle(s_2);
  thenSteeringangleAng_2AndRunningspeedSpeed_4 = new FuzzyRuleConsequent();
  thenSteeringangleAng_2AndRunningspeedSpeed_4->addOutput(ang_2);
  thenSteeringangleAng_2AndRunningspeedSpeed_4->addOutput(speed_4);
  fuzzyRule11 = new FuzzyRule(11, ifShiftS_2, thenSteeringangleAng_2AndRunningspeedSpeed_4);
  fuzzy->addFuzzyRule(fuzzyRule11);

  ifShiftS_1AndDistanceD_0 = new FuzzyRuleAntecedent();
  ifShiftS_1AndDistanceD_0->joinWithAND(s_1,d_0);
  thenSteeringangleAng_1AndRunningspeedSpeed_3 = new FuzzyRuleConsequent();
  thenSteeringangleAng_1AndRunningspeedSpeed_3->addOutput(ang_1);
  thenSteeringangleAng_1AndRunningspeedSpeed_3->addOutput(speed_3);
  fuzzyRule12 = new FuzzyRule(12, ifShiftS_1AndDistanceD_0, thenSteeringangleAng_1AndRunningspeedSpeed_3);
  fuzzy->addFuzzyRule(fuzzyRule12);

  ifShiftS_1AndDistanceD_1 = new FuzzyRuleAntecedent();
  ifShiftS_1AndDistanceD_1->joinWithAND(s_1,d_1);
  thenSteeringangleAng_1AndRunningspeedSpeed_2 = new FuzzyRuleConsequent();
  thenSteeringangleAng_1AndRunningspeedSpeed_2->addOutput(ang_1);
  thenSteeringangleAng_1AndRunningspeedSpeed_2->addOutput(speed_2);
  fuzzyRule13 = new FuzzyRule(13, ifShiftS_1AndDistanceD_1, thenSteeringangleAng_1AndRunningspeedSpeed_2);
  fuzzy->addFuzzyRule(fuzzyRule13);

  ifShiftS_1AndDistanceD_2 = new FuzzyRuleAntecedent();
  ifShiftS_1AndDistanceD_2->joinWithAND(s_1,d_2);
  thenSteeringangleAng_1AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  thenSteeringangleAng_1AndRunningspeedSpeed_1->addOutput(ang_1);
  thenSteeringangleAng_1AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule14 = new FuzzyRule(14, ifShiftS_1AndDistanceD_2, thenSteeringangleAng_1AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule14);

  ifShiftS_1AndDistanceD_3 = new FuzzyRuleAntecedent();
  ifShiftS_1AndDistanceD_3->joinWithAND(s_1,d_3);
  // FuzzyRuleConsequent* thenSteeringangleAng_1AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  // thenSteeringangleAng_1AndRunningspeedSpeed_1->addOutput(ang_1);
  // thenSteeringangleAng_1AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule15 = new FuzzyRule(15, ifShiftS_1AndDistanceD_3, thenSteeringangleAng_1AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule15);

  ifShiftS_1AndDistanceD_4 = new FuzzyRuleAntecedent();
  ifShiftS_1AndDistanceD_4->joinWithAND(s_1,d_4);
  thenSteeringangleAng_1AndRunningspeedSpeed_0 = new FuzzyRuleConsequent();
  thenSteeringangleAng_1AndRunningspeedSpeed_0->addOutput(ang_1);
  thenSteeringangleAng_1AndRunningspeedSpeed_0->addOutput(speed_0);
  fuzzyRule16 = new FuzzyRule(16, ifShiftS_1AndDistanceD_4, thenSteeringangleAng_1AndRunningspeedSpeed_0);
  fuzzy->addFuzzyRule(fuzzyRule16);

  ifShiftS_0AndDistanceD_0 = new FuzzyRuleAntecedent();
  ifShiftS_0AndDistanceD_0->joinWithAND(s_0,d_0);
  thenSteeringangleAng_0AndRunningspeedSpeed_2 = new FuzzyRuleConsequent();
  thenSteeringangleAng_0AndRunningspeedSpeed_2->addOutput(ang_0);
  thenSteeringangleAng_0AndRunningspeedSpeed_2->addOutput(speed_2);
  fuzzyRule17 = new FuzzyRule(17, ifShiftS_0AndDistanceD_0, thenSteeringangleAng_0AndRunningspeedSpeed_2);
  fuzzy->addFuzzyRule(fuzzyRule17);

  ifShiftS_0AndDistanceD_1 = new FuzzyRuleAntecedent();
  ifShiftS_0AndDistanceD_1->joinWithAND(s_0,d_1);
  thenSteeringangleAng_0AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  thenSteeringangleAng_0AndRunningspeedSpeed_1->addOutput(ang_0);
  thenSteeringangleAng_0AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule18 = new FuzzyRule(18, ifShiftS_0AndDistanceD_1, thenSteeringangleAng_0AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule18);

  ifShiftS_0AndDistanceD_2 = new FuzzyRuleAntecedent();
  ifShiftS_0AndDistanceD_2->joinWithAND(s_0,d_2);
  // FuzzyRuleConsequent* thenSteeringangleAng_0AndRunningspeedSpeed_1 = new FuzzyRuleConsequent();
  // thenSteeringangleAng_0AndRunningspeedSpeed_1->addOutput(ang_0);
  // thenSteeringangleAng_0AndRunningspeedSpeed_1->addOutput(speed_1);
  fuzzyRule19 = new FuzzyRule(19, ifShiftS_0AndDistanceD_2, thenSteeringangleAng_0AndRunningspeedSpeed_1);
  fuzzy->addFuzzyRule(fuzzyRule19);

  ifShiftS_0AndDistanceD_3 = new FuzzyRuleAntecedent();
  ifShiftS_0AndDistanceD_3->joinWithAND(s_0,d_3);
  thenSteeringangleAng_0AndRunningspeedSpeed_0 = new FuzzyRuleConsequent();
  thenSteeringangleAng_0AndRunningspeedSpeed_0->addOutput(ang_0);
  thenSteeringangleAng_0AndRunningspeedSpeed_0->addOutput(speed_0);
  fuzzyRule20 = new FuzzyRule(20, ifShiftS_0AndDistanceD_3, thenSteeringangleAng_0AndRunningspeedSpeed_0);
  fuzzy->addFuzzyRule(fuzzyRule20);

  ifShiftS_0AndDistanceD_4 = new FuzzyRuleAntecedent();
  ifShiftS_0AndDistanceD_4->joinWithAND(s_0,d_4);
  // FuzzyRuleConsequent* thenSteeringangleAng_0AndRunningspeedSpeed_0 = new FuzzyRuleConsequent();
  // thenSteeringangleAng_0AndRunningspeedSpeed_0->addOutput(ang_0);
  // thenSteeringangleAng_0AndRunningspeedSpeed_0->addOutput(speed_0);
  fuzzyRule21 = new FuzzyRule(21, ifShiftS_0AndDistanceD_4, thenSteeringangleAng_0AndRunningspeedSpeed_0);
  fuzzy->addFuzzyRule(fuzzyRule21);

  int target_x = 21.88;  //  key in the digital value
  int target_y = 32;

  // target_x and target_y are the inputs    
  fuzzy->setInput(1, target_x);  // shift
  fuzzy->setInput(2, target_y);  // deistance

  fuzzy->fuzzify(); // Executing the fuzzification

  // float output1 = fuzzy->defuzzify(1);  // steering angle
  float output2 = fuzzy->defuzzify(2);  // running speed

  // EXPECT_EQ(70, output1);
  EXPECT_EQ(75, output2);
}