@@ -106,9 +106,7 @@ namespace nlsat {
106
106
anum_manager& m_am;
107
107
mutable assumption_manager m_asm;
108
108
assignment m_assignment, m_lo, m_hi; // partial interpretation
109
- assignment m_debug_assignment;
110
109
mutable evaluator m_evaluator;
111
- mutable evaluator m_debug_evaluator;
112
110
interval_set_manager & m_ism;
113
111
ineq_atom_table m_ineq_atoms;
114
112
root_atom_table m_root_atoms;
@@ -242,50 +240,7 @@ namespace nlsat {
242
240
};
243
241
// statistics
244
242
stats m_stats;
245
- std::unordered_map<std::string, anum> m_debug_known_sat_anum_map;
246
- std::unordered_map<std::string, lbool> m_debug_known_sat_bool_non_pure_atom_vals;
247
- std::unordered_map<unsigned , lbool> m_debug_pure_bool_vals;
248
- std::string m_debug_known_sol_file_name;
249
- const anum & debug_get_known_sat_anum_value (unsigned j) {
250
- std::string name = debug_get_var_name (j);
251
-
252
- auto it = m_debug_known_sat_anum_map.find (name);
253
- if (it != m_debug_known_sat_anum_map.end ())
254
- return it->second ;
255
- else
256
- UNREACHABLE ();
257
- return it->second ;
258
- }
259
-
260
- lbool debug_get_known_literal_value (literal l) {
261
- std::string atom_string = debug_atom_string (l.var ());
262
- auto it = m_debug_known_sat_bool_non_pure_atom_vals.find (atom_string);
263
- if (it == m_debug_known_sat_bool_non_pure_atom_vals.end ())
264
- return l_undef;
265
- if (it->second == l_false) {
266
- if (l.sign ())
267
- return l_true;
268
- return l_false;
269
- } else if (it->second == l_true) {
270
- if (l.sign ())
271
- return l_false;
272
- return l_true;
273
- } else
274
- UNREACHABLE ();
275
-
276
- return l_undef;
277
- }
278
-
279
- void debug_set_known_sat_values () {
280
- std::vector<std::pair<std::string, anum>> var_sat_values = debug_parse_var_anum_file ();
281
-
282
- for (auto const & kv : var_sat_values) {
283
- anum val;
284
- // Convert kv.second to an anum using m_am
285
- m_am.set (val, kv.second );
286
- m_debug_known_sat_anum_map[kv.first ] = val;
287
- }
288
- }
243
+ std::string m_debug_known_solution_file_name;
289
244
290
245
imp (solver& s, ctx& c):
291
246
m_ctx (c),
@@ -299,9 +254,7 @@ namespace nlsat {
299
254
m_am (c.m_am),
300
255
m_asm (*this , m_allocator),
301
256
m_assignment (m_am), m_lo(m_am), m_hi(m_am),
302
- m_debug_assignment (m_am),
303
257
m_evaluator (s, m_assignment, m_pm, m_allocator),
304
- m_debug_evaluator (s, m_debug_assignment, m_pm, m_allocator),
305
258
m_ism (m_evaluator.ism()),
306
259
m_num_bool_vars (0 ),
307
260
m_simplify (s, m_atoms, m_clauses, m_learned, m_pm),
@@ -316,8 +269,6 @@ namespace nlsat {
316
269
reset_statistics ();
317
270
mk_true_bvar ();
318
271
m_lemma_count = 0 ;
319
- if (!m_debug_known_sol_file_name.empty ())
320
- debug_set_known_sat_values ();
321
272
}
322
273
323
274
~imp () {
@@ -357,7 +308,7 @@ namespace nlsat {
357
308
m_explain.set_minimize_cores (min_cores);
358
309
m_explain.set_factor (p.factor ());
359
310
m_am.updt_params (p.p );
360
- m_debug_known_sol_file_name = p.debug_known_sol_file ();
311
+ m_debug_known_solution_file_name = p.debug_known_sol_file ();
361
312
}
362
313
363
314
void reset () {
@@ -925,14 +876,6 @@ namespace nlsat {
925
876
bool_var operator [](bool_var v) const { return vec[v]; }
926
877
};
927
878
928
- void debug_set_debug_assignment_to_known_vals () {
929
- m_debug_assignment.reset ();
930
- for (var x = 0 ; x < num_vars (); ++x) {
931
- const anum& dval = debug_get_known_sat_anum_value (x);
932
- m_debug_assignment.set (x, dval);
933
- }
934
- }
935
-
936
879
std::vector<unsigned > collect_vars (literal l) {
937
880
var_vector vars;
938
881
this ->vars (l, vars);
@@ -975,21 +918,75 @@ namespace nlsat {
975
918
// At least one literal has to be evaluate to true.
976
919
// The method might ignore a lemma with pure boolean varibles.
977
920
void debug_check_lemma_on_known_sat_values (unsigned n_of_literals, literal const *cls, assumption_set a) {
978
- debug_set_debug_assignment_to_known_vals ();
979
921
SASSERT (a == nullptr );
922
+
923
+ // If no debug file is specified, just return
924
+ if (m_debug_known_solution_file_name.empty ())
925
+ return ;
926
+
927
+ // Create local debug objects
928
+ assignment debug_assignment (m_am);
929
+ evaluator debug_evaluator (m_solver, debug_assignment, m_pm, m_allocator);
930
+
931
+ // Parse the debug file to get known variable values
932
+ std::vector<std::pair<std::string, anum>> var_sat_values;
933
+ std::ifstream in (m_debug_known_solution_file_name);
934
+ std::string line;
935
+ while (std::getline (in, line)) {
936
+ std::istringstream iss (line);
937
+ std::string name, value_str;
938
+ if (!(iss >> name >> value_str)) {
939
+ std::cout << line << std::endl;
940
+ std::cout << " is not recognized\n " ;
941
+ exit (1 );
942
+ }
943
+ // Parse rational value
944
+ rational r;
945
+ size_t slash = value_str.find (' /' );
946
+ if (slash == std::string::npos) {
947
+ r = rational (value_str.c_str ());
948
+ } else {
949
+ std::string num = value_str.substr (0 , slash);
950
+ std::string den = value_str.substr (slash + 1 );
951
+ r = rational (num.c_str ()) / rational (den.c_str ());
952
+ }
953
+ anum a;
954
+ const auto & q = r.to_mpq ();
955
+ m_am.set (a, q);
956
+ var_sat_values.emplace_back (name, a);
957
+ }
958
+
959
+ // Build a map from variable names to their known values
960
+ std::unordered_map<std::string, anum> debug_known_sat_anum_map;
961
+ for (auto const & kv : var_sat_values) {
962
+ anum val;
963
+ m_am.set (val, kv.second );
964
+ debug_known_sat_anum_map[kv.first ] = val;
965
+ }
966
+
967
+ // Set up the debug assignment with known values
968
+ debug_assignment.reset ();
969
+ for (var x = 0 ; x < num_vars (); ++x) {
970
+ std::string name = debug_get_var_name (x);
971
+ auto it = debug_known_sat_anum_map.find (name);
972
+ if (it != debug_known_sat_anum_map.end ()) {
973
+ debug_assignment.set (x, it->second );
974
+ }
975
+ }
976
+
980
977
bool satisfied = false ;
981
978
for (unsigned i = 0 ; i < n_of_literals && !satisfied; ++i) {
982
979
literal l = cls[i];
983
980
bool_var b = l.var ();
984
981
atom* a = m_atoms[b];
985
982
if (a == nullptr )
986
- return ; // ignore lemmas with pure booleal variables
983
+ return ; // ignore lemmas with pure boolean variables
987
984
988
985
lbool val = l_undef;
989
986
// Arithmetic atom: evaluate directly
990
987
var max = a->max_var ();
991
- SASSERT (m_debug_assignment .is_assigned (max));
992
- val = to_lbool (m_debug_evaluator .eval (a, l.sign ()));
988
+ SASSERT (debug_assignment .is_assigned (max));
989
+ val = to_lbool (debug_evaluator .eval (a, l.sign ()));
993
990
SASSERT (val != l_undef);
994
991
if (val == l_true)
995
992
satisfied = true ;
@@ -998,7 +995,7 @@ namespace nlsat {
998
995
m_display_var.m_proc = nullptr ;
999
996
std::cout << " Known sat assignment does not satisfy valid lemma!\n " ;
1000
997
display (std::cout, n_of_literals, cls) << " \n " ;
1001
- display_assignment_on_clause (std::cout, m_debug_assignment , n_of_literals, cls);
998
+ display_assignment_on_clause (std::cout, debug_assignment , n_of_literals, cls);
1002
999
exit (1 );
1003
1000
}
1004
1001
}
@@ -1357,16 +1354,10 @@ namespace nlsat {
1357
1354
\brief Assign literal to true using the given justification
1358
1355
*/
1359
1356
void set_literal_to_true (literal l, justification j) {
1360
- if (!m_debug_known_sol_file_name.empty ())
1361
- debug_set_debug_assignment_to_known_vals ();
1362
1357
TRACE (" nlsat_assign" ,
1363
1358
tout << " literal" << l << " \n " ;
1364
1359
display (tout << " assigning literal to true: " , l) << " \n " ;
1365
- display (tout << " <- " , j);
1366
- auto known_val = debug_get_known_literal_value (l);
1367
- if (known_val != l_undef) {
1368
- tout << " known val of literal is " << known_val << " \n " ;
1369
- });
1360
+ display (tout << " <- " , j););
1370
1361
1371
1362
SASSERT (assigned_value (l) == l_undef);
1372
1363
SASSERT (j != null_justification);
@@ -1578,12 +1569,11 @@ namespace nlsat {
1578
1569
atom * a = m_atoms[b];
1579
1570
SASSERT (a != nullptr );
1580
1571
interval_set_ref curr_set (m_ism);
1581
- curr_set = m_evaluator.infeasible_intervals (a, l.sign (), &cls);
1582
- TRACE (" nlsat_inf_set" ,
1572
+ curr_set = m_evaluator.infeasible_intervals (a, l.sign (), &cls);
1573
+ TRACE (" nlsat_inf_set" ,
1583
1574
tout << " infeasible set for literal: " ; display (tout, l); tout << " \n " ; m_ism.display (tout, curr_set); tout << " \n " ;
1584
1575
display (tout << " cls: " , cls) << " \n " ;
1585
- tout << " m_xk:" << m_xk << " (" << debug_get_var_name (m_xk) << " )" << " \n " ;
1586
- tout << " known deb value of the literal is: " << debug_get_known_literal_value (l) << " \n " ;);
1576
+ tout << " m_xk:" << m_xk << " (" << debug_get_var_name (m_xk) << " )" << " \n " ;);
1587
1577
if (m_ism.is_empty (curr_set)) {
1588
1578
TRACE (" nlsat_inf_set" , tout << " infeasible set is empty, found literal\n " ;);
1589
1579
R_propagate (l, nullptr );
@@ -1700,18 +1690,6 @@ namespace nlsat {
1700
1690
}
1701
1691
}
1702
1692
1703
- bool debug_set_known_sat_value_to_xk_ () {
1704
- const anum& dw = debug_get_known_sat_anum_value (m_xk);
1705
- bool can_use = m_ism.contains_in_complement (m_infeasible[m_xk], false , dw);
1706
- if (!can_use){
1707
- return false ;
1708
- }
1709
- anum val;
1710
- m_am.set (val, dw);
1711
- m_assignment.set_core (m_xk, val);
1712
- return true ;
1713
- }
1714
-
1715
1693
/* *
1716
1694
\brief Assign m_xk
1717
1695
*/
@@ -4077,7 +4055,7 @@ namespace nlsat {
4077
4055
4078
4056
std::vector<std::pair<std::string, anum>> debug_parse_var_anum_file () {
4079
4057
std::vector<std::pair<std::string, anum>> result;
4080
- std::ifstream in (m_debug_known_sol_file_name );
4058
+ std::ifstream in (m_debug_known_solution_file_name );
4081
4059
std::string line;
4082
4060
while (std::getline (in, line)) {
4083
4061
std::istringstream iss (line);
0 commit comments