mirror of
				https://github.com/Z3Prover/z3
				synced 2025-10-31 03:32:28 +00:00 
			
		
		
		
	add detection of non-fixed variables to consequence finding
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
		
							parent
							
								
									7562efbe84
								
							
						
					
					
						commit
						cb2d8d2107
					
				
					 10 changed files with 188 additions and 25 deletions
				
			
		|  | @ -23,9 +23,10 @@ Revision History: | |||
| #include"api_util.h" | ||||
| #include"api_model.h" | ||||
| #include"opt_context.h" | ||||
| #include"opt_cmds.h" | ||||
| #include"cancel_eh.h" | ||||
| #include"scoped_timer.h" | ||||
| 
 | ||||
| #include"smt2parser.h" | ||||
| 
 | ||||
| extern "C" { | ||||
| 
 | ||||
|  | @ -248,6 +249,53 @@ extern "C" { | |||
|         Z3_CATCH_RETURN(0); | ||||
|     } | ||||
| 
 | ||||
|     static void Z3_optimize_from_stream( | ||||
|         Z3_context    c, | ||||
|         Z3_optimize opt, | ||||
|         std::istream& s) { | ||||
|         ast_manager& m = mk_c(c)->m(); | ||||
|         cmd_context ctx(false, &m); | ||||
|         install_opt_cmds(ctx, to_optimize_ptr(opt)); | ||||
|         ctx.set_ignore_check(true); | ||||
|         if (!parse_smt2_commands(ctx, s)) { | ||||
|             SET_ERROR_CODE(Z3_PARSER_ERROR); | ||||
|             return; | ||||
|         }         | ||||
|         ptr_vector<expr>::const_iterator it  = ctx.begin_assertions(); | ||||
|         ptr_vector<expr>::const_iterator end = ctx.end_assertions(); | ||||
|         for (; it != end; ++it) { | ||||
|             to_optimize_ptr(opt)->add_hard_constraint(*it); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void Z3_API Z3_optimize_from_string( | ||||
|         Z3_context    c, | ||||
|         Z3_optimize   d, | ||||
|         Z3_string     s) { | ||||
|         Z3_TRY; | ||||
|         //LOG_Z3_optimize_from_string(c, d, s);
 | ||||
|         std::string str(s); | ||||
|         std::istringstream is(str); | ||||
|         Z3_optimize_from_stream(c, d, is); | ||||
|         Z3_CATCH; | ||||
|     } | ||||
| 
 | ||||
|     void Z3_API Z3_optimize_from_file( | ||||
|         Z3_context    c, | ||||
|         Z3_optimize   d, | ||||
|         Z3_string     s) { | ||||
|         Z3_TRY; | ||||
|         //LOG_Z3_optimize_from_file(c, d, s);
 | ||||
|         std::ifstream is(s); | ||||
|         if (!is) { | ||||
|             SET_ERROR_CODE(Z3_PARSER_ERROR); | ||||
|             return; | ||||
|         } | ||||
|         Z3_optimize_from_stream(c, d, is); | ||||
|         Z3_CATCH; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| }; | ||||
|  |  | |||
|  | @ -2035,6 +2035,8 @@ namespace z3 { | |||
|         } | ||||
|         stats statistics() const { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); } | ||||
|         friend std::ostream & operator<<(std::ostream & out, optimize const & s); | ||||
|         void from_file(char const* filename) { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); } | ||||
|         void from_string(char const* constraints) { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); } | ||||
|         std::string help() const { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error();  return r; } | ||||
|     }; | ||||
|     inline std::ostream & operator<<(std::ostream & out, optimize const & s) { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; } | ||||
|  |  | |||
|  | @ -273,6 +273,25 @@ namespace Microsoft.Z3 | |||
|             return Native.Z3_optimize_to_string(Context.nCtx, NativeObject); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Parse an SMT-LIB2 file with optimization objectives and constraints. | ||||
|         /// The parsed constraints and objectives are added to the optimization context. | ||||
|         /// </summary>                 | ||||
|         public void FromFile(string file) | ||||
|         { | ||||
|             Native.Z3_optimize_from_file(Context.nCtx, NativeObject, file); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Similar to FromFile. Instead it takes as argument a string. | ||||
|         /// </summary> | ||||
|         public void FromString(string s) | ||||
|         { | ||||
|             Native.Z3_optimize_from_string(Context.nCtx, NativeObject, s); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Optimize statistics. | ||||
|         /// </summary> | ||||
|  |  | |||
|  | @ -6755,6 +6755,14 @@ class Optimize(Z3PPObject): | |||
|             raise Z3Exception("Expecting objective handle returned by maximize/minimize") | ||||
|         return obj.upper() | ||||
| 
 | ||||
|     def from_file(self, filename): | ||||
|         """Parse assertions and objectives from a file""" | ||||
|         Z3_optimize_from_file(self.ctx.ref(), self.optimize, filename) | ||||
| 
 | ||||
|     def from_string(self, s): | ||||
|         """Parse assertions and objectives from a string""" | ||||
|         Z3_optimize_from_string(self.ctx.ref(), self.optimize, s) | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         """Return a formatted string with all added rules and constraints.""" | ||||
|         return self.sexpr() | ||||
|  |  | |||
|  | @ -197,6 +197,34 @@ extern "C" { | |||
|     */ | ||||
|     Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o); | ||||
| 
 | ||||
|     /**
 | ||||
|        \brief Parse an SMT-LIB2 string with assertions,  | ||||
|        soft constraints and optimization objectives. | ||||
|        Add the parsed constraints and objectives to the optimization context. | ||||
| 
 | ||||
|        \param c - context. | ||||
|        \param o - optimize context. | ||||
|        \param s - string containing SMT2 specification. | ||||
| 
 | ||||
|        def_API('Z3_optimize_from_string', VOID, (_in(CONTEXT), _in(OPTIMIZE), _in(STRING))) | ||||
|     */ | ||||
|     void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s); | ||||
| 
 | ||||
| 
 | ||||
|     /**
 | ||||
|        \brief Parse an SMT-LIB2 file with assertions,  | ||||
|        soft constraints and optimization objectives. | ||||
|        Add the parsed constraints and objectives to the optimization context. | ||||
| 
 | ||||
| 
 | ||||
|        \param c - context. | ||||
|        \param o - optimize context. | ||||
|        \param s - string containing SMT2 specification. | ||||
| 
 | ||||
|        def_API('Z3_optimize_from_file', VOID, (_in(CONTEXT), _in(OPTIMIZE), _in(STRING))) | ||||
|     */ | ||||
|     void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s); | ||||
| 
 | ||||
| 
 | ||||
|     /**
 | ||||
|        \brief Return a string containing a description of parameters accepted by optimize. | ||||
|  | @ -218,4 +246,4 @@ extern "C" { | |||
| } | ||||
| #endif // __cplusplus
 | ||||
| 
 | ||||
| #endif | ||||
| #endif | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue