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

com.exigen.ie.constrainer.IntExp Maven / Gradle / Ivy

package com.exigen.ie.constrainer;

///////////////////////////////////////////////////////////////////////////////
/*
 * Copyright Exigen Group 1998, 1999, 2000
 * 320 Amboy Ave., Metuchen, NJ, 08840, USA, www.exigengroup.com
 *
 * The copyright to the computer program(s) herein
 * is the property of Exigen Group, USA. All rights reserved.
 * The program(s) may be used and/or copied only with
 * the written permission of Exigen Group
 * or in accordance with the terms and conditions
 * stipulated in the agreement/contract under which
 * the program(s) have been supplied.
 */
///////////////////////////////////////////////////////////////////////////////

//
//: IntExp.java
//
/**
 * An interface for the constrained integer expression.
 * Any arithmetic operation where the operands
 * are the integer variables/expressions returns the integer expression.
 */
public interface IntExp extends Expression
{

  /**
   * The smallest value of type int.
   * Please notice that MIN_VALUE == -MAX_VALUE which is not
   * true for java.lang.Integer.
   */
  static public int MIN_VALUE = -Integer.MAX_VALUE;

  /**
   * The largest value of type int.
   */
  static public int MAX_VALUE = Integer.MAX_VALUE;

 /**
  * Returns the cast of this integer expression into floating-point expression.
  *
  * @return the FloatExp equals to this.
  */
  public FloatExp asFloat();

 /**
  * Returns the expression: (this + exp).
  */
  public IntExp add(IntExp exp);

 /**
  * Returns the expression: (this + value).
  */
  public IntExp add(int value);

 /**
  * Returns the expression: (this + exp).
  */
  public FloatExp add(FloatExp exp);

 /**
  * Returns the expression: (this + value).
  */
  public FloatExp add(double value);

 /**
  * Returns the expression: (-this).
  * That expression is opposite by sign to this expression.
  */
  public IntExp neg();

 /**
  * Returns the expression: abs(this).
  */
  public IntExp abs();

  /**
   * Returns true if this expression is bound.
   * An expression is considered bound if contains only one value in its domain.
   *
   * @return true if this expression is bound: it's domain has only one value.
   */
  public boolean bound();

  /**
   * Returns true if the domain of this expression contains the value.

   * NOTE: in some cases it is not possible (or feasible) to calculate contains with
   * 100% accuracy. We also can not guarantee a consistency between contains and
   * size method for all expressions. In other words if contains(value) returns
   * true it might happen that value does not belong to the expression's domain.
   * The opposite (false) is always true :).
   *
   * @return true if the expression contains the value in it's domain.
   */
  public boolean contains(int value);

  /**
   * Returns the largest value of the domain of this expression.
   */
  public int max();

  /**
   * Returns the smallest value of the domain of this expression.
   */
  public int min();

  /**
   * Sets the maximum value for this expression.
   *
   * @param max new maximum value.
   * @throws Failure if domain becomes empty.
   */
  public void setMax(int max) throws Failure;

 /**
   * Sets the minimum value for this expression.
   *
   * @param min new miminum value.
   * @throws Failure if domain becomes empty.
   */
  public void setMin(int min) throws Failure;

  /**
   * Bounds this variable to be equal to the value.
   *
   * @param value a value to be set.
   * @throws Failure when: !this.contains(value).
   * @see #bound
   */
  public void setValue(int value) throws Failure;

  /**
   * Removes the value from the domain of this expression.
   *
   * @throws Failure if domain becomes empty.
   */
  public void removeValue(int value) throws Failure;

  /**
   * Removes the range [min..max] from the domain of this expression.
   *
   * @param min range minimum value.
   * @param max range maxinum value.
   * @throws Failure if domain becomes empty.
   */
  public void removeRange(int min, int max) throws Failure;

  /**
   * Returns the size (cardinality) of the domain of this expression.
   * The domain's size is the number of integer values the domain.
   *
   * @return the number of values in the domain of this variable.
   */
  public int size();

  /**
   * Returns the value this expression if it is bound.
   *
   * @return the value of this expresion.
   * @throws Failure if this expresionis not bound.
   *
   * @see #bound
   */
  public int value() throws Failure;

  /**
   * Returns the constraint: (this == value).
   */
  public Constraint equals(int value);

  /**
   * Returns the constraint: (this == exp).
   */
  public Constraint equals(IntExp exp);

  /**
   * Returns the constraint: (this == exp).
   */
//  public Constraint equals(FloatExp exp);

  /**
   * Returns the constraint: (this == exp + value).
   */
  public Constraint equals(IntExp exp, int value);

  /**
   * Returns the constraint: (this == exp + value).
   */
  public Constraint equals(FloatExp exp, double value);

  /**
   * Returns the constraint: (this less value).
   */
  public Constraint less(int value);

  /**
   * Returns the constraint: (this less exp).
   */
  public Constraint less(IntExp exp);

  /**
   * Returns the constraint: (this LE value).
   */
  public Constraint lessOrEqual(int value);

  /**
   * Returns the constraint: (this LE exp).
   */
  public Constraint lessOrEqual(IntExp exp);

  /**
   * Returns the constraint: (this LE exp).
   */
  public Constraint lessOrEqual(FloatExp exp);

  /**
   * Returns the constraint: (this more value).
   */
  public Constraint more(int value);

  /**
   * Returns the constraint: (this more exp).
   */
  public Constraint more(IntExp exp);

