Пример #1
0
bool glpk_wrapper::is_linear(Enode * const e) {
    bool is_eq = e->isEq() && (!e->hasPolarity() || e->getPolarity() != l_False);
    return
        (is_eq || e->isLeq()) &&
        is_expr_linear(e->get1st()) &&
        is_expr_linear(e->get2nd());
}
Пример #2
0
void glpk_wrapper::set_objective(Enode * const e) {
    assert(is_expr_linear(e));
    LAExpression la(e);
    for (auto it = la.begin(); it != la.end(); ++it) {
        auto v = it->first;
        auto c = it->second;
        if (v != nullptr) {
            glp_set_obj_coef(lp, get_index(v) + 1, c);
        }
    }
}
Пример #3
0
bool glpk_wrapper::is_expr_linear(Enode * const t) {
    if ( t->isPlus() ) {
        for (Enode * arg_list = t->getCdr(); !arg_list->isEnil(); arg_list = arg_list->getCdr()) {
            if (!is_expr_linear(arg_list->getCar())) {
                return false;
            }
        }
        return true;
    } else if ( t->isTimes() ) {
        Enode * x = t->get1st();
        Enode * y = t->get2nd();
        if ( x->isConstant() ) {
            return is_expr_linear(y);
        } else if ( y->isConstant() ) {
            return is_expr_linear(x);
        } else {
            return false;
        }
    } else {
        return t->isVar() || t->isConstant();
    }
}
Пример #4
0
void glpk_wrapper::set_objective(Enode * const e) {
    changed = true;
    for (unsigned int i = 1; i <= domain.size(); i++) {
        glp_set_obj_coef(lp, i, 0);
    }
    if (e != nullptr) {
        assert(is_expr_linear(e));
        LAExpression la(e);
        for (auto it = la.begin(); it != la.end(); ++it) {
            auto v = it->first;
            auto c = it->second;
            if (v != nullptr) {
                glp_set_obj_coef(lp, get_index(v) + 1, c);
            }
        }
    }
}