edu.neu.ccs.evergreen.ir
Class Relation

java.lang.Object
  extended by edu.neu.ccs.evergreen.ir.Relation
All Implemented Interfaces:
RelationI

public class Relation
extends java.lang.Object
implements RelationI


Field Summary
 
Fields inherited from interface edu.neu.ccs.evergreen.ir.RelationI
SOURCE, TARGET
 
Constructor Summary
Relation(int rank, int relationNumber)
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 int firstForcedVariable(int startPosition)
          starting at the given startPosition, get the position of the first variable forced by the relation.
 int getMagicNumber(int variablePosition, int value)
          Returns a magic number associated with a certain truth table column and value The magic number associated with column number 0 of the truth table and value 0 is basically a sequence of alternating 0 and 1 bits, packed together in one integer.
 int getMask()
           
 int getRank()
           
 int getRelationNumber()
           
 int isForced(int variablePosition)
          Checks if the relation forces the given variablePosition
 boolean isIrrelevant(int variablePosition)
          Checks if the variable at a given position is irrelevant to the internally stored relation
 int nMap(int variablePosition)
          NMaps one of the variables in a relation i.e.
 int numberOfRelevantVariables()
          Counts the number of relevantVariables in the relation
 int ones()
          returns the number of ones in the given relationNumber
 int q(int s)
           
 int reduce(int variablePosition, int value)
          Reduces a relation by assigning a value to one of its variables
 int renme(int permutationSemantics, int... permutation)
           
 void setRank(int rank)
          Currently unsupported Usually converting to a higher rank is simple.
 void setRelationNumber(int relationNumber)
           
 int swap(int variablePosition1, int variablePosition2)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Relation

public Relation(int rank,
                int relationNumber)
Parameters:
rank -
relationNumber -
Method Detail

firstForcedVariable

public int firstForcedVariable(int startPosition)
                        throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
starting at the given startPosition, get the position of the first variable forced by the relation.

Specified by:
firstForcedVariable in interface RelationI
Returns:
-1 if nothing is forced the position of the first forced variable
Throws:
java.lang.IllegalArgumentException

getMagicNumber

public int getMagicNumber(int variablePosition,
                          int value)
                   throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
Returns a magic number associated with a certain truth table column and value The magic number associated with column number 0 of the truth table and value 0 is basically a sequence of alternating 0 and 1 bits, packed together in one integer. The magic number associated with column number 0 of the truth table and value 1 is a sequence of alternating 1 and 0 bits, packed together in one integer. In general: (getMagicNumber(n,0) == ~getMagicNumber(n,1)) For column 1: magic numbers are fromed from sequences of two 0's followed by two 1's For column 2: magic numbers are formed from sequences of four 0's followed by four 1's For column 3: magic numbers are formed from sequeneces of eight 0's followed by eight 1's For column 4:magic numbers are formed from sequeneces of sixteen 0's followed by sixteen 1's There is no other possible columns as long as we are using 32 bit integers The lenght of the magic number depends on the internally stored relation rank

Specified by:
getMagicNumber in interface RelationI
Parameters:
variablePosition - the position of the desired magic number
value - the value associated with the desired magic number
Returns:
Throws:
java.lang.IllegalArgumentException

getMask

public int getMask()
Specified by:
getMask in interface RelationI
Returns:
An integer with all of its bits set to 1. The length of the integer depends on the internally stored rank.
the result is: 2^2^rank-1
Note: the method takes care of the case where 2^2^n is outside the integer range but 2^2^n-1 is not.

getRank

public int getRank()
Specified by:
getRank in interface RelationI
Returns:
rank of the relation

getRelationNumber

public int getRelationNumber()
Specified by:
getRelationNumber in interface RelationI
Returns:
an integer representing the relation number

isForced

public int isForced(int variablePosition)
             throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
Checks if the relation forces the given variablePosition

Specified by:
isForced in interface RelationI
Parameters:
variablePosition - positon of the varible checked for being forced
Returns:
0 if the given relation forces the given variable to 0 1 if the given relation forces the given variable to 1 -1 given relation doesn't forces the given variable
Throws:
java.lang.IllegalArgumentException

isIrrelevant

public boolean isIrrelevant(int variablePosition)
                     throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
Checks if the variable at a given position is irrelevant to the internally stored relation

Specified by:
isIrrelevant in interface RelationI
Parameters:
variablePosition - the variable to be checked
Returns:
true if the variable at vairablePosition is irrelevant otherwise returns false
Throws:
java.lang.IllegalArgumentException

nMap

public int nMap(int variablePosition)
         throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
NMaps one of the variables in a relation i.e. replaces it by it's complement for example: nMapping x in Or(x,y,z) results in: or(!x,y,z)

Specified by:
nMap in interface RelationI
Parameters:
variablePosition - the variable to be nmapped
Returns:
The number of the given relation with the specified variable nmapped
Throws:
java.lang.IllegalArgumentException

numberOfRelevantVariables

public int numberOfRelevantVariables()
Description copied from interface: RelationI
Counts the number of relevantVariables in the relation

Specified by:
numberOfRelevantVariables in interface RelationI
Returns:
The number of relevant variables in the relation

ones

public int ones()
Description copied from interface: RelationI
returns the number of ones in the given relationNumber

Specified by:
ones in interface RelationI
Returns:

q

public int q(int s)
      throws java.lang.IllegalArgumentException
Specified by:
q in interface RelationI
Returns:
the number of rows in the truth table with s 1's
Throws:
java.lang.IllegalArgumentException

reduce

public int reduce(int variablePosition,
                  int value)
           throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
Reduces a relation by assigning a value to one of its variables

Specified by:
reduce in interface RelationI
Returns:
Throws:
java.lang.IllegalArgumentException

renme

public int renme(int permutationSemantics,
                 int... permutation)
          throws java.lang.IllegalArgumentException
Specified by:
renme in interface RelationI
Returns:
Throws:
java.lang.IllegalArgumentException

setRank

public void setRank(int rank)
             throws java.lang.IllegalArgumentException
Description copied from interface: RelationI
Currently unsupported Usually converting to a higher rank is simple. however converting to a lower rank might require the introduction of auxiliary variables and more than one relation might result from the operation

Specified by:
setRank in interface RelationI
Parameters:
rank - sets the rank of the relation
Throws:
java.lang.IllegalArgumentException

setRelationNumber

public void setRelationNumber(int relationNumber)
                       throws java.lang.IllegalArgumentException
Specified by:
setRelationNumber in interface RelationI
Throws:
java.lang.IllegalArgumentException - Thrwon if the relation number is invalid according to the rank

swap

public int swap(int variablePosition1,
                int variablePosition2)
         throws java.lang.IllegalArgumentException
Specified by:
swap in interface RelationI
Throws:
java.lang.IllegalArgumentException

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

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