simulation.cc 41.5 KB
Newer Older
Thomas Badie's avatar
Thomas Badie committed
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et Développement
Thomas Badie's avatar
Thomas Badie committed
3
// de l'Epita (LRDE).
Thomas Badie's avatar
Thomas Badie committed
4
5
6
7
8
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 3 of the License, or
Thomas Badie's avatar
Thomas Badie committed
10
11
12
13
14
15
16
17
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
18
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
Thomas Badie's avatar
Thomas Badie committed
19
20
21
22

#include <queue>
#include <map>
#include <utility>
Thomas Badie's avatar
Thomas Badie committed
23
24
#include <cmath>
#include <limits>
Thomas Badie's avatar
Thomas Badie committed
25
#include "simulation.hh"
26
#include "priv/acccompl.hh"
Thomas Badie's avatar
Thomas Badie committed
27
28
29
#include "misc/minato.hh"
#include "tgba/bddprint.hh"
#include "tgbaalgos/reachiter.hh"
30
#include "tgbaalgos/sccfilter.hh"
31
#include "tgbaalgos/sccinfo.hh"
Thomas Badie's avatar
Thomas Badie committed
32
#include "tgbaalgos/dupexp.hh"
Thomas Badie's avatar
Thomas Badie committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

// The way we developed this algorithm is the following: We take an
// automaton, and reverse all these acceptance conditions.  We reverse
// them to go make the meaning of the signature easier. We are using
// bdd, and we want to let it make all the simplification. Because of
// the format of the acceptance condition, it doesn't allow easy
// simplification. Instead of encoding them as: "a!b!c + !ab!c", we
// use them as: "ab". We complement them because we want a
// simplification if the condition of the transition A implies the
// transition of B, and if the acceptance condition of A is included
// in the acceptance condition of B. To let the bdd makes the job, we
// revert them.

// Then, to check if a transition i-dominates another, we'll use the bdd:
// "sig(transA) = cond(trans) & acc(trans) & implied(class(trans->state))"
// Idem for sig(transB). The 'implied'
// (represented by a hash table 'relation_' in the implementation) is
// a conjunction of all the class dominated by the class of the
// destination. This is how the relation is included in the
// signature. It makes the simplifications alone, and the work is
// done.  The algorithm is cut into several step:
//
// 1. Run through the tgba and switch the acceptance condition to their
//    negation, and initializing relation_ by the 'init_ -> init_' where
//    init_ is the bdd which represents the class. This function is the
//    constructor of Simulation.
// 2. Enter in the loop (run).
//    - Rename the class.
//    - run through the automaton and computing the signature of each
//      state. This function is `update_sig'.
//    - Enter in a double loop to adapt the partial order, and set
//      'relation_' accordingly. This function is `update_po'.
65
// 3. Rename the class (to actualize the name in the previous_class and
Thomas Badie's avatar
Thomas Badie committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//    in relation_).
// 4. Building an automaton with the result, with the condition:
// "a transition in the original automaton appears in the simulated one
// iff this transition is included in the set of i-maximal neighbour."
// This function is `build_output'.
// The automaton simulated is recomplemented to come back to its initial
// state when the object Simulation is destroyed.
//
// Obviously these functions are possibly cut into several little one.
// This is just the general development idea.

// How to use isop:
// I need all variable non_acceptance & non_class.
// bdd_support(sig(X)): All var
// bdd_support(sig(X)) - allacc - allclassvar


Thomas Badie's avatar
Thomas Badie committed
83
84
85
86
// TODO LIST: Play on the order of the selection in the
// dont_care_simulation. The good place to work is in add_to_map_imply.


Thomas Badie's avatar
Thomas Badie committed
87
88
89
90
91
92
93
namespace spot
{
  namespace
  {
    // Some useful typedef:

    // Used to get the signature of the state.
94
    typedef std::vector<bdd> vector_state_bdd;
Thomas Badie's avatar
Thomas Badie committed
95

96
97
    typedef std::vector<const state*> vector_state_state;

Thomas Badie's avatar
Thomas Badie committed
98

Thomas Badie's avatar
Thomas Badie committed
99
    // Get the list of state for each class.
100
    typedef std::map<bdd, std::list<unsigned>,
Thomas Badie's avatar
Thomas Badie committed
101
102
                     bdd_less_than> map_bdd_lstate;

103
    typedef std::map<bdd, unsigned, bdd_less_than> map_bdd_state;
Thomas Badie's avatar
Thomas Badie committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

    // Our constraint: (state_src, state_dst) = to_add.
    // We define the couple of state as the key of the constraint.
    typedef std::pair<const state*, const state*> constraint_key;

    // But we need a comparator for that key.
    struct constraint_key_comparator
    {
      bool operator()(const constraint_key& l,
                      const constraint_key& r) const
      {
        if (l.first->compare(r.first) < 0)
          return true;
        else
          if (l.first->compare(r.first) > 0)
            return false;

        if (l.second->compare(r.second) < 0)
          return true;
        else
          if (l.second->compare(r.second) > 0)
            return false;

        return false;
      }
    };

    // The full definition of the constraint.
    typedef std::map<constraint_key, bdd,
                     constraint_key_comparator> map_constraint;

135
    typedef std::tuple<const state*, const state*, bdd> constraint;
Thomas Badie's avatar
Thomas Badie committed
136
137
138
139
140
141

    // Helper to create the map of constraints to give to the
    // simulation.
    void add_to_map(const std::list<constraint>& list,
                    map_constraint& feed_me)
    {
142
      for (auto& p: list)
143
144
145
	feed_me.emplace(std::make_pair(std::get<0>(p),
				       std::get<1>(p)),
			std::get<2>(p));
Thomas Badie's avatar
Thomas Badie committed
146
147
148
149
150
    }


    // This class helps to compare two automata in term of
    // size.
151
152
153
154
155
156
157
158
    struct automaton_size
    {
      automaton_size()
        : transitions(0),
          states(0)
      {
      }

159
160
161
162
163
164
165
166
167
168
169
170
      automaton_size(const tgba_digraph_ptr& a)
        : transitions(a->num_transitions()),
          states(a->num_states())
      {
      }

