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

int    type   = -1;
double offset = 1.0;

public Inverter(int type, double offset)
{
   this.type = type;
   this.offset = offset;
}

/**
 * Executed by WorkerController, working on a collection of nodes.
 * Recalculates the values. Assuming the the values are between 0..1 
 * (use DistanceNormalizer to achieve that) will invert the value
 * to be between 1..0.
 * This is usefull to invert the meaning of distance. 
 */
public void work (String a, String b) throws GraphModelException
{
   double d = edges.distance(a, b);
//   double d1 = d;
   if (type >= 0)
   {
      EdgeInfo E = edges.getInfo(a, b);
      if (E.type != type)
         return;
   }
   d += offset;
   d = 1.0 / d;
//   SysUtl.trace("[" + type + "] " + a + " <> " + b + " : " + d1 + " --> " + d);
   edges.setDistance(a, b, d);
}
}
