org.pealfactory.compose.halfleadspliced
Class Composition

java.lang.Object
  |
  +--org.pealfactory.compose.halfleadspliced.Composition

class Composition
extends java.lang.Object

Tightly bound to the Composer class, a Composition instance holds the leads of a spliced composition as it is generated. It is also home to analysis methods such as checkRots() and isTrue().

Note that this class has been heavily tuned for performance, and should not be modified without extensive benchmarking on a range of searches.


Field Summary
private  int f1stPartFalseLead
           
private  boolean fAllRotsGood
          Set if neither fTenorsHomePE nor fNicePartEnds are set
private  int fBalance
          Method balance 0-100%
private  int fBestRot
           
private  int[] fCOMs
           
private  int fFirstRot
           
private  Lead[] fLeads
           
private  Method[] fMethods
           
private  int fMusic
          Cache last calculated values
private  boolean fNicePartEnds
           
private  int fNLeadsPerPart
           
private  int fNParts
           
private  RowNode fPartEnd
           
private  RowNode fRounds
           
private  int[] fRowNumBuf
           
private  Tables fTables
           
private  boolean fTenorsHomePE
          Set if tenors must also be home at part end
private  boolean[] fTruthTable
           
private  int fUnbalance
          Count for balance pruning
private  boolean[] fZeroTable
           
 
Constructor Summary
Composition(Method[] methods, Tables tables, int nleads, boolean tenorsHomePE, boolean nicePE)
           
 
Method Summary
private  int calcMusic(int rot)
          Calculates the total music score of the entire composition starting from the given lead rotation.
 int calcMusicRots(int minMusic)
          Checks all acceptable rotations of the composition for music score.
 boolean checkRots()
          Returns true if there is at least one rotation of the composition with an acceptable part end; in this case, fFirstRot is also set to the rotation number of the first acceptable rotation.
 int get1stPartFalseLead()
          If the composition was false in the first part, returns the lead it went false at, otherwise -1.
 int getBalance()
          Relies on setBalance() being called by the Composer
 int getBestRot()
           
 int getCOM()
          Changes of method per part
 int getCOM(int lead)
          Get changes of method in composition up to and including this lead (does not include end-start wraparound).
 Lead getLead(int n)
          Final for speed (inlining)
 int getMusic()
          Returns music score of best rotation.
 int getNLeadsPerPart()
          Final for speed (inlining)
 int getNParts()
          Calculates number of parts from part end.
 OutputComp getOutputComp(int score, boolean lhOnly)
          Produces a newly-constructed OutputComp instance populated with the leadheads from the best rotation of the current composition.
 int getUnbalanceCount()
           
private  boolean isGoodRotPartEnd(int rot)
          Returns true if the composition rotation starting from lead rot has an acceptable part end; rot MUST BE GREATER THAN 0! This method also assumes that one of fTenorsHomePE or fNicePartEnds is set, i.e.
 boolean isTrue()
          Checks the composition is true.
 void setBalance(int balance, int unbalanceCount)
          Called by Composer whenever a comp is checked to ensure getBalance() etc is up-to-date
 RowNode setLead(int n, RowNode start, Method composite, int call)
          Final for speed (inlining)
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

fNParts

private int fNParts

fNLeadsPerPart

private int fNLeadsPerPart

fMethods

private Method[] fMethods

fTenorsHomePE

private boolean fTenorsHomePE
Set if tenors must also be home at part end

fNicePartEnds

private boolean fNicePartEnds

fAllRotsGood

private boolean fAllRotsGood
Set if neither fTenorsHomePE nor fNicePartEnds are set

fCOMs

private int[] fCOMs

fLeads

private Lead[] fLeads

fPartEnd

private RowNode fPartEnd

fFirstRot

private int fFirstRot

fTables

private Tables fTables

fTruthTable

private boolean[] fTruthTable

fZeroTable

private boolean[] fZeroTable

fRowNumBuf

private int[] fRowNumBuf

fRounds

private RowNode fRounds

fBestRot

private int fBestRot

f1stPartFalseLead

private int f1stPartFalseLead

fMusic

private int fMusic
Cache last calculated values

fBalance

private int fBalance
Method balance 0-100%

fUnbalance

private int fUnbalance
Count for balance pruning
Constructor Detail

Composition

public Composition(Method[] methods,
                   Tables tables,
                   int nleads,
                   boolean tenorsHomePE,
                   boolean nicePE)
Method Detail

getOutputComp

public OutputComp getOutputComp(int score,
                                boolean lhOnly)
Produces a newly-constructed OutputComp instance populated with the leadheads from the best rotation of the current composition.

getNLeadsPerPart

public final int getNLeadsPerPart()
Final for speed (inlining)

getLead

public final Lead getLead(int n)
Final for speed (inlining)

setLead

public final RowNode setLead(int n,
                             RowNode start,
                             Method composite,
                             int call)
Final for speed (inlining)

getCOM

public final int getCOM(int lead)
Get changes of method in composition up to and including this lead (does not include end-start wraparound). Final for speed.

getCOM

public int getCOM()
Changes of method per part

getNParts

public final int getNParts()
Calculates number of parts from part end. Has the side effect of setting fPartEnd for subsequent methods such as checkRots(). Final for speed.

getBestRot

public int getBestRot()

get1stPartFalseLead

public final int get1stPartFalseLead()
If the composition was false in the first part, returns the lead it went false at, otherwise -1. This is used to backtrack the composition to prune false parts. Final for speed.

checkRots

public final boolean checkRots()
Returns true if there is at least one rotation of the composition with an acceptable part end; in this case, fFirstRot is also set to the rotation number of the first acceptable rotation. Final for speed, but on the borderline of bytecode size for inlining.

isGoodRotPartEnd

private final boolean isGoodRotPartEnd(int rot)
Returns true if the composition rotation starting from lead rot has an acceptable part end; rot MUST BE GREATER THAN 0! This method also assumes that one of fTenorsHomePE or fNicePartEnds is set, i.e. that fAllRotsGood is false. Final for speed.

calcMusicRots

public int calcMusicRots(int minMusic)
Checks all acceptable rotations of the composition for music score. If a rotation is found better or equal to minMusic, the composition is also checked for truth.
Returns:
best music score, or -1 if composition false in the first part, or 0 if composition is otherwise false or no rotations meet music minimum.

calcMusic

private final int calcMusic(int rot)
Calculates the total music score of the entire composition starting from the given lead rotation. This is relatively slow, although the node lead-music tables are used to ensure only one count operation is required per lead.

Final for speed


getMusic

public final int getMusic()
Returns music score of best rotation. Final for speed.

setBalance

public void setBalance(int balance,
                       int unbalanceCount)
Called by Composer whenever a comp is checked to ensure getBalance() etc is up-to-date

getBalance

public int getBalance()
Relies on setBalance() being called by the Composer

getUnbalanceCount

public int getUnbalanceCount()

isTrue

public boolean isTrue()
Checks the composition is true. For multiparts, we can save time by only checking (one more than) half of the parts. If the composition proves to be false in the first part, this is fed back into the main composing loop in order to prune the search tree.