      void set_size(const tgba_digraph_ptr& a)
      {
	states = a->num_states();
	transitions = a->num_transitions();
      }

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
171
      inline bool operator!=(const automaton_size& r)
172
173
174
175
      {
        return transitions != r.transitions || states != r.states;
      }

Thomas Badie's avatar
Thomas Badie committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
      inline bool operator<(const automaton_size& r)
      {
        if (states < r.states)
          return true;
        if (states > r.states)
          return false;

        if (transitions < r.transitions)
          return true;
        if (transitions > r.transitions)
          return false;

        return false;
      }

      inline bool operator>(const automaton_size& r)
      {
        if (states < r.states)
          return false;
        if (states > r.states)
          return true;

        if (transitions < r.transitions)
          return false;
        if (transitions > r.transitions)
          return true;

        return false;
      }

206
207
208
      int transitions;
      int states;
    };
Thomas Badie's avatar
Thomas Badie committed
209

Thomas Badie's avatar
Thomas Badie committed
210
    // The direct_simulation. If Cosimulation is true, we are doing a
211
212
    // cosimulation.
    template <bool Cosimulation, bool Sba>
213
    class direct_simulation
Thomas Badie's avatar
Thomas Badie committed
214
    {
Thomas Badie's avatar
Thomas Badie committed
215
    protected:
216
217
      // Shortcut used in update_po and go_to_next_it.
      typedef std::map<bdd, bdd, bdd_less_than> map_bdd_bdd;
218
      int acc_vars;
219
    public:
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

      bdd mark_to_bdd(acc_cond::mark_t m)
      {
	// FIXME: Use a cache.
	bdd res = bddtrue;
	for (auto n: a_->acc().sets(m))
	  res &= bdd_ithvar(acc_vars + n);
	return res;
      }

      acc_cond::mark_t bdd_to_mark(const tgba_digraph_ptr& aut, bdd b)
      {
	// FIXME: Use a cache.
	std::vector<unsigned> res;
	while (b != bddtrue)
	  {
	    res.push_back(bdd_var(b) - acc_vars);
	    b = bdd_high(b);
	  }
	return aut->acc().marks(res.begin(), res.end());
      }

242
243
      direct_simulation(const const_tgba_ptr& t,
			const map_constraint* map_cst = 0)
Thomas Badie's avatar
Thomas Badie committed
244
245
246
247
        : a_(0),
          po_size_(0),
          all_class_var_(bddtrue),
          map_cst_(map_cst),
248
          original_(t)
249
      {
250
        // We need to do a dupexp for being able to run scc_info later.
Thomas Badie's avatar
Thomas Badie committed
251
252
253
254
255
        // new_original_ is the map that contains the relation between
        // the names (addresses) of the states in the automaton
        // returned by dupexp, and in automaton given in argument to
        // the constructor.
        a_ = tgba_dupexp_dfs(t, new_original_);
256
        scc_info_.reset(new scc_info(a_));
Thomas Badie's avatar
Thomas Badie committed
257
258
        old_a_ = a_;

259

260
261
262
263
264
	// Replace all the acceptance conditions by their complements.
	// (In the case of Cosimulation, we also flip the transitions.)
	{
	  if (Cosimulation)
	    {
265
	      a_ = make_tgba_digraph(a_->get_dict());
266
	      a_->copy_ap_of(old_a_);
267
268
	      a_->copy_acceptance_conditions_of(old_a_);
	    }
269
	  unsigned ns = old_a_->num_states();
270
	  if (Cosimulation)
271
	    a_->new_states(ns);
272
273
	  for (unsigned s = 0; s < ns; ++s)
	    {
274
	      for (auto& t: old_a_->out(s))
275
		{
276
		  acc_cond::mark_t acc;
277
278
279
280
281
282
283
284
		  if (Sba && Cosimulation)
		    {
		      // If the acceptance is interpreted as
		      // state-based, to apply the reverse simulation
		      // on a SBA, we should pull the acceptance of
		      // the destination state on its incoming arcs
		      // (which now become outgoing arcs after
		      // transposition).
285
		      acc = 0U;
286
		      for (auto& td: old_a_->out(t.dst))
287
			{
288
			  acc = old_a_->acc().comp(td.acc);
289
290
291
292
293
			  break;
			}
		    }
		  else
		    {
294
		      acc = old_a_->acc().comp(t.acc);
295
296
		    }
		  if (Cosimulation)
297
		    a_->new_transition(t.dst, s, t.cond, acc);
298
299
300
301
302
303
		  else
		    t.acc = acc;
		}
	    }
	  size_a_ = ns;
	}
304
305
306
307
308

	// Now, we have to get the bdd which will represent the
	// class. We register one bdd by state, because in the worst
	// case, |Class| == |State|.
	unsigned set_num = a_->get_dict()
309
	  ->register_anonymous_variables(size_a_ + 1, this);
310

311
312
313
314
315
316
317
	unsigned n_acc = a_->acc().num_sets();
	acc_vars = a_->get_dict()
	  ->register_anonymous_variables(n_acc, this);

	all_proms_ = bddtrue;
	for (unsigned v = acc_vars; v < acc_vars + n_acc; ++v)
	  all_proms_ &= bdd_ithvar(v);
Thomas Badie's avatar
Thomas Badie committed
318

Thomas Badie's avatar
Thomas Badie committed
319
320
        bdd_initial = bdd_ithvar(set_num++);
	bdd init = bdd_ithvar(set_num++);
321
322
323

	used_var_.push_back(init);

324
325
326
327
	// Initialize all classes to init.
	previous_class_.resize(size_a_);
	for (unsigned s = 0; s < size_a_; ++s)
	  previous_class_[s] = init;
Thomas Badie's avatar
Thomas Badie committed
328

329
330
331
332
	// Put all the anonymous variable in a queue, and record all
	// of these in a variable all_class_var_ which will be used
	// to understand the destination part in the signature when
	// building the resulting automaton.
333
	all_class_var_ = init;
334
	for (unsigned i = set_num; i < set_num + size_a_ - 1; ++i)
Thomas Badie's avatar
Thomas Badie committed
335
336
337
338
339
          {
            free_var_.push(i);
            all_class_var_ &= bdd_ithvar(i);
          }

340
341
	relation_[init] = init;
      }
Thomas Badie's avatar
Thomas Badie committed
342
343


344
345
346
      // Reverse all the acceptance condition at the destruction of
      // this object, because it occurs after the return of the
      // function simulation.
Thomas Badie's avatar
Thomas Badie committed
347
      virtual ~direct_simulation()
348
      {
349
	a_->get_dict()->unregister_all_my_variables(this);
350
      }
Thomas Badie's avatar
Thomas Badie committed
351

352
      // Update the name of the classes.
353
354
355
356
357
358
      void update_previous_class()
      {
	std::list<bdd>::iterator it_bdd = used_var_.begin();

	// We run through the map bdd/list<state>, and we update
	// the previous_class_ with the new data.
359
	for (auto& p: bdd_lstate_)
Thomas Badie's avatar
Thomas Badie committed
360
          {
361
362
363
364
365
366
367
368
	    // If the signature of a state is bddfalse (no
	    // transitions) the class of this state is bddfalse
	    // instead of an anonymous variable. It allows
	    // simplifications in the signature by removing a
	    // transition which has as a destination a state with
	    // no outgoing transition.
	    if (p.first == bddfalse)
	      for (auto s: p.second)
369
		previous_class_[s] = bddfalse;
370
371
	    else
	      for (auto s: p.second)
372
		previous_class_[s] = *it_bdd;
373
	    ++it_bdd;
Thomas Badie's avatar
Thomas Badie committed
374
          }
375
376
      }

Thomas Badie's avatar
Thomas Badie committed
377
      void main_loop()
378
379
380
381
382
      {
	unsigned int nb_partition_before = 0;
	unsigned int nb_po_before = po_size_ - 1;
	while (nb_partition_before != bdd_lstate_.size()
	       || nb_po_before != po_size_)
Thomas Badie's avatar
Thomas Badie committed
383
          {
384
            update_previous_class();
Thomas Badie's avatar
Thomas Badie committed
385
386
387
388
389
390
391
392
            nb_partition_before = bdd_lstate_.size();
            bdd_lstate_.clear();
            nb_po_before = po_size_;
            po_size_ = 0;
            update_sig();
            go_to_next_it();
          }

393
	update_previous_class();
Thomas Badie's avatar
Thomas Badie committed
394
395
396
      }

      // The core loop of the algorithm.
397
      tgba_digraph_ptr run()
Thomas Badie's avatar
Thomas Badie committed
398
399
      {
        main_loop();
400
401
	return build_result();
      }
Thomas Badie's avatar
Thomas Badie committed
402

403
      // Take a state and compute its signature.
404
      bdd compute_sig(unsigned src)
405
      {
Thomas Badie's avatar
Thomas Badie committed
406
        bdd res = bddfalse;
Thomas Badie's avatar
Thomas Badie committed
407

408
        for (auto& t: a_->out(src))
Thomas Badie's avatar
Thomas Badie committed
409
          {
Thomas Badie's avatar
Thomas Badie committed
410
            bdd acc = bddtrue;
Thomas Badie's avatar
Thomas Badie committed
411

412
	    map_constraint::const_iterator it;
413
414
	    // Check if we have a constraint about this edge in the
	    // original automaton.
415
416
	    if (map_cst_
		&& ((it = map_cst_
417
418
		     ->find(std::make_pair(new_original_[src],
					   new_original_[t.dst])))
419
420
421
422
423
424
		    != map_cst_->end()))
	      {
		acc = it->second;
	      }
	    else
	      {
425
		acc = mark_to_bdd(t.acc);
426
427
428
429
430
	      }

	    // to_add is a conjunction of the acceptance condition,
	    // the label of the transition and the class of the
	    // destination and all the class it implies.
431
	    bdd to_add = acc & t.cond & relation_[previous_class_[t.dst]];
Thomas Badie's avatar
Thomas Badie committed
432

433
434
	    res |= to_add;
	  }
Thomas Badie's avatar
Thomas Badie committed
435

Thomas Badie's avatar
Thomas Badie committed
436
        // When we Cosimulate, we add a special flag to differentiate
437
        // the initial state from the other.
438
        if (Cosimulation && src == 0)
Thomas Badie's avatar
Thomas Badie committed
439
440
441
          res |= bdd_initial;

        return res;
442
443
      }

Thomas Badie's avatar
Thomas Badie committed
444

445
446
      void update_sig()
      {
447
	for (unsigned s = 0; s < size_a_; ++s)
448
	  bdd_lstate_[compute_sig(s)].push_back(s);
449
      }
Thomas Badie's avatar
Thomas Badie committed
450
451


452
453
454
455
      // This method rename the color set, update the partial order.
      void go_to_next_it()
      {
	int nb_new_color = bdd_lstate_.size() - used_var_.size();
Thomas Badie's avatar
Thomas Badie committed
456

Thomas Badie's avatar
Thomas Badie committed
457
458
459

        // If we have created more partitions, we need to use more
        // variables.
460
	for (int i = 0; i < nb_new_color; ++i)
Thomas Badie's avatar
Thomas Badie committed
461
462
463
464
465
466
          {
            assert(!free_var_.empty());
            used_var_.push_back(bdd_ithvar(free_var_.front()));
            free_var_.pop();
          }

Thomas Badie's avatar
Thomas Badie committed
467
468
469

        // If we have reduced the number of partition, we 'free' them
        // in the free_var_ list.
470
471
472
473
474
475
476
477
478
479
480
	for (int i = 0; i > nb_new_color; --i)
          {
            assert(!used_var_.empty());
            free_var_.push(bdd_var(used_var_.front()));
            used_var_.pop_front();
          }


	assert((bdd_lstate_.size() == used_var_.size())
               || (bdd_lstate_.find(bddfalse) != bdd_lstate_.end()
                   && bdd_lstate_.size() == used_var_.size() + 1));
Thomas Badie's avatar
Thomas Badie committed
481

482
483
484
485
486
487
488
	// Now we make a temporary hash_table which links the tuple
	// "C^(i-1), N^(i-1)" to the new class coloring.  If we
	// rename the class before updating the partial order, we
	// loose the information, and if we make it after, I can't
	// figure out how to apply this renaming on rel_.
	// It adds a data structure but it solves our problem.
	map_bdd_bdd now_to_next;
Thomas Badie's avatar
Thomas Badie committed
489

490
	std::list<bdd>::iterator it_bdd = used_var_.begin();
Thomas Badie's avatar
Thomas Badie committed
491

492
	for (auto& p: bdd_lstate_)
Thomas Badie's avatar
Thomas Badie committed
493
          {
494
495
496
497
498
499
	    // If the signature of a state is bddfalse (no
	    // transitions) the class of this state is bddfalse
	    // instead of an anonymous variable. It allows
	    // simplifications in the signature by removing a
	    // transition which has as a destination a state with
	    // no outgoing transition.
500
501
502
503
	    bdd acc = bddfalse;
	    if (p.first != bddfalse)
	      acc = *it_bdd;
	    now_to_next[p.first] = acc;
504
	    ++it_bdd;
Thomas Badie's avatar
Thomas Badie committed
505
506
          }

Thomas Badie's avatar
Thomas Badie committed
507
	update_po(now_to_next, relation_);
508
509
      }

Thomas Badie's avatar
Thomas Badie committed
510
511
512
513
514
515
516
517
518
      // This function computes the new po with previous_class_ and
      // the argument. `now_to_next' contains the relation between the
      // signature and the future name of the class.  We need a
      // template parameter because we use this function with a
      // map_bdd_bdd, but later, we need a list_bdd_bdd. So to
      // factorize some code we use a template.
      template <typename container_bdd_bdd>
      void update_po(const container_bdd_bdd& now_to_next,
                     map_bdd_bdd& relation)
519
520
521
522
523
524
525
526
      {
	// This loop follows the pattern given by the paper.
	// foreach class do
	// |  foreach class do
	// |  | update po if needed
	// |  od
	// od

Thomas Badie's avatar
Thomas Badie committed
527
528
	for (typename container_bdd_bdd::const_iterator it1
               = now_to_next.begin();
529
530
	     it1 != now_to_next.end();
	     ++it1)
Thomas Badie's avatar
Thomas Badie committed
531
532
          {
            bdd accu = it1->second;
Thomas Badie's avatar
Thomas Badie committed
533
534
            for (typename container_bdd_bdd::const_iterator it2
                   = now_to_next.begin();
Thomas Badie's avatar
Thomas Badie committed
535
536
                 it2 != now_to_next.end();
                 ++it2)
Thomas Badie's avatar
Thomas Badie committed
537
538
539
540
541
542
543
544
545
546
547
              {
                // Skip the case managed by the initialization of accu.
                if (it1 == it2)
                  continue;

                if (bdd_implies(it1->first, it2->first))
                  {
                    accu &= it2->second;
                    ++po_size_;
                  }
              }
Thomas Badie's avatar
Thomas Badie committed
548
            relation[it1->second] = accu;
Thomas Badie's avatar
Thomas Badie committed
549
          }
550
551
552
      }

      // Build the minimal resulting automaton.
553
      tgba_digraph_ptr build_result()
554
      {
555
	tgba_digraph_ptr res = make_tgba_digraph(a_->get_dict());
556
	res->copy_ap_of(a_);
557
	res->copy_acceptance_conditions_of(a_);
558
	if (Sba)
559
	  res->prop_state_based_acc();
560
561

	// Non atomic propositions variables (= acc and class)
562
	bdd nonapvars = all_proms_ & bdd_support(all_class_var_);
563

564
565
	auto* gb = res->create_namer<int>();

566
	// Create one state per partition.
567
	for (auto& p: bdd_lstate_)
Thomas Badie's avatar
Thomas Badie committed
568
          {
569
570
571
572
573
            bdd cl = previous_class_[p.second.front()];
	    // A state may be referred to either by
	    // its class, or by all the implied classes.
	    auto s = gb->new_state(cl.id());
	    gb->alias_state(s, relation_[cl].id());
Thomas Badie's avatar
Thomas Badie committed
574
575
          }

576
	// Acceptance of states.  Only used if Sba && Cosimulation.
577
	std::vector<acc_cond::mark_t> accst;
578
	if (Sba && Cosimulation)
579
	  accst.resize(res->num_states(), 0U);
580

581
582
583
        stat.states = bdd_lstate_.size();
        stat.transitions = 0;

Thomas Badie's avatar
Thomas Badie committed
584
585
586
        unsigned nb_satoneset = 0;
        unsigned nb_minato = 0;

587
	// For each class, we will create
588
	// all the transitions between the states.
589
	for (auto& p: bdd_lstate_)
Thomas Badie's avatar
Thomas Badie committed
590
          {
591
592
593
594
595
	    // All states in p.second have the same class, so just
	    // pick the class of the first one first one.
	    bdd src = previous_class_[p.second.front()];

            // Get the signature to derive successors.
596
            bdd sig = compute_sig(p.second.front());
Thomas Badie's avatar
Thomas Badie committed
597

Thomas Badie's avatar
Thomas Badie committed
598
599
600
            if (Cosimulation)
              sig = bdd_compose(sig, bddfalse, bdd_var(bdd_initial));

Thomas Badie's avatar
Thomas Badie committed
601
602
603
604
605
606
607
608
609
610
611
612
613
            // Get all the variable in the signature.
            bdd sup_sig = bdd_support(sig);

            // Get the variable in the signature which represents the
            // conditions.
            bdd sup_all_atomic_prop = bdd_exist(sup_sig, nonapvars);

            // Get the part of the signature composed only with the atomic
            // proposition.
            bdd all_atomic_prop = bdd_exist(sig, nonapvars);

	    // First loop over all possible valuations atomic properties.
            while (all_atomic_prop != bddfalse)
614
615
616
617
618
619
	      {
		bdd one = bdd_satoneset(all_atomic_prop,
					sup_all_atomic_prop,
					bddtrue);
		all_atomic_prop -= one;

620
		// For each possible valuation, iterate over all possible
621
622
623
624
625
626
627
628
629
		// destination classes.   We use minato_isop here, because
		// if the same valuation of atomic properties can go
		// to two different classes C1 and C2, iterating on
		// C1 + C2 with the above bdd_satoneset loop will see
		// C1 then (!C1)C2, instead of C1 then C2.
		// With minatop_isop, we ensure that the no negative
		// class variable will be seen (likewise for promises).
		minato_isop isop(sig & one);

Thomas Badie's avatar
Thomas Badie committed
630
631
                ++nb_satoneset;

632
633
634
		bdd cond_acc_dest;
		while ((cond_acc_dest = isop.next()) != bddfalse)
		  {
635
636
                    ++stat.transitions;

Thomas Badie's avatar
Thomas Badie committed
637
638
                    ++nb_minato;

639
640
		    // Take the transition, and keep only the variable which
		    // are used to represent the class.
641
		    bdd dst = bdd_existcomp(cond_acc_dest,
642
643
644
					     all_class_var_);

		    // Keep only ones who are acceptance condition.
645
646
		    auto acc = bdd_to_mark(res, bdd_existcomp(cond_acc_dest,
							      all_proms_));
647

648
		    // Keep the other!
649
650
651
652
		    bdd cond = bdd_existcomp(cond_acc_dest,
					     sup_all_atomic_prop);

		    // Because we have complemented all the acceptance
653
654
		    // conditions on the input automaton, we must
		    // revert them to create a new transition.
655
		    acc = res->acc().comp(acc);
656

657
658
659
		    if (Cosimulation)
		      {
			if (Sba)
660
661
662
663
664
665
666
			  {
			    // acc should be attached to src, or rather,
			    // in our transition-based representation)
			    // to all transitions leaving src.  As we
			    // can't do this here, store this in a table
			    // so we can fix it later.
			    accst[gb->get_state(src.id())] = acc;
667
			    acc = 0U;
668
669
			  }
			gb->new_transition(dst.id(), src.id(), cond, acc);
670
		      }
671
		    else
672
673
674
		      {
			gb->new_transition(src.id(), dst.id(), cond, acc);
		      }
675
676
		  }
	      }
Thomas Badie's avatar
Thomas Badie committed
677
678
          }

679
680
	res->set_init_state(gb->get_state(previous_class_
					  [a_->get_init_state_number()].id()));
Thomas Badie's avatar
Thomas Badie committed
681

682
	res->merge_transitions(); // FIXME: is this really needed?
Thomas Badie's avatar
Thomas Badie committed
683

684
685
686
	// Mark all accepting state in a second pass, when
	// dealing with SBA in cosimulation.
	if (Sba && Cosimulation)
687
688
689
690
	  {
	    unsigned ns = res->num_states();
	    for (unsigned s = 0; s < ns; ++s)
	      {
691
692
		acc_cond::mark_t acc = accst[s];
		if (acc == 0U)
693
		  continue;
694
		for (auto& t: res->out(s))
695
696
697
		  t.acc = acc;
	      }
	  }
698

699
	delete gb;
700
701
702
703
704
705
706
707
708
	res->prop_copy(original_,
		       false, // state-based acc forced below
		       false, // single acc is set by set_acceptance_conditions
		       true,  // weakness preserved,
		       false);	// determinism checked and set below
        if (nb_minato == nb_satoneset)
	  res->prop_deterministic();
	if (Sba)
	  res->prop_state_based_acc();
Thomas Badie's avatar
Thomas Badie committed
709

710
711
712
713
714
715
716
717
718
719
720
	return res;
      }


      // Debug:
      // In a first time, print the signature, and the print a list
      // of each state in this partition.
      // In a second time, print foreach state, who is where,
      // where is the new class name.
      void print_partition()
      {
721
	for (auto& p: bdd_lstate_)
Thomas Badie's avatar
Thomas Badie committed
722
723
          {
            std::cerr << "partition: "
724
                      << bdd_format_isop(a_->get_dict(), p.first)
Thomas Badie's avatar
Thomas Badie committed
725
                      << std::endl;
726
            for (auto s: p.second)
727
728
729
	      std::cerr << "  - "
			<< a_->format_state(a_->state_from_number(s))
			<< '\n';
Thomas Badie's avatar
Thomas Badie committed
730
731
          }

732
	std::cerr << "\nPrevious iteration\n" << std::endl;
Thomas Badie's avatar
Thomas Badie committed
733

734
735
	unsigned ps = previous_class_.size();
	for (unsigned p = 0; p < ps; ++p)
Thomas Badie's avatar
Thomas Badie committed
736
          {
737
            std::cerr << a_->format_state(a_->state_from_number(p))
Thomas Badie's avatar
Thomas Badie committed
738
                      << " was in "
739
                      << bdd_format_set(a_->get_dict(), previous_class_[p])
740
                      << '\n';
Thomas Badie's avatar
Thomas Badie committed
741
          }
742
      }
Thomas Badie's avatar
Thomas Badie committed
743

Thomas Badie's avatar
Thomas Badie committed
744
    protected:
745
      // The automaton which is simulated.
746
747
      tgba_digraph_ptr a_;
      tgba_digraph_ptr old_a_;
Thomas Badie's avatar
Thomas Badie committed
748

749
750
751
752
753
754
755
      // Relation is aimed to represent the same thing than
      // rel_. The difference is in the way it does.
      // If A => A /\ A => B, rel will be (!A U B), but relation_
      // will have A /\ B at the key A. This trick is due to a problem
      // with the computation of the resulting automaton with the signature.
      // rel_ will pollute the meaning of the signature.
      map_bdd_bdd relation_;
Thomas Badie's avatar
Thomas Badie committed
756

757
      // Represent the class of each state at the previous iteration.
758
      vector_state_bdd previous_class_;
Thomas Badie's avatar
Thomas Badie committed
759

760
761
762
      // The list of state for each class at the current_iteration.
      // Computed in `update_sig'.
      map_bdd_lstate bdd_lstate_;
Thomas Badie's avatar
Thomas Badie committed
763

764
765
766
      // The queue of free bdd. They will be used as the identifier
      // for the class.
      std::queue<int> free_var_;
Thomas Badie's avatar
Thomas Badie committed
767

768
769
      // The list of used bdd. They are in used as identifier for class.
      std::list<bdd> used_var_;
Thomas Badie's avatar
Thomas Badie committed
770

771
772
      // Size of the automaton.
      unsigned int size_a_;
Thomas Badie's avatar
Thomas Badie committed
773

774
775
776
      // Used to know when there is no evolution in the po. Updated
      // in the `update_po' method.
      unsigned int po_size_;
Thomas Badie's avatar
Thomas Badie committed
777

778
779
      // All the class variable:
      bdd all_class_var_;
Thomas Badie's avatar
Thomas Badie committed
780
781
782
783

      // The flag to say if the outgoing state is initial or not
      bdd bdd_initial;

Thomas Badie's avatar
Thomas Badie committed
784
785
      bdd all_proms_;

786
      automaton_size stat;
787

788
      std::unique_ptr<scc_info> scc_info_;
789
      std::vector<const state*> new_original_;
Thomas Badie's avatar
Thomas Badie committed
790
791
792

      const map_constraint* map_cst_;

793
      const_tgba_ptr original_;
Thomas Badie's avatar
Thomas Badie committed
794
795
796
    };

