scale.common
Class Cost

java.lang.Object
  extended by scale.common.Cost

public class Cost
extends java.lang.Object

This class implements a cost model based on a power expansion.

$Id: Cost.java,v 1.15 2007-05-15 17:36:06 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

The cost model is the sum of a set of terms. Each term is of the form

 c*x**n
 


Constructor Summary
Cost()
          Create a cost with one term with a zero coefficient, power of 0.
Cost(double coefficient, int power)
          Create a cost with one term with the given coefficient, etc.
 
Method Summary
 void add(Cost cost)
          Add all the terms of another Cost to this one.
 void add(double coefficient, int power)
          Add new term to cost expression:
 void add(int c)
          Increment cost expression by constant:
 double calcCost(double x)
          Return the cost based on value x.
 Cost copy()
          Return a deep copy of this cost.
 void divide(double c)
          Divide cost expression by constant:
 Cost getHighestOrderTerm()
          Return the term with the highest exponent.
 boolean lessThan(Cost cost)
          Return true if this cost is less than the specified cost.
 void multiply(Cost cost)
          Multiply all the terms of this loop with the terms of the argument cost.
 void multiply(double mfactor)
          Multiply cost expression by constant:
 void multiply(double coefficient, int power)
          Multiply cost expression by cost term:
 int order()
          Return the order of the polynomial: the power of the largest non-zero term.
 void reset()
          Set all terms to 0.
 void subtract(double coefficient, int power)
          Add new term to cost expression:
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cost

public Cost()
Create a cost with one term with a zero coefficient, power of 0.


Cost

public Cost(double coefficient,
            int power)
Create a cost with one term with the given coefficient, etc.

Parameters:
coefficient - of the cost term
power - of the cost term
Method Detail

calcCost

public double calcCost(double x)
Return the cost based on value x.


reset

public void reset()
Set all terms to 0.


add

public void add(int c)
Increment cost expression by constant:


add

public void add(double coefficient,
                int power)
Add new term to cost expression:


add

public void add(Cost cost)
Add all the terms of another Cost to this one.


subtract

public void subtract(double coefficient,
                     int power)
Add new term to cost expression:


multiply

public void multiply(double mfactor)
Multiply cost expression by constant:


multiply

public void multiply(double coefficient,
                     int power)
Multiply cost expression by cost term:


multiply

public void multiply(Cost cost)
Multiply all the terms of this loop with the terms of the argument cost.


divide

public void divide(double c)
Divide cost expression by constant:


order

public int order()
Return the order of the polynomial: the power of the largest non-zero term.


getHighestOrderTerm

public Cost getHighestOrderTerm()
Return the term with the highest exponent.


toString

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

lessThan

public boolean lessThan(Cost cost)
Return true if this cost is less than the specified cost.


copy

public Cost copy()
Return a deep copy of this cost.