struct sml_fuzzy_term*
sml_fuzzy_bridge_variable_add_term_gaussian(struct sml_fuzzy *fuzzy,
                                            struct sml_variable *variable,
                                            const char *name, float mean,
                                            float standard_deviation)
{
    fl::Variable *fl_var = (fl::Variable*) variable;
    fl::Term *term;

    if (!_check_name(name))
        return NULL;

    term = new (std::nothrow) fl::Gaussian(name, mean, standard_deviation,
                                           1.0);
    if (!term) {
        sml_critical("Failed to create term");
        return NULL;
    }

    if (sml_fuzzy_is_input(fuzzy, variable, NULL))
        fuzzy->input_terms_count++;
    else if (sml_fuzzy_is_output(fuzzy, variable, NULL))
        fuzzy->output_terms_count++;
    else {
        delete term;
        return NULL;
    }

    fl_var->addTerm(term);
    return (struct sml_fuzzy_term *) term;
}
struct sml_fuzzy_term*
sml_fuzzy_bridge_variable_add_term_cosine(struct sml_fuzzy *fuzzy,
                                          struct sml_variable *variable,
                                          const char *name, float center,
                                          float width)
{
    fl::Variable *fl_var = (fl::Variable*) variable;
    fl::Term *term;

    if (!_check_name(name))
        return NULL;

    term = new (std::nothrow) fl::Cosine(name, center, width, 1.0);
    if (!term) {
        sml_critical("Failed to create term");
        return NULL;
    }

    if (sml_fuzzy_is_input(fuzzy, variable, NULL))
        fuzzy->input_terms_count++;
    else if (sml_fuzzy_is_output(fuzzy, variable, NULL))
        fuzzy->output_terms_count++;
    else {
        delete term;
        return NULL;
    }

    fl_var->addTerm(term);
    return (struct sml_fuzzy_term *) term;
}
Beispiel #3
0
  PathMan::LookUp PathMan::add_file(Dir * dir, const char * name, uint8_t mode)
  {
    LookUp lu = {SUCCESS, State(), 0, 0};
    PTrie::Tuple tuple;
    uint32_t     len;

    lu.err = CORRUPTION;

    if (trie.root) {
      lu.err = NO_DIR;
      if (dir) {
        tuple = dir->state.top;
        lu.err = CORRUPTION;
        if (tuple.index) {
          lu.err = _check_name(name, len);
        }
      }
    }

    if (lu.err == SUCCESS) {
      {
        uint16_t alen = len + 1;
        char word[alen];

        memcpy(word + 1, name, len);
        word[0] = '/';

        FileTuple file = _mkfile();
        if (!file.index) {
          lu.err = ALLOCATION_FALILURE;
          goto out;
        }

        Node node = {0,1,0,file.index};
        file.node->isused = 1;

        PTrie::Epo epo = {SUCCESS, tuple, {0,0}, {0,0}, PTrie::FAIL, 0, 0};
        epo = trie._insert(epo, alen, word, node, false);

        if (epo.err == SUCCESS) {
          State s = State(epo);
          file.node->next = dir->file;
          dir->file = file.index;
          lu.state = s;
          lu.file = file.node;
        } else {
          _rmfile(file.index);
          lu.err = epo.err;
        }
      }
    }

  out:
    return lu;
  }