javax.constraints.impl
Class AbstractVar

java.lang.Object
  extended by javax.constraints.impl.CommonBase
      extended by javax.constraints.impl.AbstractConstrainedVariable
          extended by javax.constraints.impl.AbstractVar
All Implemented Interfaces:
ConstrainedVariable, Var

public abstract class AbstractVar
extends AbstractConstrainedVariable
implements Var


Constructor Summary
AbstractVar(Problem problem)
           
AbstractVar(Problem problem, java.lang.String name)
           
 
Method Summary
abstract  void addPropagator(Propagator propagator, PropagationEvent event)
          This method associates a custom Propagator with an "event" related to changes in the domain of a constrained variable "var".
 int compareTo(Var var)
           
 Var divide(int value)
          Returns a new Var that is constrained to be the division of this variable by the given value, i.e.
 Var divide(Var var)
          Returns a new Var that is constrained to be the division of this variable by the given variable, i.e.
 int getDomainSize()
          Provides the default implementation as return getMax() - getMin() + 1; This method is better to be redefined to take into consideration an actual domain implementations.
 DomainType getDomainType()
          Returns the type of this variable's domain.
 java.lang.String getInitialDomain()
          Returns a string representation of the initial domain of this variable.
 int getValue()
          Returns the value to which this variable has been instantiated, throws a RuntimeException if the variable is not instantiated.
 Var minus(int value)
          Returns a new Var that is constrained to be the difference of this variable and the given value, i.e.
 Var minus(Var var)
          Returns a new Var that is constrained to be the difference of this variable and the given variable, i.e.
 Var mod(int value)
          Returns a new Var that is constrained to be the remainder after performing integer division of this variable by the given value, i.e.
 Var negative()
          Returns a new Var that is constrained to be the negation of this variable, i.e.
 Var power(int value)
          Returns a new Var that is constrained to be this variable raised to the power of the given value, i.e.
 void setDomainType(DomainType type)
          Changes the domain type of this variable.
 Var sqr()
          Returns a new Var that is constrained to be the product of this variable and itself, i.e.
 java.lang.String toString()
           
 
Methods inherited from class javax.constraints.impl.CommonBase
getImpl, getName, getObject, getProblem, setImpl, setName, setObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.constraints.Var
abs, contains, getMax, getMin, isBound, multiply, multiply, plus, plus
 
Methods inherited from interface javax.constraints.ConstrainedVariable
getImpl, getName, getObject, getProblem, setImpl, setName, setObject
 

Constructor Detail

AbstractVar

public AbstractVar(Problem problem)

AbstractVar

public AbstractVar(Problem problem,
                   java.lang.String name)
Method Detail

addPropagator

public abstract void addPropagator(Propagator propagator,
                                   PropagationEvent event)
This method associates a custom Propagator with an "event" related to changes in the domain of a constrained variable "var". It forces the solver to keep an eye on these events and invoke the Propagator "propagator" when these events actually occur. When such events occur, the Propagator's method propagate() will be executed.

Parameters:
propagator - the Propagator we wish to associate with events on the variable.
event - the events that will trigger the invocation of the Propagator.

compareTo

public int compareTo(Var var)
Specified by:
compareTo in interface Var

divide

public Var divide(int value)
Description copied from interface: Var
Returns a new Var that is constrained to be the division of this variable by the given value, i.e. this / value.

Specified by:
divide in interface Var
Parameters:
value - the given value.
Returns:
this / value

divide

public Var divide(Var var)
           throws java.lang.Exception
Description copied from interface: Var
Returns a new Var that is constrained to be the division of this variable by the given variable, i.e. this / var.

Specified by:
divide in interface Var
Parameters:
var - the given variable.
Returns:
this / var
Throws:
java.lang.Exception - if dividing by zero.

getDomainSize

public int getDomainSize()
Provides the default implementation as return getMax() - getMin() + 1; This method is better to be redefined to take into consideration an actual domain implementations.

Specified by:
getDomainSize in interface Var
Returns:
the current number of values inside the domain of this variable

getDomainType

public DomainType getDomainType()
Description copied from interface: Var
Returns the type of this variable's domain.

Specified by:
getDomainType in interface Var
Returns:
domainType

getInitialDomain

public java.lang.String getInitialDomain()
Description copied from interface: Var
Returns a string representation of the initial domain of this variable.

Specified by:
getInitialDomain in interface Var
Returns:
a string representing the initial domain of the variable

getValue

public int getValue()
Description copied from interface: Var
Returns the value to which this variable has been instantiated, throws a RuntimeException if the variable is not instantiated.

Specified by:
getValue in interface Var
Returns:
int that is a value of this instantiated variable
Throws:
java.lang.RuntimeException - if this variable is not instantiated

minus

public Var minus(int value)
Description copied from interface: Var
Returns a new Var that is constrained to be the difference of this variable and the given value, i.e. this - value.

Specified by:
minus in interface Var
Parameters:
value - the given value.
Returns:
this - value

minus

public Var minus(Var var)
Description copied from interface: Var
Returns a new Var that is constrained to be the difference of this variable and the given variable, i.e. this - var.

Specified by:
minus in interface Var
Parameters:
var - the given variable.
Returns:
this - var

mod

public Var mod(int value)
Description copied from interface: Var
Returns a new Var that is constrained to be the remainder after performing integer division of this variable by the given value, i.e. mod(this,value).

Specified by:
mod in interface Var
Parameters:
value - the given value.
Returns:
remainder of this/value: mod(this,value)

negative

public Var negative()
Description copied from interface: Var
Returns a new Var that is constrained to be the negation of this variable, i.e. 0 - this.

Specified by:
negative in interface Var
Returns:
-this

power

public Var power(int value)
Returns a new Var that is constrained to be this variable raised to the power of the given value, i.e. this^value.

Specified by:
power in interface Var
Parameters:
value - the given value.
Returns:
a Var that represents: this^value.

setDomainType

public void setDomainType(DomainType type)
Changes the domain type of this variable. Setting domain type AFTER a variable was created allows to take into consideration posted constraints and other problem state specific information. To take advantage of such domain type as DOMAIN_AUTOMATIC this method should be overloaded by an implementation solver

Specified by:
setDomainType in interface Var
Parameters:
type -

sqr

public Var sqr()
Returns a new Var that is constrained to be the product of this variable and itself, i.e. this * this.

Specified by:
sqr in interface Var
Returns:
a Var that represents: this * this.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object