chordDiagrams
Class FourTProcessor

java.lang.Object
  extended by chordDiagrams.FourTGenerator
      extended by chordDiagrams.FourTProcessor

public class FourTProcessor
extends FourTGenerator

The class processes a list of 4T relations to leave out only independent ones in row-reduced echelon form. Mathematica is used to generate this form.

Author:
Romwell

Field Summary
 java.util.TreeSet<Relation> indRelations
          Data structire to hold the independent relations
(package private)  boolean[] isInBasis
          isInBasis[i] is true if diagram referenced by keys.get(i) is in the basis
Not initialized until evaluateRelations() is called
(package private)  int MAX
          Maximum size of the matrix (rows*cols) that will be sent to Mathematica.
 com.wolfram.jlink.KernelLink ml
          Kernel Link object to interface with Mathematica
 
Fields inherited from class chordDiagrams.FourTGenerator
count, diag_gen, diags, k, keys, n, relations
 
Constructor Summary
FourTProcessor(int n, int k, int MAXnum, UnframedDiagramGenerator gen)
          Creates a new instance of the class
 
Method Summary
 void closeKernelLink()
          Finalizes Kernel Link Mathematica connection
 void DrawBasis(DiagramDrawer DDrawer)
          Once the basis has been computed (after Mathematica computations were run), this method draws the diagrams in the basis and saves them into files.
 void DrawRelations(DiagramDrawer DDrawer)
          Draws the set of 4T relations computed by this class with a DDRawer
 java.util.SortedSet<Relation> evaluateRelations()
          Row-reduces the relation matrix using Mathematica (via J/Link API) and puts result into indRelation using the recursive processRelation() method
 void evaluateRelations(java.util.Iterator<Relation> iter, java.util.Set<Relation> resultSet, int num)
          Row-reduces the relation matrix using Mathematica (via J/Link API) and puts result into resultSet
 int extractBasis()
          Extracts the basis from the list of independent relations, once it has been computed.
 java.lang.String indRelationDataFname()
          Generates a name of the file to save relations in.
 boolean initKernelLink()
          Initialize Mathematica KernelLink
 boolean loadIndRelations()
          Load the independent relation data from file.
 int nnz(java.util.Set<Relation> relSet)
          Returns the number of non-zero entries in a relation set
static void printMatrix(double[][] A)
          Outputs matrix to console
 void printMatrix(int[][] A)
          Outputs matrix to console
 void processMathematicaOutput(double[][] data, java.util.Set<Relation> relations)
          Takes a relation matrix (usually this is a result of Mathematica computation) and puts it into a relation set
 void processRelations(java.util.Iterator<Relation> iter, java.util.Set<Relation> resultSet, int num, int MAX)
          Sends a certain number of relations to Mathematica to row-reduce, no more than a MAX at a time, and puts the result into the resultSet
 void putRelationRulesToMathematica(java.util.Set<Relation> relSet)
          Sends the relations matrix "rules" to Mathematica ("rules" for sparse array notation) The relations are obtained from the provided set.
 int putRelationsToMathematica(java.util.Iterator<Relation> iter, int num)
          Sends the relations to mathematica in the sparse array form The sparse array is asigned to variable "matrix".
 boolean saveIndRelations()
          Saves the independent relations to the file The name of the file depends on n and k ans is returned by indRelationDataFname() function
 int setFromIterator(java.util.Iterator<Relation> iter, java.util.Set<Relation> resultSet, int n)
          Takes and iterator and tries to take a specified number of Relations from the iterator.
 boolean TestMegaConjecture()
          Tests the mega conjecture that all relations have size 2.
 
Methods inherited from class chordDiagrams.FourTGenerator
account4Ts, charMatch, DrawRelations, generate4Ts, generateA, generateAll4Ts, generateAll4Ts, identify4Tdiagrams, isNew, JoinArrays, loadRelations, printArray, relationDataFname, reverseString, rotateStringArray, saveRelations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isInBasis

boolean[] isInBasis
isInBasis[i] is true if diagram referenced by keys.get(i) is in the basis
Not initialized until evaluateRelations() is called


indRelations

public java.util.TreeSet<Relation> indRelations
Data structire to hold the independent relations


ml

public com.wolfram.jlink.KernelLink ml
Kernel Link object to interface with Mathematica


MAX

int MAX
Maximum size of the matrix (rows*cols) that will be sent to Mathematica. If the matrix exceeds this size, it will be broken into submatrices of smaller sizes.

Constructor Detail

FourTProcessor

public FourTProcessor(int n,
                      int k,
                      int MAXnum,
                      UnframedDiagramGenerator gen)
Creates a new instance of the class

Parameters:
n - number of chords
k - number of links
MAXnum - maximum size of the matrix that Mathematica will handle
NOTE: if MAX is not big enough(i.e., big enough to fit the row-reduced form in its full [not sparse] form), the program will run FOREVER. Be careful.
gen - Diagram generator to use
Method Detail

processRelations

