Package net.wigis.graph.dnv

Examples of net.wigis.graph.dnv.DNVEdge


          toNode.setId( new Integer( toId ) );
          toNode.setLabel( "" + toId );
          dnvGraph.addNode( 0, toNode );
        }

        DNVEdge dnvEdge = new DNVEdge( dnvGraph );
        dnvEdge.setFrom( fromNode );
        dnvEdge.setId( new Integer( edge_id + 10000000 ) );
        dnvEdge.setTo( toNode );
        dnvGraph.addNode( 0, dnvEdge );
        line = br.readLine();
      }
    }
    catch( NullPointerException npe )
View Full Code Here


        node2.setColor( color );
        node2.setProperty( "time", "" + time );
        graph.addNode( level, node2 );
      }

      DNVEdge edge = new DNVEdge( graph );
      edge.setFrom( node1 );
      edge.setTo( node2 );
      edge.setBbId( edgeStr );
      edge.setProperty( "time", "" + time );
      graph.addNode( level, edge );
    }
  }
View Full Code Here

          + ".csv" );
      out = new BufferedWriter( fstream );
      if( writeCSV )
        out.write( "from,to" + "\n" );

      DNVEdge dnvEdge;
      List<DNVEdge> edges = dnvGraph.getEdges( 0 );
      for( int i = 0; i < edges.size(); i++ )
      {
        dnvEdge = edges.get( i );

        // csv
        out.write( dnvEdge.getFromId() + "," );
        out.write( dnvEdge.getToId() + "\n" );
      }

      // csv
      out.close();
    }
View Full Code Here

    List<DNVNode> neighbors;
    DNVNode subNode;
    DNVNode neighbor;
    DNVNode secondParent;
    Map<Integer, Boolean> isNeighbor;
    DNVEdge newEdge;
    for( int i = 0; i < parents.size(); i++ )
    {
      parent = parents.get( i );
      isNeighbor = new HashMap<Integer, Boolean>();
      tempMap = parentToPlanetsOrMoons.get( parent.getId() );
      iterator = tempMap.values().iterator();
      while( iterator.hasNext() )
      {
        subNode = iterator.next();
        neighbors = subNode.getNeighbors();
        for( int j = 0; j < neighbors.size(); j++ )
        {
          neighbor = neighbors.get( j );
          secondParent = subNodeToParent.get( neighbor.getId() );
          if( !secondParent.equals( parent ) && isNeighbor.get( secondParent.getId() ) == null )
          {
            isNeighbor.put( secondParent.getId(), true );
            newEdge = new DNVEdge( newLevel, DNVEdge.DEFAULT_RESTING_DISTANCE, false, parent, secondParent, graph );
            graph.addNode( newLevel, newEdge );
          }
        }
      }
    }
