chordDiagrams
Class diagram

java.lang.Object
  extended by chordDiagrams.diagram
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<diagram>

public class diagram
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<diagram>

This class implements a chord diagram: stores it and has methods to compare it to other diagrams.

Author:
Romwell
See Also:
Serialized Form

Field Summary
(package private)  int[] chords
          data structure to store the chords in the "coloring" format
(package private)  boolean[][] connected
          stores connectivity graph between links
(package private)  java.lang.String diagID
          Diagram's unique string ID obtained from its canonical form
(package private)  boolean isConnected
          is the link graph connected ?
(package private)  int k
          number of links
(package private)  int[] linkcolors
          same as above; stores links by coloring chord endpoints
(package private)  int[] links
          data structure to store links configuration; stores indices of endpoints of links in the chords array
(package private)  int n
          number of chord endpoints
(package private)  int[] ringsizes
          sort of same as links: stores the link configuration by storing the number of entries each ring occupies
(package private) static long serialVersionUID
          Version number, needed for serialization
(package private)  int[] skipdiag
          data structure to hold chords in "skip" format
 
Constructor Summary
diagram(int[] chordcolors, int[] linksdel)
          Constructs an instance of the digram from chord colors description and link delimiter descripion
diagram(int[] dchords, int[] dlinks, int[] dlinkcolors)
          Creates an instance of the diagram class
diagram(java.lang.String S)
          Constructs an instance of the diagram from standard string representation
 
Method Summary
static int[] arrcopy(int[] a)
          returns a copy of the integer array a
private  void checkConnected()
          calls the corresponding recursive method to set the isConnected field.
private  void checkConnected(boolean[] visited, int t)
          recursive function to check connectivity of the link graph vertices = links edges = "connectivity" matrix
static int[] ColoringToSkip(int[] chords)
          Converts a chord diagram description from coloring to skip
static int[] colorsFromString(java.lang.String Str)
          Returns a color band for the diagram (chord endpoint colors array) that can be passed to the contructor.
 int compareTo(diagram g)
          Compares this diagram to another one by comparing the diagID strings
 void copyArray(int[] a, int[] b)
          Copies the content of array a into array b
 boolean eqials(diagram g)
          Returns whether this diagram is equivalent to another one.
 boolean equals_ex(diagram g)
          returns whether two diagrams are equivalent under link rotation Obsolete with introduction of canonical form
private  boolean EqualsTo(diagram g, int link)
          Recursive function to check whether this diagram is equivalent to some other diagram g.
 void fillConnectivity()
          Fills the connectivity graph
 void getCanonicalForm()
          Converts the diagram into its canonical form by rotating and recoloring links in the chords array
 void getCanonicalForm(int[] best, int link)
           
static java.lang.String getString(int[] a)
          Converts an array into string
 java.lang.String getStringRepresentation()
          Converts a diagram into a string form.
