Package net.wigis.graph.dnv.utilities

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


      }

      // ------------------------------
      // edges
      // ------------------------------
      Timer edgesTimer = new Timer( Timer.MILLISECONDS );
      edgesTimer.setStart();
      drawEdges( subgraph, g2d, nodeSize, width, height, minXPercent, minYPercent, maxXPercent, maxYPercent, ratio, edgeThickness, drawLabels && !hideEdgeLabels,
          outlinedLabels, labelSize, minX, maxX, minY, maxY, overview, scaleNodesOnZoom, highlightNeighbors || highlightEdges,
          standardColor, g2d, boldLabels, nodeWidth );
      edgesTimer.setEnd();

      // ------------------------------
      // nodes
      // ------------------------------
      g2d.setStroke( new BasicStroke( 1 ) );

      List<DNVNode> nodes;

      Timer transformTimer = new Timer( Timer.MILLISECONDS );
      Timer nodesTimer = new Timer( Timer.MILLISECONDS );
      Timer drawNodeTimer = new Timer( Timer.MILLISECONDS );
      SortByLabelSize sortByLabelSize = new SortByLabelSize( highlightNeighbors );
      if( subgraph != null && subgraph.getNodes() != null && subgraph.getNodes().values() != null )
      {
        nodesTimer.setStart();
        nodes = drawNodes( subgraph, g2d, width, height, minXPercent, minYPercent, maxXPercent, maxYPercent, showIcons, minX, maxX, minY,
            maxY, highlightNeighbors, type, nodeWidth, selectedNodes, transformTimer, drawNodeTimer, sortByLabelSize,
            hideConflictingLabels && drawLabels, maxDistanceToHighlight );
        nodesTimer.setEnd();

        // ------------------------------
        // Store Bounding Boxes
        // ------------------------------
        if( !overview )
        {
          float maxSize = 0;
          for( DNVNode node : nodes )
          {
            maxSize = Math.max( maxSize, nodeWidth * node.getRadius() );
            double tempLabelSize = getLabelSize( node, labelSize, minXPercent, maxXPercent, ratio, scaleLabels );
            maxSize = (float)Math.max( maxSize, tempLabelSize * 1.6 );
          }
          subgraph.getSuperGraph().setAttribute( "maxSize", (int)Math.round( maxSize ) );
          Map<Integer, Rectangle> boundingRectangles = new HashMap<Integer, Rectangle>();
          Map<Integer, List<DNVNode>> nodesByYPos = new HashMap<Integer, List<DNVNode>>();
          Map<Integer, Map<Integer, Integer>> nodeAndKeyToIndex = new HashMap<Integer, Map<Integer, Integer>>();
          getNodesByYPos( nodes, g2d, nodeWidth, interpolationLabels, curvedLabels, labelSize, minX, maxX, minY, maxY, minXPercent,
              maxXPercent, minYPercent, maxYPercent, width, height, ratio, scaleLabels, maxLabelLength, curvedLabelAngle, boldLabels,
              subgraph.getSuperGraph(), boundingRectangles, nodesByYPos, nodeAndKeyToIndex, true, (int)Math.round( maxSize ) );
        }

        // ------------------------------
        // Animations
        // ------------------------------
        if( !overview )
        {
          Animation animation;
          List<Animation> animations = subgraph.getSuperGraph().getAnimations();
          for( int i = 0; i < animations.size(); i++ )
          {
            animation = animations.get( i );
            animation.paint( g2d, pb );
            if( animation.hasCompleted() )
            {
              animations.remove( i );
              i--;
            }
          }
        }

        // ------------------------------
        // labels
        // ------------------------------
        Timer labelsTimer = new Timer( Timer.MILLISECONDS );
        labelsTimer.setStart();
        drawLabels( subgraph, width, height, minXPercent, minYPercent, maxXPercent, maxYPercent, ratio, drawLabels, curvedLabels,
            outlinedLabels, labelSize, interpolationLabels, showSearchSelectedLabels, minX, maxX, minY, maxY, overview, level,
            highlightNeighbors, maxLabelLength, curvedLabelAngle, scaleLabels, hideConflictingLabels, drawLabelBox, g2d, nodeWidth,
            nodes, selectedNodes, sortByLabelSize, boldLabels, fadeFactor, maxNumberOfSelectedLabels, neighborHighlightColor );
        labelsTimer.setEnd();
        // ------------------------------
        if( Settings.DEBUG && !overview )
        {
          System.out.println( "Edges took " + edgesTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
          System.out.println( "Labels took " + labelsTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
          System.out.println( "Nodes took " + nodesTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
          System.out.println( "Transforming node positions took " + transformTimer.getTotalTime( Timer.SECONDS ) + " seconds." );
          System.out.println( "drawNode took " + drawNodeTimer.getTotalTime( Timer.SECONDS ) + " seconds." );
        }
      }
View Full Code Here


   * @throws IOException
   *             Signals that an I/O exception has occurred.
   */
  public void paint( OutputStream out, int width, int height, boolean overview, int rendering ) throws IOException
  {
    Timer createImageTimer = new Timer( Timer.MILLISECONDS );
    Timer writeImageTimer = new Timer( Timer.MILLISECONDS );
    createImageTimer.setStart();
    if( width == 0 )
    {
      width = getWidthInt();
    }
    if( height == 0 )
    {
      height = getHeightInt();
    }
    BufferedImage img = new BufferedImage( width, height, rendering );
    createImageTimer.setEnd();
    Graphics2D graphics2D = img.createGraphics();
    paint( graphics2D, width, height, overview, sortNodes && ( rendering != BufferedImage.TYPE_BYTE_INDEXED ) );
    writeImageTimer.setStart();
    try
    {
      ImageIO.write( img, "gif", out );
    }
    catch( Exception e )
    {}
    out.flush();
    writeImageTimer.setEnd();
    if( Settings.DEBUG && !overview )
    {
      System.out.println( "Creating image took " + createImageTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
      System.out.println( "Writing image took  " + writeImageTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
    }
  }
View Full Code Here

      }

      g2d.setColor( Color.white );
      g2d.fillRect( 0, 0, width, height );

      Timer globalBoundariesTimer = new Timer( Timer.MILLISECONDS );

      if( isRenderImage() || overview )
      {
        if( graph != null )
        {
          globalBoundariesTimer.setStart();
          refreshGlobalBoundaries( level );
          globalBoundariesTimer.setEnd();
          boolean drawLabels = ( !overview && showLabels );
          Timer drawTimer = new Timer( Timer.MILLISECONDS );
          drawTimer.setStart();
          int maxDistanceToHighlight = (int)numberAffected;
          if( !(interactionMethod instanceof InterpolationMethod) || selectedNode == null )
          {
            // Don't highlight nodes if no nodes is selected or not
            // using interpolation method
            maxDistanceToHighlight = -1;
          }
          else if( interpolationMethodUseWholeGraph )
          {
            // Highlight all nodes if useWholeGraph
            maxDistanceToHighlight = graph.getNodes( level ).size();
          }
          ImageRenderer.drawGraph( subGraph, g2d, this, (int)getNodeSize(), width, height, minX, minY, maxX, maxY, width / getWidth(),
              edgeThickness, edgeColor, drawLabels, curvedLabels, outlinedLabels, labelSize, interpolationLabels,
              showSearchSelectedLabels, showIcons, globalMinX, globalMaxX, globalMinY, globalMaxY, overview, level, scaleNodesOnZoom,
              sortNodes, highlightNeighbors, highlightEdges, maxLabelLength, curvedLabelAngle, scaleLabels, hideConflictingLabels,
              drawLabelBox, boldLabels, fadeFactor, maxNumberOfSelectedLabels, maxDistanceToHighlight, drawWatermark,
              drawNeighborHighlight, drawNumberOfNodesInBox, drawNeighborHighlightAsBoxes, drawAllNeighborsHighlight,
              alignBoxInfoRelativeToBox, timeText, drawAxis, neighborHighlightColor, hideEdgeLabels );
          drawTimer.setEnd();
          if( Settings.DEBUG && !overview )
          {
            System.out.println( "Refreshing global boundaries took " + globalBoundariesTimer.getLastSegment( Timer.SECONDS )
                + " seconds." );
            System.out.println( "Pure drawing took " + drawTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
          }
        }
      }
    }
    printTime( "paint(graph2d)", startTime );
View Full Code Here

  /**
   * Save graph.
   */
  public void saveGraph()
  {
    Timer timer = new Timer( Timer.MILLISECONDS );
    timer.setStart();
    graph.writeGraph( selectedFile );
    timer.setEnd();
    System.out.println( "Saving " + selectedFile + " took " + timer.getLastSegment( Timer.SECONDS ) + " seconds." );
    GraphsBean gb = (GraphsBean)ContextLookup.lookup( "graphsBean", FacesContext.getCurrentInstance() );
    if( gb != null )
    {
      gb.buildFileList();
    }
View Full Code Here

  public void loadGraph()
  {
    long startTime = System.currentTimeMillis();
    synchronized( graph )
    {
      Timer loadTimer = new Timer( Timer.MILLISECONDS );
      loadTimer.setStart();
      graph = new DNVGraph( getSelectedFile() );
      graph.setFilename(getSelectedFile());
      graph.setPaintBean( this );
      loadTimer.setEnd();
      System.out.println( "Loading '" + selectedFile + "' took " + loadTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
      int maxLevel = graph.getMaxLevel();
      if( level > maxLevel )
        level = maxLevel;

      resetNumberOfClusters();
View Full Code Here

    if( graph.hasStoredPosition() )
    {
      graph.startInterpolation();
    }

    Timer timer = new Timer( Timer.MILLISECONDS );
    timer.setStart();
    while( graph.hasStoredPosition() )
    {
      synchronized( graph )
      {
        timer.setEnd();
        if( timer.getTotalTime( Timer.SECONDS ) > 5 && graph.getCurrentFrame() == 0 )
        {
          break;
        }
        timer.setStart();
      }
    }

    if( graph.hasStoredPosition() )
    {
View Full Code Here

      if( renderingStr != null && renderingStr.equals( "qual" ) )
      {
        rendering = BufferedImage.TYPE_INT_RGB;
      }

      Timer pickingTimer = new Timer( Timer.MILLISECONDS );
     
      // ------------------------------------
      // interaction with static image
      // ------------------------------------
      String mouseDownXstr = request.getParameter( "mouseDownX" );
      // boolean mouseDown = false;
      if( mouseDownXstr != null && !mouseDownXstr.equals( "" ) )
      {
        // mouseDown = true;
        pickingTimer.setStart();
        // drag closest node to this position
        int mouseDownX = Integer.parseInt( mouseDownXstr );
        int mouseDownY = Integer.parseInt( request.getParameter( "mouseDownY" ) );

        // drag it to here
        int mouseUpX = Integer.parseInt( request.getParameter( "mouseUpX" ) );
        int mouseUpY = Integer.parseInt( request.getParameter( "mouseUpY" ) );

        boolean sameNode = Boolean.parseBoolean( request.getParameter( "sameNode" ) );
        boolean ctrlPressed = Boolean.parseBoolean( request.getParameter( "ctrlPressed" ) );

        // - - - - - - - - - - -
        // find closest node
        // - - - - - - - - - - -
        // float maxDepth = Integer.MAX_VALUE;

        double globalMinX = GraphFunctions.getMinXPosition( graph, level, true );
        double globalMaxX = GraphFunctions.getMaxXPosition( graph, level, true );
        double globalMinY = GraphFunctions.getMinYPosition( graph, level, true );
        double globalMaxY = GraphFunctions.getMaxYPosition( graph, level, true );
        if( globalMinY == globalMaxY )
        {
          globalMinY -= 10;
          globalMaxY += 10;
        }
        if( globalMinX == globalMaxX )
        {
          globalMinX -= 10;
          globalMaxX += 10;
        }
        double yBuffer = ( globalMaxY - globalMinY ) * pb.getWhiteSpaceBuffer();
        double xBuffer = ( globalMaxX - globalMinX ) * pb.getWhiteSpaceBuffer();
        DNVNode selectedNode = null;
        globalMaxY += yBuffer;
        globalMinY -= yBuffer;
        globalMaxX += xBuffer;
        globalMinX -= xBuffer;

        if( !sameNode )
        {
          List<DNVNode> nodes = graph.getNodes( level );
          SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
          Collections.sort( nodes, sbls );
          DNVNode node;
          Vector2D screenPosition;
          double distance;
          double minDistance = Integer.MAX_VALUE;
          int nodeI = -1;
          int distX = 0; // dist b/w this node and mouse click
          int distY = 0;

          // Check if user clicked on a solid node label
          for( int i = nodes.size() - 1; i >= 0; i-- )
          {
            node = nodes.get( i );
            if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) == null )
            {
              screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY,
                  width, height, node.getPosition( true ) );
              ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null,
                  (int)Math.round( pb.getNodeSize() * node.getRadius() ), node.getLabel( pb.isInterpolationLabels() ), pb
                      .isCurvedLabels()
                      || node.isCurvedLabel(), pb.getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb
                      .getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
              if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                  && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
              {
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );
                node.setProperty( "distX", "" + distX );
                node.setProperty( "distY", "" + distY );
                minDistance = 0;
                nodeI = i;
                break;
              }
            }
          }

          if( nodeI == -1 )
          {
            // loop thru all nodes to find closest node
            for( int i = nodes.size() - 1; i >= 0; i-- )
            {
              node = nodes.get( i );
              if( node.isVisible() )
              {
                screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, node.getPosition( true ) );

                // find node closest to mouseDown
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );

                distance = distX * distX + distY * distY;

                if( distance < minDistance )
                {
                  node.setProperty( "distX", "" + distX );
                  node.setProperty( "distY", "" + distY );

                  minDistance = distance;
                  nodeI = i;
                }
              }
            }
          }

          if( nodes.size() > 0 && nodeI != -1 )
          {
            node = nodes.get( nodeI );

            double nodeWidth;
            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );

            if( Math.sqrt( minDistance ) >= nodeWidth )
            {
              // Still no node selected so check nodes with faded
              // labels
              for( int i = nodes.size() - 1; i >= 0; i-- )
              {
                node = nodes.get( i );
                if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) != null
                    && Float.parseFloat( node.getProperty( "faded" ) ) > 0.1 )
                {
                  screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX,
                      minY, maxY, width, height, node.getPosition( true ) );
                  ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition,
                      null, (int)Math.round( pb.getNodeSize() * node.getRadius() ),
                      node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb
                          .getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(),
                      pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
                  if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                      && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
                  {
                    distX = (int)( mouseDownX - screenPosition.getX() );
                    distY = (int)( mouseDownY - screenPosition.getY() );
                    node.setProperty( "distX", "" + distX );
                    node.setProperty( "distY", "" + distY );
                    minDistance = 0;
                    nodeI = i;
                    break;
                  }
                }
              }
            }

            node = nodes.get( nodeI );

            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
            if( Math.sqrt( minDistance ) < nodeWidth )
            {
              // if( node.isSelected() )
              // {
              // sameNode = true;
              // }
              pb.setSelectedNode( node, ctrlPressed );
              selectedNode = node;
            }
            else
            {
              if( pb.getSelectedNode() != null )
              {
                pb.setSelectedNode( null, ctrlPressed );
//                runDocumentTopicsCircularLayout( request, pb, graph, level );
              }
            }
          }

          if( selectedNode == null )
          {
            minDistance = Integer.MAX_VALUE;
            List<DNVEdge> edges = graph.getEdges( level );
            DNVEdge edge;
            Vector2D screenPosition2;
            int edgeI = 0;
            for( int i = 0; i < edges.size(); i++ )
            {
              edge = edges.get( i );
              if( edge.isVisible() )
              {
                screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, edge.getFrom().getPosition( true ) );
                screenPosition2 = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, edge.getTo().getPosition( true ) );
                distance = getPointLineDistance( screenPosition, screenPosition2, mouseDownX, mouseDownY );
                if( distance < minDistance )
                {
                  minDistance = distance;
                  edgeI = i;
                }
              }
            }

            if( edges.size() > 0 )
            {
              edge = edges.get( edgeI );

              double edgeWidth = Math.max( edge.getThickness(), 4 );
              // check if selected node is close enough to
              // mouseDown
              if( Settings.DEBUG )
                System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
              if( Math.sqrt( minDistance ) < edgeWidth / 2.0 )
              {
                if( edge.isSelected() )
                {
                  sameNode = true;
                }
                pb.setSelectedEdge( edge, ctrlPressed );
              }
              else
              {
                pb.setSelectedEdge( null, ctrlPressed );
              }
            }
          }
        }

        pickingTimer.setEnd();
        if( Settings.DEBUG )
          System.out.println( "Picking took " + pickingTimer.getLastSegment( Timer.SECONDS ) + " seconds." );

        String releasedStr = request.getParameter( "released" );
        boolean released = false;
        if( releasedStr != null )
        {
          try
          {
            released = Boolean.parseBoolean( releasedStr );
          }
          catch( Exception e )
          {}
        }
       
        moveSelectedNode( request, pb, graph, level, width, height, minX, minY, maxX, maxY, mouseUpX, mouseUpY, sameNode, globalMinX,
            globalMaxX, globalMinY, globalMaxY, selectedNode, released );
      }

      // ------------------------------------

      Timer paintTimer = new Timer( Timer.MILLISECONDS );
      paintTimer.setStart();
      response.setContentType( "image/gif" );
      pb.paint( response.getOutputStream(), width, height, overview, rendering );
      paintTimer.setEnd();

      if( Settings.DEBUG && !overview && !pb.isRenderJS() )
        System.out.println( "Drawing took " + paintTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
    }
    catch( IOException e )
    {
      // e.printStackTrace();
    }
