mirror of
https://github.com/Z3Prover/z3
synced 2025-05-04 06:15:46 +00:00
adding model-based opt facility
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
51e34e8b5f
commit
68c7d64d00
11 changed files with 465 additions and 227 deletions
102
src/math/simplex/model_based_opt.h
Normal file
102
src/math/simplex/model_based_opt.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*++
|
||||
Copyright (c) 2016 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
model_based_opt.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Model-based optimization for linear real arithmetic.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2016-27-4
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef __MODEL_BASED_OPT_H__
|
||||
#define __MODEL_BASED_OPT_H__
|
||||
|
||||
#include "util.h"
|
||||
#include "rational.h"
|
||||
|
||||
namespace opt {
|
||||
|
||||
enum ineq_type {
|
||||
t_eq,
|
||||
t_lt,
|
||||
t_le
|
||||
};
|
||||
|
||||
enum bound_type {
|
||||
unbounded,
|
||||
strict,
|
||||
non_strict
|
||||
};
|
||||
|
||||
class model_based_opt {
|
||||
public:
|
||||
struct var {
|
||||
unsigned m_id;
|
||||
rational m_coeff;
|
||||
var(unsigned id, rational const& c): m_id(id), m_coeff(c) {}
|
||||
};
|
||||
private:
|
||||
struct row {
|
||||
vector<var> m_vars; // variables with coefficients
|
||||
rational m_coeff; // constant in inequality
|
||||
ineq_type m_type; // inequality type
|
||||
rational m_value; // value of m_vars + m_coeff under interpretation of m_var2value.
|
||||
bool m_alive; // rows can be marked dead if they have been processed.
|
||||
};
|
||||
vector<row> m_rows;
|
||||
vector<unsigned_vector> m_var2row_ids;
|
||||
vector<rational> m_var2value;
|
||||
row m_objective;
|
||||
vector<var> m_new_vars;
|
||||
|
||||
bool invariant();
|
||||
bool invariant(row const& r);
|
||||
|
||||
|
||||
bool find_bound(unsigned x, unsigned& bound_index, unsigned_vector& other, bool is_pos);
|
||||
|
||||
rational get_coefficient(unsigned row_id, unsigned var_id);
|
||||
|
||||
bool resolve(unsigned row_id1, rational const& a1, unsigned row_id2, unsigned x);
|
||||
|
||||
void multiply(rational const& c, unsigned row_id);
|
||||
|
||||
void add(unsigned row_id1, unsigned row_id2);
|
||||
|
||||
public:
|
||||
|
||||
// add a fresh variable with value 'value'.
|
||||
unsigned add_var(rational const& value);
|
||||
|
||||
// add a constraint. We assume that the constraint is
|
||||
// satisfied under the values provided to the variables.
|
||||
void add_constraint(vector<var> const& coeffs, rational const& c, ineq_type r);
|
||||
|
||||
// Set the objective function (linear).
|
||||
void set_objective(vector<var> const& coeffs, rational const& c);
|
||||
|
||||
// find a maximal value for the objective function over the current values.
|
||||
// in other words, the returned maximal value may not be globally optimal,
|
||||
// but the current evaluation of variables are used to select a local
|
||||
// optimal.
|
||||
bound_type maximize(rational& value);
|
||||
|
||||
|
||||
void display(std::ostream& out) const;
|
||||
void display(std::ostream& out, row const& r) const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue