org.akutan.optimization
Class SASolution

java.lang.Object
  extended by org.akutan.optimization.SASolution
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<SASolution>

public class SASolution
extends java.lang.Object
implements java.lang.Comparable<SASolution>, java.lang.Cloneable

Consists of the vector of weights before processing and a convenience data structure to identify which assets are in the weight vector.


Field Summary
protected  double _objective
           
protected  int[] _Q
           
protected  cern.colt.matrix.DoubleMatrix1D _s
           
protected  cern.colt.matrix.DoubleMatrix1D _w
           
 
Constructor Summary
SASolution(int[] Q, cern.colt.matrix.DoubleMatrix1D s, double objective)
          Constructs
 
Method Summary
 void addAsset(double w, int ptr, java.lang.Integer[] potential)
          Adds the selected asset to the solution
protected  java.lang.Object clone()
          Deep copy of the solution
 int compareTo(SASolution s)
          Compares a SASolution object to this
 boolean equals(java.lang.Object obj)
          equivalence of two solutions, _s vector and objectives match.
 double getObjective()
          Returns the value of the objective function for this proposed solution
 int[] getQ()
          Returns the Q vector (Indicates point in or out of weights) for this potential solution
 cern.colt.matrix.DoubleMatrix1D getS()
          Returns the S vector
 cern.colt.matrix.DoubleMatrix1D getW()
          Returns the weights of the assets at this solution
 int hashCode()
          Hashcode.
 java.lang.Integer[] removeAsset(int index)
          Removes an asset from the solution, and returns a set containing the assets which are not currently in the solution, and are not the asset just removed from the solution.
 void rescale(double epsilon)
          Called to readjust the s values to be s = w - _epsilon
 cern.colt.matrix.DoubleMatrix1D reweight(double epsilon)
          Updates the weights based on the values in the 's' vector.
 java.lang.String toString()
          Formats this object into a string for debugging
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_Q

protected int[] _Q

_s

protected cern.colt.matrix.DoubleMatrix1D _s

_w

protected cern.colt.matrix.DoubleMatrix1D _w

_objective

protected double _objective
Constructor Detail

SASolution

public SASolution(int[] Q,
                  cern.colt.matrix.DoubleMatrix1D s,
                  double objective)
Constructs

Parameters:
Q -
s -
objective -
Method Detail

getObjective

public double getObjective()
Returns the value of the objective function for this proposed solution

Returns:
The value of the objective function at this point.

getQ

public int[] getQ()
Returns the Q vector (Indicates point in or out of weights) for this potential solution

Returns:
Q vector

getS

public cern.colt.matrix.DoubleMatrix1D getS()
Returns the S vector

Returns:
S Vector

getW

public cern.colt.matrix.DoubleMatrix1D getW()
Returns the weights of the assets at this solution

Returns:
Weights of the assets

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Deep copy of the solution

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

compareTo

public int compareTo(SASolution s)
Compares a SASolution object to this

Specified by:
compareTo in interface java.lang.Comparable<SASolution>
Parameters:
s - SASolution to compare to this
Returns:
-1 if less, 0 if equal, +1 if more

equals

public boolean equals(java.lang.Object obj)
equivalence of two solutions, _s vector and objectives match.

Overrides:
equals in class java.lang.Object
Parameters:
obj - to compare to this
Returns:
true if the objects are equal
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Hashcode. Note this is pretty lame, but I just need something that will match the equals for the time being. I'll put in a better one later.

Overrides:
hashCode in class java.lang.Object
Returns:
hashcode for this object

toString

public java.lang.String toString()
Formats this object into a string for debugging

Overrides:
toString in class java.lang.Object
Returns:
Object formatted as a string
See Also:
Object.toString()

addAsset

public void addAsset(double w,
                     int ptr,
                     java.lang.Integer[] potential)
Adds the selected asset to the solution

Parameters:
w - Weight of the asset
ptr - Ptr to this asset in the vector
potential - Array of potentials for each asset

removeAsset

public java.lang.Integer[] removeAsset(int index)
Removes an asset from the solution, and returns a set containing the assets which are not currently in the solution, and are not the asset just removed from the solution.

Parameters:
index - Index of asset to remove from the solution
Returns:
New array of assets in the solution

rescale

public void rescale(double epsilon)
Called to readjust the s values to be s = w - _epsilon

Parameters:
epsilon - Constant to subtract from each weight

reweight

public cern.colt.matrix.DoubleMatrix1D reweight(double epsilon)
Updates the weights based on the values in the 's' vector. Weights must sum to 1, and must be either = 0 or on the range (epsilon, delta). Note: We don't have delta in here yet, and if we add it then this logic needs to truncate weights at delta.

Parameters:
epsilon - Constant to subtract from each weight
Returns:
New vector of weights