Esempio n. 1
0
int main(int argc, char** argv){
//Code automatically generated with jfuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("tipper");
engine->setDescription("");

InputVariable* service = new InputVariable;
service->setName("service");
service->setDescription("");
service->setEnabled(true);
service->setRange(0.000, 10.000);
service->setLockValueInRange(false);
service->addTerm(new Gaussian("poor", 0.000, 1.500));
service->addTerm(new Gaussian("good", 5.000, 1.500));
service->addTerm(new Gaussian("excellent", 10.000, 1.500));
engine->addInputVariable(service);

InputVariable* food = new InputVariable;
food->setName("food");
food->setDescription("");
food->setEnabled(true);
food->setRange(0.000, 10.000);
food->setLockValueInRange(false);
food->addTerm(new Trapezoid("rancid", 0.000, 0.000, 1.000, 3.000));
food->addTerm(new Trapezoid("delicious", 7.000, 9.000, 10.000, 10.000));
engine->addInputVariable(food);

OutputVariable* tip = new OutputVariable;
tip->setName("tip");
tip->setDescription("");
tip->setEnabled(true);
tip->setRange(0.000, 30.000);
tip->setLockValueInRange(false);
tip->setAggregation(new Maximum);
tip->setDefuzzifier(new Centroid(200));
tip->setDefaultValue(fl::nan);
tip->setLockPreviousValue(false);
tip->addTerm(new Triangle("cheap", 0.000, 5.000, 10.000));
tip->addTerm(new Triangle("average", 10.000, 15.000, 20.000));
tip->addTerm(new Triangle("generous", 20.000, 25.000, 30.000));
engine->addOutputVariable(tip);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setName("");
ruleBlock->setDescription("");
ruleBlock->setEnabled(true);
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setImplication(new Minimum);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if service is poor or food is rancid then tip is cheap", engine));
ruleBlock->addRule(Rule::parse("if service is good then tip is average", engine));
ruleBlock->addRule(Rule::parse("if service is excellent or food is delicious then tip is generous", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 2
0
int main(int argc, char** argv){
//C++ code generated with fuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("sltbu_fl");

InputVariable* distance = new InputVariable;
distance->setEnabled(true);
distance->setName("distance");
distance->setRange(0.000, 25.000);
distance->setLockValueInRange(false);
distance->addTerm(new ZShape("near", 1.000, 2.000));
distance->addTerm(new SShape("far", 1.000, 2.000));
engine->addInputVariable(distance);

InputVariable* control1 = new InputVariable;
control1->setEnabled(true);
control1->setName("control1");
control1->setRange(-0.785, 0.785);
control1->setLockValueInRange(false);
engine->addInputVariable(control1);

InputVariable* control2 = new InputVariable;
control2->setEnabled(true);
control2->setName("control2");
control2->setRange(-0.785, 0.785);
control2->setLockValueInRange(false);
engine->addInputVariable(control2);

OutputVariable* control = new OutputVariable;
control->setEnabled(true);
control->setName("control");
control->setRange(-0.785, 0.785);
control->setLockValueInRange(false);
control->fuzzyOutput()->setAggregation(fl::null);
control->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
control->setDefaultValue(fl::nan);
control->setLockPreviousValue(false);
control->addTerm(Linear::create("out1mf1", engine, 0.000, 0.000, 1.000, 0.000));
control->addTerm(Linear::create("out1mf2", engine, 0.000, 1.000, 0.000, 0.000));
engine->addOutputVariable(control);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(fl::null);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if distance is near then control is out1mf1", engine));
ruleBlock->addRule(Rule::parse("if distance is far then control is out1mf2", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 3
0
int main(int argc, char** argv) {
    using namespace fl;

    Engine* engine = new Engine;
    engine->setName("mam21");

    InputVariable* angle = new InputVariable;
    angle->setEnabled(true);
    angle->setName("angle");
    angle->setRange(-5.000, 5.000);
    angle->setLockValueInRange(false);
    angle->addTerm(new Bell("small", -5.000, 5.000, 8.000));
    angle->addTerm(new Bell("big", 5.000, 5.000, 8.000));
    engine->addInputVariable(angle);

    InputVariable* velocity = new InputVariable;
    velocity->setEnabled(true);
    velocity->setName("velocity");
    velocity->setRange(-5.000, 5.000);
    velocity->setLockValueInRange(false);
    velocity->addTerm(new Bell("small", -5.000, 5.000, 2.000));
    velocity->addTerm(new Bell("big", 5.000, 5.000, 2.000));
    engine->addInputVariable(velocity);

    OutputVariable* force = new OutputVariable;
    force->setEnabled(true);
    force->setName("force");
    force->setRange(-5.000, 5.000);
    force->setLockValueInRange(false);
    force->fuzzyOutput()->setAggregation(new Maximum);
    force->setDefuzzifier(new Centroid(200));
    force->setDefaultValue(fl::nan);
    force->setLockPreviousValue(false);
    force->addTerm(new Bell("negBig", -5.000, 1.670, 8.000));
    force->addTerm(new Bell("negSmall", -1.670, 1.670, 8.000));
    force->addTerm(new Bell("posSmall", 1.670, 1.670, 8.000));
    force->addTerm(new Bell("posBig", 5.000, 1.670, 8.000));
    engine->addOutputVariable(force);

    RuleBlock* ruleBlock = new RuleBlock;
    ruleBlock->setEnabled(true);
    ruleBlock->setName("");
    ruleBlock->setConjunction(new Minimum);
    ruleBlock->setDisjunction(new Maximum);
    ruleBlock->setImplication(new Minimum);
    ruleBlock->setActivation(new General);
    ruleBlock->addRule(fl::Rule::parse("if angle is small and velocity is small then force is negBig", engine));
    ruleBlock->addRule(fl::Rule::parse("if angle is small and velocity is big then force is negSmall", engine));
    ruleBlock->addRule(fl::Rule::parse("if angle is big and velocity is small then force is posSmall", engine));
    ruleBlock->addRule(fl::Rule::parse("if angle is big and velocity is big then force is posBig", engine));
    engine->addRuleBlock(ruleBlock);


}
Esempio n. 4
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("anfis");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("in_n1");
inputVariable1->setRange(1.000, 31.000);
inputVariable1->setLockValueInRange(false);
inputVariable1->addTerm(new Bell("in1mf1", 2.253, 16.220, 5.050));
inputVariable1->addTerm(new Bell("in1mf2", 31.260, 15.021, 1.843));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("in_n2");
inputVariable2->setRange(1.000, 31.000);
inputVariable2->setLockValueInRange(false);
inputVariable2->addTerm(new Bell("in2mf1", 0.740, 15.021, 1.843));
inputVariable2->addTerm(new Bell("in2mf2", 29.747, 16.220, 5.050));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("out1");
outputVariable->setRange(-0.334, 1.000);
outputVariable->setLockValueInRange(false);
outputVariable->fuzzyOutput()->setAccumulation(fl::null);
outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousValue(false);
outputVariable->addTerm(Linear::create("out1mf1", engine, 0.026, 0.071, -0.615));
outputVariable->addTerm(Linear::create("out1mf2", engine, -0.036, 0.036, -1.169));
outputVariable->addTerm(Linear::create("out1mf3", engine, -0.094, 0.094, 2.231));
outputVariable->addTerm(Linear::create("out1mf4", engine, -0.071, -0.026, 2.479));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new AlgebraicProduct);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf1 and in_n2 is in2mf1 then out1 is out1mf1", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf1 and in_n2 is in2mf2 then out1 is out1mf2", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf2 and in_n2 is in2mf1 then out1 is out1mf3", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf2 and in_n2 is in2mf2 then out1 is out1mf4", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 5
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("tipper");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("service");
inputVariable1->setRange(0.000, 10.000);
inputVariable1->setLockValueInRange(false);
inputVariable1->addTerm(new Gaussian("poor", 0.000, 1.500));
inputVariable1->addTerm(new Gaussian("good", 5.000, 1.500));
inputVariable1->addTerm(new Gaussian("excellent", 10.000, 1.500));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("food");
inputVariable2->setRange(0.000, 10.000);
inputVariable2->setLockValueInRange(false);
inputVariable2->addTerm(new Trapezoid("rancid", 0.000, 0.000, 1.000, 3.000));
inputVariable2->addTerm(new Trapezoid("delicious", 7.000, 9.000, 10.000, 10.000));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("tip");
outputVariable->setRange(0.000, 30.000);
outputVariable->setLockValueInRange(false);
outputVariable->fuzzyOutput()->setAccumulation(new Maximum);
outputVariable->setDefuzzifier(new Centroid(200));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousValue(false);
outputVariable->addTerm(new Triangle("cheap", 0.000, 5.000, 10.000));
outputVariable->addTerm(new Triangle("average", 10.000, 15.000, 20.000));
outputVariable->addTerm(new Triangle("generous", 20.000, 25.000, 30.000));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setImplication(new Minimum);
ruleBlock->addRule(fl::Rule::parse("if service is poor or food is rancid then tip is cheap", engine));
ruleBlock->addRule(fl::Rule::parse("if service is good then tip is average", engine));
ruleBlock->addRule(fl::Rule::parse("if service is excellent or food is delicious then tip is generous", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 6
0
 void FllImporter::processRuleBlock(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     RuleBlock* ruleBlock = new RuleBlock;
     engine->addRuleBlock(ruleBlock);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("RuleBlock" == keyValue.first) {
             ruleBlock->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             ruleBlock->setEnabled(parseBoolean(keyValue.second));
         } else if ("conjunction" == keyValue.first) {
             ruleBlock->setConjunction(parseTNorm(keyValue.second));
         } else if ("disjunction" == keyValue.first) {
             ruleBlock->setDisjunction(parseSNorm(keyValue.second));
         } else if ("activation" == keyValue.first) {
             ruleBlock->setActivation(parseTNorm(keyValue.second));
         } else if ("rule" == keyValue.first) {
             ruleBlock->addRule(fl::Rule::parse(keyValue.second, engine));
         } else {
             throw fl::Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
 }
Esempio n. 7
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("simple-dimmer");

InputVariable* inputVariable = new InputVariable;
inputVariable->setEnabled(true);
inputVariable->setName("Ambient");
inputVariable->setRange(0.000, 1.000);
inputVariable->addTerm(new Triangle("DARK", 0.000, 0.250, 0.500));
inputVariable->addTerm(new Triangle("MEDIUM", 0.250, 0.500, 0.750));
inputVariable->addTerm(new Triangle("BRIGHT", 0.500, 0.750, 1.000));
engine->addInputVariable(inputVariable);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("Power");
outputVariable->setRange(0.000, 1.000);
outputVariable->fuzzyOutput()->setAccumulation(fl::null);
outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousOutputValue(false);
outputVariable->setLockOutputValueInRange(false);
outputVariable->addTerm(new Constant("LOW", 0.250));
outputVariable->addTerm(new Constant("MEDIUM", 0.500));
outputVariable->addTerm(new Constant("HIGH", 0.750));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(fl::null);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setActivation(fl::null);
ruleBlock->addRule(fl::Rule::parse("if Ambient is DARK then Power is HIGH", engine));
ruleBlock->addRule(fl::Rule::parse("if Ambient is MEDIUM then Power is MEDIUM", engine));
ruleBlock->addRule(fl::Rule::parse("if Ambient is BRIGHT then Power is LOW", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 8
0
int main(int argc, char** argv){
//Code automatically generated with jfuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("tank2");
engine->setDescription("");

InputVariable* level = new InputVariable;
level->setName("level");
level->setDescription("");
level->setEnabled(true);
level->setRange(-1.000, 1.000);
level->setLockValueInRange(false);
level->addTerm(new Trapezoid("high", -2.000, -1.000, -0.800, -0.001));
level->addTerm(new Triangle("good", -0.150, 0.000, 0.500));
level->addTerm(new Trapezoid("low", 0.001, 0.800, 1.000, 1.500));
engine->addInputVariable(level);

InputVariable* change = new InputVariable;
change->setName("change");
change->setDescription("");
change->setEnabled(true);
change->setRange(-0.100, 0.100);
change->setLockValueInRange(false);
change->addTerm(new Trapezoid("falling", -0.140, -0.100, -0.060, 0.000));
change->addTerm(new Trapezoid("rising", -0.001, 0.060, 0.100, 0.140));
engine->addInputVariable(change);

OutputVariable* valve = new OutputVariable;
valve->setName("valve");
valve->setDescription("");
valve->setEnabled(true);
valve->setRange(-1.000, 1.000);
valve->setLockValueInRange(false);
valve->setAggregation(new Maximum);
valve->setDefuzzifier(new Centroid(200));
valve->setDefaultValue(fl::nan);
valve->setLockPreviousValue(false);
valve->addTerm(new Triangle("close_fast", -1.000, -0.900, -0.800));
valve->addTerm(new Triangle("close_slow", -0.600, -0.500, -0.400));
valve->addTerm(new Triangle("no_change", -0.100, 0.000, 0.100));
valve->addTerm(new Triangle("open_slow", 0.400, 0.500, 0.600));
valve->addTerm(new Triangle("open_fast", 0.800, 0.900, 1.000));
engine->addOutputVariable(valve);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setName("");
ruleBlock->setDescription("");
ruleBlock->setEnabled(true);
ruleBlock->setConjunction(new AlgebraicProduct);
ruleBlock->setDisjunction(new AlgebraicSum);
ruleBlock->setImplication(new AlgebraicProduct);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if level is low then valve is open_fast", engine));
ruleBlock->addRule(Rule::parse("if level is high then valve is close_fast", engine));
ruleBlock->addRule(Rule::parse("if level is good and change is rising then valve is close_slow", engine));
ruleBlock->addRule(Rule::parse("if level is good and change is falling then valve is open_slow", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 9
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("slcp1");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("in1");
inputVariable1->setRange(-0.300, 0.300);
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("in2");
inputVariable2->setRange(-1.000, 1.000);
engine->addInputVariable(inputVariable2);

InputVariable* inputVariable3 = new InputVariable;
inputVariable3->setEnabled(true);
inputVariable3->setName("in3");
inputVariable3->setRange(-3.000, 3.000);
engine->addInputVariable(inputVariable3);

InputVariable* inputVariable4 = new InputVariable;
inputVariable4->setEnabled(true);
inputVariable4->setName("in4");
inputVariable4->setRange(-3.000, 3.000);
engine->addInputVariable(inputVariable4);

InputVariable* inputVariable5 = new InputVariable;
inputVariable5->setEnabled(true);
inputVariable5->setName("in5");
inputVariable5->setRange(0.500, 1.500);
inputVariable5->addTerm(new Gaussian("small", 0.500, 0.200));
inputVariable5->addTerm(new Gaussian("medium", 1.000, 0.200));
inputVariable5->addTerm(new Gaussian("large", 1.500, 0.200));
engine->addInputVariable(inputVariable5);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("out");
outputVariable->setRange(-10.000, 10.000);
outputVariable->fuzzyOutput()->setAccumulation(fl::null);
outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousOutputValue(false);
outputVariable->setLockOutputValueInRange(false);
outputVariable->addTerm(Linear::create("outmf1", engine, 32.166, 5.835, 3.162, 3.757, 0.000, 0.000));
outputVariable->addTerm(Linear::create("outmf2", engine, 39.012, 9.947, 3.162, 4.269, 0.000, 0.000));
outputVariable->addTerm(Linear::create("outmf3", engine, 45.009, 13.985, 3.162, 4.666, 0.000, 0.000));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(fl::null);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setActivation(fl::null);
ruleBlock->addRule(fl::Rule::parse("if in5 is small then out is outmf1", engine));
ruleBlock->addRule(fl::Rule::parse("if in5 is medium then out is outmf2", engine));
ruleBlock->addRule(fl::Rule::parse("if in5 is large then out is outmf3", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 10
0
    void Test::SimplePendulum() {
        FuzzyOperator& op = FuzzyOperator::DefaultFuzzyOperator();
        FuzzyEngine engine("pendulum-3d",op);

        InputLVar* anglex = new InputLVar("AngleX");
        std::vector<std::string> labels;
        labels.push_back("NEAR_0");
        labels.push_back("NEAR_45");
        labels.push_back("NEAR_90");
        labels.push_back("NEAR_135");
        labels.push_back("NEAR_180");
        anglex->createTerms(5, LinguisticTerm::MF_SHOULDER, 0, 180, labels);
        engine.addInputLVar(anglex);

        InputLVar* anglez = new InputLVar("AngleZ");
        labels.clear();
        labels.push_back("NEAR_0");
        labels.push_back("NEAR_45");
        labels.push_back("NEAR_90");
        labels.push_back("NEAR_135");
        labels.push_back("NEAR_180");
        anglez->createTerms(5, LinguisticTerm::MF_SHOULDER, 0, 180, labels);
        engine.addInputLVar(anglez);

        OutputLVar* forcex = new OutputLVar("ForceX");
        labels.clear();
        labels.push_back("NL");
        labels.push_back("NS");
        labels.push_back("ZR");
        labels.push_back("PS");
        labels.push_back("PL");
        forcex->createTerms(5, LinguisticTerm::MF_TRIANGULAR, -1, 1, labels);
        engine.addOutputLVar(forcex);

        OutputLVar* forcez = new OutputLVar("ForceZ");
        labels.clear();
        labels.push_back("NL");
        labels.push_back("NS");
        labels.push_back("ZR");
        labels.push_back("PS");
        labels.push_back("PL");
        forcez->createTerms(5, LinguisticTerm::MF_TRIANGULAR, -1, 1, labels);
        engine.addOutputLVar(forcez);

        RuleBlock* ruleblock = new RuleBlock("Rules");
        ruleblock->addRule(new MamdaniRule("if AngleX is NEAR_180 then ForceX is NL", engine));
        ruleblock->addRule(new MamdaniRule("if AngleX is NEAR_135 then ForceX is NS", engine));
        ruleblock->addRule(new MamdaniRule("if AngleX is NEAR_90 then ForceX is ZR", engine));
        ruleblock->addRule(new MamdaniRule("if AngleX is NEAR_45 then ForceX is PS", engine));
        ruleblock->addRule(new MamdaniRule("if AngleX is NEAR_0 then ForceX is PL", engine));

        ruleblock->addRule(new MamdaniRule("if AngleZ is NEAR_180 then ForceZ is NL", engine));
        ruleblock->addRule(new MamdaniRule("if AngleZ is NEAR_135 then ForceZ is NS", engine));
        ruleblock->addRule(new MamdaniRule("if AngleZ is NEAR_90 then ForceZ is ZR", engine));
        ruleblock->addRule(new MamdaniRule("if AngleZ is NEAR_45 then ForceZ is PS", engine));
        ruleblock->addRule(new MamdaniRule("if AngleZ is NEAR_0 then ForceZ is PL", engine));
        engine.addRuleBlock(ruleblock);

        FL_LOG(engine.toString());
        for (int i = 0; i < 180; i += 20) {
            engine.setInput("AngleX", i);
            engine.process();
            FL_LOG("angle=" << i << "\tforce=" << engine.output("ForceX"));
        }
    }
Esempio n. 11
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("shower");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("temp");
inputVariable1->setRange(-20.000, 20.000);
inputVariable1->addTerm(new Trapezoid("cold", -30.000, -30.000, -15.000, 0.000));
inputVariable1->addTerm(new Triangle("good", -10.000, 0.000, 10.000));
inputVariable1->addTerm(new Trapezoid("hot", 0.000, 15.000, 30.000, 30.000));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("flow");
inputVariable2->setRange(-1.000, 1.000);
inputVariable2->addTerm(new Trapezoid("soft", -3.000, -3.000, -0.800, 0.000));
inputVariable2->addTerm(new Triangle("good", -0.400, 0.000, 0.400));
inputVariable2->addTerm(new Trapezoid("hard", 0.000, 0.800, 3.000, 3.000));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable1 = new OutputVariable;
outputVariable1->setEnabled(true);
outputVariable1->setName("cold");
outputVariable1->setRange(-1.000, 1.000);
outputVariable1->fuzzyOutput()->setAccumulation(new Maximum);
outputVariable1->setDefuzzifier(new Centroid(200));
outputVariable1->setDefaultValue(fl::nan);
outputVariable1->setLockPreviousOutputValue(false);
outputVariable1->setLockOutputValueInRange(false);
outputVariable1->addTerm(new Triangle("closeFast", -1.000, -0.600, -0.300));
outputVariable1->addTerm(new Triangle("closeSlow", -0.600, -0.300, 0.000));
outputVariable1->addTerm(new Triangle("steady", -0.300, 0.000, 0.300));
outputVariable1->addTerm(new Triangle("openSlow", 0.000, 0.300, 0.600));
outputVariable1->addTerm(new Triangle("openFast", 0.300, 0.600, 1.000));
engine->addOutputVariable(outputVariable1);

OutputVariable* outputVariable2 = new OutputVariable;
outputVariable2->setEnabled(true);
outputVariable2->setName("hot");
outputVariable2->setRange(-1.000, 1.000);
outputVariable2->fuzzyOutput()->setAccumulation(new Maximum);
outputVariable2->setDefuzzifier(new Centroid(200));
outputVariable2->setDefaultValue(fl::nan);
outputVariable2->setLockPreviousOutputValue(false);
outputVariable2->setLockOutputValueInRange(false);
outputVariable2->addTerm(new Triangle("closeFast", -1.000, -0.600, -0.300));
outputVariable2->addTerm(new Triangle("closeSlow", -0.600, -0.300, 0.000));
outputVariable2->addTerm(new Triangle("steady", -0.300, 0.000, 0.300));
outputVariable2->addTerm(new Triangle("openSlow", 0.000, 0.300, 0.600));
outputVariable2->addTerm(new Triangle("openFast", 0.300, 0.600, 1.000));
engine->addOutputVariable(outputVariable2);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setActivation(new Minimum);
ruleBlock->addRule(fl::Rule::parse("if temp is cold and flow is soft then cold is openSlow and hot is openFast", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is cold and flow is good then cold is closeSlow and hot is openSlow", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is cold and flow is hard then cold is closeFast and hot is closeSlow", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is good and flow is soft then cold is openSlow and hot is openSlow", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is good and flow is good then cold is steady and hot is steady", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is good and flow is hard then cold is closeSlow and hot is closeSlow", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is hot and flow is soft then cold is openFast and hot is openSlow", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is hot and flow is good then cold is openSlow and hot is closeSlow", engine));
ruleBlock->addRule(fl::Rule::parse("if temp is hot and flow is hard then cold is closeSlow and hot is closeFast", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 12
0
int main(int argc, char** argv){
//C++ code generated with fuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("slcpp1");

InputVariable* in1 = new InputVariable;
in1->setEnabled(true);
in1->setName("in1");
in1->setRange(-0.300, 0.300);
in1->setLockValueInRange(false);
engine->addInputVariable(in1);

InputVariable* in2 = new InputVariable;
in2->setEnabled(true);
in2->setName("in2");
in2->setRange(-1.000, 1.000);
in2->setLockValueInRange(false);
engine->addInputVariable(in2);

InputVariable* in3 = new InputVariable;
in3->setEnabled(true);
in3->setName("in3");
in3->setRange(-3.000, 3.000);
in3->setLockValueInRange(false);
engine->addInputVariable(in3);

InputVariable* in4 = new InputVariable;
in4->setEnabled(true);
in4->setName("in4");
in4->setRange(-3.000, 3.000);
in4->setLockValueInRange(false);
engine->addInputVariable(in4);

InputVariable* in5 = new InputVariable;
in5->setEnabled(true);
in5->setName("in5");
in5->setRange(-3.000, 3.000);
in5->setLockValueInRange(false);
engine->addInputVariable(in5);

InputVariable* in6 = new InputVariable;
in6->setEnabled(true);
in6->setName("in6");
in6->setRange(-3.000, 3.000);
in6->setLockValueInRange(false);
engine->addInputVariable(in6);

InputVariable* pole_length = new InputVariable;
pole_length->setEnabled(true);
pole_length->setName("pole_length");
pole_length->setRange(0.500, 1.500);
pole_length->setLockValueInRange(false);
pole_length->addTerm(new ZShape("mf1", 0.500, 0.600));
pole_length->addTerm(new PiShape("mf2", 0.500, 0.600, 0.600, 0.700));
pole_length->addTerm(new PiShape("mf3", 0.600, 0.700, 0.700, 0.800));
pole_length->addTerm(new PiShape("mf4", 0.700, 0.800, 0.800, 0.900));
pole_length->addTerm(new PiShape("mf5", 0.800, 0.900, 0.900, 1.000));
pole_length->addTerm(new PiShape("mf6", 0.900, 1.000, 1.000, 1.100));
pole_length->addTerm(new PiShape("mf7", 1.000, 1.100, 1.100, 1.200));
pole_length->addTerm(new PiShape("mf8", 1.100, 1.200, 1.200, 1.300));
pole_length->addTerm(new PiShape("mf9", 1.200, 1.300, 1.300, 1.400));
pole_length->addTerm(new PiShape("mf10", 1.300, 1.400, 1.400, 1.500));
pole_length->addTerm(new SShape("mf11", 1.400, 1.500));
engine->addInputVariable(pole_length);

OutputVariable* out = new OutputVariable;
out->setEnabled(true);
out->setName("out");
out->setRange(-10.000, 10.000);
out->setLockValueInRange(false);
out->fuzzyOutput()->setAggregation(fl::null);
out->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
out->setDefaultValue(fl::nan);
out->setLockPreviousValue(false);
out->addTerm(Linear::create("outmf1", engine, 168.400, 31.000, -188.050, -49.250, -1.000, -2.700, 0.000, 0.000));
out->addTerm(Linear::create("outmf2", engine, 233.950, 47.190, -254.520, -66.580, -1.000, -2.740, 0.000, 0.000));
out->addTerm(Linear::create("outmf3", engine, 342.940, 74.730, -364.370, -95.230, -1.000, -2.780, 0.000, 0.000));
out->addTerm(Linear::create("outmf4", engine, 560.710, 130.670, -582.960, -152.240, -1.000, -2.810, 0.000, 0.000));
out->addTerm(Linear::create("outmf5", engine, 1213.880, 300.190, -1236.900, -322.800, -1.000, -2.840, 0.000, 0.000));
out->addTerm(Linear::create("outmf6", engine, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000));
out->addTerm(Linear::create("outmf7", engine, -1399.120, -382.950, 1374.630, 358.340, -1.000, -2.900, 0.000, 0.000));
out->addTerm(Linear::create("outmf8", engine, -746.070, -213.420, 720.900, 187.840, -1.000, -2.930, 0.000, 0.000));
out->addTerm(Linear::create("outmf9", engine, -528.520, -157.460, 502.680, 130.920, -1.000, -2.960, 0.000, 0.000));
out->addTerm(Linear::create("outmf10", engine, -419.870, -129.890, 393.380, 102.410, -1.000, -2.980, 0.000, 0.000));
out->addTerm(Linear::create("outmf11", engine, -354.770, -113.680, 327.650, 85.270, -1.000, -3.010, 0.000, 0.000));
engine->addOutputVariable(out);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(fl::null);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if pole_length is mf1 then out is outmf1", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf2 then out is outmf2", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf3 then out is outmf3", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf4 then out is outmf4", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf5 then out is outmf5", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf6 then out is outmf6", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf7 then out is outmf7", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf8 then out is outmf8", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf9 then out is outmf9", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf10 then out is outmf10", engine));
ruleBlock->addRule(Rule::parse("if pole_length is mf11 then out is outmf11", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 13
0
int main(int argc, char** argv){
//Code automatically generated with jfuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("shower");
engine->setDescription("");

InputVariable* temp = new InputVariable;
temp->setName("temp");
temp->setDescription("");
temp->setEnabled(true);
temp->setRange(-20.000, 20.000);
temp->setLockValueInRange(false);
temp->addTerm(new Trapezoid("cold", -30.000, -30.000, -15.000, 0.000));
temp->addTerm(new Triangle("good", -10.000, 0.000, 10.000));
temp->addTerm(new Trapezoid("hot", 0.000, 15.000, 30.000, 30.000));
engine->addInputVariable(temp);

InputVariable* flow = new InputVariable;
flow->setName("flow");
flow->setDescription("");
flow->setEnabled(true);
flow->setRange(-1.000, 1.000);
flow->setLockValueInRange(false);
flow->addTerm(new Trapezoid("soft", -3.000, -3.000, -0.800, 0.000));
flow->addTerm(new Triangle("good", -0.400, 0.000, 0.400));
flow->addTerm(new Trapezoid("hard", 0.000, 0.800, 3.000, 3.000));
engine->addInputVariable(flow);

OutputVariable* cold = new OutputVariable;
cold->setName("cold");
cold->setDescription("");
cold->setEnabled(true);
cold->setRange(-1.000, 1.000);
cold->setLockValueInRange(false);
cold->setAggregation(new Maximum);
cold->setDefuzzifier(new Centroid(200));
cold->setDefaultValue(fl::nan);
cold->setLockPreviousValue(false);
cold->addTerm(new Triangle("closeFast", -1.000, -0.600, -0.300));
cold->addTerm(new Triangle("closeSlow", -0.600, -0.300, 0.000));
cold->addTerm(new Triangle("steady", -0.300, 0.000, 0.300));
cold->addTerm(new Triangle("openSlow", 0.000, 0.300, 0.600));
cold->addTerm(new Triangle("openFast", 0.300, 0.600, 1.000));
engine->addOutputVariable(cold);

OutputVariable* hot = new OutputVariable;
hot->setName("hot");
hot->setDescription("");
hot->setEnabled(true);
hot->setRange(-1.000, 1.000);
hot->setLockValueInRange(false);
hot->setAggregation(new Maximum);
hot->setDefuzzifier(new Centroid(200));
hot->setDefaultValue(fl::nan);
hot->setLockPreviousValue(false);
hot->addTerm(new Triangle("closeFast", -1.000, -0.600, -0.300));
hot->addTerm(new Triangle("closeSlow", -0.600, -0.300, 0.000));
hot->addTerm(new Triangle("steady", -0.300, 0.000, 0.300));
hot->addTerm(new Triangle("openSlow", 0.000, 0.300, 0.600));
hot->addTerm(new Triangle("openFast", 0.300, 0.600, 1.000));
engine->addOutputVariable(hot);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setName("");
ruleBlock->setDescription("");
ruleBlock->setEnabled(true);
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setImplication(new Minimum);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if temp is cold and flow is soft then cold is openSlow and hot is openFast", engine));
ruleBlock->addRule(Rule::parse("if temp is cold and flow is good then cold is closeSlow and hot is openSlow", engine));
ruleBlock->addRule(Rule::parse("if temp is cold and flow is hard then cold is closeFast and hot is closeSlow", engine));
ruleBlock->addRule(Rule::parse("if temp is good and flow is soft then cold is openSlow and hot is openSlow", engine));
ruleBlock->addRule(Rule::parse("if temp is good and flow is good then cold is steady and hot is steady", engine));
ruleBlock->addRule(Rule::parse("if temp is good and flow is hard then cold is closeSlow and hot is closeSlow", engine));
ruleBlock->addRule(Rule::parse("if temp is hot and flow is soft then cold is openFast and hot is openSlow", engine));
ruleBlock->addRule(Rule::parse("if temp is hot and flow is good then cold is openSlow and hot is closeSlow", engine));
ruleBlock->addRule(Rule::parse("if temp is hot and flow is hard then cold is closeSlow and hot is closeFast", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 14
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("anfis");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("in_n1");
inputVariable1->setRange(1.000, 31.000);
inputVariable1->setLockValueInRange(false);
inputVariable1->addTerm(new Bell("in1mf1", 1.152, 8.206, 0.874));
inputVariable1->addTerm(new Bell("in1mf2", 15.882, 7.078, 0.444));
inputVariable1->addTerm(new Bell("in1mf3", 30.575, 8.602, 0.818));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("in_n2");
inputVariable2->setRange(1.000, 31.000);
inputVariable2->setLockValueInRange(false);
inputVariable2->addTerm(new Bell("in2mf1", 1.426, 8.602, 0.818));
inputVariable2->addTerm(new Bell("in2mf2", 16.118, 7.078, 0.445));
inputVariable2->addTerm(new Bell("in2mf3", 30.847, 8.206, 0.875));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("out1");
outputVariable->setRange(-0.334, 1.000);
outputVariable->setLockValueInRange(false);
outputVariable->fuzzyOutput()->setAccumulation(fl::null);
outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousValue(false);
outputVariable->addTerm(Linear::create("out1mf1", engine, -0.035, 0.002, -0.352));
outputVariable->addTerm(Linear::create("out1mf2", engine, 0.044, 0.079, -0.028));
outputVariable->addTerm(Linear::create("out1mf3", engine, -0.024, 0.024, -1.599));
outputVariable->addTerm(Linear::create("out1mf4", engine, -0.067, 0.384, 0.007));
outputVariable->addTerm(Linear::create("out1mf5", engine, 0.351, -0.351, -3.663));
outputVariable->addTerm(Linear::create("out1mf6", engine, -0.079, -0.044, 3.909));
outputVariable->addTerm(Linear::create("out1mf7", engine, 0.012, -0.012, -0.600));
outputVariable->addTerm(Linear::create("out1mf8", engine, -0.384, 0.067, 10.158));
outputVariable->addTerm(Linear::create("out1mf9", engine, -0.002, 0.035, -1.402));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new AlgebraicProduct);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf1 and in_n2 is in2mf1 then out1 is out1mf1", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf1 and in_n2 is in2mf2 then out1 is out1mf2", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf1 and in_n2 is in2mf3 then out1 is out1mf3", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf2 and in_n2 is in2mf1 then out1 is out1mf4", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf2 and in_n2 is in2mf2 then out1 is out1mf5", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf2 and in_n2 is in2mf3 then out1 is out1mf6", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf3 and in_n2 is in2mf1 then out1 is out1mf7", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf3 and in_n2 is in2mf2 then out1 is out1mf8", engine));
ruleBlock->addRule(fl::Rule::parse("if in_n1 is in1mf3 and in_n2 is in2mf3 then out1 is out1mf9", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 15
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("peaks");

InputVariable* in1 = new InputVariable;
in1->setEnabled(true);
in1->setName("in1");
in1->setRange(-3.000, 3.000);
in1->setLockValueInRange(false);
in1->addTerm(new Bell("in1mf1", -2.233, 1.578, 2.151));
in1->addTerm(new Bell("in1mf2", -0.394, 0.753, 1.838));
in1->addTerm(new Bell("in1mf3", 0.497, 0.689, 1.844));
in1->addTerm(new Bell("in1mf4", 2.270, 1.528, 2.156));
engine->addInputVariable(in1);

InputVariable* in2 = new InputVariable;
in2->setEnabled(true);
in2->setName("in2");
in2->setRange(-3.000, 3.000);
in2->setLockValueInRange(false);
in2->addTerm(new Bell("in1mf1", -2.686, 1.267, 2.044));
in2->addTerm(new Bell("in1mf2", -0.836, 1.266, 1.796));
in2->addTerm(new Bell("in1mf3", 0.859, 1.314, 1.937));
in2->addTerm(new Bell("in1mf4", 2.727, 1.214, 2.047));
engine->addInputVariable(in2);

OutputVariable* out1 = new OutputVariable;
out1->setEnabled(true);
out1->setName("out1");
out1->setRange(-10.000, 10.000);
out1->setLockValueInRange(false);
out1->fuzzyOutput()->setAggregation(fl::null);
out1->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
out1->setDefaultValue(fl::nan);
out1->setLockPreviousValue(false);
out1->addTerm(Linear::create("out1mf1", engine, 0.155, -2.228, -8.974));
out1->addTerm(Linear::create("out1mf2", engine, -0.312, -7.705, -9.055));
out1->addTerm(Linear::create("out1mf3", engine, -0.454, -4.437, 6.930));
out1->addTerm(Linear::create("out1mf4", engine, 0.248, -1.122, 5.081));
out1->addTerm(Linear::create("out1mf5", engine, -6.278, 25.211, 99.148));
out1->addTerm(Linear::create("out1mf6", engine, 5.531, 105.916, 157.283));
out1->addTerm(Linear::create("out1mf7", engine, 19.519, 112.333, -127.796));
out1->addTerm(Linear::create("out1mf8", engine, -5.079, 34.738, -143.414));
out1->addTerm(Linear::create("out1mf9", engine, -5.889, 27.311, 116.585));
out1->addTerm(Linear::create("out1mf10", engine, 21.517, 97.266, 93.802));
out1->addTerm(Linear::create("out1mf11", engine, 9.198, 79.853, -118.482));
out1->addTerm(Linear::create("out1mf12", engine, -6.571, 23.026, -87.747));
out1->addTerm(Linear::create("out1mf13", engine, 0.092, -1.126, -4.527));
out1->addTerm(Linear::create("out1mf14", engine, -0.304, -4.434, -6.561));
out1->addTerm(Linear::create("out1mf15", engine, -0.166, -6.284, 7.307));
out1->addTerm(Linear::create("out1mf16", engine, 0.107, -2.028, 8.159));
engine->addOutputVariable(out1);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new AlgebraicProduct);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->setActivation(new General);
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in1mf1 then out1 is out1mf1", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in1mf2 then out1 is out1mf2", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in1mf3 then out1 is out1mf3", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in1mf4 then out1 is out1mf4", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in1mf1 then out1 is out1mf5", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in1mf2 then out1 is out1mf6", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in1mf3 then out1 is out1mf7", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in1mf4 then out1 is out1mf8", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf3 and in2 is in1mf1 then out1 is out1mf9", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf3 and in2 is in1mf2 then out1 is out1mf10", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf3 and in2 is in1mf3 then out1 is out1mf11", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf3 and in2 is in1mf4 then out1 is out1mf12", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf4 and in2 is in1mf1 then out1 is out1mf13", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf4 and in2 is in1mf2 then out1 is out1mf14", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf4 and in2 is in1mf3 then out1 is out1mf15", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf4 and in2 is in1mf4 then out1 is out1mf16", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 16
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("Sugeno-Tip-Calculator");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("FoodQuality");
inputVariable1->setRange(1.000, 10.000);
inputVariable1->addTerm(new Trapezoid("Bad", 0.000, 1.000, 3.000, 7.000));
inputVariable1->addTerm(new Trapezoid("Good", 3.000, 7.000, 10.000, 11.000));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("Service");
inputVariable2->setRange(1.000, 10.000);
inputVariable2->addTerm(new Trapezoid("Bad", 0.000, 1.000, 3.000, 7.000));
inputVariable2->addTerm(new Trapezoid("Good", 3.000, 7.000, 10.000, 11.000));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable1 = new OutputVariable;
outputVariable1->setEnabled(true);
outputVariable1->setName("CheapTip");
outputVariable1->setRange(5.000, 25.000);
outputVariable1->fuzzyOutput()->setAccumulation(fl::null);
outputVariable1->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable1->setDefaultValue(fl::nan);
outputVariable1->setLockPreviousOutputValue(false);
outputVariable1->setLockOutputValueInRange(false);
outputVariable1->addTerm(new Constant("Low", 10.000));
outputVariable1->addTerm(new Constant("Medium", 15.000));
outputVariable1->addTerm(new Constant("High", 20.000));
engine->addOutputVariable(outputVariable1);

OutputVariable* outputVariable2 = new OutputVariable;
outputVariable2->setEnabled(true);
outputVariable2->setName("AverageTip");
outputVariable2->setRange(5.000, 25.000);
outputVariable2->fuzzyOutput()->setAccumulation(fl::null);
outputVariable2->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable2->setDefaultValue(fl::nan);
outputVariable2->setLockPreviousOutputValue(false);
outputVariable2->setLockOutputValueInRange(false);
outputVariable2->addTerm(new Constant("Low", 10.000));
outputVariable2->addTerm(new Constant("Medium", 15.000));
outputVariable2->addTerm(new Constant("High", 20.000));
engine->addOutputVariable(outputVariable2);

OutputVariable* outputVariable3 = new OutputVariable;
outputVariable3->setEnabled(true);
outputVariable3->setName("GenerousTip");
outputVariable3->setRange(5.000, 25.000);
outputVariable3->fuzzyOutput()->setAccumulation(fl::null);
outputVariable3->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable3->setDefaultValue(fl::nan);
outputVariable3->setLockPreviousOutputValue(false);
outputVariable3->setLockOutputValueInRange(false);
outputVariable3->addTerm(new Constant("Low", 10.000));
outputVariable3->addTerm(new Constant("Medium", 15.000));
outputVariable3->addTerm(new Constant("High", 20.000));
engine->addOutputVariable(outputVariable3);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new EinsteinProduct);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setActivation(fl::null);
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is extremely Bad and Service is extremely Bad then CheapTip is extremely Low and AverageTip is very Low and GenerousTip is Low", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is Good and Service is extremely Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is very Good and Service is very Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is Bad and Service is Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is extremely Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is very High", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is Bad and Service is Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is Good and Service is Good then CheapTip is Medium and AverageTip is Medium and GenerousTip is very High", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is very Bad and Service is very Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine));
ruleBlock->addRule(fl::Rule::parse("if FoodQuality is very very Good and Service is very very Good then CheapTip is High and AverageTip is very High and GenerousTip is extremely High", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 17
0
int main(int argc, char** argv){
//Code automatically generated with jfuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("Laundry");
engine->setDescription("");

InputVariable* Load = new InputVariable;
Load->setName("Load");
Load->setDescription("");
Load->setEnabled(true);
Load->setRange(0.000, 6.000);
Load->setLockValueInRange(false);
Load->addTerm(Discrete::create("small", 8, 0.000, 1.000, 1.000, 1.000, 2.000, 0.800, 5.000, 0.000));
Load->addTerm(Discrete::create("normal", 6, 3.000, 0.000, 4.000, 1.000, 6.000, 0.000));
engine->addInputVariable(Load);

InputVariable* Dirt = new InputVariable;
Dirt->setName("Dirt");
Dirt->setDescription("");
Dirt->setEnabled(true);
Dirt->setRange(0.000, 6.000);
Dirt->setLockValueInRange(false);
Dirt->addTerm(Discrete::create("low", 6, 0.000, 1.000, 2.000, 0.800, 5.000, 0.000));
Dirt->addTerm(Discrete::create("high", 8, 1.000, 0.000, 2.000, 0.200, 4.000, 0.800, 6.000, 1.000));
engine->addInputVariable(Dirt);

OutputVariable* Detergent = new OutputVariable;
Detergent->setName("Detergent");
Detergent->setDescription("");
Detergent->setEnabled(true);
Detergent->setRange(0.000, 80.000);
Detergent->setLockValueInRange(false);
Detergent->setAggregation(new Maximum);
Detergent->setDefuzzifier(new MeanOfMaximum(500));
Detergent->setDefaultValue(fl::nan);
Detergent->setLockPreviousValue(false);
Detergent->addTerm(Discrete::create("less_than_usual", 6, 10.000, 0.000, 40.000, 1.000, 50.000, 0.000));
Detergent->addTerm(Discrete::create("usual", 8, 40.000, 0.000, 50.000, 1.000, 60.000, 1.000, 80.000, 0.000));
Detergent->addTerm(Discrete::create("more_than_usual", 4, 50.000, 0.000, 80.000, 1.000));
engine->addOutputVariable(Detergent);

OutputVariable* Cycle = new OutputVariable;
Cycle->setName("Cycle");
Cycle->setDescription("");
Cycle->setEnabled(true);
Cycle->setRange(0.000, 20.000);
Cycle->setLockValueInRange(false);
Cycle->setAggregation(new Maximum);
Cycle->setDefuzzifier(new MeanOfMaximum(500));
Cycle->setDefaultValue(fl::nan);
Cycle->setLockPreviousValue(false);
Cycle->addTerm(Discrete::create("short", 6, 0.000, 1.000, 10.000, 1.000, 20.000, 0.000));
Cycle->addTerm(Discrete::create("long", 4, 10.000, 0.000, 20.000, 1.000));
engine->addOutputVariable(Cycle);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setName("");
ruleBlock->setDescription("");
ruleBlock->setEnabled(true);
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setImplication(new Minimum);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if Load is small and Dirt is not high then Detergent is less_than_usual", engine));
ruleBlock->addRule(Rule::parse("if Load is small and Dirt is high then  Detergent is usual", engine));
ruleBlock->addRule(Rule::parse("if Load is normal and Dirt is low then Detergent is less_than_usual", engine));
ruleBlock->addRule(Rule::parse("if Load is normal and Dirt is high then Detergent is more_than_usual", engine));
ruleBlock->addRule(Rule::parse("if Detergent is usual  or Detergent is less_than_usual  then Cycle is short", engine));
ruleBlock->addRule(Rule::parse("if Detergent is more_than_usual  then Cycle is long", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 18
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("Laundry");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("Load");
inputVariable1->setRange(0.000, 6.000);
inputVariable1->addTerm(Discrete::create("small", 8, 0.000, 1.000, 1.000, 1.000, 2.000, 0.800, 5.000, 0.000));
inputVariable1->addTerm(Discrete::create("normal", 6, 3.000, 0.000, 4.000, 1.000, 6.000, 0.000));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("Dirt");
inputVariable2->setRange(0.000, 6.000);
inputVariable2->addTerm(Discrete::create("low", 6, 0.000, 1.000, 2.000, 0.800, 5.000, 0.000));
inputVariable2->addTerm(Discrete::create("high", 8, 1.000, 0.000, 2.000, 0.200, 4.000, 0.800, 6.000, 1.000));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable1 = new OutputVariable;
outputVariable1->setEnabled(true);
outputVariable1->setName("Detergent");
outputVariable1->setRange(0.000, 80.000);
outputVariable1->fuzzyOutput()->setAccumulation(new Maximum);
outputVariable1->setDefuzzifier(new MeanOfMaximum(500));
outputVariable1->setDefaultValue(fl::nan);
outputVariable1->setLockPreviousOutputValue(false);
outputVariable1->setLockOutputValueInRange(false);
outputVariable1->addTerm(Discrete::create("less", 6, 10.000, 0.000, 40.000, 1.000, 50.000, 0.000));
outputVariable1->addTerm(Discrete::create("normal", 8, 40.000, 0.000, 50.000, 1.000, 60.000, 1.000, 80.000, 0.000));
outputVariable1->addTerm(Discrete::create("more", 4, 50.000, 0.000, 80.000, 1.000));
engine->addOutputVariable(outputVariable1);

OutputVariable* outputVariable2 = new OutputVariable;
outputVariable2->setEnabled(true);
outputVariable2->setName("Cycle");
outputVariable2->setRange(0.000, 20.000);
outputVariable2->fuzzyOutput()->setAccumulation(new Maximum);
outputVariable2->setDefuzzifier(new MeanOfMaximum(500));
outputVariable2->setDefaultValue(fl::nan);
outputVariable2->setLockPreviousOutputValue(false);
outputVariable2->setLockOutputValueInRange(false);
outputVariable2->addTerm(Discrete::create("short", 6, 0.000, 1.000, 10.000, 1.000, 20.000, 0.000));
outputVariable2->addTerm(Discrete::create("long", 4, 10.000, 0.000, 20.000, 1.000));
engine->addOutputVariable(outputVariable2);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setActivation(new Minimum);
ruleBlock->addRule(fl::Rule::parse("if Load is small and Dirt is not high then Detergent is less", engine));
ruleBlock->addRule(fl::Rule::parse("if Load is small and Dirt is high then  Detergent is normal", engine));
ruleBlock->addRule(fl::Rule::parse("if Load is normal and Dirt is low then Detergent is less", engine));
ruleBlock->addRule(fl::Rule::parse("if Load is normal and Dirt is high then Detergent is more", engine));
ruleBlock->addRule(fl::Rule::parse("if Detergent is normal or Detergent is less then Cycle is short", engine));
ruleBlock->addRule(fl::Rule::parse("if Detergent is more then Cycle is long", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 19
0
int main(int argc, char** argv) {
    using namespace fl;

    Engine* engine = new Engine;
    engine->setName("Cubic-Approximator");

    InputVariable* inputVariable = new InputVariable;
    inputVariable->setEnabled(true);
    inputVariable->setName("X");
    inputVariable->setRange(-5.000, 5.000);
    inputVariable->addTerm(new Triangle("AboutNegFive", -6.000, -5.000, -4.000));
    inputVariable->addTerm(new Triangle("AboutNegFour", -5.000, -4.000, -3.000));
    inputVariable->addTerm(new Triangle("AboutNegThree", -4.000, -3.000, -2.000));
    inputVariable->addTerm(new Triangle("AboutNegTwo", -3.000, -2.000, -1.000));
    inputVariable->addTerm(new Triangle("AboutNegOne", -2.000, -1.000, 0.000));
    inputVariable->addTerm(new Triangle("AboutZero", -1.000, 0.000, 1.000));
    inputVariable->addTerm(new Triangle("AboutOne", 0.000, 1.000, 2.000));
    inputVariable->addTerm(new Triangle("AboutTwo", 1.000, 2.000, 3.000));
    inputVariable->addTerm(new Triangle("AboutThree", 2.000, 3.000, 4.000));
    inputVariable->addTerm(new Triangle("AboutFour", 3.000, 4.000, 5.000));
    inputVariable->addTerm(new Triangle("AboutFive", 4.000, 5.000, 6.000));
    engine->addInputVariable(inputVariable);

    OutputVariable* outputVariable = new OutputVariable;
    outputVariable->setEnabled(true);
    outputVariable->setName("ApproxXCubed");
    outputVariable->setRange(-5.000, 5.000);
    outputVariable->fuzzyOutput()->setAccumulation(fl::null);
    outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
    outputVariable->setDefaultValue(fl::nan);
    outputVariable->setLockPreviousOutputValue(false);
    outputVariable->setLockOutputValueInRange(false);
    outputVariable->addTerm(Linear::create("TangentatNegFive", engine, 75.000, 250.000));
    outputVariable->addTerm(Linear::create("TangentatNegFour", engine, 48.000, 128.000));
    outputVariable->addTerm(Linear::create("TangentatNegThree", engine, 27.000, 54.000));
    outputVariable->addTerm(Linear::create("TangentatNegTwo", engine, 12.000, 16.000));
    outputVariable->addTerm(Linear::create("TangentatNegOne", engine, 3.000, 2.000));
    outputVariable->addTerm(Linear::create("TangentatZero", engine, 0.000, 0.000));
    outputVariable->addTerm(Linear::create("TangentatOne", engine, 3.000, -2.000));
    outputVariable->addTerm(Linear::create("TangentatTwo", engine, 12.000, -16.000));
    outputVariable->addTerm(Linear::create("TangentatThree", engine, 27.000, -54.000));
    outputVariable->addTerm(Linear::create("TangentatFour", engine, 48.000, -128.000));
    outputVariable->addTerm(Linear::create("TangentatFive", engine, 75.000, -250.000));
    engine->addOutputVariable(outputVariable);

    RuleBlock* ruleBlock = new RuleBlock;
    ruleBlock->setEnabled(true);
    ruleBlock->setName("");
    ruleBlock->setConjunction(fl::null);
    ruleBlock->setDisjunction(fl::null);
    ruleBlock->setActivation(fl::null);
    ruleBlock->addRule(fl::Rule::parse("if X is AboutNegFive then ApproxXCubed is TangentatNegFive", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutNegFour then ApproxXCubed is TangentatNegFour", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutNegThree then ApproxXCubed is TangentatNegThree", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutNegTwo then ApproxXCubed is TangentatNegTwo", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutNegOne then ApproxXCubed is TangentatNegOne", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutZero then ApproxXCubed is TangentatZero", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutOne then ApproxXCubed is TangentatOne", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutTwo then ApproxXCubed is TangentatTwo", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutThree then ApproxXCubed is TangentatThree", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutFour then ApproxXCubed is TangentatFour", engine));
    ruleBlock->addRule(fl::Rule::parse("if X is AboutFive then ApproxXCubed is TangentatFive", engine));
    engine->addRuleBlock(ruleBlock);


}
Esempio n. 20
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("qtfuzzylite");

InputVariable* inputVariable = new InputVariable;
inputVariable->setEnabled(true);
inputVariable->setName("AllInputTerms");
inputVariable->setRange(0.000, 6.500);
inputVariable->setLockValueInRange(false);
inputVariable->addTerm(new Sigmoid("A", 0.500, -20.000));
inputVariable->addTerm(new ZShape("B", 0.000, 1.000));
inputVariable->addTerm(new Ramp("C", 1.000, 0.000));
inputVariable->addTerm(new Triangle("D", 0.500, 1.000, 1.500));
inputVariable->addTerm(new Trapezoid("E", 1.000, 1.250, 1.750, 2.000));
inputVariable->addTerm(new Concave("F", 0.850, 0.250));
inputVariable->addTerm(new Rectangle("G", 1.750, 2.250));
inputVariable->addTerm(Discrete::create("H", 10, 2.000, 0.000, 2.250, 1.000, 2.500, 0.500, 2.750, 1.000, 3.000, 0.000));
inputVariable->addTerm(new Gaussian("I", 3.000, 0.200));
inputVariable->addTerm(new Cosine("J", 3.250, 0.650));
inputVariable->addTerm(new GaussianProduct("K", 3.500, 0.100, 3.300, 0.300));
inputVariable->addTerm(new Spike("L", 3.640, 1.040));
inputVariable->addTerm(new Bell("M", 4.000, 0.250, 3.000));
inputVariable->addTerm(new PiShape("N", 4.000, 4.500, 4.500, 5.000));
inputVariable->addTerm(new Concave("O", 5.650, 6.250));
inputVariable->addTerm(new SigmoidDifference("P", 4.750, 10.000, 30.000, 5.250));
inputVariable->addTerm(new SigmoidProduct("Q", 5.250, 20.000, -10.000, 5.750));
inputVariable->addTerm(new Ramp("R", 5.500, 6.500));
inputVariable->addTerm(new SShape("S", 5.500, 6.500));
inputVariable->addTerm(new Sigmoid("T", 6.000, 20.000));
engine->addInputVariable(inputVariable);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("AllOutputTerms");
outputVariable->setRange(0.000, 6.500);
outputVariable->setLockValueInRange(false);
outputVariable->fuzzyOutput()->setAccumulation(new Maximum);
outputVariable->setDefuzzifier(new Centroid(200));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousValue(false);
outputVariable->addTerm(new Sigmoid("A", 0.500, -20.000));
outputVariable->addTerm(new ZShape("B", 0.000, 1.000));
outputVariable->addTerm(new Ramp("C", 1.000, 0.000));
outputVariable->addTerm(new Triangle("D", 0.500, 1.000, 1.500));
outputVariable->addTerm(new Trapezoid("E", 1.000, 1.250, 1.750, 2.000));
outputVariable->addTerm(new Concave("F", 0.850, 0.250));
outputVariable->addTerm(new Rectangle("G", 1.750, 2.250));
outputVariable->addTerm(Discrete::create("H", 10, 2.000, 0.000, 2.250, 1.000, 2.500, 0.500, 2.750, 1.000, 3.000, 0.000));
outputVariable->addTerm(new Gaussian("I", 3.000, 0.200));
outputVariable->addTerm(new Cosine("J", 3.250, 0.650));
outputVariable->addTerm(new GaussianProduct("K", 3.500, 0.100, 3.300, 0.300));
outputVariable->addTerm(new Spike("L", 3.640, 1.040));
outputVariable->addTerm(new Bell("M", 4.000, 0.250, 3.000));
outputVariable->addTerm(new PiShape("N", 4.000, 4.500, 4.500, 5.000));
outputVariable->addTerm(new Concave("O", 5.650, 6.250));
outputVariable->addTerm(new SigmoidDifference("P", 4.750, 10.000, 30.000, 5.250));
outputVariable->addTerm(new SigmoidProduct("Q", 5.250, 20.000, -10.000, 5.750));
outputVariable->addTerm(new Ramp("R", 5.500, 6.500));
outputVariable->addTerm(new SShape("S", 5.500, 6.500));
outputVariable->addTerm(new Sigmoid("T", 6.000, 20.000));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(new Maximum);
ruleBlock->setImplication(new Minimum);
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is A then AllOutputTerms is T", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is B then AllOutputTerms is S", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is C then AllOutputTerms is R", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is D then AllOutputTerms is Q", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is E then AllOutputTerms is P", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is F then AllOutputTerms is O", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is G then AllOutputTerms is N", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is H then AllOutputTerms is M", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is I then AllOutputTerms is L", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is J then AllOutputTerms is K", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is K then AllOutputTerms is J", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is L then AllOutputTerms is I", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is M then AllOutputTerms is H", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is N then AllOutputTerms is G", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is O then AllOutputTerms is F", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is P then AllOutputTerms is E", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is Q then AllOutputTerms is D", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is R then AllOutputTerms is C", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is S then AllOutputTerms is B", engine));
ruleBlock->addRule(fl::Rule::parse("if AllInputTerms is T then AllOutputTerms is A", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 21
0
int main(int argc, char** argv){
//Code automatically generated with jfuzzylite 6.0.

using namespace fl;

Engine* engine = new Engine;
engine->setName("tsukamoto");
engine->setDescription("");

InputVariable* X = new InputVariable;
X->setName("X");
X->setDescription("");
X->setEnabled(true);
X->setRange(-10.000, 10.000);
X->setLockValueInRange(false);
X->addTerm(new Bell("small", -10.000, 5.000, 3.000));
X->addTerm(new Bell("medium", 0.000, 5.000, 3.000));
X->addTerm(new Bell("large", 10.000, 5.000, 3.000));
engine->addInputVariable(X);

OutputVariable* Ramps = new OutputVariable;
Ramps->setName("Ramps");
Ramps->setDescription("");
Ramps->setEnabled(true);
Ramps->setRange(0.000, 1.000);
Ramps->setLockValueInRange(false);
Ramps->setAggregation(fl::null);
Ramps->setDefuzzifier(new WeightedAverage("Automatic"));
Ramps->setDefaultValue(fl::nan);
Ramps->setLockPreviousValue(false);
Ramps->addTerm(new Ramp("b", 0.600, 0.400));
Ramps->addTerm(new Ramp("a", 0.000, 0.250));
Ramps->addTerm(new Ramp("c", 0.700, 1.000));
engine->addOutputVariable(Ramps);

OutputVariable* Sigmoids = new OutputVariable;
Sigmoids->setName("Sigmoids");
Sigmoids->setDescription("");
Sigmoids->setEnabled(true);
Sigmoids->setRange(0.020, 1.000);
Sigmoids->setLockValueInRange(false);
Sigmoids->setAggregation(fl::null);
Sigmoids->setDefuzzifier(new WeightedAverage("Automatic"));
Sigmoids->setDefaultValue(fl::nan);
Sigmoids->setLockPreviousValue(false);
Sigmoids->addTerm(new Sigmoid("b", 0.500, -30.000));
Sigmoids->addTerm(new Sigmoid("a", 0.130, 30.000));
Sigmoids->addTerm(new Sigmoid("c", 0.830, 30.000));
engine->addOutputVariable(Sigmoids);

OutputVariable* ZSShapes = new OutputVariable;
ZSShapes->setName("ZSShapes");
ZSShapes->setDescription("");
ZSShapes->setEnabled(true);
ZSShapes->setRange(0.000, 1.000);
ZSShapes->setLockValueInRange(false);
ZSShapes->setAggregation(fl::null);
ZSShapes->setDefuzzifier(new WeightedAverage("Automatic"));
ZSShapes->setDefaultValue(fl::nan);
ZSShapes->setLockPreviousValue(false);
ZSShapes->addTerm(new ZShape("b", 0.300, 0.600));
ZSShapes->addTerm(new SShape("a", 0.000, 0.250));
ZSShapes->addTerm(new SShape("c", 0.700, 1.000));
engine->addOutputVariable(ZSShapes);

OutputVariable* Concaves = new OutputVariable;
Concaves->setName("Concaves");
Concaves->setDescription("");
Concaves->setEnabled(true);
Concaves->setRange(0.000, 1.000);
Concaves->setLockValueInRange(false);
Concaves->setAggregation(fl::null);
Concaves->setDefuzzifier(new WeightedAverage("Automatic"));
Concaves->setDefaultValue(fl::nan);
Concaves->setLockPreviousValue(false);
Concaves->addTerm(new Concave("b", 0.500, 0.400));
Concaves->addTerm(new Concave("a", 0.240, 0.250));
Concaves->addTerm(new Concave("c", 0.900, 1.000));
engine->addOutputVariable(Concaves);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setName("");
ruleBlock->setDescription("");
ruleBlock->setEnabled(true);
ruleBlock->setConjunction(fl::null);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->setActivation(new General);
ruleBlock->addRule(Rule::parse("if X is small then Ramps is a and Sigmoids is a and ZSShapes is a and Concaves is a", engine));
ruleBlock->addRule(Rule::parse("if X is medium then Ramps is b and Sigmoids is b and ZSShapes is b and Concaves is b", engine));
ruleBlock->addRule(Rule::parse("if X is large then Ramps is c and Sigmoids is c and ZSShapes is c and Concaves is c", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 22
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("slcp");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("in1");
inputVariable1->setRange(-0.300, 0.300);
inputVariable1->addTerm(new Bell("in1mf1", -0.300, 0.300, 2.000));
inputVariable1->addTerm(new Bell("in1mf2", 0.300, 0.300, 2.000));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("in2");
inputVariable2->setRange(-1.000, 1.000);
inputVariable2->addTerm(new Bell("in2mf1", -1.000, 1.000, 2.000));
inputVariable2->addTerm(new Bell("in2mf2", 1.000, 1.000, 2.000));
engine->addInputVariable(inputVariable2);

InputVariable* inputVariable3 = new InputVariable;
inputVariable3->setEnabled(true);
inputVariable3->setName("in3");
inputVariable3->setRange(-3.000, 3.000);
inputVariable3->addTerm(new Bell("in3mf1", -3.000, 3.000, 2.000));
inputVariable3->addTerm(new Bell("in3mf2", 3.000, 3.000, 2.000));
engine->addInputVariable(inputVariable3);

InputVariable* inputVariable4 = new InputVariable;
inputVariable4->setEnabled(true);
inputVariable4->setName("in4");
inputVariable4->setRange(-3.000, 3.000);
inputVariable4->addTerm(new Bell("in4mf1", -3.000, 3.000, 2.000));
inputVariable4->addTerm(new Bell("in4mf2", 3.000, 3.000, 2.000));
engine->addInputVariable(inputVariable4);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("out");
outputVariable->setRange(-10.000, 10.000);
outputVariable->fuzzyOutput()->setAccumulation(fl::null);
outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousOutputValue(false);
outputVariable->setLockOutputValueInRange(false);
outputVariable->addTerm(Linear::create("outmf1", engine, 41.373, 10.030, 3.162, 4.288, 0.339));
outputVariable->addTerm(Linear::create("outmf2", engine, 40.409, 10.053, 3.162, 4.288, 0.207));
outputVariable->addTerm(Linear::create("outmf3", engine, 41.373, 10.030, 3.162, 4.288, 0.339));
outputVariable->addTerm(Linear::create("outmf4", engine, 40.409, 10.053, 3.162, 4.288, 0.207));
outputVariable->addTerm(Linear::create("outmf5", engine, 38.561, 10.177, 3.162, 4.288, -0.049));
outputVariable->addTerm(Linear::create("outmf6", engine, 37.596, 10.154, 3.162, 4.288, -0.181));
outputVariable->addTerm(Linear::create("outmf7", engine, 38.561, 10.177, 3.162, 4.288, -0.049));
outputVariable->addTerm(Linear::create("outmf8", engine, 37.596, 10.154, 3.162, 4.288, -0.181));
outputVariable->addTerm(Linear::create("outmf9", engine, 37.596, 10.154, 3.162, 4.288, 0.181));
outputVariable->addTerm(Linear::create("outmf10", engine, 38.561, 10.177, 3.162, 4.288, 0.049));
outputVariable->addTerm(Linear::create("outmf11", engine, 37.596, 10.154, 3.162, 4.288, 0.181));
outputVariable->addTerm(Linear::create("outmf12", engine, 38.561, 10.177, 3.162, 4.288, 0.049));
outputVariable->addTerm(Linear::create("outmf13", engine, 40.408, 10.053, 3.162, 4.288, -0.207));
outputVariable->addTerm(Linear::create("outmf14", engine, 41.373, 10.030, 3.162, 4.288, -0.339));
outputVariable->addTerm(Linear::create("outmf15", engine, 40.408, 10.053, 3.162, 4.288, -0.207));
outputVariable->addTerm(Linear::create("outmf16", engine, 41.373, 10.030, 3.162, 4.288, -0.339));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new AlgebraicProduct);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setActivation(fl::null);
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf1 and in3 is in3mf1 and in4 is in4mf1 then out is outmf1", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf1 and in3 is in3mf1 and in4 is in4mf2 then out is outmf2", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf1 and in3 is in3mf2 and in4 is in4mf1 then out is outmf3", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf1 and in3 is in3mf2 and in4 is in4mf2 then out is outmf4", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf2 and in3 is in3mf1 and in4 is in4mf1 then out is outmf5", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf2 and in3 is in3mf1 and in4 is in4mf2 then out is outmf6", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf2 and in3 is in3mf2 and in4 is in4mf1 then out is outmf7", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf1 and in2 is in2mf2 and in3 is in3mf2 and in4 is in4mf2 then out is outmf8", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf1 and in3 is in3mf1 and in4 is in4mf1 then out is outmf9", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf1 and in3 is in3mf1 and in4 is in4mf2 then out is outmf10", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf1 and in3 is in3mf2 and in4 is in4mf1 then out is outmf11", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf1 and in3 is in3mf2 and in4 is in4mf2 then out is outmf12", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf2 and in3 is in3mf1 and in4 is in4mf1 then out is outmf13", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf2 and in3 is in3mf1 and in4 is in4mf2 then out is outmf14", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf2 and in3 is in3mf2 and in4 is in4mf1 then out is outmf15", engine));
ruleBlock->addRule(fl::Rule::parse("if in1 is in1mf2 and in2 is in2mf2 and in3 is in3mf2 and in4 is in4mf2 then out is outmf16", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 23
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("invkine2");

InputVariable* input1 = new InputVariable;
input1->setEnabled(true);
input1->setName("input1");
input1->setRange(-6.287, 17.000);
input1->setLockValueInRange(false);
input1->addTerm(new Bell("in1mf1", -5.763, 3.015, 1.851));
input1->addTerm(new Bell("in1mf2", -1.624, 3.130, 2.111));
input1->addTerm(new Bell("in1mf3", 3.552, 3.193, 2.104));
input1->addTerm(new Bell("in1mf4", 8.273, 2.907, 1.985));
input1->addTerm(new Bell("in1mf5", 13.232, 2.708, 2.056));
input1->addTerm(new Bell("in1mf6", 17.783, 1.635, 1.897));
engine->addInputVariable(input1);

InputVariable* input2 = new InputVariable;
input2->setEnabled(true);
input2->setName("input2");
input2->setRange(0.000, 16.972);
input2->setLockValueInRange(false);
input2->addTerm(new Bell("in2mf1", 0.005, 1.877, 1.995));
input2->addTerm(new Bell("in2mf2", 3.312, 2.017, 1.829));
input2->addTerm(new Bell("in2mf3", 6.568, 2.261, 1.793));
input2->addTerm(new Bell("in2mf4", 10.111, 2.741, 1.978));
input2->addTerm(new Bell("in2mf5", 14.952, 2.045, 1.783));
input2->addTerm(new Bell("in2mf6", 17.910, 0.824, 1.734));
engine->addInputVariable(input2);

OutputVariable* output = new OutputVariable;
output->setEnabled(true);
output->setName("output");
output->setRange(0.000, 3.100);
output->setLockValueInRange(false);
output->fuzzyOutput()->setAggregation(fl::null);
output->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
output->setDefaultValue(fl::nan);
output->setLockPreviousValue(false);
output->addTerm(Linear::create("out1mf1", engine, -0.048, 1.456, 2.222));
output->addTerm(Linear::create("out1mf2", engine, -0.218, -0.305, 2.042));
output->addTerm(Linear::create("out1mf3", engine, 0.026, -0.141, 3.067));
output->addTerm(Linear::create("out1mf4", engine, 0.052, -0.150, 3.419));
output->addTerm(Linear::create("out1mf5", engine, 0.113, -0.189, 4.339));
output->addTerm(Linear::create("out1mf6", engine, 2.543, 0.361, -2.738));
output->addTerm(Linear::create("out1mf7", engine, 2.517, -6.809, 23.353));
output->addTerm(Linear::create("out1mf8", engine, -0.208, -0.394, 4.472));
output->addTerm(Linear::create("out1mf9", engine, -0.046, -0.300, 4.452));
output->addTerm(Linear::create("out1mf10", engine, -0.006, -0.217, 4.195));
output->addTerm(Linear::create("out1mf11", engine, 0.089, -0.254, 4.992));
output->addTerm(Linear::create("out1mf12", engine, -0.033, 0.103, -2.012));
output->addTerm(Linear::create("out1mf13", engine, 1.355, 1.228, -5.678));
output->addTerm(Linear::create("out1mf14", engine, -0.245, -0.124, 3.753));
output->addTerm(Linear::create("out1mf15", engine, -0.099, -0.111, 3.304));
output->addTerm(Linear::create("out1mf16", engine, -0.052, -0.163, 3.560));
output->addTerm(Linear::create("out1mf17", engine, 0.099, -0.260, 4.662));
output->addTerm(Linear::create("out1mf18", engine, 0.082, -1.849, 31.104));
output->addTerm(Linear::create("out1mf19", engine, 2.180, -2.963, -0.061));
output->addTerm(Linear::create("out1mf20", engine, -0.982, 0.510, 5.657));
output->addTerm(Linear::create("out1mf21", engine, -0.087, -0.179, 3.744));
output->addTerm(Linear::create("out1mf22", engine, -0.124, -0.161, 4.094));
output->addTerm(Linear::create("out1mf23", engine, 0.383, 0.007, -1.559));
output->addTerm(Linear::create("out1mf24", engine, -8.415, 2.083, 5.177));
output->addTerm(Linear::create("out1mf25", engine, 1.721, -15.079, -0.687));
output->addTerm(Linear::create("out1mf26", engine, -1.043, -0.786, 20.510));
output->addTerm(Linear::create("out1mf27", engine, -0.249, -0.396, 6.995));
output->addTerm(Linear::create("out1mf28", engine, -0.076, -0.245, 4.416));
output->addTerm(Linear::create("out1mf29", engine, 0.765, -1.488, 17.384));
output->addTerm(Linear::create("out1mf30", engine, -21.210, -43.022, -2.522));
output->addTerm(Linear::create("out1mf31", engine, -0.661, 3.523, 6.215));
output->addTerm(Linear::create("out1mf32", engine, -1.998, 1.582, 33.256));
output->addTerm(Linear::create("out1mf33", engine, -2.068, 5.673, 6.520));
output->addTerm(Linear::create("out1mf34", engine, -5.044, 7.093, 3.516));
output->addTerm(Linear::create("out1mf35", engine, -46.049, -35.021, -2.926));
output->addTerm(Linear::create("out1mf36", engine, -0.448, -0.770, -0.041));
engine->addOutputVariable(output);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new AlgebraicProduct);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->setActivation(new General);
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf1 and input2 is in2mf1 then output is out1mf1", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf1 and input2 is in2mf2 then output is out1mf2", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf1 and input2 is in2mf3 then output is out1mf3", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf1 and input2 is in2mf4 then output is out1mf4", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf1 and input2 is in2mf5 then output is out1mf5", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf1 and input2 is in2mf6 then output is out1mf6", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf2 and input2 is in2mf1 then output is out1mf7", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf2 and input2 is in2mf2 then output is out1mf8", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf2 and input2 is in2mf3 then output is out1mf9", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf2 and input2 is in2mf4 then output is out1mf10", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf2 and input2 is in2mf5 then output is out1mf11", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf2 and input2 is in2mf6 then output is out1mf12", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf3 and input2 is in2mf1 then output is out1mf13", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf3 and input2 is in2mf2 then output is out1mf14", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf3 and input2 is in2mf3 then output is out1mf15", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf3 and input2 is in2mf4 then output is out1mf16", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf3 and input2 is in2mf5 then output is out1mf17", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf3 and input2 is in2mf6 then output is out1mf18", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf4 and input2 is in2mf1 then output is out1mf19", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf4 and input2 is in2mf2 then output is out1mf20", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf4 and input2 is in2mf3 then output is out1mf21", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf4 and input2 is in2mf4 then output is out1mf22", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf4 and input2 is in2mf5 then output is out1mf23", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf4 and input2 is in2mf6 then output is out1mf24", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf5 and input2 is in2mf1 then output is out1mf25", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf5 and input2 is in2mf2 then output is out1mf26", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf5 and input2 is in2mf3 then output is out1mf27", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf5 and input2 is in2mf4 then output is out1mf28", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf5 and input2 is in2mf5 then output is out1mf29", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf5 and input2 is in2mf6 then output is out1mf30", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf6 and input2 is in2mf1 then output is out1mf31", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf6 and input2 is in2mf2 then output is out1mf32", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf6 and input2 is in2mf3 then output is out1mf33", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf6 and input2 is in2mf4 then output is out1mf34", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf6 and input2 is in2mf5 then output is out1mf35", engine));
ruleBlock->addRule(fl::Rule::parse("if input1 is in1mf6 and input2 is in2mf6 then output is out1mf36", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 24
0
int main(int argc, char** argv){
using namespace fl;

Engine* engine = new Engine;
engine->setName("Heart-Disease-Risk");

InputVariable* inputVariable1 = new InputVariable;
inputVariable1->setEnabled(true);
inputVariable1->setName("LDLLevel");
inputVariable1->setRange(0.000, 300.000);
inputVariable1->setLockValueInRange(false);
inputVariable1->addTerm(new Trapezoid("Low", -1.000, 0.000, 90.000, 110.000));
inputVariable1->addTerm(new Trapezoid("LowBorderline", 90.000, 110.000, 120.000, 140.000));
inputVariable1->addTerm(new Trapezoid("Borderline", 120.000, 140.000, 150.000, 170.000));
inputVariable1->addTerm(new Trapezoid("HighBorderline", 150.000, 170.000, 180.000, 200.000));
inputVariable1->addTerm(new Trapezoid("High", 180.000, 200.000, 300.000, 301.000));
engine->addInputVariable(inputVariable1);

InputVariable* inputVariable2 = new InputVariable;
inputVariable2->setEnabled(true);
inputVariable2->setName("HDLLevel");
inputVariable2->setRange(0.000, 100.000);
inputVariable2->setLockValueInRange(false);
inputVariable2->addTerm(new Trapezoid("LowHDL", -1.000, 0.000, 35.000, 45.000));
inputVariable2->addTerm(new Trapezoid("ModerateHDL", 35.000, 45.000, 55.000, 65.000));
inputVariable2->addTerm(new Trapezoid("HighHDL", 55.000, 65.000, 100.000, 101.000));
engine->addInputVariable(inputVariable2);

OutputVariable* outputVariable = new OutputVariable;
outputVariable->setEnabled(true);
outputVariable->setName("HeartDiseaseRisk");
outputVariable->setRange(0.000, 10.000);
outputVariable->setLockValueInRange(false);
outputVariable->fuzzyOutput()->setAccumulation(fl::null);
outputVariable->setDefuzzifier(new WeightedAverage("TakagiSugeno"));
outputVariable->setDefaultValue(fl::nan);
outputVariable->setLockPreviousValue(false);
outputVariable->addTerm(new Constant("NoRisk", 0.000));
outputVariable->addTerm(new Constant("LowRisk", 2.500));
outputVariable->addTerm(new Constant("MediumRisk", 5.000));
outputVariable->addTerm(new Constant("HighRisk", 7.500));
outputVariable->addTerm(new Constant("ExtremeRisk", 10.000));
engine->addOutputVariable(outputVariable);

RuleBlock* ruleBlock = new RuleBlock;
ruleBlock->setEnabled(true);
ruleBlock->setName("");
ruleBlock->setConjunction(new Minimum);
ruleBlock->setDisjunction(fl::null);
ruleBlock->setImplication(fl::null);
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is Low and HDLLevel is LowHDL then HeartDiseaseRisk is MediumRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is Low and HDLLevel is ModerateHDL then HeartDiseaseRisk is LowRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is Low and HDLLevel is HighHDL then HeartDiseaseRisk is NoRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is LowBorderline and HDLLevel is LowHDL then HeartDiseaseRisk is MediumRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is LowBorderline and HDLLevel is ModerateHDL then HeartDiseaseRisk is LowRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is LowBorderline and HDLLevel is HighHDL then HeartDiseaseRisk is LowRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is Borderline and HDLLevel is LowHDL then HeartDiseaseRisk is HighRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is Borderline and HDLLevel is ModerateHDL then HeartDiseaseRisk is MediumRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is Borderline and HDLLevel is HighHDL then HeartDiseaseRisk is LowRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is HighBorderline and HDLLevel is LowHDL then HeartDiseaseRisk is HighRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is HighBorderline and HDLLevel is ModerateHDL then HeartDiseaseRisk is HighRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is HighBorderline and HDLLevel is HighHDL then HeartDiseaseRisk is MediumRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is High and HDLLevel is LowHDL then HeartDiseaseRisk is ExtremeRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is High and HDLLevel is ModerateHDL then HeartDiseaseRisk is HighRisk", engine));
ruleBlock->addRule(fl::Rule::parse("if LDLLevel is High and HDLLevel is HighHDL then HeartDiseaseRisk is MediumRisk", engine));
engine->addRuleBlock(ruleBlock);


}
Esempio n. 25
0
DecisionInfo NizikFuzzy::ProcessAI(const std::vector<NodeInfo>& graphInfo, const Pawn* const myPawn)
{
	engine->restart();

	Node* choice;
	double value = 10.0;

    Node* shootChoice = myPawn->GetNode()->GetConnections()->at(0);
	double shootValue = -1.0;

	const std::string playersNames[] = { "Player1" };

	InputVariable* iv = new InputVariable();
	iv->setName(playersNames[0]);
	iv->setRange(0.0, 5.0);
	iv->addTerm(new Triangle("NEAR", 0.0, 1.0, 1.0));
	iv->addTerm(new Triangle("MIDDLE", 1.0, 3.0, 3.0));
	iv->addTerm(new Triangle("FAR", 2.5, 5.0, 5.0));
	engine->addInputVariable(iv);

	OutputVariable* danger = new OutputVariable;
	danger->setName("Danger");
	danger->setRange(0, 2);
	danger->setDefaultValue(fl::nan);
	danger->addTerm(new Triangle("LOW", 0, 0.5f));
	danger->addTerm(new Triangle("MEDIUM", 0.5f, 1.5f));
	danger->addTerm(new Triangle("HIGH", 1.0f, 2.0f));
	engine->addOutputVariable(danger);

	RuleBlock* ruleblock = new RuleBlock;
	ruleblock->addRule(Rule::parse("if Player1 is NEAR then Danger is HIGH", engine));
	ruleblock->addRule(Rule::parse("if Player1 is MIDDLE then Danger is MEDIUM", engine));
	ruleblock->addRule(Rule::parse("if Player1 is FAR then Danger is LOW", engine));
	engine->addRuleBlock(ruleblock);
	engine->configure("", "", "Minimum", "Maximum", "Centroid");

	std::string status;
	if (!engine->isReady(&status))
		printf("Engine not ready. \nThe following errors were encountered:\n" + *status.c_str());

	const size_t nodesCount = myPawn->GetNode()->GetConnections()->size();
	const size_t nc = graphInfo.size();
	const NodeInfo* ni;
	Node* n;

	for (size_t i = 0; i < nodesCount; ++i)
	{
		n = myPawn->GetNode()->GetConnections()->at(i);
		for (size_t j = 0; j < nc; ++j)
		{
			if (graphInfo.at(j).myId == n->GetId())
			{
				ni = &graphInfo.at(j);
				break;
			}
		}
		AddVariables(playersNames, ni, 1);
		engine->process();
		printf("\nDECISION: ");
		double tmp = danger->getOutputValue();
		std::cout << ' ' << tmp << std::endl;
		if (tmp < value)
		{
			value = tmp;
			choice = n;
		}
		if (tmp > shootValue)
		{
			shootValue = tmp;
			shootChoice = n;
		}
	}
	engine->removeInputVariable("Player1");
	engine->removeOutputVariable("Danger");
	engine->removeRuleBlock(0);
	Decision dec;
	if (shootValue >= 1.4f)
	{
		dec.type = Decision::Type::SHOOT;
		dec.target = shootChoice;
	}
	else
	{
		dec.type = Decision::Type::MOVE;
		dec.target = shootChoice;
	}
	return dec;
}