All Downloads are FREE. Search and download functionalities are using the official Maven repository.

optimus.algebra.Constraint.scala Maven / Gradle / Ivy

There is a newer version: 3.4.3
Show newest version
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
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy