/* Constraint class implementation: inline functions.
Copyright (C) 2001-2004 Roberto Bagnara <bagnara@cs.unipr.it>
This file is part of the Parma Polyhedra Library (PPL).
The PPL is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The PPL is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
For the most up-to-date information see the Parma Polyhedra Library
site: http://www.cs.unipr.it/ppl/ . */
#ifndef PPL_Constraint_inlines_hh
#define PPL_Constraint_inlines_hh 1
#include "LinExpression.defs.hh"
namespace Parma_Polyhedra_Library {
inline
Constraint::Constraint(LinExpression& e) {
Row::swap(e);
}
inline
Constraint::Constraint(const Constraint& c)
: Row(c) {
}
inline
Constraint::Constraint(const Constraint& c, const dimension_type sz)
: Row(c, sz, sz) {
}
inline
Constraint::Constraint(Row::Type t, const dimension_type sz)
: Row(t, sz) {
}
inline
Constraint::~Constraint() {
}
inline Constraint&
Constraint::operator=(const Constraint& c) {
Row::operator=(c);
return *this;
}
inline dimension_type
Constraint::space_dimension() const {
return Row::space_dimension();
}
inline bool
Constraint::is_equality() const {
return is_line_or_equality();
}
inline bool
Constraint::is_inequality() const {
return is_ray_or_point_or_inequality();
}
inline Constraint::Type
Constraint::type() const {
if (is_equality())
return EQUALITY;
if (is_necessarily_closed())
return NONSTRICT_INEQUALITY;
else
return ((*this)[size() - 1] < 0)
? STRICT_INEQUALITY
: NONSTRICT_INEQUALITY;
}
inline bool
Constraint::is_nonstrict_inequality() const {
return type() == NONSTRICT_INEQUALITY;
}
inline bool
Constraint::is_strict_inequality() const {
return type() == STRICT_INEQUALITY;
}
inline void
Constraint::set_is_equality() {
set_is_line_or_equality();
}
inline void
Constraint::set_is_inequality() {
set_is_ray_or_point_or_inequality();
}
inline const Integer&
Constraint::coefficient(const Variable v) const {
const dimension_type v_id = v.id();
if (v_id >= space_dimension())
throw_dimension_incompatible("coefficient(v)", "v", v);
return Row::coefficient(v_id);
}
inline const Integer&
Constraint::inhomogeneous_term() const {
return Row::inhomogeneous_term();
}
/*! \relates Constraint */
inline Constraint
operator==(const LinExpression& e1, const LinExpression& e2) {
LinExpression diff = e1 - e2;
Constraint c(diff);
c.set_is_equality();
// Enforce normalization.
c.strong_normalize();
return c;
}
/*! \relates Constraint */
inline Constraint
operator>=(const LinExpression& e1, const LinExpression& e2) {
LinExpression diff = e1 - e2;
Constraint c(diff);
c.set_is_inequality();
// Enforcing normalization.
c.normalize();
return c;
}
/*! \relates Constraint */
inline Constraint
operator>(const LinExpression& e1, const LinExpression& e2) {
LinExpression diff;
// Setting the epsilon coefficient to -1.
// NOTE: this also enforces normalization.
const dimension_type e1_dim = e1.space_dimension();
const dimension_type e2_dim = e2.space_dimension();
if (e1_dim > e2_dim)
diff -= Variable(e1_dim);
else
diff -= Variable(e2_dim);
diff += e1;
diff -= e2;
Constraint c(diff);
c.set_not_necessarily_closed();
c.set_is_inequality();
return c;
}
/*! \relates Constraint */
inline Constraint
operator==(const Integer& n, const LinExpression& e) {
LinExpression diff = n - e;
Constraint c(diff);
c.set_is_equality();
// Enforce normalization.
c.strong_normalize();
return c;
}
/*! \relates Constraint */
inline Constraint
operator>=(const Integer& n, const LinExpression& e) {
LinExpression diff = n - e;
Constraint c(diff);
c.set_is_inequality();
// Enforcing normalization.
c.normalize();
return c;
}
/*! \relates Constraint */
inline Constraint
operator>(const Integer& n, const LinExpression& e) {
LinExpression diff;
// Setting the epsilon coefficient to -1.
// NOTE: this also enforces normalization.
diff -= Variable(e.space_dimension());
diff += n;
diff -= e;
Constraint c(diff);
c.set_not_necessarily_closed();
c.set_is_inequality();
return c;
}
/*! \relates Constraint */
inline Constraint
operator==(const LinExpression& e, const Integer& n) {
LinExpression diff = e - n;
Constraint c(diff);
c.set_is_equality();
// Enforce normalization.
c.strong_normalize();
return c;
}
/*! \relates Constraint */
inline Constraint
operator>=(const LinExpression& e, const Integer& n) {
LinExpression diff = e - n;
Constraint c(diff);
c.set_is_inequality();
// Enforcing normalization.
c.normalize();
return c;
}
/*! \relates Constraint */
inline Constraint
operator>(const LinExpression& e, const Integer& n) {
LinExpression diff;
// Setting the epsilon coefficient to -1.
// NOTE: this also enforces normalization.
diff -= Variable(e.space_dimension());
diff += e;
diff -= n;
Constraint c(diff);
c.set_not_necessarily_closed();
c.set_is_inequality();
return c;
}
/*! \relates Constraint */
inline Constraint
operator<=(const LinExpression& e1, const LinExpression& e2) {
return e2 >= e1;
}
/*! \relates Constraint */
inline Constraint
operator<=(const Integer& n, const LinExpression& e) {
return e >= n;
}
/*! \relates Constraint */
inline Constraint
operator<=(const LinExpression& e, const Integer& n) {
return n >= e;
}
/*! \relates Constraint */
inline Constraint
operator<(const LinExpression& e1, const LinExpression& e2) {
return e2 > e1;
}
/*! \relates Constraint */
inline Constraint
operator<(const Integer& n, const LinExpression& e) {
return e > n;
}
/*! \relates Constraint */
inline Constraint
operator<(const LinExpression& e, const Integer& n) {
return n > e;
}
inline const Constraint&
Constraint::zero_dim_false() {
static const Constraint zdf(LinExpression::zero() == Integer_one());
return zdf;
}
inline const Constraint&
Constraint::zero_dim_positivity() {
static const Constraint zdp(LinExpression::zero() <= Integer_one());
return zdp;
}
inline const Constraint&
Constraint::epsilon_geq_zero() {
static const Constraint eps_geq_zero = construct_epsilon_geq_zero();
return eps_geq_zero;
}
inline const Constraint&
Constraint::epsilon_leq_one() {
static const Constraint eps_leq_one(LinExpression::zero() < Integer_one());
return eps_leq_one;
}
inline void
Constraint::swap(Constraint& y) {
Row::swap(y);
}
} // namespace Parma_Polyhedra_Library
namespace std {
/*! \relates Parma_Polyhedra_Library::Constraint */
inline void
swap(Parma_Polyhedra_Library::Constraint& x,
Parma_Polyhedra_Library::Constraint& y) {
x.swap(y);
}
} // namespace std
#endif // !defined(PPL_Constraint_inlines_hh)
syntax highlighted by Code2HTML, v. 0.9.1