/****************************************************************************
 *   This file is part of the aGrUM/pyAgrum library.                        *
 *                                                                          *
 *   Copyright (c) 2005-2026 by                                             *
 *       - Pierre-Henri WUILLEMIN(_at_LIP6)                                 *
 *       - Christophe GONZALES(_at_AMU)                                     *
 *                                                                          *
 *   The aGrUM/pyAgrum library is free software; you can redistribute it    *
 *   and/or modify it under the terms of either :                           *
 *                                                                          *
 *    - the GNU Lesser General Public License as published by               *
 *      the Free Software Foundation, either version 3 of the License,      *
 *      or (at your option) any later version,                              *
 *    - the MIT license (MIT),                                              *
 *    - or both in dual license, as here.                                   *
 *                                                                          *
 *   (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html)    *
 *                                                                          *
 *   This aGrUM/pyAgrum library is distributed in the hope that it will be  *
 *   useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,          *
 *   INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
 *   FOR A PARTICULAR PURPOSE  AND NONINFRINGEMENT. IN NO EVENT SHALL THE   *
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,        *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR  *
 *   OTHER DEALINGS IN THE SOFTWARE.                                        *
 *                                                                          *
 *   See LICENCES for more details.                                         *
 *                                                                          *
 *   SPDX-FileCopyrightText: Copyright 2005-2026                            *
 *       - Pierre-Henri WUILLEMIN(_at_LIP6)                                 *
 *       - Christophe GONZALES(_at_AMU)                                     *
 *   SPDX-License-Identifier: LGPL-3.0-or-later OR MIT                      *
 *                                                                          *
 *   Contact  : info_at_agrum_dot_org                                       *
 *   homepage : http://agrum.gitlab.io                                      *
 *   gitlab   : https://gitlab.com/agrumery/agrum                           *
 *                                                                          *
 ****************************************************************************/


/**
 * @file
 * @brief class for multiDimNoisyORCompound
 *
 * @author Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU)
 */

#ifndef GUM_MULTI_DIM_NOISY_OR_COMPOUND_H
#define GUM_MULTI_DIM_NOISY_OR_COMPOUND_H

#include <agrum/base/multidim/ICIModels/multiDimICIModel.h>

namespace gum {

  // ===========================================================================
  // ===                       GUM_MULTI_DIM_NOISYOR_COMPOU                  ===
  // ===========================================================================
  // clang-format off
  /**
   * @class MultiDimNoisyORCompound
   * @headerfile multiDimNoisyORCompound.h <agrum/base/multidim/ICIModels/multiDimNoisyORCompound.h>
   * @ingroup multidim_group
   *
   * @brief Noisy OR representation
   *
   * Noisy-OR as described by Henrion (UAI-3, 1989, pp161-173)
   *
   * @warning
   *   - The first variable is assumed to be the NOISY-OR. The latter are
   *     the causes.
   *   - This code give probabilities for BINARY VARIABLES (other values are
   *     assumed to be of probability 0). But for optimization reason, we will
   *     never check if it is the case.
   */
  // clang-format on

  template < GUM_Numeric GUM_SCALAR >

  class MultiDimNoisyORCompound final: public MultiDimICIModel< GUM_SCALAR > {
    public:
    // ============================================================================
    /// @name Constructors / Destructors
    // ============================================================================
    /// @{

    /// Default constructor.
    MultiDimNoisyORCompound(GUM_SCALAR external_weight,
                            GUM_SCALAR default_weight = (GUM_SCALAR)1.0);

    MultiDimNoisyORCompound(const MultiDimNoisyORCompound< GUM_SCALAR >& from);

    /**
     * Copy constructor using a bijection to swap variables from source.
     *
     * @param bij First variables are new variables, seconds are in from.
     * @param from the copied instance
     */
    MultiDimNoisyORCompound(
        const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bij,
        const MultiDimNoisyORCompound< GUM_SCALAR >&                         from);

    /// Destructor.
    ~MultiDimNoisyORCompound() override;

    /// @}

    /**
     * This method creates a clone of this object, withouth its content
     * (including variable), you must use this method if you want to ensure
     * that the generated object has the same type than the object containing
     * the called newFactory()
     * For example :
     *   MultiDimArray<double> y;
     *   MultiDimContainer<double>* x = y.newFactory();
     * Then x is a MultiDimArray<double>*
     *
     * @warning you must desallocate by yourself the memory
     * @return an empty clone of this object with the same type
     */
    [[nodiscard]] MultiDimContainer< GUM_SCALAR >* newFactory() const override;

    // ############################################################################
    /// @name Accessors / Modifiers
    // ############################################################################
    /// @{

    public:
    GUM_SCALAR get(const Instantiation& i) const override;

    std::string toString() const override;

    /// returns the real name of the multiDimArray
    /** In aGrUM, all the types of multi-dimensional arrays/functionals have a
     * name that describes what they are in reality. For instance, a table
     * stored
     * in extension is a "MultiDimArray", one that stores only non zero elements
     * is a "MultiDimSparseArray", and so on. These names are unique for each
     * type
     * of implementation and is used by the system to determine which is the
     * best
     * functions to use, say, when we wish to use operators such as operator+ on
     * two MultiDimImplementations */
    const std::string& name() const override;

    /// @}
  };


#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
  extern template class MultiDimNoisyORCompound< double >;
#endif

  /// For friendly displaying the content of the array.
  template < GUM_Numeric GUM_SCALAR >
  std::ostream& operator<<(std::ostream& s, const MultiDimNoisyORCompound< GUM_SCALAR >& ag);

} /* namespace gum */

#include <agrum/base/multidim/ICIModels/multiDimNoisyORCompound_tpl.h>

#endif /* GUM_MULTI_DIM_NOISY_OR_COMPOUND_H */
