Ejemplo n.º 1
0
static void check_random_ineqs(random_gen& r, ast_manager& m, unsigned num_vars, unsigned max_value, unsigned num_ineqs, unsigned max_vars, unsigned max_coeff) {
    opt::model_based_opt mbo;
    expr_ref_vector fmls(m);

    svector<int> values;
    for (unsigned i = 0; i < num_vars; ++i) {
        values.push_back(r(max_value + 1));
        mbo.add_var(rational(values.back()));
    }
    for (unsigned i = 0; i < num_ineqs; ++i) {
        add_random_ineq(fmls, mbo, r, values, max_vars, max_coeff);
    }

    vector<var_t> vars;
    vars.reset();
    vars.push_back(var_t(0, rational(2)));
    vars.push_back(var_t(1, rational(-2)));
    mbo.set_objective(vars, rational(0));
       

    mbo.display(std::cout);
    app_ref t(m);
    mk_term(vars, rational(0), t);
    
    test_maximize(mbo, m, num_vars, fmls, t);
    
    for (unsigned i = 0; i < values.size(); ++i) {
        std::cout << i << ": " << values[i] << " -> " << mbo.get_value(i) << "\n";
    }
}
Ejemplo n.º 2
0
static void check_random_ineqs(random_gen& r, unsigned num_vars, unsigned max_value, unsigned num_ineqs, unsigned max_vars, unsigned max_coeff) {
    opt::model_based_opt mbo;
    svector<int> values;
    for (unsigned i = 0; i < num_vars; ++i) {
        values.push_back(r(max_value + 1));
        mbo.add_var(rational(values.back()));
    }
    for (unsigned i = 0; i < num_ineqs; ++i) {
        add_random_ineq(mbo, r, values, max_vars, max_coeff);
    }

    vector<var> vars;
    vars.reset();
    vars.push_back(var(0, rational(2)));
    vars.push_back(var(1, rational(-2)));
    mbo.set_objective(vars, rational(0));

    mbo.display(std::cout);
    opt::inf_eps value = mbo.maximize();    
    std::cout << "optimal: " << value << "\n";
    mbo.display(std::cout);
    for (unsigned i = 0; i < values.size(); ++i) {
        std::cout << i << ": " << values[i] << " -> " << mbo.get_value(i) << "\n";
    }
}