Package net.wigis.graph.dnv

Examples of net.wigis.graph.dnv.DNVNode


      HashSet<DNVNode> nodes = new HashSet<DNVNode>();
      HashSet<DNVEdge> edges = new HashSet<DNVEdge>();

      ArrayList<Tuple<Integer, Integer, DNVEdge>> nodeEdgeIndex = degreeNodeEdgeIndexTableDK2.get(key);
      for(Tuple<Integer, Integer, DNVEdge> tuple : nodeEdgeIndex){
        DNVNode node1 = mGraph.getNode(level, tuple.getLeft());
        nodes.add(node1);
        DNVNode node2 = mGraph.getNode(level, tuple.getMiddle());
        nodes.add(node2);
        DNVEdge edge = tuple.getRight();
        edges.add(edge);       
      }
View Full Code Here


        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;
              Tuple<Integer, Integer, Integer> degreeTuple;
              //for each node tuple, the left node degree should be no smaller than the right one
              if(degree1 >= degree2){
                leftNodeId = neighbors.get(i).getId();
                rightNodeId = neighbors.get(j).getId();
                degreeTuple = new Tuple<Integer, Integer, Integer>(degree1, highDegree,degree2);
              }else{
                leftNodeId = neighbors.get(j).getId();
                rightNodeId = neighbors.get(i).getId();
                degreeTuple = new Tuple<Integer, Integer, Integer>(degree2, highDegree,degree1);
              }
             
              if(!degreeEdgeTableDK3.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>(middlenode.getEdgeToNeighbor(leftNodeId),middlenode.getEdgeToNeighbor(rightNodeId)));
              degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);
             
              degreeUniqueEdgeTableDK3.get(degreeTuple).add(middlenode.getEdgeToNeighbor(leftNodeId));
              degreeUniqueEdgeTableDK3.get(degreeTuple).add(middlenode.getEdgeToNeighbor(rightNodeId));
              degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
              degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbors.get(i));
              degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbors.get(j));
              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);
       
        //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();
          //if(neighborDegree <= highDegree){
          Tuple<Integer, Integer, Integer> degreeTuple = new Tuple<Integer, Integer, Integer>(highDegree, lowDegree, neighborDegree);
          if(!degreeEdgeTableDK3.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(tuple.getRight());
          degreeUniqueEdgeTableDK3.get(degreeTuple).add(middlenode.getEdgeToNeighbor(neighborId));
          degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
          degreeUniqueNodeTableDK3.get(degreeTuple).add(graph.getNode(level, highDegreeNodeId));
          degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbor);
          cnt++;
        }
