//
// Copyright (c) 2009 Froduald Kabanza and the Université de Sherbrooke.
// Use of this software is permitted for non-commercial research purposes, and
// it may be copied or applied only for that use. All copies must include this
// copyright message.
// 
// This is a research prototype that has not gone through intensive tests and
// is delivered as is. It may still contain bugs. Froduald Kabanza and the
// Université de Sherbrooke disclaim any responsibility for damage that may be
// caused by using it.
//
// Please note that this file was inspired in part by the PDDL4J library:
// http://www.math-info.univ-paris5.fr/~pellier/software/software.php 
//
// Implementation: Daniel Castonguay
// Project Manager: Froduald Kabanza
//
#ifndef _TRUE_EXP_H
#define _TRUE_EXP_H

#include "../ILogicalExp.h"

namespace planning
{
  /// <summary>
  /// This class represents a true logical expression, i.e. a tautology.
  /// </summary>
  class TrueExp : public ILogicalExp
  {
  public:
    static const TrueExp* getInstance()
    {
      return &s_instance;
    }

    /// <summary>
    /// Evaluates this logical expression in the specified closed world.
    /// The bindings should not be modified by this call.
    /// </summary>
    /// <param name="world">The evaluation world.</param>
    /// <param name="bindings">A set of variable bindings.</param>
    /// <returns>True, false, or undefined.</returns>
    /// <exception cref="PDDLParser.Exception.BindingException">A BindingException is thrown if an attempt
    /// is made to evaluate an unbound variable.</exception>
    virtual bool evaluate(const IClosedWorld* world, const Bindings* bindings) const;

    /// <summary>
    /// Enumerates all the worlds within which this logical expression evaluates to true.
    /// This method is used to support the goal modality expressions.
    /// </summary>
    /// <returns>All the worlds satisfying this logical expression.</returns>
    virtual void enumerateSatisfyingWorlds(PartialWorldSet& worlds) const;

  protected:
    virtual void _output(std::ostream& out) const;

    virtual size_t _calculateHashCode() const
    {
      return 899299211;
    }

    virtual const IExp* _internalApply(const Bindings* bindings) const;

    virtual int _internalCompareTo(const IExp& other) const;

  private:
    static TrueExp s_instance;
    TrueExp();

    ///// <summary>
    ///// The immutable true expression.
    ///// </summary>
    //private static TrueExp s_trueExp = new TrueExp();

    ///// <summary>
    ///// Creates a new true expression. Note that this constructor is private.
    ///// </summary>
    //private TrueExp()
    //  : base()
    //{
    //}

    ///// <summary>
    ///// The true expression.
    ///// </summary>
    //public static TrueExp True
    //{
    //  get
    //  {
    //    return s_trueExp;
    //  }
    //}

    ///// <summary>
    ///// Evaluates this logical expression in the specified open world.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //public override FuzzyBool Evaluate(IReadOnlyOpenWorld world, LocalBindings bindings)
    //{
    //  return FuzzyBool.True;
    //}

    ///// <summary>
    ///// Evaluates this logical expression in the specified open world.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //[TLPlan]
    //public override ShortCircuitFuzzyBool EvaluateWithImmediateShortCircuit(IReadOnlyOpenWorld world, LocalBindings bindings)
    //{
    //  return ShortCircuitFuzzyBool.True;
    //}

    ///// <summary>
    ///// Simplifies this logical expression by evaluating its known expression parts.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //public override LogicalValue Simplify(IReadOnlyOpenWorld world, LocalBindings bindings)
    //{
    //  return LogicalValue.True;
    //}

    ///// <summary>
    ///// Evaluates this logical expression in the specified closed world.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //public override Bool Evaluate(IReadOnlyClosedWorld world, LocalBindings bindings)
    //{
    //  return Bool.True;
    //}

