void VertexIsotropicOffsetParameter::apply(VectorF& results,
        const PatternParameter::Variables& vars) {
    const size_t dim = m_wire_network->get_dim();
    const size_t num_vertices = m_wire_network->get_num_vertices();
    const size_t roi_size = m_roi.size();
    const VectorF center = m_wire_network->center();
    const VectorF bbox_max = m_wire_network->get_bbox_max();
    assert(results.size() == dim * num_vertices);
    assert(roi_size == m_transforms.size());

    if (m_formula != "") evaluate_formula(vars);

    const MatrixFr& vertices = m_wire_network->get_vertices();
    size_t seed_vertex_index = m_roi.minCoeff();
    VectorF seed_vertex = vertices.row(seed_vertex_index);
    VectorF seed_offset = VectorF::Zero(dim);
    seed_offset = (bbox_max - center).cwiseProduct(m_dof_dir) * m_value;

    for (size_t i=0; i<roi_size; i++) {
        size_t v_idx = m_roi[i];
        assert(v_idx < num_vertices);
        const MatrixF& trans = m_transforms[i];
        results.segment(v_idx*dim, dim) += trans * seed_offset;
    }
}
Exemplo n.º 2
0
// Generating all 3-SAT formulas with distinct literal clauses 
// (i.e it is forbidden to have a clause of a type: (x, x))
void gen_distinct_formulas(int i) {
    if (i < size) {
        for (int j = 1; j <= nvars; ++j) {
            if (i % 3 == 0) {
                formula[i] = j;
                gen_distinct_formulas(i+1);
                formula[i] = -j;
                gen_distinct_formulas(i+1);
            } else if (i % 3 == 1) {
                if (formula[i-1] != j) {
                    formula[i] = j;
                    gen_distinct_formulas(i+1);
                }
                if (formula[i-1] != -j) {
                    formula[i] = -j;
                    gen_distinct_formulas(i+1);
                }
            } else if (i % 3 == 2) {
                 if (formula[i-1] != j && formula[i-2] != j) {
                    formula[i] = j;
                    gen_distinct_formulas(i+1);
                }
                if (formula[i-1] != -j && formula[i-2] != -j) {
                    formula[i] = -j;
                    gen_distinct_formulas(i+1);
                }               
            }
        }
    }
    else if (i == size) {
        evaluate_formula();
    }
}
Exemplo n.º 3
0
// Generating all 3-SAT formulas with nvars and nclauses
void gen_formulas(int i) {
    if (i < size) {
        for (int j = 1; j <= nvars; ++j) {
            formula[i] = j;
            gen_formulas(i+1);
            formula[i] = -j;
            gen_formulas(i+1);
        }
    }
    else if (i == size) {
        evaluate_formula();
    }
}
Exemplo n.º 4
0
void RegEditPanel::OnFormulaGenerate(bool checked)
{
    Q_UNUSED(checked);
    bool ok;
    int count = QInputDialog::getInt(this, "Instance generator", "Number of instances",
        0, 0, 100, 1, &ok);
    if(!ok)
        return;
    std::string name(m_ref.GetReg().name);
    size_t pos = name.find('n');
    if(pos == std::string::npos)
    {
        name.push_back('n');
        pos = name.size() - 1;
    }
    std::map< std::string, soc_word_t > map;
    std::vector< std::pair< std::string, soc_word_t > > list;
    std::string formula = m_ref.GetReg().formula.string;
    for(int n = 0; n < count; n++)
    {
        map["n"] = n;
        std::string err;
        soc_word_t res;
        if(!evaluate_formula(formula, map, res, err))
        {
            qDebug() << "Cannot evaluator " << QString::fromStdString(formula) 
                << "for n=" << n << ": " << QString::fromStdString(err);
            return;
        }
        std::string regname = name;
        std::string strn = QString("%1").arg(n).toStdString();
        regname.replace(pos, 1, strn);
        list.push_back(std::make_pair(regname, res));
    }
    // everything went good, commit result
    while(m_instances_table->rowCount() > 1)
        m_instances_table->removeRow(0);
    m_ref.GetReg().addr.resize(list.size());
    for(size_t i = 0; i < list.size(); i++)
    {
        m_instances_table->insertRow(i);
        m_ref.GetReg().addr[i].name = list[i].first;
        m_ref.GetReg().addr[i].addr = list[i].second;
        FillRow(i, m_ref.GetReg().addr[i]);
    }
}