optimus.algebra.Constraint.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of optimus_2.12 Show documentation
Show all versions of optimus_2.12 Show documentation
Optimus is a mathematical programming library for Scala
package optimus.algebra
/*
* /\\\\\
* /\\\///\\\
* /\\\/ \///\\\ /\\\\\\\\\ /\\\ /\\\
* /\\\ \//\\\ /\\\/////\\\ /\\\\\\\\\\\ \/// /\\\\\ /\\\\\ /\\\ /\\\ /\\\\\\\\\\
* \/\\\ \/\\\ \/\\\\\\\\\\ \////\\\//// /\\\ /\\\///\\\\\///\\\ \/\\\ \/\\\ \/\\\//////
* \//\\\ /\\\ \/\\\////// \/\\\ \/\\\ \/\\\ \//\\\ \/\\\ \/\\\ \/\\\ \/\\\\\\\\\\
* \///\\\ /\\\ \/\\\ \/\\\_/\\ \/\\\ \/\\\ \/\\\ \/\\\ \/\\\ \/\\\ \////////\\\
* \///\\\\\/ \/\\\ \//\\\\\ \/\\\ \/\\\ \/\\\ \/\\\ \//\\\\\\\\\ /\\\\\\\\\\
* \///// \/// \///// \/// \/// \/// \/// \///////// \//////////
*
* Copyright (C) 2014 Evangelos Michelioudakis, Anastasios Skarlatidis
*
* Optimus is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Optimus 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
import optimus.algebra.ConstraintRelation.ConstraintRelation
/**
* A constraint has the form (expression RELATION expression) with RELATION in {<=, =, >=}
*/
class Constraint(val lhs: Expression, val operator: ConstraintRelation, val rhs: Expression) {
override def toString = lhs + " " + operator + " " + rhs
// Move all terms in the left hand side of the expression in order to properly check equality
override def equals(that: Any) = that match {
case other: Constraint =>
val (a, b) = (lhs - rhs, other.lhs - other.rhs)
operator == other.operator &&
(a == b || -a == b || a == -b || -a == -b)
case _ => false
}
}