Beispiel #1
0
 WorkflowStep InputVariable_Impl::asWorkflowStep() const {
   if (parent()) {
     return parent()->cast<WorkflowStep>();
   }
   InputVariable copyOfThis = getPublicObject<InputVariable>();
   boost::shared_ptr<detail::WorkflowStep_Impl> workflowStepImpl(new detail::WorkflowStep_Impl(copyOfThis));
   WorkflowStep result(workflowStepImpl);
   copyOfThis.setParent(result);
   return result;
 }
 scalar Function::membership(scalar x) const {
     if (not this->_root.get()) {
         throw fl::Exception("[function error] function <" + _formula + "> not loaded.", FL_AT);
     }
     if (this->_engine) {
         for (int i = 0; i < this->_engine->numberOfInputVariables(); ++i) {
             InputVariable* input = this->_engine->getInputVariable(i);
             this->variables[input->getName()] = input->getInputValue();
         }
         for (int i = 0; i < this->_engine->numberOfOutputVariables(); ++i) {
             OutputVariable* output = this->_engine->getOutputVariable(i);
             this->variables[output->getName()] = output->getOutputValue();
         }
     }
     this->variables["x"] = x;
     return this->evaluate(&this->variables);
 }
Beispiel #3
0
    scalar Antecedent::activationDegree(const TNorm* conjunction, const SNorm* disjunction,
            const Expression* node) const {
        if (not node->isOperator) { //then it is a Proposition
            const Proposition* proposition =
                    dynamic_cast<const Proposition*> (node);
            if (not proposition->variable->isEnabled()){
                return 0.0;
            }
            bool isAny = false;
            for (std::size_t i = 0; i < proposition->hedges.size(); ++i) {
                isAny |= proposition->hedges.at(i)->name() == Any().name();
                if (isAny) return 1.0;
            }
            InputVariable* inputVariable = dynamic_cast<InputVariable*> (proposition->variable);
            scalar result = proposition->term->membership(inputVariable->getInputValue());
            for (std::size_t i = 0; i < proposition->hedges.size(); ++i) {
                result = proposition->hedges.at(i)->hedge(result);
            }
            return result;
        }
        //if node is an operatorsk
        const Operator* fuzzyOperator =
                dynamic_cast<const Operator*> (node);
        if (not fuzzyOperator->left or not fuzzyOperator->right) {
            std::ostringstream ex;
            ex << "[syntax error] left and right operands must exist";
            throw fl::Exception(ex.str(), FL_AT);
        }
        if (fuzzyOperator->name == Rule::FL_AND)
            return conjunction->compute(
                this->activationDegree(conjunction, disjunction, fuzzyOperator->left),
                this->activationDegree(conjunction, disjunction, fuzzyOperator->right));

        if (fuzzyOperator->name == Rule::FL_OR)
            return disjunction->compute(
                this->activationDegree(conjunction, disjunction, fuzzyOperator->left),
                this->activationDegree(conjunction, disjunction, fuzzyOperator->right));
        std::ostringstream ex;
        ex << "[syntax error] operator <" << fuzzyOperator->name << "> not recognized";
        throw fl::Exception(ex.str(), FL_AT);

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


}
Beispiel #5
0
 void FllImporter::processInputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     InputVariable* inputVariable = new InputVariable;
     engine->addInputVariable(inputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("InputVariable" == keyValue.first) {
             inputVariable->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             inputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             inputVariable->setRange(range.first, range.second);
         } else if ("term" == keyValue.first) {
             inputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw fl::Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
 }
Beispiel #6
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);


}
Beispiel #7
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);


}
Beispiel #8
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);


}
Beispiel #9
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);


}
Beispiel #10
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);


}
Beispiel #11
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);


}
Beispiel #12
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);


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


}
Beispiel #14
0
void Engine::parseInput() throw (std::string) 
{
    // TODO: Add more error checking (if strings and numbers really exist)
    std::string line;
    std::getline(*inputFile, line);
    ParseStateEnum parseState = Invalid;
    InputVariable* actInputVar = NULL;
    OutputVariable* actOutputVar = NULL;

    while (!inputFile->eof())
    {
        if (line.find("#") == std::string::npos) // No comment
        {
            std::size_t delimiterPos = line.find(":");
            std::string token = line.substr(0, delimiterPos);
            if (token.compare("Engine") == 0)
            {
                std::size_t endPos = line.find(" ", delimiterPos + 2);
                name = line.substr(delimiterPos + 2, endPos - delimiterPos - 2);
                projectName = name;
                name = name + "App";
            }
            else if (token.compare("InputVariable") == 0)
            {
                parseState = Input;
                std::size_t endPos = line.find(" ", delimiterPos + 2);
                actInputVar = addInputVariable(line.substr(delimiterPos + 2, endPos - delimiterPos - 2));
            }
            else if (token.compare("OutputVariable") == 0)
            {
                parseState = Output;
                std::size_t endPos = line.find(" ", delimiterPos + 2);
                actOutputVar = addOutputVariable(line.substr(delimiterPos + 2, endPos - delimiterPos - 2));
            }
            else if (token.compare("RuleBlock") == 0)
            {
                parseState = Rule;
            }
            else if (token.compare("  enabled") == 0)
            {
                switch(parseState) 
                {
                    case Invalid:
                        throw parseError;
                        break;
                    default:
                        std::cout << "Warning: The enabled option is not supported" << std::endl;
                        break;
                }
            }
            else if (token.compare("  range") == 0)
            {
                std::size_t endFirstNumber = line.find(" ", delimiterPos + 2);
                std::size_t endSecondNumber = line.find(" ", endFirstNumber + 1);
                if (line.length() == endFirstNumber) throw parseError;
                switch(parseState) // range: scalar scalar
                {
                    case Input:
                        actInputVar->setRange(strtod(line.substr(delimiterPos + 2, endFirstNumber - delimiterPos - 2).c_str(), NULL),
                        strtod(line.substr(endFirstNumber + 1, endSecondNumber - endFirstNumber - 1).c_str(), NULL));
                        break;
                    case Output:
                        actOutputVar->setRange(strtod(line.substr(delimiterPos + 2, endFirstNumber - delimiterPos - 2).c_str(), NULL),
                        strtod(line.substr(endFirstNumber + 1, endSecondNumber - endFirstNumber - 1).c_str(), NULL));
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  term") == 0)
            {
                switch(parseState) 
                {
                    case Input:
                        try
                        {
                            parseTerm(actInputVar, line.substr(delimiterPos + 2), true);
                        }
                        catch (std::string error)
                        {
                            throw error;
                        }
                        break;
                    case Output:
                        try
                        {
                            parseTerm(actOutputVar, line.substr(delimiterPos + 2), false);
                        }
                        catch (std::string error)
                        {
                            throw error;
                        }
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  accumulation") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The accumulation option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  defuzzifier") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The defuzzifier option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  default") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The default option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  lock-previous") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The lock-previous option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  lock-range") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The lock-range option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  conjunction") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        std::cout << "Warning: The conjunction option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  disjunction") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        std::cout << "Warning: The disjunction option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  activation") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        std::cout << "Warning: The activation option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  rule") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        try
                        {
                            parseRule(line.substr(delimiterPos + 2));
                        }
                        catch (std::string error)
                        {
                            throw error;
                        }
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else // Not a valid symbol
            {
                throw parseError;
            }
        }
        std::getline(*inputFile, line);
    }
}
Beispiel #15
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);


}
Beispiel #16
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;
}