babase.ranker
Class AutoRanker

java.lang.Object
  extended by babase.ranker.AutoRanker

public class AutoRanker
extends java.lang.Object

A utility that allows for the automatic ranking of individual baboons within a Cage. Has varios methods that can be called to produce a list of matrix positions 0-n which would be the returned ranking for the Cage.

Author:
tjb13

Constructor Summary
AutoRanker(GUI g, Controller c)
          Constructor which takes a GUI g, in order to maintain communication with the rest of the program, and a controller c in order to have access to the Cage.
 
Method Summary
 int checkInconsistancies(int[][] rankMatrix, Ranking ranks)
           
 void constructDG(Cage c)
          Constructs a directed graph within a Cage of individuals by creating edges or connections among them to represent dominance.
 void createDomScore()
          Find and store a domination score for all individuals in myCage Domination scores are the number of wins an individual has
 void createMatrixScore()
          Find and store matrix scores for all the individuals in myCage Matrix scores are the number of wins less the number of losses an individual has.
 java.util.Vector<Individual> DFS(Cage c)
          Performs a depth first search in order to get a post ordering of individuals.
 java.util.ArrayList<Cage> DFST(Cage c, java.util.Vector<Individual> postorder)
          Do a modified depth first search on a Cage using the post ordering as starting nodes in order to identify the strongly connected components and create an arraylist which contains them individually.
 int findDomScore(int row)
          Finds the domination score for an individual given their row in the ranking matrix, otherwise known as the matrix position
 int findMatrixScore(int matrixPos)
          finds the matrix score for an individual given their matrix position
 java.util.ArrayList<Cage> findSCC(Cage currentCage)
          Finds the strongly connected components within a Cage.
 int findWinner(int f, int t)
          Figures which individual dominated the other when comparing the number of interactions won between them.
 boolean hasInteractions(int f, int t)
          Returns a boolean that is true of the individuals have had interactions
 Cage rankDirectedGraph(Cage currentCage)
          Ranks the directed graph within a cage using the connections amongst individuals to determine who should be ranked above who.
 Cage RankSCC(Cage c)
          Produces a Rank for a strongly connected component of individuals.
 void runBrockRank(int[][] rm, Ranking r)
          Runs an automatic Brock ranking that produces a ranking based upon dyadic interaction data, breaking ties using a matrix score.
 void runBrute(int[][] rankMatrix, Ranking ranks)
          Runs a brute force automatic ranking which runs through all possible permutations of rankings to determin which has the smallest amount of interactions below the diagonal.
 void runDOM(int[][] rm, Ranking r)
          Runs an automatic domination ranking that produces a ranking based on the number of wins an individual has.
 void search(Individual i, java.util.Vector<Individual> postorder)
          The actual depth first search implementation
 void searchMod(Individual i, Cage scc, java.util.Vector<Individual> postorder)
          Performs a modified depth first search in order to find the SCCs.
 Ranking topologicalSort(Cage c)
          Performs a topological sort on the Cage c which contains individuals connected through a directed acyclic graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoRanker

public AutoRanker(GUI g,
                  Controller c)
Constructor which takes a GUI g, in order to maintain communication with the rest of the program, and a controller c in order to have access to the Cage.

Parameters:
g - the GUI
c - the Controller
Method Detail

runDOM

public void runDOM(int[][] rm,
                   Ranking r)
Runs an automatic domination ranking that produces a ranking based on the number of wins an individual has.

Parameters:
rm - a ranking matrix
r - the current ranking

runBrockRank

public void runBrockRank(int[][] rm,
                         Ranking r)
Runs an automatic Brock ranking that produces a ranking based upon dyadic interaction data, breaking ties using a matrix score.

Parameters:
rm - a ranking matrix
r - the current ranking

rankDirectedGraph