View Full Code Here

      query = "SELECT * FROM nodes WHERE idGraphs = " + idGraphs + ";";
      results = dbm.getResults( query );
      results.last();
      System.out.println( "Processing " + results.getRow() + " nodes" );
      results.beforeFirst();
      DNVNode newNode;
      Vector2D position;
      float r, g = 0, b = 0;
      r = graphName.charAt( 0 ) / 120.0f;

      if( graphName.length() > 1 )
        g = graphName.charAt( graphName.length() / 2 ) / 150.0f;
      if( graphName.length() > 2 )
        b = graphName.charAt( graphName.length() - 1 ) / 100.0f;
      while( results.next() )
      {
        position = new Vector2D( 100.0f * (float)Math.random(), 100.0f * (float)Math.random() );
        // position = new Vector2D( results.getFloat( "xPos" ),
        // results.getFloat( "yPos" ) );
        newNode = new DNVNode( position, graph );
        newNode.setColor( r, g, b );
        newNode.setPosition( position );
        newNode.setRadius( results.getFloat( "radius" ) );
        newNode.setMass( results.getFloat( "mass" ) );
        newNode.setLevel( 0 );
        newNode.setId( results.getInt( "idNodes" ) );
        graph.addNode( 0, newNode );
      }

      query = "SELECT * FROM edges WHERE idGraphs = " + idGraphs + ";";
      System.out.println( query );
      results = dbm.getResults( query );
      results.last();
      System.out.println( "Processing " + results.getRow() + " edges" );
      results.beforeFirst();
      DNVEdge newEdge;
      DNVNode fromNode;
      DNVNode toNode;
      while( results.next() )
      {
        fromNode = (DNVNode)graph.getNodeById( results.getInt( "fromNodeId" ) );
        toNode = (DNVNode)graph.getNodeById( results.getInt( "toNodeId" ) );
        newEdge = new DNVEdge( 0, DNVEdge.DEFAULT_RESTING_DISTANCE, false, fromNode, toNode, graph );
        if( fromNode != null && toNode != null )
        {
          fromNode.addFromEdge( newEdge );
          toNode.addToEdge( newEdge );
          graph.addNode( 0, newEdge );
        }
        else
          System.out.println( "Error with a node for edge " + results.getInt( "fromNodeId" ) + "->" + results.getInt( "toNodeId" ) );

View Full Code Here

   *             Signals that an I/O exception has occurred.
   */
  private static void writeNodes( FileWriter fw, DNVGraph graph ) throws IOException
  {
    Iterator<DNVNode> nodes = graph.getNodes( 0 ).iterator();
    DNVNode tempNode;
    while( nodes.hasNext() )
    {
      counter++;
      tempNode = nodes.next();
      tempNode.setId( counter );
      fw.write( "            <node id=\"" + counter + "\">\n" );
      fw.write( "              <attributes>\n" );
      fw.write( "                <attribute index=\"2\" name=\"Background_Color\" type=\"Color\" value=\""
          + Math.round( 255 * tempNode.getColor().getX() ) + " " + Math.round( 255 * tempNode.getColor().getY() ) + " "
          + Math.round( 255 * tempNode.getColor().getZ() ) + "\"/>\n" );
      fw.write( "              </attributes>\n" );
      fw.write( "              <center x=\"" + ( tempNode.getPosition().getX() * 800.0 ) + "\" y=\"" + ( tempNode.getPosition().getY() * 800.0 )
          + "\"/>\n" );
      fw.write( "            </node>\n" );
    }
  }
View Full Code Here

    // --------------------------
    // generate a dnvgraph object
    // --------------------------

    DNVGraph dnvGraph = new DNVGraph();
    DNVNode fromNode;
    DNVNode toNode;
    // int id = 0;
    int edge_id = OFFSET_DIFFERENCE;
    try
    {
      line = br.readLine();
      while( line != null )
      {
        edge_id += OFFSET_DIFFERENCE;
        String[] a = line.split( "[\\s,',']+" );

        // check type- we accept int or hex ids
        int fromId = 0;
        int toId = 0;
        if( a[0].trim().length() == 32 )
        { // check for a 32 bit string
          fromId = Math.abs( hex2decimal( a[0] ) );
          toId = Math.abs( hex2decimal( a[1] ) );
        }
        else
        {
          fromId = Math.abs( Integer.parseInt( a[0] ) );
          toId = Math.abs( Integer.parseInt( a[1] ) );
        }
        // check if the node already exists in the graph
        fromNode = (DNVNode)dnvGraph.getNodeById( fromId );
        if( fromNode == null )
        {
          fromNode = new DNVNode( new Vector2D( (float)Math.random(), (float)Math.random() ), dnvGraph );
          fromNode.setLevel( 0 );
          fromNode.setId( new Integer( fromId ) );
          fromNode.setLabel( "" + fromId );
          dnvGraph.addNode( 0, fromNode );
        }
        toNode = (DNVNode)dnvGraph.getNodeById( toId );
        if( toNode == null )
        {
          toNode = new DNVNode( new Vector2D( (float)Math.random(), (float)Math.random() ), dnvGraph );
          toNode.setLevel( 0 );
          toNode.setId( new Integer( toId ) );
          toNode.setLabel( "" + toId );
          dnvGraph.addNode( 0, toNode );
        }

        DNVEdge dnvEdge = new DNVEdge( dnvGraph );
        dnvEdge.setFrom( fromNode );
View Full Code Here

    }
    String color = "#22AAFF";
    for( String edgeStr : edgesToCreate )
    {
      String nodes[] = edgeStr.split( "->" );
      DNVNode node1 = (DNVNode)graph.getNodeByBbId( nodes[0] );
      if( node1 == null )
      {
        node1 = new DNVNode( graph );
        node1.setLabel( nodes[0] );
        node1.setBbId( nodes[0] );
        node1.setColor( color );
        node1.setProperty( "time", "" + time );
        graph.addNode( level, node1 );
      }
      DNVNode node2 = (DNVNode)graph.getNodeByBbId( nodes[1] );
      if( node2 == null )
      {
        node2 = new DNVNode( graph );
        node2.setLabel( nodes[1] );
        node2.setBbId( nodes[1] );
        node2.setColor( color );
        node2.setProperty( "time", "" + time );
        graph.addNode( level, node2 );
      }

      DNVEdge edge = new DNVEdge( graph );
      edge.setFrom( node1 );
View Full Code Here

    List<DNVNode> parents = new ArrayList<DNVNode>();
    Map<Integer, Map<Integer, DNVNode>> parentToPlanetsOrMoons = new HashMap<Integer, Map<Integer, DNVNode>>();
    Map<Integer, DNVNode> subNodeToParent = new HashMap<Integer, DNVNode>();
    List<DNVNode> planets;
    List<DNVNode> moons;
    DNVNode sun;
    DNVNode planet;
    Map<Integer, DNVNode> tempMap;
    DNVNode parent;

    // Find the suns and their solar systems
    while( nodes.size() > 0 )
    {
      sun = nodes.remove( (int)( Math.random() * nodes.size() ) );
      parent = createParentNode( sun, newLevel, graph );
      tempMap = parentToPlanetsOrMoons.get( parent.getId() );
      if( tempMap == null )
      {
        tempMap = new HashMap<Integer, DNVNode>();
        parentToPlanetsOrMoons.put( parent.getId(), tempMap );
      }

      parents.add( parent );

      planets = sun.getNeighbors();
      addAllNodesToMap( planets, tempMap );
      setLinkToParent( planets, parent, subNodeToParent );
      nodes.removeAll( planets );
      for( int i = 0; i < planets.size(); i++ )
      {
        planet = planets.get( i );
        moons = planet.getNeighbors();
        addAllNodesToMap( moons, tempMap );
        setLinkToParent( moons, parent, subNodeToParent );
        nodes.removeAll( moons );
      }
    }

    // Assign parent nodes with sub nodes
    List<DNVNode> subNodes;
    for( int i = 0; i < parents.size(); i++ )
    {
      parent = parents.get( i );
      tempMap = parentToPlanetsOrMoons.get( parent.getId() );
      subNodes = new ArrayList<DNVNode>( tempMap.values() );
      parent.setSubNodes( subNodes );
    }

    // Create the edges
    Iterator<DNVNode> iterator;
    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

   * @param map
   *            the map
   */
  public static void addAllNodesToMap( List<DNVNode> nodes, Map<Integer, DNVNode> map )
  {
    DNVNode tempNode;
    for( int i = 0; i < nodes.size(); i++ )
    {
      tempNode = nodes.get( i );
      map.put( tempNode.getId(), tempNode );
    }
  }
View Full Code Here

   *            the graph
   * @return the dNV node
   */
  public static DNVNode createParentNode( DNVNode child, Integer newLevel, DNVGraph graph )
  {
    DNVNode parent = new DNVNode( new Vector2D( child.getPosition() ), graph );
    parent.setColor( child.getColor() );
    parent.setLevel( newLevel.intValue() );
    parent.setFirstChild( child );
    child.setParentNode( parent );
    graph.addNode( newLevel, parent );

    return parent;
  }
View Full Code Here

    DNVGraph graph = new DNVGraph();
    List<DNVNode> unconnectedNodes = new ArrayList<DNVNode>( 1000000 );

    Timer timer = new Timer( Timer.MILLISECONDS );
    DNVNode tempNode;
    Vector3D color = new Vector3D( 1, 0, 1 );
    timer.setStart();
    for( int i = 0; i < numberOfVertices; i++ )
    {
      tempNode = new DNVNode( new Vector2D( (float)Math.random(), (float)Math.random() ), graph );
      tempNode.setColor( color );
      unconnectedNodes.add( tempNode );
      graph.addNode( 0, tempNode );
      if( ( i + 1 ) % 10000 == 0 )
      {
        timer.setEnd();
        System.out.println( "node " + ( i + 1 ) + " - Total time: " + timer.getTotalTime( Timer.SECONDS ) + " seconds. Last segment: "
            + timer.getLastSegment( Timer.SECONDS ) + " seconds." );
        timer.setStart();
      }
    }

    DNVEdge tempEdge;
    DNVNode tempNode2;
    int tempIndex;
    for( int i = 0; i < numberOfEdges; i++ )
    {
      tempIndex = (int)( Math.random() * graph.getGraphSize( 0 ) );
      tempNode = graph.getNodes( 0 ).get( tempIndex );
      if( unconnectedNodes.size() > 0 )
      {
        tempIndex = (int)( Math.random() * unconnectedNodes.size() );
        tempNode2 = unconnectedNodes.get( tempIndex );
        while( tempNode2.equals( tempNode ) )
        {
          tempIndex = (int)( Math.random() * unconnectedNodes.size() );
          tempNode2 = unconnectedNodes.get( tempIndex );
        }
        unconnectedNodes.remove( tempIndex );
      }
      else
      {
        tempIndex = (int)( Math.random() * graph.getGraphSize( 0 ) );
        tempNode2 = graph.getNodes( 0 ).get( tempIndex );
        while( tempNode2.equals( tempNode ) )
        {
          tempIndex = (int)( Math.random() * unconnectedNodes.size() );
          tempNode2 = graph.getNodes( 0 ).get( tempIndex );
        }
      }
View Full Code Here

TOP

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

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.