2020-05-20 23:32:41 -04:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
| Copyright (c) 2013-2017, Nucleic Development Team.
|
|
|
|
|
|
|
|
|
| Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
|
|
|
| The full license is in the file LICENSE, distributed with this software.
|
|
|
|
|----------------------------------------------------------------------------*/
|
|
|
|
#pragma once
|
2020-06-10 16:39:52 -04:00
|
|
|
#include <ostream>
|
2020-05-20 23:32:41 -04:00
|
|
|
#include <utility>
|
|
|
|
#include "variable.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace kiwi
|
|
|
|
{
|
|
|
|
|
|
|
|
class Term
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Term( const Variable& variable, double coefficient = 1.0 ) :
|
|
|
|
m_variable( variable ), m_coefficient( coefficient ) {}
|
|
|
|
|
|
|
|
// to facilitate efficient map -> vector copies
|
|
|
|
Term( const std::pair<const Variable, double>& pair ) :
|
|
|
|
m_variable( pair.first ), m_coefficient( pair.second ) {}
|
|
|
|
|
|
|
|
~Term() {}
|
|
|
|
|
|
|
|
const Variable& variable() const
|
|
|
|
{
|
|
|
|
return m_variable;
|
|
|
|
}
|
|
|
|
|
|
|
|
double coefficient() const
|
|
|
|
{
|
|
|
|
return m_coefficient;
|
|
|
|
}
|
|
|
|
|
|
|
|
double value() const
|
|
|
|
{
|
|
|
|
return m_coefficient * m_variable.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Variable m_variable;
|
|
|
|
double m_coefficient;
|
|
|
|
};
|
|
|
|
|
2020-06-10 16:39:52 -04:00
|
|
|
static std::ostream& operator<< (std::ostream& o, kiwi::Term const & t)
|
|
|
|
{
|
|
|
|
return o << t.variable().name() << " * " << t.coefficient();
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:32:41 -04:00
|
|
|
} // namespace kiwi
|
2020-06-10 16:39:52 -04:00
|
|
|
|