//
// 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 and it 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.
//
// Implementation: Simon Chamberland
// Project Manager: Froduald Kabanza
//

#include "stdafx.h"
#include "MaximizeExp.h"

using namespace planning;

/// <summary>
/// Creates a minimize metric with the given expression.
/// </summary>
/// <param name="exp">The expression to minimize.</param>
/// <param name="unnamedPrefs">The unnamed preferences.</param>
MaximizeExp::MaximizeExp(const INumericExp* exp)
  : MetricExp(exp)
{
  INITIALIZE_HASH_CODE();
}

/// <summary>
/// Substitutes all occurrences of the variables that occur in this
/// expression by their corresponding bindings.
/// </summary>
/// <param name="bindings">The bindings.</param>
/// <returns>A substituted copy of this expression.</returns>
const IExp* MaximizeExp::_internalApply(const Bindings* bindings) const
{
  return new MaximizeExp(m_exp->apply(bindings));
}

std::string MaximizeExp::getTypeName() const
{
  return "maximize";
}

/// <summary>
/// Returns a minimized version of the metric evaluated on a given world.
/// </summary>
/// <param name="world">The evaluation world.</param>
/// <param name="bindings">A set of variable bindings.</param>
/// <returns>The minimized version of the metric.</returns>
double MaximizeExp::evaluateMinimizedMetric(const IClosedWorld* world, const Bindings* bindings) const
{
  return -m_exp->evaluate(world, bindings);
}

double MaximizeExp::evaluateMaximizedMetric(const IClosedWorld* world, const Bindings* bindings) const
{
  return m_exp->evaluate(world, bindings);
}
