org.opencores.placement
Class Annealing

java.lang.Object
  |
  +--org.opencores.placement.Annealing

public class Annealing
extends java.lang.Object

This is main class, consisting of simulated annealing routine. Nodes must be are already placed correctly (using preplacement) and their pos (.x, .y) and index .idx are set. All work here is done using indexes, but coordinates are also maintaned to speed up placement.

Alpha functions and some other dinamic parameters are adopted from VPR.

See Also:

Field Summary
private  double[][] alpha
          Discrete temperature update - alpha function.
private  float[] costs
           
private  int[][] distance
          Precalculated distance based on (x,y) coordinates.
private static double DONE_CONSTANT
          Stoping treshold.
private  Graph g
          graph we are working on
private static int INITIAL_TEMP_K
          Initial temperature coefficient.
private  int INNER_NUM
          Number of inner loop execution times.
private static int INNER_NUM_K
          Coefficient, which linearly changes number of inner loop executions.
private  NodeGPC[] posGPC
          table of all possible GPC positions (and current assignments)
private  NodeIOC[] posIOC
          table of all possible Port positions (and current assignments)
private  double temp
          current temperature, @see setTemp
private  int tempAccepted
          number of (accepted) moves performed per current temperature
private  int tempMoves
          number of (possible) moves performed per current temperature
private  int tempWiringChange
          total wiring change per current temperature
private  int wiringCost
          current total wiring cost, @see calcTotalWiringCost, getWiringCost
 
Constructor Summary
Annealing(Graph g)
          Construct and resets new SA object on graph g.
 
Method Summary
private  boolean allowMove(float dCost)
          Decides whether move with delta cost dCost should be taken.
 void anneal()
          simulates anneal at current temperature temp.
private  void buildDist()
          Build estimated #hops for each vector (dx, dy).
private  int calcTotalWiringCost()
          Wiring length is sum of sizes of all minimum spanning trees.
private  float checkWiringCost()
          Checks MST trees currently built with stored number in nets.cost
private  int dist(int dx, int dy)
          Returns estimated distance of vector (dx, dy).
 boolean doneCriteria()
          Decides whether annealing has good solution and it is unlikely that we will find it, so we should stop.
 double getTemp()
          Returns current temperature.
 int getWiringCost()
          Returns current total wiring cost.
private static int manhattan(int dx, int dy)
          Returns manhattan distance of vector (dx, dy).
private  boolean move(IndexedNode a, IndexedNode b, int bx, int by, int bidx)
          Returns true if node has been moved from a to b
private  void move(NodeGPC a)
          Tries to move node n, using current Conf.
private  void move(NodeIOC a)
          Tries to move node n, using current configuration
private  float moveCost(Node n, int x, int y)
          Estimates cost (wiring cost change) of move, after n is moved to (x,y).
private  int MST(Net nt)
          Calculates minimum spanning tree size.
 void reset()
          Resets SA.
 void setTemp(double temp)
          Changes temperature and resets temperature specific data.
private  double stdDev()
          Calculates standard deviation of one random move for each graph node.
private  boolean stopCriteria()
          Decides whether we should stop annealing at current temperature.
private  void takeBackMove(Node n)
          This function is called when move is not accepted, and updates net MST costs, to previous moveCost costs
 void updateTemperature()
          Changes temperature - function alpha(T)
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

INNER_NUM_K

private static final int INNER_NUM_K
Coefficient, which linearly changes number of inner loop executions.

INITIAL_TEMP_K

private static final int INITIAL_TEMP_K
Initial temperature coefficient. Larger, more moves will be accepted at start.

INNER_NUM

private int INNER_NUM
Number of inner loop execution times. Set at reset().

DONE_CONSTANT

private static final double DONE_CONSTANT
Stoping treshold. Larger it is sooner we will stop. Should be positive.

g

private Graph g
graph we are working on

posGPC

private NodeGPC[] posGPC
table of all possible GPC positions (and current assignments)

posIOC

private NodeIOC[] posIOC
table of all possible Port positions (and current assignments)

temp

private double temp
current temperature, @see setTemp

wiringCost