View Full Code Here

          if(nodeToTriangles.get(node) != null){
            for(Triangle newTri : nodeToTriangles.get(node)){
              if(newTri != tri){
                DNVNode otherNode = triangleToParent.get(newTri);
                if(otherNode != null && !parent.getAllNeighbors().contains(otherNode) && !parent.shareNeighbors(otherNode)){
                  DNVEdge edge = new DNVEdge(compressedGraph);
                  edge.setTo(parent);
                  edge.setFrom(otherNode);
                  compressedGraph.addEdge(0, edge);
                }
              }
            }
          }
          if(nodeToLines.get(node) != null){
            for(Line newLine: nodeToLines.get(node)){
              DNVNode otherNode = lineToParent.get(newLine);
              if(otherNode != null && !parent.getAllNeighbors().contains(otherNode) && !parent.shareNeighbors(otherNode)){
                DNVEdge edge = new DNVEdge(compressedGraph);
                edge.setTo(parent);
                edge.setFrom(otherNode);
                compressedGraph.addEdge(0, edge);
              }
            }
          }
        }
      }
     
      Line line = parentToLine.get(parent);
      if(line != null){
        for(DNVNode node : line.vertices){
          if(nodeToTriangles.get(node) != null){
            for(Triangle newTri : nodeToTriangles.get(node)){
              DNVNode otherNode = triangleToParent.get(newTri);
              if(otherNode != null && !parent.getAllNeighbors().contains(otherNode) && !parent.shareNeighbors(otherNode)){
                DNVEdge edge = new DNVEdge(compressedGraph);
                edge.setTo(parent);
                edge.setFrom(otherNode);
                compressedGraph.addEdge(0, edge);
              }
            }
          }
          if(nodeToLines.get(node) != null){
            for(Line newLine: nodeToLines.get(node)){
              if(newLine != line){
                DNVNode otherNode = lineToParent.get(newLine);
                if(otherNode != null && !parent.getAllNeighbors().contains(otherNode) && !parent.shareNeighbors(otherNode)){
                  //if(!parent.getNeighbors().contains(otherNode) && !otherNode.getNeighbors().contains(parent)){
                    DNVEdge edge = new DNVEdge(compressedGraph);
                    edge.setTo(parent);
                    edge.setFrom(otherNode);
                    compressedGraph.addEdge(0, edge);
                }
              }
            }
          }
        }
      }
    }
    //put in the disconnected nodes
    for(DNVNode node : untraveledNode){
      if(node.getConnectivity() > 1){
        System.out.println("connectivity > 1, shouldn't be happening");
      }
      DNVNode parent = new DNVNode(compressedGraph);
      compressedGraph.addNode(0, parent);
      nodeToParent.put(node, parent);
    }
    for(DNVEdge edge : untraveledEdge){
      if(! (edge.getFrom().getConnectivity() == 1 && edge.getTo().getConnectivity() == 1)){
        System.out.println("weird edge");
        continue;
      }
      DNVNode p1 = nodeToParent.get(edge.getFrom());
      DNVNode p2 = nodeToParent.get(edge.getTo());
      if(p1 == null){
        System.out.println("p1 is null");
      }
      if(p2 == null){
        System.out.println("p2 is null " + edge.getFrom().getConnectivity() + " " + edge.getTo().getConnectivity());
        DNVNode node = edge.getTo();
        if(nodeToTriangles.get(node) == null){
          System.out.println("no triangle");
        }else{
          System.out.println("belong to triangle");
        }
        if(nodeToLines.get(node) == null){
          System.out.println("no line");
        }else{
          System.out.println("belong to line");
        }
      }
      DNVEdge pedge = new DNVEdge(compressedGraph);
      pedge.setFrom(p1);
      pedge.setTo(p2);
      compressedGraph.addEdge(0, pedge);
    }
    compressedGraph.writeGraph(Settings.GRAPHS_PATH + "fb1000_level1.dnv");
    System.out.println("this level contains " + compressedGraph.getGraphSize(0) + " nodes " + compressedGraph.getEdges(0).size() + " edges");
  }
