//
// 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 _I_TEMPORAL_EXP_H
#define _I_TEMPORAL_EXP_H

#include "IExp.h"
#include "ProgressionValue.h"
#include "../Utils/Utils.h"


namespace planning
{
  
  class IDurativeClosedWorld;

  /// <summary>
  /// A constraint expression is an expression which imposes restrictions on the trajectory
  /// (sequence of worlds) followed to reach a certain goal world.
  /// </summary>
  class ITemporalExp : public virtual IExp
  {
  public:
    ITemporalExp();

    /// <summary>
    /// Evaluates the progression of this constraint expression in the next worlds.
    /// This function returns false if this constraint expression is not satisfied 
    /// in the given world;
    /// it returns true if the progression is always satisfied in the next worlds;
    /// else it returns the progressed expression.
    /// </summary>
    /// <param name="world">The current world.</param>
    /// <param name="bindings">A set of variable bindings.</param>
    /// <returns>True, false, undefined, or a progressed expression.</returns>
    /// <exception cref="PDDLParser.Exception.BindingException">A BindingException is thrown if an attempt
    /// is made to evaluate an unbound variable.</exception>
    virtual ProgressionValue progress(const IDurativeClosedWorld* world, const Bindings* bindings) const = 0;

    /// <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, 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 evaluateIdle(const IDurativeClosedWorld* world, const Bindings* bindings) const = 0;

    const ITemporalExp* apply(const Bindings* bindings) const;

  private:

    ///// <summary>
    ///// Evaluates the progression of this constraint expression in the next worlds.
    ///// This function returns false if this constraint expression is not satisfied 
    ///// in the given world;
    ///// it returns true if the progression is always satisfied in the next worlds;
    ///// else it returns the progressed expression.
    ///// </summary>
    ///// <param name="world">The current world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>True, false, undefined, or a progressed expression.</returns>
    ///// <exception cref="PDDLParser.Exception.BindingException">A BindingException is thrown if an attempt
    ///// is made to evaluate an unbound variable.</exception>
    //ProgressionValue Progress(IReadOnlyDurativeClosedWorld world, LocalBindings bindings);

    ///// <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, false, or undefined.</returns>
    ///// <exception cref="PDDLParser.Exception.BindingException">A BindingException is thrown if an attempt
    ///// is made to evaluate an unbound variable.</exception>
    //Bool EvaluateIdle(IReadOnlyDurativeClosedWorld idleWorld, LocalBindings bindings);
  };
}

#endif