term.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) 2013-2017, Nucleic Development Team.
  3. |
  4. | Distributed under the terms of the Modified BSD License.
  5. |
  6. | The full license is in the file COPYING.txt, distributed with this software.
  7. |----------------------------------------------------------------------------*/
  8. #pragma once
  9. #include <utility>
  10. #include "variable.h"
  11. namespace kiwi
  12. {
  13. class Term
  14. {
  15. public:
  16. Term( const Variable& variable, double coefficient = 1.0 ) :
  17. m_variable( variable ), m_coefficient( coefficient ) {}
  18. // to facilitate efficient map -> vector copies
  19. Term( const std::pair<const Variable, double>& pair ) :
  20. m_variable( pair.first ), m_coefficient( pair.second ) {}
  21. ~Term() {}
  22. const Variable& variable() const
  23. {
  24. return m_variable;
  25. }
  26. double coefficient() const
  27. {
  28. return m_coefficient;
  29. }
  30. double value() const
  31. {
  32. return m_coefficient * m_variable.value();
  33. }
  34. private:
  35. Variable m_variable;
  36. double m_coefficient;
  37. };
  38. } // namespace kiwi