View Full Code Here

      Collections.sort( currentNodes, sorter );

    DNVNode tempNode;
    DNVNode tempNode2;
    DNVNode newNode;
    DNVEdge tempEdge;

    System.out.println( "First node neighbors : " + currentNodes.get( 0 ).getNeighbors().size() );
    System.out.println( "Last node neighbors : " + currentNodes.get( currentNodes.size() - 1 ).getNeighbors().size() );

    Map<Integer, Integer> nodeDistance = new HashMap<Integer, Integer>();
    Map<Integer, DNVNode> nodeToParent = new HashMap<Integer, DNVNode>();
    Map<Integer, List<DNVNode>> parentToNodes = new HashMap<Integer, List<DNVNode>>();

    List<DNVNode> tempList;

    // Assign all nodes with a parent node
    for( int i = 0; i < numberOfClusters; i++ )
    {
      tempNode = currentNodes.get( i );
      newNode = createParentNode( tempNode, newLevel, graph, nodeDistance, nodeToParent, parentToNodes );
      if( Settings.DEBUG )
      {
        System.out.println( "Parent node has id " + newNode.getId() + " subnode has id " + tempNode.getId() );
        System.out.println( "Subnode[" + tempNode.getId() + "] has " + tempNode.getNeighbors().size() + " neighbors" );
      }
      tempNodeList = tempNode.getNeighbors();
      handleNeighbors( 1, tempNodeList, newNode, nodeDistance, nodeToParent );
    }

    // Handle nodes that are not connected to any other nodes
    tempList = graph.getNodes( currentLevel );
    for( int i = 0; i < tempList.size(); i++ )
    {
      tempNode = tempList.get( i );
      if( tempNode.getNeighbors().size() == 0 )
      {
        newNode = createParentNode( tempNode, newLevel, graph, nodeDistance, nodeToParent, parentToNodes );
        if( Settings.DEBUG )
        {
          System.out.println( "Node with id " + tempNode.getId() + " at level " + currentLevel + " has no neighbors. Create parent node." );
          System.out.println( "Parent node has id " + newNode.getId() );
          System.out.println( "" );
        }
      }
    }

    if( Settings.DEBUG )
    {
      System.out.println( "Number of nodes that have a parent node: " + nodeToParent.keySet().size() );
      System.out.println( "Number of nodes at current level: " + currentNodes.size() );

      for( int i = 0; i < currentNodes.size(); i++ )
      {
        if( nodeToParent.get( currentNodes.get( i ).getId() ) == null )
        {
          System.out.println( "node " + currentNodes.get( i ).getId() + " has no parent." );
        }
      }
    }

    // Set connections from parent to sub nodes
    Iterator<Integer> ids = nodeToParent.keySet().iterator();
    Integer tempId;
    while( ids.hasNext() )
    {
      tempId = ids.next();
      tempNode = nodeToParent.get( tempId );
      tempList = parentToNodes.get( tempNode.getId() );
      tempNode2 = (DNVNode)graph.getNodeById( tempId );
      if( tempNode2 != null && !tempList.contains( tempNode2 ) )
      {
        tempList.add( tempNode2 );
        parentToNodes.put( tempNode.getId(), tempList );
        tempNode.setLabel( "" + tempList.size() );
      }

      if( tempNode2 == null )
      {
        System.out.println( "Trying to add a link from a non-existing node" );
      }
    }

    // Create the edges
    List<DNVEdge> edgeList;
    ids = parentToNodes.keySet().iterator();
    DNVNode tempParent;
    DNVNode tempParent2;
    while( ids.hasNext() )
    {
      tempId = ids.next();
      tempParent2 = (DNVNode)graph.getNodeById( tempId );
      tempList = parentToNodes.get( tempId );
      tempParent2.setSubNodes( tempList );
      for( int i = 0; i < tempList.size(); i++ )
      {
        tempNode = tempList.get( i );
        edgeList = tempNode.getFromEdges();
        for( int j = 0; j < edgeList.size(); j++ )
        {
          tempEdge = edgeList.get( j );
          tempNode2 = tempEdge.getTo();
          tempParent = nodeToParent.get( tempNode2.getId() );
          if( tempParent != null && !tempParent.getId().equals( tempId ) && tempParent != tempParent2 )
          {
            if( !tempParent.getNeighbors().contains( tempParent2 ) )
            {
              tempEdge = new DNVEdge( newLevel.intValue(), DNVEdge.DEFAULT_RESTING_DISTANCE, false, tempParent2, tempParent, graph );
              tempParent2.addFromEdge( tempEdge );
              tempParent.addToEdge( tempEdge );
              graph.addNode( newLevel, tempEdge );
            }
          }
        }

        edgeList = tempNode.getToEdges();
        for( int j = 0; j < edgeList.size(); j++ )
        {
          tempEdge = edgeList.get( j );
          tempNode2 = tempEdge.getFrom();
          tempParent = nodeToParent.get( tempNode2.getId() );

          if( tempParent != null && !tempParent.getId().equals( tempId ) && tempParent != tempParent2 )
          {
            tempParent2 = (DNVNode)graph.getNodeById( tempId );
            if( !tempParent.getNeighbors().contains( tempParent2 ) )
            {
              tempEdge = new DNVEdge( newLevel.intValue(), DNVEdge.DEFAULT_RESTING_DISTANCE, false, tempParent, tempParent2, graph );
              tempParent2.addToEdge( tempEdge );
              tempParent.addFromEdge( tempEdge );
              graph.addNode( newLevel, tempEdge );
            }
          }
        }
      }
    }

    // float constant = 0.1f;
    for( int i = 0; i < currentNodes.size(); i++ )
    {
      tempNode = currentNodes.get( i );
      edgeList = tempNode.getFromEdges();
      for( int j = 0; j < edgeList.size(); j++ )
      {
        tempEdge = edgeList.get( j );
        tempNode2 = tempEdge.getTo();
        // tempEdge.setRestingDistance( DNVEdge.DEFAULT_RESTING_DISTANCE
        // + constant * ( tempNode.getTotalNumberOfSubNodes() +
        // tempNode2.getTotalNumberOfSubNodes() ) );
      }
      edgeList = tempNode.getToEdges();
      for( int j = 0; j < edgeList.size(); j++ )
      {
        tempEdge = edgeList.get( j );
        tempNode2 = tempEdge.getFrom();
        // tempEdge.setRestingDistance( DNVEdge.DEFAULT_RESTING_DISTANCE
        // + constant * ( tempNode.getTotalNumberOfSubNodes() +
        // tempNode2.getTotalNumberOfSubNodes() ) );
      }
    }
