Package net.wigis.graph.dnv.utilities

Examples of net.wigis.graph.dnv.utilities.Timer


    //double relNorm = vecNorm(addvec(b, mat_mul_vec(alpha, res),false));
    //System.out.println("after cg " + relNorm);
    return res;
  }
  public void runBSMLayout(){ 
    Timer timer = new Timer();
    timer.setStart();
   
    mapNodeIndex(nodes);

    //get the default layout of the graph, store positions in x_pos and y_pos
    int index = 0;
    generateInitRandomCoord();
   
    Bound range = getRange(x_pos, y_pos)
    for(int i = 0; i < nodeListSize; i++){
      double[] constrainedPos = range.constrain(x_pos[i], y_pos[i]);
      x_pos[i] = constrainedPos[0];
      y_pos[i] = constrainedPos[1];
    }
    calcCosSin();

    //System.out.println("x_pos length " + x_pos.length);
    //System.out.println("cosB length " + cosB.length);
   
    int iter = 0;
    double alpha = nodeListSize;
 
    for(; iter < maxIteration; iter++){
      System.out.println("running iteration " + iter);
      double[] newx_pos = ConjugateGradient(alpha, x_pos, cosB);//JNILib.LUSolver(cosB);
      double[] newy_pos = ConjugateGradient(alpha, y_pos, sinB);//JNILib.LUSolver(sinB);
      range = getRange(newx_pos, newy_pos);
      for(int i = 0; i < nodeListSize; 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));   
      x_pos = newx_pos;
      y_pos = newy_pos;
      //System.out.println("x_pos " + x_pos[0] + " y_pos " + y_pos[0]);
      if(diff <= BSthreshold){
        break;
      }
     
      calcCosSin();     
    }
   

    timer.setEnd();

    System.out.println("Binary Stress Calculation finished in " + timer.getLastSegment(Timer.SECONDS) + " seconds. " + iter + " iterations " +nodes.size() + " nodes");
    System.out.println(timer.getLastSegment(Timer.SECONDS) / (double)iter + " seconds per iteration\n");
   
    //set the layout positions
    index = 0;
    for(DNVNode node : nodes){
      node.setPosition((float)x_pos[index], (float)y_pos[index]);
View Full Code Here


    }*/
    //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 {