public void processRelations(java.util.Iterator<Relation> iter,
                             java.util.Set<Relation> resultSet,
                             int num,
                             int MAX)
Sends a certain number of relations to Mathematica to row-reduce, no more than a MAX at a time, and puts the result into the resultSet

Parameters:
iter - Iterator to get the relations from
num - number of relations to send
resultSet - the set to put resuling (independent)relations into
MAX - maximum number of relations to send at a time

evaluateRelations

public java.util.SortedSet<Relation> evaluateRelations()
Row-reduces the relation matrix using Mathematica (via J/Link API) and puts result into indRelation using the recursive processRelation() method

Returns:
Sorted set with independent relations

evaluateRelations

public void evaluateRelations(java.util.Iterator<Relation> iter,
                              java.util.Set<Relation> resultSet,
                              int num)
Row-reduces the relation matrix using Mathematica (via J/Link API) and puts result into resultSet

Parameters:
iter - Iterator to get the relations from
num - number of relations to send
resultSet - the set to put resuling (independent)relations into

initKernelLink

public boolean initKernelLink()
Initialize Mathematica KernelLink

Returns:
true if the kernel was loaded successfully

closeKernelLink

public void closeKernelLink()
Finalizes Kernel Link Mathematica connection


printMatrix

public void printMatrix(int[][] A)
Outputs matrix to console

Parameters:
A - matrix to print

printMatrix

public static void printMatrix(double[][] A)
Outputs matrix to console

Parameters:
A - matrix to print

putRelationsToMathematica

public int putRelationsToMathematica(java.util.Iterator<Relation> iter,
                                     int num)
                              throws com.wolfram.jlink.MathLinkException
Sends the relations to mathematica in the sparse array form The sparse array is asigned to variable "matrix".
The relations are obtained from the provided iterator; the method attempts to get num relations, and stops when the iterator has no next element. Note that this method advances the iterator by calling the setFromIterator method.

Parameters:
iter - Iterator to get the relations from
num - Number of relations to get from the Iterator
Returns:
the number of relations sent
Throws:
com.wolfram.jlink.MathLinkException - and exception is thrown when Mathematica cries

putRelationRulesToMathematica

public void putRelationRulesToMathematica(java.util.Set<Relation> relSet)
                                   throws com.wolfram.jlink.MathLinkException
Sends the relations matrix "rules" to Mathematica ("rules" for sparse array notation) The relations are obtained from the provided set.

Parameters:
relSet - the set to take relations from
Throws:
com.wolfram.jlink.MathLinkException

setFromIterator

public int setFromIterator(java.util.Iterator<Relation> iter,
                           java.util.Set<Relation> resultSet,
                           int n)
Takes and iterator and tries to take a specified number of Relations from the iterator. The result is added to a set provided to the method.
Note that the iterator is being advanced n times (or till the end of a a collection, whichever occurs first)
The method returns the number of relations obtained from the Iterator.

Parameters:
iter - the Iterator to take the Relations from
n - number of elements to take (mwthod will stop once the Iterator is depleted, if this occurs sooner)
resultSet - the set to put the relations into
Returns:
the number of relations obtained from the iterator

nnz

public int nnz(java.util.Set<Relation> relSet)
Returns the number of non-zero entries in a relation set

Parameters:
relSet - the set with relations
Returns:
number of nonzero entries in the set

processMathematicaOutput

public void processMathematicaOutput(double[][] data,
                                     java.util.Set<Relation> relations)
Takes a relation matrix (usually this is a result of Mathematica computation) and puts it into a relation set

Parameters:
data - relation matrix
relations - data structure (Set) to store relations in

extractBasis

public int extractBasis()
Extracts the basis from the list of independent relations, once it has been computed. The isInBasis array is filled with booleans; isinabsis[i]=true means diagram i is in the basis.

Returns:
number of elements in the basis

DrawBasis

public void DrawBasis(DiagramDrawer DDrawer)
Once the basis has been computed (after Mathematica computations were run), this method draws the diagrams in the basis and saves them into files.

Parameters:
DDrawer - diagram drawer to draw basis with

DrawRelations

public void DrawRelations(DiagramDrawer DDrawer)
Draws the set of 4T relations computed by this class with a DDRawer

Overrides:
DrawRelations in class FourTGenerator
Parameters:
DDrawer - DiagramDrawer to draw the relations with

saveIndRelations

public boolean saveIndRelations()
Saves the independent relations to the file The name of the file depends on n and k ans is returned by indRelationDataFname() function

Returns:
true if the relations were saved successfully; false otherwise

loadIndRelations

public boolean loadIndRelations()
Load the independent relation data from file. The filename is given by indRelationDataFname() function.

Returns:
true if the data was loaded successfully

indRelationDataFname

public java.lang.String indRelationDataFname()
Generates a name of the file to save relations in. If the file with such a name is present, data is loaded from the file instead of being generated.

Returns:
name of the file with relations

TestMegaConjecture

public boolean TestMegaConjecture()
Tests the mega conjecture that all relations have size 2.

Returns:
true if the conjecture is true