  /**
   * Returns the constraint: (this GE value).
   */
  public Constraint moreOrEqual(int value);

  /**
   * Returns the constraint: (this GE exp).
   */
  public Constraint moreOrEqual(IntExp exp);

  /**
   * Returns the constraint: (this GE exp).
   */
  public Constraint moreOrEqual(FloatExp exp);

  /**
   * Returns the expression: (this - exp).
   */
  public IntExp sub(IntExp exp);

  /**
   * Returns the expression: (this - value).
   */
  public IntExp sub(int value);

  /**
   * Returns the expression: (this - exp).
   */
  public FloatExp sub(FloatExp exp);

  /**
   * Returns the expression: (this - value).
   */
  public FloatExp sub(double value);

  /**
   * Returns the expression: (this * exp).
   */
  public IntExp mul(IntExp exp);

  /**
   * Returns the expression: (this * value).
   */
  public IntExp mul(int value);

  /**
   * Returns the expression: (this * exp).
   */
  public FloatExp mul(FloatExp exp);

  /**
   * Returns the expression: (this * value).
   */
  public FloatExp mul(double value);

  /**
   * Returns the expression: (this / value).
   */
  public IntExp div(int value);

  /**
   * Returns the expression: (this / divisor).
   */
  public IntExp div(IntExp divisor) throws Failure;

  /**
   * Returns the expression: (this / value).
   */
  public FloatExp div(double value);

  /**
   * Returns the expression: (this * this).
   */
  public IntExp sqr();

  /**
   * Returns true if domain is not empty.
   * @return true if domain is not empty.
   */
  public boolean valid();

  /**
   * Returns the display string for the current domain of this expression.
   */
  public String domainToString();

  /**
   * An interface used in the iteration of the domain of the integer expression.
   * @see #iterateDomain
   */
  public interface IntDomainIterator
  {
    /**
     * Processes each value contained within domain one by one
     * (by convention from lowest to highest value).
     *
     * It should return false to stop iteration or true to continue.
     *
     * @see IntExp#iterateDomain
     */
    public boolean doSomethingOrStop(int val) throws Failure;
  }

  /**
   * Iterates the domain of this expression by calling
   * doSomethingOrStop(int val) of IntDomainIterator.
   *
   * @see IntDomainIterator
   * @see IntDomainIterator#doSomethingOrStop
   */
  public void iterateDomain(IntDomainIterator it) throws Failure;

  /**
   * Returns the expression:
   * ((this less rangeMin)*(rangeMin - this) + (this more rangeMax)*(this - rangeMax)).
   */
   public IntExp rangeViolation(int rangeMin, int rangeMax);

 /**
  * Returns the boolean expression: (this == exp).
  */
  public IntBoolExp eq(IntExp exp);

 /**
  * Returns the boolean expression: (this == value).
  */
  public IntBoolExp eq(int value);

 /**
  * Returns the boolean expression: (this == value).
  */
  public IntBoolExp eq(double value);

 /**
  * Returns the boolean expression: (this != exp).
  */
  public IntBoolExp ne(IntExp exp);

 /**
  * Returns the boolean expression: (this != value).
  */
  public IntBoolExp ne(int value);

 /**
  * Returns the boolean expression: (this != value).
  */
  public IntBoolExp ne(double value);

 /**
  * Returns the boolean expression: (this lt exp).
  */
  public IntBoolExp lt(IntExp exp);

 /**
  * Returns the boolean expression: (this lt value).
  */
  public IntBoolExp lt(int value);

 /**
  * Returns the boolean expression: (this lt value).
  */
  public IntBoolExp lt(double value);

 /**
  * Returns the boolean expression: (this gt exp).
  */
  public IntBoolExp gt(IntExp exp);

 /**
  * Returns the boolean expression: (this gt value).
  */
  public IntBoolExp gt(int value);

 /**
  * Returns the boolean expression: (this gt value).
  */
  public IntBoolExp gt(double value);

 /**
  * Returns the boolean expression: (this le exp).
  */
  public IntBoolExp le(IntExp exp);

 /**
  * Returns the boolean expression: (this le value).
  */
  public IntBoolExp le(int value);

 /**
  * Returns the boolean expression: (this ge value).
  */
  public IntBoolExp le(double value);

 /**
  * Returns the boolean expression: (this ge exp).
  */
  public IntBoolExp ge(IntExp exp);

 /**
  * Returns the boolean expression: (this ge value).
  */
  public IntBoolExp ge(int value);

 /**
  * Returns the boolean expression: (this ge value).
  */
  public IntBoolExp ge(double value);

 /**
  * Returns the expression: (this % value).
  */
  public IntExp mod(int value);

 /**
  * Returns the expression: (this % value).
  */
  public FloatExp mod(double value);

  /**
   * Returns the expression: pow(this,value).
   */
  public FloatExp pow(double value) throws Failure;

  /**
   * Returns the expression: pow(this,value).
   * Value should be ge 0.
   * For value lt 0 use pow(double value).
   *
   * Throws RuntimeException if there value less 0.
   */
  public IntExp pow(int value);

  /**
   * Returns the expression: pow(this,pow_exp).
   * The constraint "pow_exp ge 0" is added to Constrainer.
   *
   * Throws RuntimeException if there value LT 0.
   */
  public IntExp pow(IntExp pow_exp) throws Failure;

} // ~IntExp




© 2015 - 2024 Weber Informatics LLC | Privacy Policy