View Full Code Here

   */
  private static Vector2D accumulateEdgeForce( DNVGraph graph, DNVNode dnvNode, Integer level, List<DNVEdge> fromEdges, List<DNVEdge> toEdges,
      Vector2D tempForce, Vector2D source )
  {
    DNVNode tempNeighbor;
    DNVEdge tempEdge;
    for( int i = 0; i < fromEdges.size(); i++ )
    {
      tempEdge = fromEdges.get( i );
      tempNeighbor = tempEdge.getTo();
      tempForce = getSpringForce( tempNeighbor.getPosition(), source, tempEdge.getRestingDistance(), tempEdge.getK() );
      if( tempForce.length() > MIN_SPRING_STRENGTH && tempNeighbor.canRevive() )
        graph.setNodeActive( level, tempNeighbor.getId(), tempNeighbor );
      dnvNode.addForce( tempForce );
    }

    for( int i = 0; i < toEdges.size(); i++ )
    {
      tempEdge = toEdges.get( i );
      tempNeighbor = tempEdge.getFrom();
      tempForce = getSpringForce( tempNeighbor.getPosition(), source, tempEdge.getRestingDistance(), tempEdge.getK() );
      if( tempForce.length() > MIN_SPRING_STRENGTH && tempNeighbor.canRevive() )
        graph.setNodeActive( level, tempNeighbor.getId(), tempNeighbor );
      dnvNode.addForce( tempForce );
    }
    return tempForce;
View Full Code Here

   * @param tempEdge
   *            the temp edge
   */
  private static void createEdge( DNVGraph graph, Integer currentLevel, DNVNode fromNode, DNVNode toNode, DNVEdge tempEdge )
  {
    DNVEdge newEdge;
    newEdge = new DNVEdge( currentLevel + 1, DNVEdge.DEFAULT_RESTING_DISTANCE, false, fromNode, toNode, graph );
    newEdge.setColor( tempEdge.getColor() );
    newEdge.setDirectional( tempEdge.isDirectional() );
    newEdge.setThickness( tempEdge.getThickness() );
    newEdge.setLabel( tempEdge.getLabel() );
    newEdge.setLabelColor( tempEdge.getLabelColor() );
    newEdge.setLabelOutlineColor( tempEdge.getLabelOutlineColor() );
    newEdge.setForceLabel( tempEdge.isForceLabel() );
    toNode.addToEdge( newEdge );
    fromNode.addFromEdge( newEdge );
    graph.addNode( currentLevel + 1, newEdge );
  }
View Full Code Here

    String to;

    DNVGraph graph = new DNVGraph();
    DNVNode fromNode;
    DNVNode toNode;
    DNVEdge edge;

    while( ( line = br.readLine() ) != null )
    {
      if( line.indexOf( "->" ) != -1 )
      {
        from = line.substring( 0, line.indexOf( "->" ) ).trim().replaceAll( "\"", "" );
        to = line.substring( line.indexOf( "->" ) + 2 ).trim().replaceAll( "\"", "" );
        fromNode = (DNVNode)getNode( from, graph );
        toNode = (DNVNode)getNode( to, graph );
        edge = new DNVEdge( graph );
        edge.setFrom( fromNode );
        edge.setTo( toNode );
        edge.setDirectional( true );
        graph.addNode( 0, edge );
      }
    }

    new FruchtermanReingold().runLayout( 100, 100, graph, 0.1f, 0, false, false );
View Full Code Here

          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)){
View Full Code Here

TOP

Related Classes of net.wigis.graph.dnv.DNVEdge

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.