View Full Code Here

    this.level = level;
    prepairDK3Table(graph);
  }
 
  private void prepairDK3Table(DNVGraph graph){
    Timer timer = new Timer();
    timer.setStart();
   
    Dk2Calc dk2Calc = new Dk2Calc(graph, level);
    //degreeEdgeTableDK3 = new Hashtable<Tuple<Integer,Integer,Integer>, ArrayList<Pair<DNVEdge, DNVEdge>>>();
    degreeUniqueEdgeTableDK3 = new Hashtable<Tuple<Integer,Integer,Integer>, HashSet<DNVEdge>>();
    degreeUniqueNodeTableDK3 = new Hashtable<Tuple<Integer,Integer,Integer>, HashSet<DNVNode>>();
    degreeOccurTableDK3 = new Hashtable<Tuple<Integer,Integer,Integer>, Integer>();   
    triangles = new HashSet<Triangle>();
    lines = new HashSet<Line>();
   
    int cnt = 0;
    int triangleCnt = 0;
    int lineCnt = 0;
    HashSet<Integer> traveledNodesId = new HashSet<Integer>();
    for(Object key : dk2Calc.getDegreeOrderedListDK2()){
      Pair<Integer, Integer> degreePair = (Pair<Integer, Integer>)key;
      Integer highDegree = degreePair.getFirst();
      Integer lowDegree = degreePair.getSecond();

      ArrayList<Tuple<Integer, Integer, DNVEdge>> dk2EdgeTuple = dk2Calc.getDegreeNodeEdgeIndexTableDK2().get(degreePair);
      for(Tuple<Integer, Integer, DNVEdge> tuple : dk2EdgeTuple){
        Integer highDegreeNodeId = tuple.getLeft();
        Integer lowDegreeNodeId = tuple.getMiddle();
       
        //first add all the tuple nodes with the higher degree node in the center, no redundancy
        if(!traveledNodesId.contains(highDegreeNodeId)){
          traveledNodesId.add(highDegreeNodeId);
          DNVNode middlenode = graph.getNode(level, highDegreeNodeId);
          //List<DNVNode> neighbors = middlenode.getNeighbors();
         
          //get all the neighbors of the higher degree node which haven't been traveled
          ArrayList<DNVNode> neighbors = new ArrayList<DNVNode>();
          for(DNVEdge edge : middlenode.getFromEdges()){
            if(!traveledNodesId.contains(edge.getToId())){
              neighbors.add(graph.getNode(level, edge.getToId()));
            }
          }
          for(DNVEdge edge : middlenode.getToEdges()){
            if(!traveledNodesId.contains(edge.getFromId())){
              neighbors.add(graph.getNode(level, edge.getFromId()));
            }
          }
         
          for(int i = 0; i < neighbors.size(); i++){
            for(int j = i + 1; j < neighbors.size(); j++){
              Integer degree1 = neighbors.get(i).getConnectivity();
              Integer degree2 = neighbors.get(j).getConnectivity();             
              Integer leftNodeId, rightNodeId;
              DNVNode leftNode, rightNode;
              DNVEdge leftEdge, rightEdge, middleEdge;
              Tuple<Integer, Integer, Integer> degreeTuple;
              //for each node tuple, the left node degree should be no smaller than the right one
              if(degree1 >= degree2){
                leftNode = neighbors.get(i);
                rightNode = neighbors.get(j);             
                degreeTuple = new Tuple<Integer, Integer, Integer>(degree1, highDegree,degree2);
              }else{
                leftNode = neighbors.get(j);
                rightNode = neighbors.get(i);
                degreeTuple = new Tuple<Integer, Integer, Integer>(degree2, highDegree,degree1);
              }
              leftNodeId = leftNode.getId();
              rightNodeId = rightNode.getId();
              leftEdge = middlenode.getEdgeToNeighbor(leftNodeId);
              rightEdge = middlenode.getEdgeToNeighbor(rightNodeId);
             
              if(!degreeOccurTableDK3.containsKey(degreeTuple)){
                degreeOccurTableDK3.put(degreeTuple, 0)
                degreeUniqueEdgeTableDK3.put(degreeTuple, new HashSet<DNVEdge>());
                degreeUniqueNodeTableDK3.put(degreeTuple, new HashSet<DNVNode>());
              }         
              degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);
              degreeUniqueEdgeTableDK3.get(degreeTuple).add(leftEdge);
              degreeUniqueEdgeTableDK3.get(degreeTuple).add(rightEdge);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(leftNode);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(rightNode);
             
              if(leftNode.getNeighbors().contains(rightNode) || rightNode.getNeighbors().contains(leftNode)){
                middleEdge = leftNode.getEdgeToNeighbor(rightNodeId);
                Triangle triangle = new Triangle(leftNode, middlenode, rightNode, leftEdge, middleEdge, rightEdge);
                triangles.add(triangle);
                degreeUniqueEdgeTableDK3.get(degreeTuple).add(middleEdge);
                triangleCnt++;
              }else{
                Line line = new Line(leftNode, middlenode, rightNode, leftEdge, rightEdge);
                lines.add(line);
                lineCnt++;
              }
              cnt++;
            }
          }
        }
       
        if(traveledNodesId.contains(lowDegreeNodeId)){
          continue;
        }
        //next get all the tuple nodes with the lower degree node in the center and the higher degree node at one end
        DNVNode middlenode = graph.getNode(level, lowDegreeNodeId);
        DNVNode leftNode = graph.getNode(level, highDegreeNodeId);
        DNVEdge leftEdge = tuple.getRight();
        DNVEdge rightEdge, middleEdge;
        //get all the neighbors of the lower degree node which haven't been traveled
        ArrayList<DNVNode> neighbors = new ArrayList<DNVNode>();
        for(DNVEdge edge : middlenode.getFromEdges()){
          if(!traveledNodesId.contains(edge.getToId())){
            neighbors.add(graph.getNode(level, edge.getToId()));
          }
        }
        for(DNVEdge edge : middlenode.getToEdges()){
          if(!traveledNodesId.contains(edge.getFromId())){
            neighbors.add(graph.getNode(level, edge.getFromId()));
          }
        }
        for(DNVNode neighbor : neighbors){
          Integer neighborId = neighbor.getId();
          Integer neighborDegree = neighbor.getConnectivity();
          rightEdge = middlenode.getEdgeToNeighbor(neighborId);
          Tuple<Integer, Integer, Integer> degreeTuple = new Tuple<Integer, Integer, Integer>(highDegree, lowDegree, neighborDegree);
          if(!degreeOccurTableDK3.containsKey(degreeTuple)){
            //degreeEdgeTableDK3.put(degreeTuple, new ArrayList<Pair<DNVEdge, DNVEdge>>());
            degreeOccurTableDK3.put(degreeTuple, 0)
            degreeUniqueEdgeTableDK3.put(degreeTuple, new HashSet<DNVEdge>());
            degreeUniqueNodeTableDK3.put(degreeTuple, new HashSet<DNVNode>());
          }
          //degreeEdgeTableDK3.get(degreeTuple).add(new Pair<DNVEdge,DNVEdge>(tuple.getRight(),middlenode.getEdgeToNeighbor(neighborId)));
          degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);

          degreeUniqueEdgeTableDK3.get(degreeTuple).add(leftEdge);
          degreeUniqueEdgeTableDK3.get(degreeTuple).add(rightEdge);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(leftNode);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbor);
         
         
          if(leftNode.getNeighbors().contains(neighbor) || neighbor.getNeighbors().contains(leftNode)){
            middleEdge = leftNode.getEdgeToNeighbor(neighborId);
            Triangle triangle = new Triangle(leftNode, middlenode, neighbor, leftEdge, middleEdge, rightEdge);
            triangles.add(triangle);
            degreeUniqueEdgeTableDK3.get(degreeTuple).add(middleEdge);
            triangleCnt++;
          }else{
            Line line = new Line(leftNode, middlenode, neighbor, leftEdge, rightEdge);
            lines.add(line);
            lineCnt++;
          }
          cnt++;
        }
      }
    }
    occurOrderedListDK3 = hashTableSort.sortByValueDesc(degreeOccurTableDK3);
    degreeOrderedListDK3 = hashTableSort.sortByKeyDesc(degreeOccurTableDK3);
   
    timer.setEnd();
    System.out.println("  computing dk3 took " + timer.getLastSegment(Timer.SECONDS) + " seconds number of tuples " + cnt + " triangles " + triangleCnt + " lineCnt " + lineCnt);
  }
