mil.af.afit.uvr
Class HSolution

java.lang.Object
  |
  +--mil.af.afit.uvr.HSolution
All Implemented Interfaces:
java.lang.Cloneable

public final class HSolution
extends java.lang.Object
implements java.lang.Cloneable

A solution with vehicles servicing orders.

Since:
1.0
See Also:
HOrder, HVehicle, HTour

Constructor Summary
HSolution(HSolution copyThis)
          Create a solution that is a copy of copyThis.
HSolution(HVehicle[] vehicles, HOrder[] orders)
          Makes a solution based on the passed arguments.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this solution
 java.lang.String costsToString()
          Returns a string representation of the costs, including the names for the costs, if available.
 double[] getCosts()
          Return the costs for this solution.
 HTour getDummyHTour()
          Returns the dummy tour.
 HTour[] getHTours()
          Returns the tours in the solution, excluding the dummy tour.
 HEvaluator getLastEvaluatorUsed()
          Get the last evaluator that was used to validate this solution.
 int hashCode()
          Returns a hashcode for the solution.
 void invalidate()
          Should be called if the solution is changed.
 boolean isValid()
          Returns whether or not the costs associated with the solution are valid.
 void setCosts(double[] costs)
          Normally this should not be called, but if you have a reason to do it, this sets the costs and does not change the validity of the solution.
 java.lang.String toString()
           
 void validate(HEvaluator evaluator)
          Validate a solution based on a given evaluator.
 void validateTours()
          Validates each tour.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HSolution

public HSolution(HVehicle[] vehicles,
                 HOrder[] orders)
Makes a solution based on the passed arguments. The vehicles are immediately cloned.
Parameters:
vehicles - veh
customers - cust
Since:
1.0
See Also:
HOrder, HVehicle

HSolution

public HSolution(HSolution copyThis)
Create a solution that is a copy of copyThis.
Parameters:
copyThis - solution to copy
Since:
1.0
Method Detail

isValid

public final boolean isValid()
Returns whether or not the costs associated with the solution are valid. When orders move around in the tours, the costs are invalidated.
Returns:
whether or not the costs are validated
Since:
1.0
See Also:
HEvaluator

validate

public final void validate(HEvaluator evaluator)
Validate a solution based on a given evaluator.
Parameters:
evaluator - the evaluator to use for determing solution costs
Since:
1.0
See Also:
HEvaluator

invalidate

public final void invalidate()
Should be called if the solution is changed.
Since:
1.0

validateTours

public final void validateTours()
Validates each tour.
Since:
1.0
See Also:
HTour

getHTours

public HTour[] getHTours()
Returns the tours in the solution, excluding the dummy tour.
Returns:
tours used
Since:
1.0
See Also:
HTour

getDummyHTour

public HTour getDummyHTour()
Returns the dummy tour. This tour holds the orders that are not serviced.
Returns:
dummy tour
Since:
1.0
See Also:
HTour

getCosts

public double[] getCosts()
Return the costs for this solution. Be sure to check isValid() to know if the costs are meaningful.
Returns:
costs for solution
Since:
1.0
See Also:
HEvaluator

setCosts

public void setCosts(double[] costs)
Normally this should not be called, but if you have a reason to do it, this sets the costs and does not change the validity of the solution.
Parameters:
costs - new costs for the solution
Since:
1.0
See Also:
HEvaluator

getLastEvaluatorUsed

public final HEvaluator getLastEvaluatorUsed()
Get the last evaluator that was used to validate this solution.
Returns:
last evalutor used
Since:
1.0
See Also:
HEvaluator

clone

public java.lang.Object clone()
Returns a clone of this solution
Overrides:
clone in class java.lang.Object
Since:
1.0

hashCode

public int hashCode()
Returns a hashcode for the solution. The actual code used to compute the hashcode follows.

 
  int hash = 0;
  double product = 1;
  for( int i = 0; i < costs.length; i++ )
      product *= ( costs[i] == 0 ? 1 : costs[i] );
  hash = (int) ((product*1000)%Integer.MAX_VALUE);
  return hash;
 

Overrides:
hashCode in class java.lang.Object
Returns:
hash code
Since:
1.0

costsToString

public java.lang.String costsToString()
Returns a string representation of the costs, including the names for the costs, if available.
Returns:
string representation of costs
Since:
1.0
See Also:
HEvaluator

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object