View Full Code Here

   *            the layout all levels
   */
  @Override
  public void runLayout( DNVGraph graph, int level, double maxSeconds, boolean initializePositions, boolean layoutAllLevels )
  {
    Timer timer = new Timer(Timer.MILLISECONDS);
    timer.setStart();
    if( layoutAllLevels )
    {
      for( level = graph.getMaxLevel(); level >= 0; level-- )
      {
        layoutLevel( graph, level, maxSeconds, initializePositions );
      }
    }
    else
    {
      layoutLevel( graph, level, maxSeconds, initializePositions );
    }
    timer.setEnd();
    if(writer != null){
      try{
        //writer.write(LABEL + " finished in " + timer.getLastSegment( Timer.SECONDS ) + " seconds.\n");
        int n = graph.getNodes(0).size();
        int e = graph.getEdges().size();
        double time = timer.getTimeSinceStart(Timer.SECONDS);;
        writer.write(time + "\t" + time/n + "\t" + time/e + "\t" + time/(n+e) + "\t" + time/(e/n) + "\n");
      }catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
View Full Code Here

   *            the initialize positions
   */
  public static void layoutLevel( DNVGraph graph, int level, double maxSeconds, boolean initializePositions )
  {
    Springs springs = new Springs( graph, level, initializePositions );
    Timer timer = new Timer( Timer.MILLISECONDS );
    graph.setAllNodesActive();
    float totalTime = timer.getTotalTime( Timer.SECONDS );
    // float graphSize_5 = (graph.getGraphSize( level ) / 5.0f);
    graph.setAllNodesActive( level );
    int activeNodes = graph.getActiveNodes( level ).size();
    while( totalTime < maxSeconds && activeNodes > 0 )
    {
      timer.setStart();
      springs.move();
      timer.setEnd();
      activeNodes = graph.getActiveNodes( level ).size();
      totalTime = timer.getTotalTime( Timer.SECONDS );
    }
  }
View Full Code Here

   
    //HashSet<DNVNode> traveledNodes = new HashSet<DNVNode>();
    //HashSet<DNVEdge> traveledEdges = new HashSet<DNVEdge>();
       

    Timer timer = new Timer( Timer.MILLISECONDS );
    timer.setStart();
   

    while(!degreeOrderedListDK2.isEmpty()){
     
     
      HashSet<DNVNode> impNodes = new HashSet<DNVNode>();
      HashSet<DNVNode> nodes = new HashSet<DNVNode>();
      HashSet<DNVEdge> edges = new HashSet<DNVEdge>();
     
      //for(int i = 0; i < iterateDecrease; i++){
      while(!degreeOrderedListDK2.isEmpty() && impNodes.size() <= 10 && edges.size() <= 10){
        Object key = degreeOrderedListDK2.get(0);
        degreeOrderedListDK2.remove(0);
       
        ArrayList<Tuple<Integer, Integer, DNVEdge>> nodeEdgeIndex = degreeNodeEdgeIndexTableDK2.get(key);
        for(Tuple<Integer, Integer, DNVEdge> tuple : nodeEdgeIndex){
          DNVNode node1 = graph.getNode(0, tuple.getLeft());
          impNodes.add(node1);
          DNVNode node2 = graph.getNode(0, tuple.getMiddle());
          nodes.add(node1);
          nodes.add(node2);         
          //nodes.add(node2);
          DNVEdge edge = tuple.getRight();
          edges.add(edge);   
          //traveledEdges.add(edge);   
        }
       
        /*for(DNVNode node : tableNodes.get(key)){
          traveledNodes.add(node);
          nodes.add(node);
                 
        }
        for(DNVEdge edge : tableEdges.get(key)){
         
          edges.add(edge);   
          traveledEdges.add(edge);
         
        }*/
      }
      /*if(iterateDecrease > 2){
        iterateDecrease--;
      }*/

     
      FR.runLayout(WIDTH,HEIGHT,nodes,edges,COOLING_FACTOR,false);
      for(DNVNode n : impNodes){
        //n.setVisible(true); 
        n.setProperty("pinned", "true");
      }
      for(DNVEdge e: edges){
        //e.setVisible(true);
        e.setProperty("pinned", "true");
      }

    }
   
    timer.setEnd();
    System.out.println( "Dk2 Layout took " + timer.getLastSegment( Timer.SECONDS ) + " seconds." );
    if(writer != null){
      try{
        int n = graph.getNodes(0).size();
        int e = graph.getEdges().size();
        double time = timer.getTimeSinceStart(Timer.SECONDS);;
        writer.write(time + "\t" + time/n + "\t" + time/e + "\t" + time/(n+e) + "\t" + time/(e/n) + "\n");
        //writer.write(timer.getLastSegment( Timer.SECONDS ) + "\n");
        //writer.write(LABEL + " finished in " + timer.getLastSegment( Timer.SECONDS ) + " seconds.\n\n");
      }catch (IOException e) {
        // TODO Auto-generated catch block
View Full Code Here

        System.out.print( "---------------------------------------------------------------------------------------\n" );
        System.out.print( "Results for " + fileNames[i] + "\n" );
        for( int k = 0; k < maxDepths.length; k++ )
        {
          maxDepth = maxDepths[k];
          selectionTimers[i] = new Timer( Timer.NANOSECONDS );
          movementTimers[i] = new Timer( Timer.NANOSECONDS );
          for( int j = 0; j < numberOfIterationsPerGraph; j++ )
          {
            movedNode = graph.getNodes( level ).get( (int)( Math.random() * graphSize ) );

            selectionTimers[i].setStart();
View Full Code Here

  public void loadGraphFromFile( String filename )
  {
    clearAll();
    this.filename = filename;
    File file = new File( filename );
    Timer timer = new Timer( Timer.MILLISECONDS );   
    if( file.exists() )
    {
      String line;
      FileReader fr;
      //int lineCnt=0;
View Full Code Here

      {
        node.storeCurrentPosition();
      }
      hasStoredPosition = true;
      this.displayStoredPosition = displayStoredPosition;
      storedPositionTimer = new Timer( Timer.NANOSECONDS );

//      System.out.println( "Set Stored Position" );
    }
  }
View Full Code Here

    this.initSettingsFrame();

    this.handler = handler;
    new Thread()
    {
      Timer timer = new Timer();
      public void run()
      {
        while( true )
        {
          timer.setStart();
          repaint();
          timer.setEnd();
          if( timer.getLastSegment( Timer.MILLISECONDS ) < 33 )
          {
            try
            {
              Thread.sleep( 33 - (int)timer.getLastSegment( Timer.MILLISECONDS ) );
            }
            catch( InterruptedException e )
            {
              e.printStackTrace();
            }
View Full Code Here

TOP

Related Classes of net.wigis.graph.dnv.utilities.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.