private int wiringCost
current total wiring cost, @see calcTotalWiringCost, getWiringCost

tempMoves

private int tempMoves
number of (possible) moves performed per current temperature

tempAccepted

private int tempAccepted
number of (accepted) moves performed per current temperature

tempWiringChange

private int tempWiringChange
total wiring change per current temperature

alpha

private final double[][] alpha
Discrete temperature update - alpha function.

First number is acceptance ratio, second coefficient K, and T = K * T


costs

private float[] costs

distance

private int[][] distance
Precalculated distance based on (x,y) coordinates.
Constructor Detail

Annealing

public Annealing(Graph g)
Construct and resets new SA object on graph g.
Parameters:
g - mapped, preplaced graph to work on
Method Detail

reset

public void reset()
Resets SA. Should be called every time, when SA is restarted.

setTemp

public void setTemp(double temp)
Changes temperature and resets temperature specific data.

Should be called after each temp change.

Parameters:
temp - new temperature

updateTemperature

public void updateTemperature()
Changes temperature - function alpha(T)

anneal

public void anneal()
simulates anneal at current temperature temp.

stopCriteria

private final boolean stopCriteria()
Decides whether we should stop annealing at current temperature. Also called InnerLoop criterion.
Returns:
true when annealing at current temperature should be stopped, false otherwise

doneCriteria

public final boolean doneCriteria()
Decides whether annealing has good solution and it is unlikely that we will find it, so we should stop.

NOTE: call this before updateTemperature, since it destroys temperature dependent data, needed here

Returns:
true when annealing should be stopped, false otherwise

move

private void move(NodeGPC a)
Tries to move node n, using current Conf.
Parameters:
temp - current temperature
a - GPC node to move

move

private void move(NodeIOC a)
Tries to move node n, using current configuration
Parameters:
an - IOC node to move
Returns:
wiring cost change

allowMove

private final boolean allowMove(float dCost)
Decides whether move with delta cost dCost should be taken.
Parameters:
dCost - movement delta cost
Returns:
true if decision should be taken, false otherwise.

moveCost

private final float moveCost(Node n,
                             int x,
                             int y)
Estimates cost (wiring cost change) of move, after n is moved to (x,y).

NOTE: no replacement is made. Does not calculate replacement cost of node at (x,y).

This function stores computed costs in costs, which can be used later if move is not accepted.

Proceed as following:

1. find closest pin on each a's port net, and calculate cost to move it to next neighbour or if no other to new position

2. find closest pin for each a's port net, based on new position

Parameters:
n - node to calculate movement cost on
dest - node, we will exchange n with
x - destination x position
y - destination y position
Returns:
movement cost

takeBackMove

private void takeBackMove(Node n)
This function is called when move is not accepted, and updates net MST costs, to previous moveCost costs
See Also:
moveCost

move

private boolean move(IndexedNode a,
                     IndexedNode b,
                     int bx,
                     int by,
                     int bidx)
Returns true if node has been moved from a to b

buildDist

private final void buildDist()
Build estimated #hops for each vector (dx, dy). Calculated table is stored in distance

dist

private final int dist(int dx,
                       int dy)
Returns estimated distance of vector (dx, dy).
Parameters:
dx - vector x component
dy - vector y component
Returns:
min distance

manhattan

private static final int manhattan(int dx,
                                   int dy)
Returns manhattan distance of vector (dx, dy).
Parameters:
dx - vector x component
dy - vector y component
Returns:
distance

MST

private int MST(Net nt)
Calculates minimum spanning tree size.
Parameters:
net - to compute MST on
Returns:
MST size

calcTotalWiringCost

private int calcTotalWiringCost()
Wiring length is sum of sizes of all minimum spanning trees.
Returns:
total wiring cost

checkWiringCost

private float checkWiringCost()
Checks MST trees currently built with stored number in nets.cost
Returns:
difference

stdDev

private double stdDev()
Calculates standard deviation of one random move for each graph node.
Returns:
standard deviation of cost

getWiringCost

public int getWiringCost()
Returns current total wiring cost.
Returns:
total wiring cost

getTemp

public double getTemp()
Returns current temperature.
Returns:
current temperature
See Also:
temp