예제 #1
0
        void Variable::edit(const OutputVariable* outputVariable) {
            variable->setMinimum(outputVariable->getMinimum());
            variable->setMaximum(outputVariable->getMaximum());
            for (int i = 0; i < outputVariable->numberOfTerms(); ++i) {
                this->variable->addTerm(outputVariable->getTerm(i)->copy());
            }

            scalar singleStep = (variable->getMaximum() - variable->getMinimum()) / 100;
            ui->sbx_min->setSingleStep(std::max(scalar(0.01), singleStep));
            ui->sbx_max->setSingleStep(std::max(scalar(0.01), singleStep));

            setWindowTitle("Edit variable");
            ui->led_name->setText(QString::fromStdString(outputVariable->getName()));
            ui->cbx_enabled->setChecked(outputVariable->isEnabled());

            OutputVariable* editable = dynamic_cast<OutputVariable*> (this->variable);
            editable->setDefaultValue(outputVariable->getDefaultValue());
            editable->setLastValidOutput(fl::nan);
            editable->setLockValidOutput(outputVariable->isLockingValidOutput());
            editable->setLockOutputRange(outputVariable->isLockingOutputRange());

            editable->fuzzyOutput()->setAccumulation(outputVariable->fuzzyOutput()->getAccumulation());
            Defuzzifier* defuzzifier = outputVariable->getDefuzzifier();
            //            if (not defuzzifier) {
            //                defuzzifier = Factory::instance()->defuzzifier()->
            //                        create(Centroid().className(), fl::fuzzylite::defaultDivisions());
            //            }
            editable->setDefuzzifier(defuzzifier);

            reloadModel();
        }
예제 #2
0
 void FllImporter::processOutputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     OutputVariable* outputVariable = new OutputVariable;
     engine->addOutputVariable(outputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("OutputVariable" == keyValue.first) {
             outputVariable->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             outputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             outputVariable->setRange(range.first, range.second);
         } else if ("default" == keyValue.first) {
             outputVariable->setDefaultValue(Op::toScalar(keyValue.second));
         } else if ("lock-valid" == keyValue.first) {
             outputVariable->setLockValidOutput(parseBoolean(keyValue.second));
         } else if ("lock-range" == keyValue.first) {
             outputVariable->setLockOutputRange(parseBoolean(keyValue.second));
         } else if ("defuzzifier" == keyValue.first) {
             outputVariable->setDefuzzifier(parseDefuzzifier(keyValue.second));
         } else if ("accumulation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAccumulation(parseSNorm(keyValue.second));
         } else if ("term" == keyValue.first) {
             outputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw fl::Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
 }
예제 #3
0
        void Variable::accept() {
            OutputVariable* outputVariable = dynamic_cast<OutputVariable*> (variable);
            if (outputVariable) {
                try {
                    outputVariable->setDefaultValue(
                            fl::Op::toScalar(ui->led_default->text().toStdString()));
                } catch (fl::Exception& ex) {
                    std::ostringstream message;
                    message << ex.what() << std::endl <<
                            "Expected numeric values (including nan or inf)" << std::endl;
                    QMessageBox::critical(this, tr("Error"),
                            fl::qt::Window::toHtmlEscaped(
                            QString::fromStdString(message.str())),
                            QMessageBox::Ok);
                    return;
                }
                outputVariable->setLockValidOutput(ui->chx_lock_valid->isChecked());
                outputVariable->setLockOutputRange(ui->chx_lock_range->isChecked());

                SNorm* accumulation = FactoryManager::instance()->snorm()->createInstance(
                        ui->cbx_accumulation->currentText().toStdString());
                outputVariable->fuzzyOutput()->setAccumulation(accumulation);
                Defuzzifier* defuzzifier = NULL;
                if (ui->cbx_defuzzifier->currentIndex() >= 0) {
                    defuzzifier = FactoryManager::instance()->defuzzifier()->createInstance(
                            ui->cbx_defuzzifier->currentText().toStdString());
                    IntegralDefuzzifier* integralDefuzzifier =
                            dynamic_cast<IntegralDefuzzifier*> (defuzzifier);
                    if (integralDefuzzifier) {
                        integralDefuzzifier->setResolution(ui->sbx_accuracy->value());
                    }
                }
                outputVariable->setDefuzzifier(defuzzifier);

            }
            variable->setName(fl::Op::makeValidId(ui->led_name->text().toStdString()));
            variable->setEnabled(ui->cbx_enabled->isChecked());
            QDialog::accept();
        }