    ///// <summary>
    ///// Evaluates this logical expression in the specified closed world.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //[TLPlan]
    //public override ShortCircuitBool EvaluateWithImmediateShortCircuit(IReadOnlyClosedWorld world, LocalBindings bindings)
    //{
    //  return ShortCircuitBool.True;
    //}

    ///// <summary>
    ///// Enumerates all the worlds within which this logical expression evaluates to true.
    ///// This method is used to support the goal modality expressions.
    ///// Note that no world can satisfy a false expression.
    ///// </summary>
    ///// <returns>All worlds</returns>
    //public override HashSet<PartialWorld> EnumerateAllSatisfyingWorlds()
    //{
    //  HashSet<PartialWorld> worlds = new HashSet<PartialWorld>();
    //  worlds.Add(new PartialWorld());

    //  return worlds;
    //}

    ///// <summary>
    ///// Evaluates the progression of this constraint expression in the next worlds.
    ///// </summary>
    ///// <param name="world">The current world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //public override ProgressionValue Progress(IReadOnlyDurativeClosedWorld world, LocalBindings bindings)
    //{
    //  return ProgressionValue.True;
    //}

    ///// <summary>
    ///// Evaluates this constraint expression in an idle world, i.e. a world which
    ///// won't be modified by further updates.
    ///// </summary>
    ///// <param name="idleWorld">The (idle) evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True.</returns>
    //public override Bool EvaluateIdle(IReadOnlyDurativeClosedWorld idleWorld, LocalBindings bindings)
    //{
    //  return Bool.True;
    //}

    ///// <summary>
    ///// Substitutes all occurrences of the variables that occur in this
    ///// expression by their corresponding bindings.
    ///// </summary>
    ///// <param name="bindings">The bindings.</param>
    ///// <returns>This.</returns>
    //public override IExp Apply(ParameterBindings bindings)
    //{
    //  return this;
    //}

    ///// <summary>
    ///// Standardizes all occurrences of the variables that occur in this
    ///// expression. The IDictionary argument is used to store the variable already
    ///// standardized. Remember that free variables are existentially quantified.
    ///// </summary>
    ///// <param name="images">The object that maps old variable images to the standardize
    ///// image.</param>
    ///// <returns>This.</returns>
    //public override IExp Standardize(IDictionary<string, string> images)
    //{
    //  return this;
    //}

    ///// <summary>
    ///// Returns true if the expression is ground, i.e. it does not contain any variables.
    ///// </summary>
    ///// <returns>True.</returns>
    //public override bool IsGround()
    //{
    //  return true;
    //}

    ///// <summary>
    ///// Returns the free variables in this expression.
    ///// </summary>
    ///// <returns>The empty set.</returns>
    //public override HashSet<Variable> GetFreeVariables()
    //{
    //  return new HashSet<Variable>();
    //}

    ///// <summary>
    ///// Returns a clone of this expression.
    ///// </summary>
    ///// <returns>This.</returns>
    //public override object Clone()
    //{
    //  return this;
    //}

    ///// <summary>
    ///// Returns true if this expression is equal to a specified object.
    ///// </summary>
    ///// <param name="obj">Object to test for equality.</param>
    ///// <returns>True if this expression is equal to the specified objet.</returns>
    //public override bool Equals(object obj)
    //{
    //  return this == obj;
    //}

    ///// <summary>
    ///// Returns the hash code of this expression.
    ///// </summary>
    ///// <returns>The hash code of this expression.</returns>
    //public override int GetHashCode()
    //{
    //  return FuzzyBool.True.GetHashCode();
    //}

    ///// <summary>
    ///// Returns a typed string of this expression.
    ///// </summary>
    ///// <returns>A typed string representation of this expression.</returns>
    //public override string ToTypedString()
    //{
    //  return "True";
    //}

    ///// <summary>
    ///// Returns a string representation of this expression.
    ///// </summary>
    ///// <returns>A string representation of this expression.</returns>
    //public override string ToString()
    //{
    //  return "True";
    //}
  };
}

#endif