View Full Code Here

   *            the use actual distance
   * @return the float
   */
  public static float performBFS( DNVNode selectedNode, float maxDepth, boolean useActualDistance )
  {
    Timer bfsTimer = new Timer( Timer.MILLISECONDS );
    List<DNVNode> queue = new ArrayList<DNVNode>();
    bfsTimer.setStart();
    selectedNode.setDistanceFromSelectedNode( 0 );
    selectedNode.setActualDistanceFromSelectedNode( 0 );
    selectedNode.setDistanceFromNode( selectedNode, 0 );
    Iterator<DNVEdge> edges;
    queue.add( selectedNode );
    DNVNode tempNode;
    float actualDistance;
    int maxDistance = 0;
    int distance;
    float maxActualDistance = 0;
    DNVEdge tempEdge;
    if( maxDepth > 0 )
    {
      while( queue.size() > 0 )
      {
        tempNode = queue.remove( 0 );
        distance = tempNode.getDistanceFromNodeWithId( selectedNode.getId() );
        actualDistance = tempNode.getActualDistanceFromSelectedNode();
        if( actualDistance > maxActualDistance )
        {
          maxActualDistance = actualDistance;
        }

        if( distance > maxDistance )
        {
          maxDistance = distance;
        }

        if( distance < maxDepth )
        {
          // From edges
          edges = tempNode.getFromEdges().iterator();
          while( edges.hasNext() )
          {
            tempEdge = edges.next();
            if( tempEdge.isVisible() )
            {
              addNode( selectedNode, distance + 1, actualDistance + tempEdge.getRestingDistance(), queue, tempEdge.getTo() );
            }
          }

          // To edges
          edges = tempNode.getToEdges().iterator();
          while( edges.hasNext() )
          {
            tempEdge = edges.next();
            if( tempEdge.isVisible() )
            {
              addNode( selectedNode, distance + 1, actualDistance + tempEdge.getRestingDistance(), queue, tempEdge.getFrom() );
            }
          }
        }
      }
    }
    bfsTimer.setEnd();
    if( Settings.DEBUG )
    {
      System.out.println( "Interpolation BFS took " + bfsTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
    }

    // if( useActualDistance )
    // return Math.round( maxActualDistance );

View Full Code Here

   *            the selected node
   */
  public static void setWeights( DNVGraph graph, Integer level, float maxDistance, float scalar1, float scalar2, float sCurveLowEnd, float sCurveHighEnd,
      boolean useActualDistance, DNVNode selectedNode )
  {
    Timer weightsTimer = new Timer( Timer.MILLISECONDS );
    DNVNode tempNode;
    float tempWeight;
    weightsTimer.setStart();
    Iterator<DNVNode> nodes = graph.getNodes( level ).iterator();
    float tempDistance;
    while( nodes.hasNext() )
    {
      tempNode = nodes.next();
      if( useActualDistance )
        tempDistance = tempNode.getActualDistanceFromSelectedNode();
      else
        tempDistance = tempNode.getDistanceFromNodeWithId( selectedNode.getId() );

      if( tempDistance != Integer.MAX_VALUE )
      {
        graph.addInterpolationNode( tempNode, level );
        tempWeight = 1.0f - ( ( tempDistance ) / ( maxDistance ) );
        // tempWeight = 1.0f / (tempDistance + 1);
        // System.out.println( "1.0 - (" +
        // tempNode.getDistanceFromSelectedNode() + " / " + maxDistance
        // + ") = " + tempWeight );
        if( tempWeight > sCurveLowEnd )
        {
          // tempWeight = ( tempWeight - sCurveLowEnd ) / (
          // sCurveHighEnd - sCurveLowEnd );
          // tempWeight = scalar1 * tempWeight * tempWeight - scalar2
          // * tempWeight * tempWeight * tempWeight;
          tempNode.setInterpolationWeight( selectedNode.getId(), tempWeight );
        }
      }
      else
      {
        tempWeight = 0;
        tempNode.setInterpolationWeight( selectedNode.getId(), tempWeight );
      }
    }

    weightsTimer.setEnd();
    if( Settings.DEBUG )
    {
      System.out.println( "Interpolation set weights took " + weightsTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
    }
  }
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.