static java.lang.String getSubstring(int[] a, int start, int end)
          Takes the numbers in the subarray from start to end and puts them into comma-separated string
 void initialize()
          Initializes
 diagram insertKinkAt(int linknumber)
          Returns a new diagram with a kink inserted into link referenced by linknumber
 diagram insertKinksAt(int[] presc)
          Inserts kinks into the diagram according to the prescription in presc: presc[# of link] = # of kinks to insert into that link
static int[] linksFromString(java.lang.String Str)
          Takes a standard string representation of a string S and returns the links delimiter array
static int[] LinksToColors(int[] linksdel)
          Converts links config from delimiter index to coloring format
 int linkStringStart(int link)
          Returns the position of the link start in the string representation of the diagram NOTE: the implementation must be consistent with getStringRepresentation() method.
 int posInRing(int t)
          Returns the position of the endpoint in its ring Used for diagram drawing
 void print()
          Prints the diagram' string form
static void PrintArray(int[] a)
          Prints array to the console
static int[] recolorCanonically(int[] chordcol)
          Recolors the chord diagram canonically (colors in the recoloring start from 0 and go to [number of colors]-1 in the order of occurence)
 boolean recolored(int[] a, int[] b)
          returns whether a and b are same by recoloring
 boolean recolorexists(int[] a, int[] b)
          returns whether there exists a recoloring map from a to b
static java.lang.String removeChar(java.lang.String S, char c)
          Removes all occurrences of a character from a string
 void rotatering(int ring)
          Rotates a ring to the right; only affects the coloring format
 boolean same(int[] a, int[] b)
          returns whether two arrays have the same data
static int[] SkipToColoring(int[] a)
          Converts a chord diagram description from skip format to coloring
 java.lang.String toString()
          Provides a string representations of the diagram in a human-readable way
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
Version number, needed for serialization

See Also:
Constant Field Values

skipdiag

int[] skipdiag
data structure to hold chords in "skip" format


chords

int[] chords
data structure to store the chords in the "coloring" format


links

int[] links
data structure to store links configuration; stores indices of endpoints of links in the chords array


linkcolors

int[] linkcolors
same as above; stores links by coloring chord endpoints


ringsizes

int[] ringsizes
sort of same as links: stores the link configuration by storing the number of entries each ring occupies


n

int n
number of chord endpoints


k

int k
number of links


connected

boolean[][] connected
stores connectivity graph between links


isConnected

boolean isConnected
is the link graph connected ?


diagID

java.lang.String diagID
Diagram's unique string ID obtained from its canonical form

Constructor Detail

diagram

public diagram(int[] dchords,
               int[] dlinks,
               int[] dlinkcolors)
Creates an instance of the diagram class

Parameters:
dchords - chords in the "skip" format
dlinks - links in regular format

diagram

public diagram(java.lang.String S)
Constructs an instance of the diagram from standard string representation

Parameters:
S - standard string representation of the diagram. Ex: a|bcd|ef|dec|bf Pipes ('|') denote link delimiters; any characters are OK as long as distinct characters denote distinct colors.

diagram

public diagram(int[] chordcolors,
               int[] linksdel)
Constructs an instance of the digram from chord colors description and link delimiter descripion

Parameters:
chordcolors - chords in coloring format
links - links in link delimiter format
Method Detail

initialize

public void initialize()
Initializes


rotatering

public void rotatering(int ring)
Rotates a ring to the right; only affects the coloring format

Parameters:
ring - The ring index

recolorexists

public boolean recolorexists(int[] a,
                             int[] b)
returns whether there exists a recoloring map from a to b

Parameters:
a - one diagram coloring
b - another diagram coloring
Returns:
true, if there is a recoloring

recolored

public boolean recolored(int[] a,
                         int[] b)
returns whether a and b are same by recoloring

Parameters:
a -
b -
Returns:

arrcopy

public static int[] arrcopy(int[] a)
returns a copy of the integer array a

Parameters:
a -
Returns:

PrintArray

public static void PrintArray(int[] a)
Prints array to the console

Parameters:
a - the array to print

toString

public java.lang.String toString()
Provides a string representations of the diagram in a human-readable way

Overrides:
toString in class java.lang.Object

getStringRepresentation

public java.lang.String getStringRepresentation()
Converts a diagram into a string form. Example:
{A|ABCD|BC|D}
{ -> start of diagram
} -> end of diagram
A -> color symbol (every symbol must occur exactly two times!)
| -> link sepearator (diagram must not start or end with |, and || must not occcur) This function is separate from toString() so that the toString() method could provide additional extra info; this form, however, is fixed so that a constructor could be called with it.

Returns:
a standard string representation of the diagram

print

public void print()
Prints the diagram' string form


EqualsTo

private boolean EqualsTo(diagram g,
                         int link)
Recursive function to check whether this diagram is equivalent to some other diagram g.

Parameters:
g - The other diagram
link - link number to check all rotations
Returns:
returns true if the diagrams are equivalent

equals_ex

public boolean equals_ex(diagram g)
returns whether two diagrams are equivalent under link rotation Obsolete with introduction of canonical form

Parameters:
g -
Returns:

eqials

public boolean eqials(diagram g)
Returns whether this diagram is equivalent to another one. Both diagrams must have their diagID set properly.

Parameters:
g - other diagram
Returns:
this == g

same

public boolean same(int[] a,
                    int[] b)
returns whether two arrays have the same data

Parameters:
a -
b -
Returns:

SkipToColoring

public static int[] SkipToColoring(int[] a)
Converts a chord diagram description from skip format to coloring

Parameters:
a - the chord diagram description in skip format
Returns:
diagram description in coloring format

ColoringToSkip

public static int[] ColoringToSkip(int[] chords)
Converts a chord diagram description from coloring to skip

Parameters:
a - the chord diagram description in coloring format
Returns:
diagram description in skip format

fillConnectivity

public void fillConnectivity()
Fills the connectivity graph


checkConnected

private void checkConnected(boolean[] visited,
                            int t)
recursive function to check connectivity of the link graph vertices = links edges = "connectivity" matrix

Parameters:
visited - array of booleans to mark visited vertices
t - current vertex

checkConnected

private void checkConnected()
calls the corresponding recursive method to set the isConnected field.


posInRing

public int posInRing(int t)
Returns the position of the endpoint in its ring Used for diagram drawing

Parameters:
t - the index of the endpoint
Returns:
index of the endpoint in its ring

insertKinkAt

public diagram insertKinkAt(int linknumber)
Returns a new diagram with a kink inserted into link referenced by linknumber

Parameters:
linknumber - the index of the link to insert the kink into
Returns:
a new diagram with a kink

insertKinksAt

public diagram insertKinksAt(int[] presc)
Inserts kinks into the diagram according to the prescription in presc: presc[# of link] = # of kinks to insert into that link

Parameters:
presc - kink insertion prescription
Returns:
a new diagram with kinks

LinksToColors

public static int[] LinksToColors(int[] linksdel)
Converts links config from delimiter index to coloring format

Parameters:
linksdel - links in link delimiter format
Returns:
link in coloring format

getCanonicalForm

public void getCanonicalForm()
Converts the diagram into its canonical form by rotating and recoloring links in the chords array


getCanonicalForm

public void getCanonicalForm(int[] best,
                             int link)

recolorCanonically

public static int[] recolorCanonically(int[] chordcol)
Recolors the chord diagram canonically (colors in the recoloring start from 0 and go to [number of colors]-1 in the order of occurence)

Parameters:
chorcol - the color diagram to recolor (the colors can be any numbers in range 0..255)
Returns:
the recoloring

getSubstring

public static java.lang.String getSubstring(int[] a,
                                            int start,
                                            int end)
Takes the numbers in the subarray from start to end and puts them into comma-separated string

Parameters:
a - the array
start - index of the beginning of the subarray
end - index of the end of the subarray
Returns:
the string of the form "x_1,x_2,...,x_n"

getString

public static java.lang.String getString(int[] a)
Converts an array into string

Parameters:
a - array
Returns:
string representation

compareTo

public int compareTo(diagram g)
Compares this diagram to another one by comparing the diagID strings

Specified by:
compareTo in interface java.lang.Comparable<diagram>
Parameters:
g - the diagram to compare to
Returns:
0, if equal; 1, if this one is greater than g; -1 - otherwise.

copyArray

public void copyArray(int[] a,
                      int[] b)
Copies the content of array a into array b

Parameters:
a - array to copy FROM
b - array to copy TO

linksFromString

public static int[] linksFromString(java.lang.String Str)
Takes a standard string representation of a string S and returns the links delimiter array

Parameters:
S - the standard string representation of S
Returns:
the links delimiter array that can be passed to the constructor Ex: called with string AB|BC|CD the color string is ABBCCD links arrays is {1,3,5}

colorsFromString

public static int[] colorsFromString(java.lang.String Str)
Returns a color band for the diagram (chord endpoint colors array) that can be passed to the contructor. Basically, it removes all the link delimiters (pipes, '|') from the string, and converts the rest into colors in canonical coloring.

Parameters:
S - the standard string representation of S
Returns:
the color band Ex: called with string ABC|DE|CD|ABE, the color band is ABCDECDABE

removeChar

public static java.lang.String removeChar(java.lang.String S,
                                          char c)
Removes all occurrences of a character from a string

Parameters:
S - the string to remove the character from
c - the character to be removed from a string
Returns:
the string S without occurrences of character c

linkStringStart

public int linkStringStart(int link)
Returns the position of the link start in the string representation of the diagram NOTE: the implementation must be consistent with getStringRepresentation() method.

Parameters:
link - the index of the link
Returns:
the position of the first symbol in the link in the string representation of the diagram