    // For now, we don't try to handle cosimulation.
797
    class direct_simulation_dont_care: public direct_simulation<false, false>
Thomas Badie's avatar
Thomas Badie committed
798
799
800
801
802
803
804
805
806
807
808
    {
      typedef std::vector<std::list<constraint> > constraints;
      typedef std::map<bdd,                  // Source Class.
                       std::map<bdd,         // Destination (implied) Class.
                                std::list<constraint>, // Constraints list.
                                bdd_less_than>,
                       bdd_less_than> constraint_list;
      typedef std::list<std::pair<bdd, bdd> > list_bdd_bdd;


    public:
809
      direct_simulation_dont_care(const const_tgba_ptr& t)
810
      : direct_simulation<false, false>(t)
Thomas Badie's avatar
Thomas Badie committed
811
812
813
      {
        // This variable is used in the new signature.
        on_cycle_ =
814
          bdd_ithvar(a_->get_dict()->register_anonymous_variables(1, this));
Thomas Badie's avatar
Thomas Badie committed
815
816
817
818
819
820
821
822
823
824

        // This one is used for the iteration on all the
        // possibilities. Avoid computing two times "no constraints".
        empty_seen_ = false;


        // If this variable is set to true, we have a number limit of
        // simulation to run.
        has_limit_ = false;

825
	notap = bdd_support(all_proms_) & all_class_var_ & on_cycle_;
Thomas Badie's avatar
Thomas Badie committed
826
827
828
829
830
831
832
      }

      // This function computes the don't care signature of the state
      // src. This signature is similar to the classic one, excepts
      // that if the transition is on a SCC, we add a on_cycle_ on it,
      // otherwise we add !on_cycle_. This allows us to split the
      // signature later.
833
      bdd dont_care_compute_sig(unsigned src)
Thomas Badie's avatar
Thomas Badie committed
834
835
836
      {
        bdd res = bddfalse;

837
838
        unsigned scc = scc_info_->scc_of(src);
        bool sccacc = scc_info_->is_accepting_scc(scc);
Thomas Badie's avatar
Thomas Badie committed
839

840
	for (auto& t: a_->out(src))
Thomas Badie's avatar
Thomas Badie committed
841
          {
842
            bdd cl = previous_class_[t.dst];
Thomas Badie's avatar
Thomas Badie committed
843
844
            bdd acc;

845
            if (scc != scc_info_->scc_of(t.dst))
Thomas Badie's avatar
Thomas Badie committed
846
847
              acc = !on_cycle_;
            else if (sccacc)
848
              acc = on_cycle_ & mark_to_bdd(t.acc);
Thomas Badie's avatar
Thomas Badie committed
849
850
851
            else
              acc = on_cycle_ & all_proms_;

852
            bdd to_add = acc & t.cond & relation_[cl];
Thomas Badie's avatar
Thomas Badie committed
853
854
            res |= to_add;
          }
855

Thomas Badie's avatar
Thomas Badie committed
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
        return res;
      }

      // We used to have
      //   sig(s1) = (f1 | g1)
      //   sig(s2) = (f2 | g2)
      // and we say that s2 simulates s1 if sig(s1)=>sig(s2).
      // This amount to testing whether (f1|g1)=>(f2|g2),
      // which is equivalent to testing both
      //    f1=>(f2|g2)  and g1=>(f2|g2)
      // separately.
      //
      // Now we have a slightly improved version of this rule.
      // g1 and g2 are not on cycle, so they can make as many
      // promises as we wish, if that helps.  Adding promises
      // to g2 will not help, but adding promises to g1 can.
      //
      // So we test whether
      //    f1=>(f2|g2)
      //    g1=>noprom(f2|g2)
      // Where noprom(f2|g2) removes all promises from f2|g2.
      // (g1 do not have promises, and neither do g2).

      bool could_imply_aux(bdd f1, bdd g1, bdd left_class,
			   bdd right, bdd right_class)
      {
        bdd f2g2 = bdd_exist(right, on_cycle_);
        bdd f2g2n = bdd_exist(f2g2, all_proms_);

	bdd both = left_class & right_class;
	int lc = bdd_var(left_class);
        f1 = bdd_compose(f1, both, lc);
        g1 = bdd_compose(g1, both, lc);
        f2g2 = bdd_compose(f2g2, both, lc);
        f2g2n = bdd_compose(f2g2n, both, lc);

        return bdd_implies(f1, f2g2) && bdd_implies(g1, f2g2n);
      }

      bool could_imply(bdd left, bdd left_class,
		       bdd right, bdd right_class)
      {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
898
899
900
901
902
	bdd f1 = bdd_relprod(left, on_cycle_, on_cycle_);
	bdd g1 = bdd_relprod(left, !on_cycle_, on_cycle_);

        //bdd f1 = bdd_restrict(left, on_cycle_);
        //bdd g1 = bdd_restrict(left, !on_cycle_);
Thomas Badie's avatar
Thomas Badie committed
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
	return could_imply_aux(f1, g1, left_class,
			       right, right_class);
      }

      void dont_care_update_po(const list_bdd_bdd& now_to_next,
                               map_bdd_bdd& relation)
      {
        // This loop follows the pattern given by the paper.
        // foreach class do
        // |  foreach class do
        // |  | update po if needed
        // |  od
        // od

        for (list_bdd_bdd::const_iterator it1 = now_to_next.begin();
             it1 != now_to_next.end();
             ++it1)
          {
            bdd accu = it1->second;

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
923
924
925
926
927
	    bdd f1 = bdd_relprod(it1->first, on_cycle_, on_cycle_);
	    bdd g1 = bdd_relprod(it1->first, !on_cycle_, on_cycle_);

            // bdd f1 = bdd_restrict(it1->first_, on_cycle_);
            // bdd g1 = bdd_restrict(it1->first_, !on_cycle_);
Thomas Badie's avatar
Thomas Badie committed
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951

            for (list_bdd_bdd::const_iterator it2 = now_to_next.begin();
                 it2 != now_to_next.end();
                 ++it2)
              {
                // Skip the case managed by the initialization of accu.
                if (it1 == it2)
                  continue;

		if (could_imply_aux(f1, g1, it1->second,
				    it2->first, it2->second))
                  {
                    accu &= it2->second;
                    ++po_size_;
                  }
              }
            relation[it1->second] = accu;
          }
      }

#define ISOP(bdd) #bdd" - " << bdd_format_isop(a_->get_dict(), bdd)

      inline bool is_out_scc(bdd b)
      {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
952
953
	return bddfalse !=  bdd_relprod(b, !on_cycle_, on_cycle_);
        // return bddfalse != bdd_restrict(b, !on_cycle_);
Thomas Badie's avatar
Thomas Badie committed
954
955
956
957
958
959
960
961
962
963
      }

      // This method solves three kind of problems, where we have two
      // conjunctions of variable (that corresponds to a particular
      // transition), and where left could imply right.
      // Three cases:
      //   - αP₁ ⇒ xβP₁ where x is unknown.
      //   - xβP₁ ⇒ αP₁ where x is unknown.
      //   - xαP₁ ⇒ yβP₁ where x, y are unknown.
      void create_simple_constraint(bdd left, bdd right,
964
965
                                    unsigned src_left,
                                    unsigned src_right,
Thomas Badie's avatar
Thomas Badie committed
966
967
                                    std::list<constraint>& constraint)
      {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
968
	assert(src_left != src_right);
Thomas Badie's avatar
Thomas Badie committed
969
970
971
972
973
        // Determine which is the current case.
        bool out_scc_left = is_out_scc(left);
        bool out_scc_right = is_out_scc(right);
        bdd dest_class = bdd_existcomp(left, all_class_var_);
        assert(revert_relation_.find(dest_class) != revert_relation_.end());
974
        unsigned dst_left = revert_relation_[dest_class];
Thomas Badie's avatar
Thomas Badie committed
975
        dest_class = bdd_existcomp(right, all_class_var_);
976
        unsigned dst_right = revert_relation_[dest_class];
Thomas Badie's avatar
Thomas Badie committed
977

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
978
979
	assert(src_left != dst_left || src_right != dst_right);

Thomas Badie's avatar
Thomas Badie committed
980
981
982
983
984
985
986
987
        left = bdd_exist(left, all_class_var_ & on_cycle_);
        right = bdd_exist(right, all_class_var_ & on_cycle_);

        if (!out_scc_left && out_scc_right)
          {
            bdd b = bdd_exist(right, notap);
            bdd add = bdd_exist(left & b, bdd_support(b));

988
            if (add != bddfalse && bdd_exist(add, all_proms_) == bddtrue)
Thomas Badie's avatar
Thomas Badie committed
989
              {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
990
991
		assert(src_right != dst_right);

992
993
                constraint.emplace_back(new_original_[src_right],
					new_original_[dst_right],
994
					add);
Thomas Badie's avatar
Thomas Badie committed
995
996
997
998
999
1000
1001
              }
          }
        else if (out_scc_left && !out_scc_right)
          {
            bdd b = bdd_exist(left, notap);
            bdd add = bdd_exist(right & b, bdd_support(b));

1002
            if (add != bddfalse && bdd_exist(add, all_proms_) == bddtrue)
Thomas Badie's avatar
Thomas Badie committed
1003
              {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1004
1005
		assert(src_left != dst_left);

1006
1007
                constraint.emplace_back(new_original_[src_left],
					new_original_[dst_left],
1008
					add);
Thomas Badie's avatar
Thomas Badie committed
1009
1010
1011
1012
1013
1014
1015
              }
          }
        else if (out_scc_left && out_scc_right)
          {
            bdd b = bdd_exist(left, notap);
            bdd add = bdd_exist(right & b, bdd_support(b));

1016
            if (add != bddfalse && bdd_exist(add, all_proms_) == bddtrue)
Thomas Badie's avatar
Thomas Badie committed
1017
              {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1018
		assert(src_left != dst_left && src_right != dst_right);
Thomas Badie's avatar
Thomas Badie committed
1019
		// FIXME: cas pas compris.
1020
1021
                constraint.emplace_back(new_original_[src_left],
					new_original_[dst_left],
1022
					add);
1023
1024
		constraint.emplace_back(new_original_[src_right],
					new_original_[dst_right],
1025
					add);
Thomas Badie's avatar
Thomas Badie committed
1026
1027
1028
1029
              }

          }
        else
1030
          SPOT_UNREACHABLE();
Thomas Badie's avatar
Thomas Badie committed
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
      }


      // This function run over the signatures, and select the
      // transitions that are out of a SCC and call the function
      // create_simple_constraint to solve the problem.

      // NOTE: Currently, this may not be the most accurate method,
      // because we check for equality in the destination part of the
      // signature. We may just check the destination that can be
      // implied instead.
1042
1043
1044
      std::list<constraint> create_new_constraint(unsigned left,
                                                  unsigned right,
                                                  vector_state_bdd& state2sig)
Thomas Badie's avatar
Thomas Badie committed
1045
      {
1046
1047
	bdd pcl = previous_class_[left];
	bdd pcr = previous_class_[right];
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1048

Thomas Badie's avatar
Thomas Badie committed
1049
1050
1051
1052
1053
        bdd sigl = state2sig[left];
        bdd sigr = state2sig[right];

        std::list<constraint> res;

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1054
1055
1056
1057
1058
1059
	bdd ex = all_class_var_ & on_cycle_;

	bdd both = pcl & pcr;
	int lc = bdd_var(pcl);
#define DEST(x) bdd_compose(bdd_existcomp(x, ex), both, lc)

Thomas Badie's avatar
Thomas Badie committed
1060
1061
        // Key is destination class, value is the signature part that
        // led to this destination class.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
	map_bdd_bdd sigl_map;
	{
	  minato_isop isop(sigl & on_cycle_);
	  bdd cond_acc_dest;
	  while ((cond_acc_dest = isop.next()) != bddfalse)
	    sigl_map[DEST(cond_acc_dest)]
	      |= cond_acc_dest;
	}
	{
	  minato_isop isop(sigl & !on_cycle_);
	  bdd cond_acc_dest;
	  while ((cond_acc_dest = isop.next()) != bddfalse)
	    sigl_map[DEST(cond_acc_dest)]
	      |= cond_acc_dest;
	}
Thomas Badie's avatar
Thomas Badie committed
1077
        map_bdd_bdd sigr_map;
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
	{
	  minato_isop isop2(sigr & on_cycle_);
	  bdd cond_acc_dest2;
	  while ((cond_acc_dest2 = isop2.next()) != bddfalse)
	    sigr_map[DEST(cond_acc_dest2)]
	      |= cond_acc_dest2;
	}
	{
	  minato_isop isop2(sigr & !on_cycle_);
	  bdd cond_acc_dest2;
	  while ((cond_acc_dest2 = isop2.next()) != bddfalse)
	    sigr_map[DEST(cond_acc_dest2)]
	      |= cond_acc_dest2;
	}
Thomas Badie's avatar
Thomas Badie committed
1092
1093

        // Iterate over the transitions of both states.
1094
1095
1096
1097
1098
1099
1100
1101
1102
        for (auto lp: sigl_map)
	  for (auto rp: sigr_map)
	    // And create constraints if any of the transitions
	    // is out of the SCC and the left could imply the right.
	    if ((is_out_scc(lp.second) || is_out_scc(rp.second))
		&& (bdd_exist(lp.first, on_cycle_) ==
		    bdd_exist(rp.first, on_cycle_)))
	      create_simple_constraint(lp.second, rp.second,
				       left, right, res);
Thomas Badie's avatar
Thomas Badie committed
1103
1104
1105
        return res;
      }

1106
      tgba_digraph_ptr run()
Thomas Badie's avatar
Thomas Badie committed
1107
1108
1109
1110
1111
1112
1113
1114
1115
      {
        // Iterate the simulation until the end. We just don't return
        // an automaton. This allows us to get all the information
        // about the states and their signature.
        main_loop();

        // Compute the don't care signatures,
        map_bdd_lstate dont_care_bdd_lstate;
        // Useful to keep track of who is who.
1116
1117
        vector_state_bdd dont_care_state2sig(size_a_);
        vector_state_bdd state2sig(size_a_);
Thomas Badie's avatar
Thomas Badie committed
1118
1119
1120

        list_bdd_bdd dont_care_now_to_now;
        map_bdd_state class2state;
1121
1122
1123
        list_bdd_bdd now_to_now;
        bdd_lstate_.clear();

Thomas Badie's avatar
Thomas Badie committed
1124
        // Compute the don't care signature for all the states.
1125
	for (unsigned s = 0; s < size_a_; ++s)
Thomas Badie's avatar
Thomas Badie committed
1126
          {
1127
	    bdd clas = previous_class_[s];
1128
1129
            bdd sig = dont_care_compute_sig(s);
            dont_care_bdd_lstate[sig].push_back(s);
1130
            dont_care_state2sig[s] = sig;
1131
            dont_care_now_to_now.emplace_back(sig, clas);
1132
            class2state[clas] = s;
Thomas Badie's avatar
Thomas Badie committed
1133

1134
1135
            sig = compute_sig(s);
            bdd_lstate_[sig].push_back(s);
1136
            state2sig[s] = sig;
1137
            now_to_now.push_back(std::make_pair(sig, clas));
Thomas Badie's avatar
Thomas Badie committed
1138
1139
1140
1141
1142
1143
1144
1145
1146
          }

        map_bdd_bdd dont_care_relation;
        map_bdd_bdd relation;
        update_po(now_to_now, relation);
        dont_care_update_po(dont_care_now_to_now, dont_care_relation);

        constraint_list cc;

1147
1148
        for (auto p: relation)
	  revert_relation_[p.second] = class2state[p.first];
Thomas Badie's avatar
Thomas Badie committed
1149
1150
1151
1152
1153

        int number_constraints = 0;
        relation_ = relation;


1154
1155
1156
        // make the diff between the two tables: imply and
        // could_imply.
	for (unsigned s = 0; s < size_a_; ++s)
Thomas Badie's avatar
Thomas Badie committed
1157
          {
1158
1159
1160
            bdd clas = previous_class_[s];
            assert(relation.find(clas) != relation.end());
            assert(dont_care_relation.find(clas) != dont_care_relation.end());
Thomas Badie's avatar
Thomas Badie committed
1161

1162
1163
            bdd care_rel = relation[clas];
            bdd dont_care_rel = dont_care_relation[clas];
Thomas Badie's avatar
Thomas Badie committed
1164
1165
1166
1167

            if (care_rel == dont_care_rel)
              continue;

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1168
1169
            // If they are different we necessarily have
	    // dont_care_rel == care_rel & diff
Thomas Badie's avatar
Thomas Badie committed
1170
            bdd diff = bdd_exist(dont_care_rel, care_rel);
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1171
1172
	    assert(dont_care_rel == (care_rel & diff));
	    assert(diff != bddtrue);
Thomas Badie's avatar
Thomas Badie committed
1173

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1174
	    do
Thomas Badie's avatar
Thomas Badie committed
1175
              {
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1176
                bdd cur_diff = bdd_ithvar(bdd_var(diff));
1177
                cc[clas][cur_diff]
1178
                  = create_new_constraint(s,
Thomas Badie's avatar
Thomas Badie committed
1179
1180
1181
                                          class2state[cur_diff],
                                          dont_care_state2sig);
                ++number_constraints;
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1182
                diff = bdd_high(diff);