//
// 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 "MetricExp.h"

using namespace planning;

MetricExp::MetricExp(const INumericExp* exp) //, const INumericExp* unnamedPrefs)
  : m_exp(exp)
{
  assert(m_exp != NULL);

  m_exp->acquire(this);
  //this.m_unnamedPreferences = unnamedPrefs; // This can be null (no unnamed preferences)
}

MetricExp::~MetricExp()
{
  m_exp->release(this);
}

const MetricExp* MetricExp::apply(const Bindings* bindings) const
{
  return dynamic_cast<const MetricExp*>(IExp::apply(bindings));
}

//double MetricExp::evaluate(const IClosedWorld* world, const Bindings* bindings) const
//{
//  //if (UnnamedPreferences != null)
//  //  return EvaluateMinimizedMetric(world, bindings) + UnnamedPreferences.Evaluate(world, bindings);
//
//  return evaluateMinimizedMetric(world, bindings);
//}

void MetricExp::_output(std::ostream& out) const
{
  out << "(:metric " + this->getTypeName() + " " << *m_exp << ")";
}

int MetricExp::_internalCompareTo(const IExp& other) const
{
  const MetricExp& exp = dynamic_cast<const MetricExp&>(other);

  COMPARE(m_exp, exp.m_exp);

  return 0;
}