public Cage rankDirectedGraph(Cage currentCage)
Ranks the directed graph within a cage using the connections amongst individuals to determine who should be ranked above who. If the cage is of size 1 the current cage is returned as a ranked cage. If the cage is of larger size, strongly connected components are identified so that they can be handled seperately in the RankSCC method. All cages are ranked until each member of the original cage to be ranked has a ranking in the finalcage.

Parameters:
currentCage - a Cage to rank with individuals connected in a directed graph
Returns:
a ranked Cage

RankSCC

public Cage RankSCC(Cage c)
Produces a Rank for a strongly connected component of individuals.

Parameters:
c - is the cage containing a strongly connected component of individuals
Returns:
the ranked cage of individuals

findSCC

public java.util.ArrayList<Cage> findSCC(Cage currentCage)
Finds the strongly connected components within a Cage.

Parameters:
currentCage - the cage which contain SCCs
Returns:
an arraylist of Cage's with strongly connected componenets

DFST

public java.util.ArrayList<Cage> DFST(Cage c,
                                      java.util.Vector<Individual> postorder)
Do a modified depth first search on a Cage using the post ordering as starting nodes in order to identify the strongly connected components and create an arraylist which contains them individually.

Parameters:
c - a cage with strongly connected components
postorder - is the post order of the initial DFS
Returns:
an arraylist of SCCs

searchMod

public void searchMod(Individual i,
                      Cage scc,
                      java.util.Vector<Individual> postorder)
Performs a modified depth first search in order to find the SCCs.

Parameters:
i - is the starting element from the post ordering
scc - is the new cage to put the individuals in this SCCs
postorder - is the post ordering of individuals obtained from DFS

DFS

public java.util.Vector<Individual> DFS(Cage c)
Performs a depth first search in order to get a post ordering of individuals.

Parameters:
c - the cage of individuals which to get post ordering from
Returns:
the post ordering

search

public void search(Individual i,
                   java.util.Vector<Individual> postorder)
The actual depth first search implementation

Parameters:
i - starting individual node
postorder - a post ordering that we are constructing

topologicalSort

public Ranking topologicalSort(Cage c)
Performs a topological sort on the Cage c which contains individuals connected through a directed acyclic graph.

Parameters:
c - cage to be topologically sorted
Returns:
ranking of the cage

createMatrixScore

public void createMatrixScore()
Find and store matrix scores for all the individuals in myCage Matrix scores are the number of wins less the number of losses an individual has.


createDomScore

public void createDomScore()
Find and store a domination score for all individuals in myCage Domination scores are the number of wins an individual has


constructDG

public void constructDG(Cage c)
Constructs a directed graph within a Cage of individuals by creating edges or connections among them to represent dominance. When there is a tie, two edges are created in order to signify a tie and which introduces a cycle in the directed graph.

Parameters:
c -

findWinner

public int findWinner(int f,
                      int t)
Figures which individual dominated the other when comparing the number of interactions won between them. Returns a negative number if t wins Returns a positive number if f wins Returns a zero if there is a tie

Parameters:
f - is the first individual
t - is the second individual
Returns:
the winning individual

hasInteractions

public boolean hasInteractions(int f,
                               int t)
Returns a boolean that is true of the individuals have had interactions

Parameters:
f - first individual
t - second individual
Returns:
a boolean which says if they have had interactions

findDomScore

public int findDomScore(int row)
Finds the domination score for an individual given their row in the ranking matrix, otherwise known as the matrix position

Parameters:
row - a row in the ranking matrix, or mp
Returns:
a domination score

findMatrixScore

public int findMatrixScore(int matrixPos)
finds the matrix score for an individual given their matrix position

Parameters:
matrixPos - a matrix position
Returns:
a matrix score

runBrute

public void runBrute(int[][] rankMatrix,
                     Ranking ranks)
Runs a brute force automatic ranking which runs through all possible permutations of rankings to determin which has the smallest amount of interactions below the diagonal.

Parameters:
rankMatrix - a ranking matrix to be ranked
ranks - a current ranking

checkInconsistancies

public int checkInconsistancies(int[][] rankMatrix,
                                Ranking ranks)