twaproduct.hh 4.65 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2011, 2013, 2014, 2015, 2016, 2019 Laboratoire de Recherche
3
// et 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 26
#include <spot/twa/twa.hh>
#include <spot/misc/fixpool.hh>
27 28 29 30

namespace spot
{

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
31
  /// \ingroup twa_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
    state_product(const state* left,
46
                  const state* right,
47
                  fixed_size_pool<pool_type::Safe>* pool)
48
      :        left_(left), right_(right), count_(1), pool_(pool)
49 50
    {
    }
51

52
    virtual void destroy() const override;
53

54
    const state*
55 56 57 58 59
    left() const
    {
      return left_;
    }

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

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

  private:
71 72
    const state* left_;                ///< State from the left automaton.
    const state* right_;        ///< State from the right automaton.
73
    mutable unsigned count_;
74
    fixed_size_pool<pool_type::Safe>* pool_;
75 76

    virtual ~state_product();
77
    state_product(const state_product& o) = delete;
78 79 80 81
  };


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

91
    virtual ~twa_product();
92

93
    virtual const state* get_init_state() const override;
94

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

98
    virtual std::string format_state(const state* state) const override;
99

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

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

106
  protected:
107 108
    const_twa_ptr left_;
    const_twa_ptr right_;
109
    bool left_kripke_;
110
    fixed_size_pool<pool_type::Safe> pool_;
111

112
  private:
113
    // Disallow copy.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
114 115
    twa_product(const twa_product&) = delete;
    twa_product& operator=(const twa_product&) = delete;
116 117
  };

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

130
  /// \brief on-the-fly TGBA product
131
  inline twa_product_ptr otf_product(const const_twa_ptr& left,
132
                                      const const_twa_ptr& right)
133
  {
134
    return SPOT_make_shared_enabled__(twa_product, left, right);
135 136
  }

137
  /// \brief on-the-fly TGBA product with forced initial states
138
  inline twa_product_ptr otf_product_at(const const_twa_ptr& left,
139 140 141
                                        const const_twa_ptr& right,
                                        const state* left_init,
                                        const state* right_init)
142
  {
143 144
    return SPOT_make_shared_enabled__(twa_product_init,
                                      left, right, left_init, right_init);
145
  }
146
}