From 673f367fc5835ebce3357dfebee9c0e414e5c09b Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Tue, 7 Aug 2012 20:10:06 +0200 Subject: Add simple C++ linear program representation - Constraints are expressed as lists of terms. - Linear programs consist of only equalities and less-than-or-equal constraints. - Solvers hide behind an abstract solution class that can evaluate linear expressions. --- native/src/linprog/io.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 native/src/linprog/io.cpp (limited to 'native/src/linprog/io.cpp') diff --git a/native/src/linprog/io.cpp b/native/src/linprog/io.cpp new file mode 100644 index 0000000..1b5d503 --- /dev/null +++ b/native/src/linprog/io.cpp @@ -0,0 +1,22 @@ +#include + +#include "linprog/io.h" + +std::ostream& operator<<(std::ostream &os, const LinearExpression &exp) +{ + bool first = true; + foreach (exp.get_terms(), term) + { + if (term->first < 0) + os << "- " << -term->first; + else if (!first) + os << "+ " << term->first; + else + os << term->first; + + os << " X" << term->second << " "; + first = false; + } + + return os; +} -- cgit v1.2.2