mirror of
				https://github.com/Z3Prover/z3
				synced 2025-10-31 03:32:28 +00:00 
			
		
		
		
	Add support for initializing variable values in solver and optimize contexts in Z3
This commit is contained in:
		
							parent
							
								
									342dccdc02
								
							
						
					
					
						commit
						0c48a50d59
					
				
					 12 changed files with 98 additions and 9 deletions
				
			
		|  | @ -330,10 +330,7 @@ public: | |||
|     void set_next_arg(cmd_context& ctx, expr* e) override { if (m_var) m_value = e; else m_var = e; } | ||||
|     void execute(cmd_context& ctx) override { | ||||
|         SASSERT(m_var && m_value); | ||||
|         if (ctx.get_opt()) | ||||
|             ctx.get_opt()->initialize_value(m_var, m_value); | ||||
|         else if (ctx.get_solver()) | ||||
|             ctx.get_solver()->user_propagate_initialize_value(m_var, m_value); | ||||
|         ctx.set_initial_value(m_var, m_value); | ||||
|     }     | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -629,6 +629,7 @@ cmd_context::~cmd_context() { | |||
|     finalize_cmds(); | ||||
|     finalize_tactic_manager(); | ||||
|     m_proof_cmds = nullptr; | ||||
|     m_var2values.reset(); | ||||
|     reset(true); | ||||
|     m_mcs.reset(); | ||||
|     m_solver = nullptr; | ||||
|  | @ -654,6 +655,8 @@ void cmd_context::set_opt(opt_wrapper* opt) { | |||
|     m_opt = opt; | ||||
|     for (unsigned i = 0; i < m_scopes.size(); ++i)  | ||||
|         m_opt->push(); | ||||
|     for (auto const& [var, value] : m_var2values) | ||||
|         m_opt->initialize_value(var, value); | ||||
|     m_opt->set_logic(m_logic); | ||||
| } | ||||
| 
 | ||||
|  | @ -1874,6 +1877,17 @@ void cmd_context::display_dimacs() { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| void cmd_context::set_initial_value(expr* var, expr* value) { | ||||
|     if (get_opt()) { | ||||
|         get_opt()->initialize_value(var, value); | ||||
|         return; | ||||
|     } | ||||
|     if (get_solver())  | ||||
|         get_solver()->user_propagate_initialize_value(var, value); | ||||
|     m_var2values.push_back({expr_ref(var, m()), expr_ref(value, m())});     | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void cmd_context::display_model(model_ref& mdl) { | ||||
|     if (mdl) { | ||||
|         if (mc0()) (*mc0())(mdl); | ||||
|  |  | |||
|  | @ -262,6 +262,7 @@ protected: | |||
|     scoped_ptr_vector<builtin_decl> m_extra_builtin_decls; // make sure that dynamically allocated builtin_decls are deleted
 | ||||
|     dictionary<object_ref*>      m_object_refs; // anything that can be named.
 | ||||
|     dictionary<sexpr*>           m_user_tactic_decls; | ||||
|     vector<std::pair<expr_ref, expr_ref>> m_var2values; | ||||
| 
 | ||||
|     dictionary<func_decls>       m_func_decls; | ||||
|     obj_map<func_decl, symbol>   m_func_decl2alias; | ||||
|  | @ -421,6 +422,7 @@ public: | |||
|     solver* get_solver() { return m_solver.get(); } | ||||
|     void set_solver(solver* s) { m_solver = s; } | ||||
|     void set_proof_cmds(proof_cmds* pc) { m_proof_cmds = pc; } | ||||
|     void set_initial_value(expr* var, expr* value); | ||||
| 
 | ||||
|     void set_solver_factory(solver_factory * s); | ||||
|     void set_check_sat_result(check_sat_result * r) { m_check_sat_result = r; } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue