chordDiagrams
Class FourTGenerator

java.lang.Object
  extended by chordDiagrams.FourTGenerator
Direct Known Subclasses:
FourTProcessor

public class FourTGenerator
extends java.lang.Object

Generates all 4T relations for a list of diagrams

Author:
Romwell

Field Summary
 int count
          Stores the number of realtions found so far
private  Relation cur_row
          Hashmap to store current row
(package private)  UnframedDiagramGenerator diag_gen
          Diagram generator used to generate diagrams
 java.util.HashMap<java.lang.String,diagram> diags
          Hashmap to store diagrams
(package private)  int k
          Number of links
 java.util.ArrayList<java.lang.String> keys
          The key set for the hash map
(package private)  int n
          Number of chords
 java.util.TreeSet<Relation> relations
          Data structure to store relations
 
Constructor Summary
FourTGenerator(int n, int k, UnframedDiagramGenerator gen)
          Initializes an instance of 4T Generator
 
Method Summary
 void account4Ts(java.lang.String[][] relation)
          Finds out what diagrams are in the relation and stores their indixes (indicating their position in the keys list) in the matrix, with corresponding coefficients
static boolean charMatch(java.lang.String S, int index, char[] a)
          Tells whether a string contains a character belonging to a set at a position
 void DrawRelations(DiagramDrawer DDrawer)
          Draws the set of 4T relations computed by this class with a DDRawer
 void DrawRelations(DiagramDrawer DDrawer, java.util.Set<Relation> relSet)
          Draws a set of relations with a DDrawer
static java.lang.String[][] generate4Ts(diagram g, int link)
          Generates 4T relations for the first pair of feet in the current rotation of a linik
static java.lang.String generateA(java.lang.String[] XY, java.lang.String[] AB, boolean reverse)
          Makes a string out of two array by the rule result=wAxByCz
 void generateAll4Ts()
          Generates and accounts for all the 4T realtions for all the diagrams stored in the list
 void generateAll4Ts(diagram g)
          Generates and accounts for all 4T relations for a given diagram
 int[][] identify4Tdiagrams(java.lang.String[][] relation)
          Identifies the diagrams in the 4T relation and returns their indices in the keys list
 boolean isNew(Relation r)
          Tells whether a relation r is new to the list
static java.lang.String[] JoinArrays(java.lang.String[] A, java.lang.String[] B)
          Concatenates two string arrays
 boolean loadRelations()
          Load the relation data from file.
static void printArray(java.lang.String[] a)
           
 java.lang.String relationDataFname()
          Generates a name of the file to save relations in.
static java.lang.String reverseString(java.lang.String S)
          Takes a string and reverses characters in it
static void rotateStringArray(java.lang.String[] a)
          Rotates string array clockwise
 boolean saveRelations()
          Saves the relations to the file The name of the file depends on n and k ans is returned by relationDataFname() function
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

diags

public java.util.HashMap<java.lang.String,diagram> diags
Hashmap to store diagrams


keys

public java.util.ArrayList<java.lang.String> keys
The key set for the hash map


relations

public java.util.TreeSet<Relation> relations
Data structure to store relations


count

public int count
Stores the number of realtions found so far


cur_row

private Relation cur_row
Hashmap to store current row


n

int n
Number of chords


k

int k
Number of links


diag_gen

UnframedDiagramGenerator diag_gen
Diagram generator used to generate diagrams

Constructor Detail

FourTGenerator

public FourTGenerator(int n,
                      int k,
                      UnframedDiagramGenerator gen)
Initializes an instance of 4T Generator

Parameters:
n - number of chords
k - number of links
gen - diagram generator to use
Method Detail

generateAll4Ts

public void generateAll4Ts()
Generates and accounts for all the 4T realtions for all the diagrams stored in the list


generateAll4Ts

public void generateAll4Ts(diagram g)
Generates and accounts for all 4T relations for a given diagram

Parameters:
g - the diagram to generate all 4T's for

account4Ts

public void account4Ts(java.lang.String[][] relation)
Finds out what diagrams are in the relation and stores their indixes (indicating their position in the keys list) in the matrix, with corresponding coefficients

Parameters:
relation - the 4T relations: a-b=c-d=x-y stored as String[3][2] array.

identify4Tdiagrams

public int[][] identify4Tdiagrams(java.lang.String[][] relation)
Identifies the diagrams in the 4T relation and returns their indices in the keys list

Parameters:
relation - the 4T relation, String[3][2] array that stores a-b=x-y=c-d
Returns:
int[3][2] with indices of the srtings in relation

generate4Ts

public static java.lang.String[][] generate4Ts(diagram g,
                                               int link)
Generates 4T relations for the first pair of feet in the current rotation of a linik

Parameters:
g - the diagram to generate 4T for
link - the index of the link
Returns:
array of string representations of diagrams in 4T

rotateStringArray

public static void rotateStringArray(java.lang.String[] a)
Rotates string array clockwise

Parameters:
a - the string array to rotate

reverseString

public static java.lang.String reverseString(java.lang.String S)
Takes a string and reverses characters in it

Parameters:
S - the string to reverse
Returns:
S reversed. Ex: ABCD -> DCBA

generateA

public static java.lang.String generateA(java.lang.String[] XY,
                                         java.lang.String[] AB,
                                         boolean reverse)
Makes a string out of two array by the rule result=wAxByCz

Parameters:
XY - array containing w,x,y,z (in this order)
AB - array containing A,B,C (in this order)
reverse - if set true, each of A,B,C is reversed
Returns:
a string containing wAxByCz

printArray

public static void printArray(java.lang.String[] a)

JoinArrays

public static java.lang.String[] JoinArrays(java.lang.String[] A,
                                            java.lang.String[] B)
Concatenates two string arrays

Parameters:
A -
B -
Returns:
A+B

charMatch

public static boolean charMatch(java.lang.String S,
                                int index,
                                char[] a)
Tells whether a string contains a character belonging to a set at a position

Parameters:
S -
index -
a -
Returns:

relationDataFname

public java.lang.String relationDataFname()
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

DrawRelations

public void DrawRelations(DiagramDrawer DDrawer,
                          java.util.Set<Relation> relSet)
Draws a set of relations with a DDrawer

Parameters:
DDrawer - an instance of the DiagramDrawer class to draw the relations
relSet - the set with relations to draw

DrawRelations

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

Parameters:
DDrawer - DiagramDrawer to draw the relations with

isNew

public boolean isNew(Relation r)
Tells whether a relation r is new to the list

Parameters:
r - relation to test
Returns:
true, if r is not in the relations list

saveRelations

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

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

loadRelations

public boolean loadRelations()
Load the relation data from file. The filename is given by relationDataFname() function.

Returns:
true if the data was loaded successfully