43
43
the i-th entry.
44
44
*/
45
45
namespace lp {
46
+ template <typename T, typename K> bool contains (const T& t, K j) {
47
+ return t.find (j) != t.end ();
48
+ }
49
+
46
50
class dioph_eq ::imp {
47
51
// This class represents a term with an added constant number c, in form sum
48
52
// {x_i*a_i} + c.
@@ -280,20 +284,32 @@ namespace lp {
280
284
281
285
struct undo_add_term : public trail {
282
286
imp& m_s;
283
- lar_term m_t ;
284
- undo_add_term (imp& s, const lar_term &t): m_s(s), m_t (t) {
287
+ const lar_term* m_t ;
288
+ undo_add_term (imp& s, const lar_term *t): m_s(s), m_t (t) {
289
+ TRACE (" dioph_eq" , m_s.print_lar_term_L (*t, tout); tout << " t->j()=" << t->j () << std::endl;);
285
290
}
286
291
void undo () {
287
- TRACE (" dioph_eq" , m_s.lra .print_term (m_t , tout););
288
- for (const auto & p: m_t ) {
292
+ TRACE (" dioph_eq" , m_s.lra .print_term (*m_t , tout); tout << " , m_t->j() =" << m_t ->j () << std::endl;);
293
+ if (!contains (m_s.m_active_terms , m_t )) {
294
+ for (int i = m_s.m_added_terms .size () - 1 ; i >= 0 ; --i) {
295
+ if (m_s.m_added_terms [i] == m_t ) // the address is the same
296
+ if (i != m_s.m_added_terms .size () -1 ) m_s.m_added_terms [i] = m_s.m_added_terms .back ();
297
+ m_s.m_added_terms .pop_back ();
298
+ break ;
299
+ }
300
+ return ;
301
+ }
302
+ NOT_IMPLEMENTED_YET ();
303
+ for (const auto & p: m_t ->ext_coeffs ()) {
289
304
auto it = m_s.m_columns_to_terms .find (p.var ());
290
- it->second .erase (m_t .j ());
305
+ SASSERT (it != m_s.m_columns_to_terms .end ());
306
+ it->second .erase (m_t ->j ());
291
307
if (it->second .size () == 0 ) {
292
308
m_s.m_columns_to_terms .erase (it);
293
309
}
294
310
295
311
}
296
- }
312
+ }
297
313
};
298
314
299
315
@@ -319,23 +335,26 @@ namespace lp {
319
335
m_changed_columns.insert (j);
320
336
}
321
337
std_vector<const lar_term*> m_added_terms;
322
-
338
+ std::unordered_set< const lar_term*> m_active_terms;
323
339
std_vector<variable_branch_stats> m_branch_stats;
324
340
std_vector<branch> m_branch_stack;
325
341
std_vector<constraint_index> m_explanation_of_branches;
326
342
void add_term_delegate (const lar_term* t) {
327
343
unsigned j = t->j ();
328
344
TRACE (" dioph_eq" , tout << " term column t->j():" << j << std::endl; lra.print_term (*t, tout) << std::endl; );
329
- if (!lra.column_is_int (j) || !lra. column_has_term (j) ) {
330
- TRACE (" dioph_eq" , tout << " ignored" << std::endl;);
345
+ if (!lra.column_is_int (j)) {
346
+ TRACE (" dioph_eq" , tout << " ignored a non-integral column " << std::endl;);
331
347
return ;
332
348
}
349
+
350
+ CTRACE (" dioph_eq" , !lra.column_has_term (j), tout << " added term that is not associated with a column yet" << std::endl;);
351
+
333
352
if (!all_vars_are_int (*t)) {
334
353
TRACE (" dioph_eq" , tout << " not all vars are integrall\n " ;);
335
354
return ;
336
355
}
337
356
m_added_terms.push_back (t);
338
- auto undo = undo_add_term (*this , * t);
357
+ auto undo = undo_add_term (*this , t);
339
358
lra.trail ().push (undo);
340
359
}
341
360
@@ -371,7 +390,7 @@ namespace lp {
371
390
}
372
391
373
392
void register_columns_to_term (const lar_term& t) {
374
- TRACE (" dioph_eq" , tout << " register term:" ; lra.print_term (t, tout););
393
+ TRACE (" dioph_eq" , tout << " register term:" ; lra.print_term (t, tout); tout << " , t.j()= " << t. j () << std::endl; );
375
394
for (const auto &p: t.ext_coeffs ()) {
376
395
auto it = m_columns_to_terms.find (p.var ());
377
396
if (it != m_columns_to_terms.end ()) {
@@ -380,8 +399,7 @@ namespace lp {
380
399
else {
381
400
std::unordered_set<unsigned > s;
382
401
s.insert (t.j ());
383
- m_columns_to_terms[p.var ()] = s;
384
- TRACE (" dioph_eq" , tout << " insert " << p.var (););
402
+ m_columns_to_terms[p.var ()] = s;
385
403
}
386
404
}
387
405
}
@@ -450,9 +468,6 @@ namespace lp {
450
468
SASSERT (entry_invariant (ei));
451
469
}
452
470
453
- template <typename T> bool contains (const T& t, unsigned j) {
454
- return t.find (j) != t.end ();
455
- }
456
471
457
472
void process_changed_columns () {
458
473
for (unsigned j : m_changed_columns) {
@@ -482,11 +497,6 @@ namespace lp {
482
497
}
483
498
}
484
499
485
- for (const lar_term* t : m_added_terms) {
486
- register_columns_to_term (*t);
487
- }
488
-
489
- SASSERT (is_in_sync ());
490
500
TRACE (" dioph_eq" , tout << " entries_to_recalculate:" ; for (unsigned j : entries_to_recalculate) {tout << " " << j;});
491
501
for (unsigned j = 0 ; j < m_fresh_definitions.size (); j++) {
492
502
const fresh_definition& fd = m_fresh_definitions[j];
@@ -558,8 +568,13 @@ namespace lp {
558
568
m_lra_level = 0 ;
559
569
process_changed_columns ();
560
570
for (const lar_term* t: m_added_terms) {
571
+ m_active_terms.insert (t);
561
572
fill_entry (*t);
573
+ register_columns_to_term (*t);
562
574
}
575
+
576
+ SASSERT (is_in_sync ());
577
+
563
578
m_added_terms.clear ();
564
579
SASSERT (entries_are_ok ());
565
580
}
@@ -1298,6 +1313,7 @@ namespace lp {
1298
1313
for (unsigned k = 0 ; k < lra.terms ().size (); k ++ ) {
1299
1314
const lar_term* t = lra.terms ()[k];
1300
1315
if (!all_vars_are_int (*t)) continue ;
1316
+ SASSERT (t->j () != UINT_MAX);
1301
1317
for (const auto & p: (*t).ext_coeffs ()) {
1302
1318
unsigned j = p.var ();
1303
1319
auto it = c2t.find (j);
0 commit comments