Package net.wigis.graph.dnv

Examples of net.wigis.graph.dnv.DNVNode


          {
            l2x.add( xSortedNodes.get( i ) );
          }
        }

        DNVNode tempNode;
        for( int i = 0; i < ySortedNodes.size(); i++ )
        {
          tempNode = ySortedNodes.get( i );
          if( tempNode.getPosition().getX() <= xSplitPosition )
          {
            l1y.add( tempNode );
          }
          else
          {
            l2y.add( tempNode );
          }
        }
      }
      else
      {
        float ySplitPosition = 0;
        for( int i = 0; i < ySortedNodes.size(); i++ )
        {
          if( i < ySortedNodes.size() / 2 )
          {
            l1y.add( ySortedNodes.get( i ) );
            ySplitPosition = ySortedNodes.get( i ).getPosition().getY();
          }
          else
          {
            l2y.add( ySortedNodes.get( i ) );
          }
        }

        DNVNode tempNode;
        for( int i = 0; i < xSortedNodes.size(); i++ )
        {
          tempNode = xSortedNodes.get( i );
          if( tempNode.getPosition().getY() <= ySplitPosition )
          {
            l1x.add( tempNode );
          }
          else
          {
View Full Code Here


        }
    }

    private void evolveGraph() {
        List<DNVNode> preexistingNodes = mGraph.getNodes(0);
        DNVNode newNode = new DNVNode(mGraph);

        mGraph.addNode(0, newNode);

        // generate and store the new edges; don't add them to the graph
        // yet because we don't want to bias the degree calculations
        // (all new edges in a timestep should be added in parallel)
        HashSet<Pair<DNVNode, DNVNode>> added_pairs = new HashSet<Pair<DNVNode, DNVNode>>(
                mNumEdgesToAttachPerStep * 3);

        for (int i = 0; i < mNumEdgesToAttachPerStep; i++)
            createRandomEdge(preexistingNodes, newNode, added_pairs);

        for (Pair<DNVNode, DNVNode> pair : added_pairs) {
          DNVNode v1 = pair.getFirst();
          DNVNode v2 = pair.getSecond();
            if (!v1.getNeighbors().contains(v2)){
              DNVEdge edge = new DNVEdge(mGraph);
              edge.setFrom(v1);
              edge.setTo(v2);
                mGraph.addEdge(0, edge);
View Full Code Here

   */
  public static HashMap<Integer, Integer> generateHistogram( DNVGraph graph, int level )
  {
    HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>();
    List<DNVNode> nodes = graph.getNodes( level );
    DNVNode tempNode;
    Integer connectivity;
    Integer counter;
    for( int i = 0; i < nodes.size(); i++ )
    {
      tempNode = nodes.get( i );
      connectivity = tempNode.getConnectivity();
      counter = histogram.get( connectivity );
      if( counter == null )
      {
        counter = 0;
      }
View Full Code Here

  private static DNVEntity getNode( String[] line, DNVGraph graph, int index, String currentYear )
  {
    DNVEntity node = graph.getNodeByBbId( line[index].trim() );
    if( node == null )
    {
      node = new DNVNode( graph );
      node.setLabel( line[index].trim() );
      node.setBbId( line[index].trim() );
      ( (DNVNode)node ).setPosition( (float)( Math.random() * 100.0 ), (float)( Math.random() * 100.0 ) );
      node.setProperty( "time", currentYear );
      ( (DNVNode)node ).setRadius( 1 );
View Full Code Here

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

    Map<Integer, DNVNode> allNodes = new HashMap<Integer, DNVNode>( graph.getNodesMap( currentLevel ) );
    DNVNode tempNode;
    DNVNode parentNode;
    while( allNodes.size() > 0 )
    {
      tempNode = allNodes.values().iterator().next();

      allNodes.remove( tempNode.getId() );
      parentNode = createParentNode( tempNode, newLevel, graph, nodeToParent, parentToNodes );

      handleNeighbors( tempNode.getNeighbors(), parentNode, allNodes, nodeToParent );
    }

    // Set connections from parent to sub nodes
    Iterator<Integer> ids = nodeToParent.keySet().iterator();
    Integer tempId;
    List<DNVNode> tempList;
    DNVNode tempNode2;
    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 and set the connections from parent to subnodes
    List<DNVEdge> edgeList;
    ids = parentToNodes.keySet().iterator();
    DNVNode tempParent;
    DNVNode tempParent2;
    DNVEdge tempEdge;
    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 );
            }
          }
        }
View Full Code Here

   *            the node to parent
   */
  private static void handleNeighbors( List<DNVNode> neighbors, DNVNode parentNode, Map<Integer, DNVNode> remainingNodes,
      Map<Integer, DNVNode> nodeToParent )
  {
    DNVNode tempNode;
    for( int i = 0; i < neighbors.size(); i++ )
    {
      tempNode = neighbors.get( i );
      if( remainingNodes.containsKey( tempNode.getId() ) )
      {
        remainingNodes.remove( tempNode.getId() );
        nodeToParent.put( tempNode.getId(), parentNode );
        handleNeighbors( tempNode.getNeighbors(), parentNode, remainingNodes, nodeToParent );
      }
    }
  }
View Full Code Here

   * @return the dNV node
   */
  public static DNVNode createParentNode( DNVNode tempNode, Integer newLevel, DNVGraph graph, Map<Integer, DNVNode> nodeToParent,
      Map<Integer, List<DNVNode>> parentToNodes )
  {
    DNVNode newNode = new DNVNode( new Vector2D( tempNode.getPosition() ), graph );
    newNode.setColor( tempNode.getColor() );
    newNode.setLevel( newLevel.intValue() );
    newNode.setFirstChild( tempNode );
    graph.addNode( newLevel, newNode );
    Vector3D color = new Vector3D( tempNode.getColor() );
    newNode.setColor( color );

    nodeToParent.put( tempNode.getId(), newNode );
    List<DNVNode> tempList = new ArrayList<DNVNode>();
    tempList.add( tempNode );
    parentToNodes.put( newNode.getId(), tempList );

    return newNode;
  }
View Full Code Here

   * @return the dNV node
   */
  public static DNVNode createParentNode( DNVNode tempNode, Integer newLevel, DNVGraph graph, Map<Integer, Integer> nodeDistance,
      Map<Integer, DNVNode> nodeToParent, Map<Integer, List<DNVNode>> parentToNodes )
  {
    DNVNode newNode = new DNVNode( new Vector2D( tempNode.getPosition() ), graph );
    newNode.setColor( tempNode.getColor() );
    newNode.setLevel( newLevel.intValue() );
    newNode.setFirstChild( tempNode );
    graph.addNode( newLevel, newNode );
    if( multicolor && newLevel == 1 )
    {
      Vector3D color = new Vector3D( (float)Math.max( 0.3, Math.random() ), (float)Math.max( 0.3, Math.random() ), (float)Math.max( 0.3, Math
          .random() ) );
      newNode.setColor( color );
    }
    else
    {
      Vector3D color = new Vector3D( tempNode.getColor() );
      newNode.setColor( color );
    }

    nodeDistance.put( tempNode.getId(), Integer.valueOf( 0 ) );
    nodeToParent.put( tempNode.getId(), newNode );
    List<DNVNode> tempList = new ArrayList<DNVNode>();
    tempList.add( tempNode );
    parentToNodes.put( newNode.getId(), tempList );
    return newNode;
  }
View Full Code Here

  private static DNVGraph generateGraph( double[][] input, int n, double[][] output )
  {
    DNVGraph graph = new DNVGraph();
    for( int i = 0; i < n; i++ )
    { // output all coordinates
      DNVNode node = new DNVNode( graph );
      node.setPosition( (float)output[0][i], (float)output[1][i] );
      node.setColor( 0.3f, 0.7f, 1 );
      node.setLabel( "" + i );
      node.setBbId( "" + i );
      graph.addNode( 0, node );
    }
    for( int i = 0; i < input.length; i++ )
    {
      for( int j = 0; j < i; j++ )
      {
        DNVEdge edge = new DNVEdge( graph );
        DNVNode from = (DNVNode)graph.getNodeByBbId( "" + i );
        DNVNode to = (DNVNode)graph.getNodeByBbId( "" + j );
        edge.setFrom( from );
        edge.setTo( to );
        edge.setLabel( "" + Math.round( 100.0 * input[i][j] ) / 100.0 );
        edge.setRestingDistance( (float)input[i][j] );
        edge.setK( 1 );
View Full Code Here

   *            the node to parent
   */
  private static void handleNeighbors( int distance, List<DNVNode> neighbors, DNVNode parentNode, Map<Integer, Integer> nodeDistance,
      Map<Integer, DNVNode> nodeToParent )
  {
    DNVNode tempNode;
    Integer tempDistance;
    for( int i = 0; i < neighbors.size(); i++ )
    {
      tempNode = neighbors.get( i );
      if( multicolor && parentNode.getLevel() == 1 )
        tempNode.setColor( parentNode.getColor() );
      tempDistance = nodeDistance.get( tempNode.getId() );
      if( tempDistance == null || tempDistance > distance )
      {
        nodeDistance.put( tempNode.getId(), Integer.valueOf( distance ) );
        nodeToParent.put( tempNode.getId(), parentNode );
        handleNeighbors( distance + 1, tempNode.getNeighbors(), parentNode, nodeDistance, nodeToParent );
      }
      else
      {
        // System.out.println( "Stopping expansion at node " +
        // tempNode.getId() + " distance " + tempDistance +
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.