Menu

#110 the problem of Implemences of the Kamada-Kawai algorithm

Possible Bug
open
nobody
5
2009-01-12
2009-01-12
Anonymous
No

IN the function of advancePosition(),after we caculate some times iterations until every vertices's DeltaM smaller than a static value EPSILON, then change the location of aleatoric two vertices who are not locked,and caculate the energy after doing it.
I found there exsiting some problems in the function of
calcEnergyIfExchanged().
for example:if there is a graph with 3 vertices(0,1,2),and set p=0,q=1;then when we implement calcEnergyIfExchanged() returning value.when can only get three pairs (ii,jj) which are (1,0),(1,2),(1,2);so when using it,I found the graph can't get steady. so I try to caculate calcEnergyIfExchanged() the other way. At first before changing the vertices, we caculate the energy between the other vertices and the specific vertice "P" calling "Ep" and the energy between the other vertices and the specific vertice "Q" calling Eq";secondly afer changing the vertices,caculate Ep'+Eq' once again. at last get the returning value E-Ep-Eq+Ep'+Eq'.I'll be very appreciated to getting the affirm of yours to this caculating method.thank you sincerely!

Discussion

  • Joshua O'Madadhain

    Your explanation is not very clear; I'm not exactly sure what problem you're reporting or what your proposed solution is. Please clarify.

    Joshua

     
  • Nobody/Anonymous

    I found there is a problem in the Implementing of the Kamada-Kawai algorithm in the function of edu.uci.ics.jung.visualization.contrib.KKLayout.advancePosition(),which is : after we caculate some times iterations until every vertice's DeltaM smaller than a static value EPSILON, then change the location of aleatoric two vertices who are not locked,and caculate the new total energy generated from every two vertices after changing. I found there exsiting some problems in the function of edu.uci.ics.jung.visualization.contrib.KKLayout.calcEnergyIfExchanged().

    for example:if there is a graph with 3 vertices(0,1,2),and set p=0,q=1;then when we implement calcEnergyIfExchanged() returning value.when can only get three pairs (ii,jj) which are (1,0),(1,2),(1,2);and when using it,I found the graph can't get steady. so I try to caculate calcEnergyIfExchanged() the other way.
    At first before changing the vertices, we caculate the total energy between the other vertices and the specific vertice "P" called "Ep" and the energy between the other vertices and the specific vertice "Q" called Eq";secondly afer changing the vertices,caculate Ep'+Eq' once again. At last we get the returning value E-Ep-Eq+Ep'+Eq' as the new total energy of a graph.
    I'll be very appreciated to getting the affirm of yours to this caculating method.
    and thank you sincerely!

    the code of calcEnergyIfExchanged() of yours and the function calcEnergyPQ() to caculate Ep+Eq are as follows:

    private double calcEnergyIfExchanged(int p, int q) {

    if (p >= q)
    throw new RuntimeException("p should be < q");
    double energy = 0; // < 0

    for (int i = 0; i < vertices.length - 1; i++) {
    for (int j = i + 1; j < vertices.length; j++) {
    int ii = i;
    int jj = j;
    if (i == p) ii = q;
    if (j == q) jj = p;
    double dist = dm[ii][jj];
    double l_ij = L * dist;
    double k_ij = K / (dist * dist);
    double dx = xydata[ii].getX() - xydata[jj].getX();
    double dy = xydata[ii].getY() - xydata[jj].getY();
    double d = Math.sqrt(dx * dx + dy * dy);

    energy += k_ij / 2 * (dx * dx + dy * dy + l_ij * l_ij -
    2 * l_ij * d);
    }
    }
    return energy;
    }

    private double calcEnergyPQ(int p, int q)
    {
    if (p >= q)
    throw new RuntimeException("p should be < q");
    double energy = 0; // < 0
    for(int a=0;a<vertices.length-1;a++)
    {
    if(!(a==p)&&!(a==q))
    {
    double dist_ap = dm[a][p];
    double l_ap = L * dist_ap;
    double k_ap = K / (dist_ap * dist_ap);
    double dx_ap = xydata[a].getX() - xydata[q].getX();
    double dy_ap = xydata[a].getY() - xydata[q].getY();
    double d_ap = Math.sqrt(dx_ap * dx_ap + dy_ap * dy_ap);

    double dist_aq = dm[a][q];
    double l_aq = L * dist_aq;
    double k_aq = K / (dist_aq * dist_aq);
    double dx_aq = xydata[a].getX() - xydata[p].getX();
    double dy_aq = xydata[a].getY() - xydata[p].getY();
    double d_aq = Math.sqrt(dx_aq * dx_aq + dy_aq * dy_aq);

    energy += k_ap / 2 * (dx_ap * dx_ap + dy_ap * dy_ap + l_ap * l_ap -
    2 * l_ap * d_ap)+k_aq / 2 * (dx_aq * dx_aq + dy_aq * dy_aq + l_aq * l_aq - 2 * l_aq * d_aq);
    }
    }
    return energy;
    }

     

Log in to post a comment.

MongoDB Logo MongoDB