package commons.graph.worker;
import commons.graph.model.EdgeInfo;
import commons.graph.model.GraphModelException;
public class DistanceNormalizer extends EdgeWorker
{

private int    edgeType = -1;
private double max      = 0;

/**
 * Executed by WorkerController, working on a collection of nodes.
 * Normalize all values against the given value, the maximum normally.
 * As a result all values will be between 0 and 1.
 * Max must not be 0.
 * @param max value != 0
 */
public DistanceNormalizer(int type, double max)
{
   this.max = max;
   this.edgeType = type;
}

public void work (String a, String b) throws GraphModelException
{
   EdgeInfo E = edges.getInfo(a, b);
   if (edgeType == -1 || E.type == edgeType)
   {
      double d = edges.distance(a, b);
      d = d / max;
      d = Math.sqrt(Math.sqrt(d));
      edges.setDistance(a, b, d);
   }
}

public double getMax ()
{
   return max;
}
}
