}*/
//System.out.println("after cg " + relNorm);
return res;
}
public void runBSMLayout(DNVGraph graph, int level){
Timer timer = new Timer();
timer.setStart();
//float timeForSinCos = 0;
//float timeForCG = 0;
List<DNVNode> nodes = graph.getNodes(level);
int n = nodes.size();
mapNodeIndex(nodes);
//get the default layout of the graph, store positions in x_pos and y_pos
int index = 0;
x_pos = new double[n];
y_pos = new double[n];
for(int i = 0; i < nodes.size(); i++){
x_pos[i] = nodes.get(i).getPosition().getX();
y_pos[i] = nodes.get(i).getPosition().getY();
}
//generateInitRandomCoord(n);
Bound range = getRange(x_pos, y_pos);
for(int i = 0; i < n; i++){
double[] constrainedPos = range.constrain(x_pos[i], y_pos[i]);
x_pos[i] = constrainedPos[0];
y_pos[i] = constrainedPos[1];
}
//timer.setEnd();
//calcCosSin_quadtree();
calcCosSin();
//timer.setEnd();
//timeForSinCos += timer.getLastSegment(Timer.SECONDS);
int iter = 0;
double alpha = n;
for(; iter < maxIteration; iter++){
//System.out.println("running iteration " + iter);
double[] newx_pos = ConjugateGradient(alpha, x_pos, cosB);
double[] newy_pos = ConjugateGradient(alpha, y_pos, sinB);
//timer.setEnd();
//timeForCG += timer.getLastSegment(Timer.SECONDS);
range = getRange(newx_pos, newy_pos);
for(int i = 0; i < n; i++){
double[] constrainedPos = range.constrain(newx_pos[i], newy_pos[i]);
newx_pos[i] = constrainedPos[0];
newy_pos[i] = constrainedPos[1];
}
double diff = vecNorm(addvec(x_pos, newx_pos,false)) + vecNorm(addvec(y_pos, newy_pos,false));
/*if(diff < BSthreshold){
x_pos = newx_pos;
y_pos = newy_pos;
System.out.println("diff " + diff);
break;
}*/
x_pos = newx_pos;
y_pos = newy_pos;
//timer.setEnd();
//calcCosSin_quadtree();
calcCosSin();
//timer.setEnd();
//timeForSinCos += timer.getLastSegment(Timer.SECONDS);
}
float consumeTime = timer.getTimeSinceStart(Timer.SECONDS);
System.out.println(LABEL + " finished in " + consumeTime + " seconds. " + iter + " iterations " +nodes.size() + " nodes");
System.out.println(consumeTime / (double)iter + " seconds per iteration\n");
if(writer != null){
try {