tgbaproduct.hh 4.38 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2011, 2013, 2014, 2015 Laboratoire de Recherche et
3
// Développement de l'Epita (LRDE).
4
// Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de Paris
5 6
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
7 8 9 10 11
//
// 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
12
// the Free Software Foundation; either version 3 of the License, or
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
13 14 15 16 17 18 19 20
// (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
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
22

23
#pragma once
24 25

#include "tgba.hh"
26
#include "misc/fixpool.hh"
27 28 29 30

namespace spot
{

31
  /// \ingroup tgba_on_the_fly_algorithms
32
  /// \brief A state for spot::twa_product.
33 34 35
  ///
  /// This state is in fact a pair of state: the state from the left
  /// automaton and that of the right.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
36
  class SPOT_API state_product final: public state
37 38 39 40 41
  {
  public:
    /// \brief Constructor
    /// \param left The state from the left automaton.
    /// \param right The state from the right automaton.
42
    /// \param pool The pool from which the state was allocated.
43
    /// These states are acquired by spot::state_product, and will
44
    /// be destroyed on destruction.
45 46
    state_product(state* left, state* right, fixed_size_pool* pool)
      :	left_(left), right_(right), count_(1), pool_(pool)
47 48
    {
    }
49

50
    virtual void destroy() const;
51

52
    state*
53 54 55 56 57
    left() const
    {
      return left_;
    }

58
    state*
59 60 61 62 63 64
    right() const
    {
      return right_;
    }

    virtual int compare(const state* other) const;
65
    virtual size_t hash() const;
66
    virtual state_product* clone() const;
67 68

  private:
69 70
    state* left_;		///< State from the left automaton.
    state* right_;		///< State from the right automaton.
71 72 73 74 75
    mutable unsigned count_;
    fixed_size_pool* pool_;

    virtual ~state_product();
    state_product(const state_product& o); // No implementation.
76 77 78 79
  };


  /// \brief A lazy product.  (States are computed on the fly.)
80
  class SPOT_API twa_product: public twa
81 82 83 84 85
  {
  public:
    /// \brief Constructor.
    /// \param left The left automata in the product.
    /// \param right The right automata in the product.
86
    /// Do not be fooled by these arguments: a product is commutative.
87
    twa_product(const const_twa_ptr& left, const const_twa_ptr& right);
88

89
    virtual ~twa_product();
90

91 92
    virtual state* get_init_state() const;

93
    virtual twa_succ_iterator*
94
    succ_iter(const state* state) const;
95 96 97

    virtual std::string format_state(const state* state) const;

98
    virtual std::string
99
    transition_annotation(const twa_succ_iterator* t) const;
100

101
    virtual state* project_state(const state* s, const const_twa_ptr& t) const;
102

103 104
    const acc_cond& left_acc() const;
    const acc_cond& right_acc() const;
105

106 107 108
  protected:
    virtual bdd compute_support_conditions(const state* state) const;

109
  protected:
110 111
    const_twa_ptr left_;
    const_twa_ptr right_;
112
    bool left_kripke_;
113 114
    fixed_size_pool pool_;

115
  private:
116
    // Disallow copy.
117 118
    twa_product(const twa_product&) SPOT_DELETED;
    twa_product& operator=(const twa_product&) SPOT_DELETED;
119 120
  };

121
  /// \brief A lazy product with different initial states.
122
  class SPOT_API twa_product_init final: public twa_product
123 124
  {
  public:
125
    twa_product_init(const const_twa_ptr& left, const const_twa_ptr& right,
126 127
		      const state* left_init, const state* right_init);
    virtual state* get_init_state() const;
128
  protected:
129 130 131 132
    const state* left_init_;
    const state* right_init_;
  };

133
  /// \brief on-the-fly TGBA product
134 135
  inline twa_product_ptr otf_product(const const_twa_ptr& left,
				      const const_twa_ptr& right)
136
  {
137
    return std::make_shared<twa_product>(left, right);
138 139
  }

140
  /// \brief on-the-fly TGBA product with forced initial states
141 142
  inline twa_product_ptr otf_product_at(const const_twa_ptr& left,
					 const const_twa_ptr& right,
143 144
					 const state* left_init,
					 const state* right_init)
145
  {
146
    return std::make_shared<twa_product_init>(left, right,
147 148
					       left_init, right_init);
  }
149
}