Package net.wigis.graph.dnv

Examples of net.wigis.graph.dnv.DNVEdge


            + 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 );
        }
      }

      tempEdge = new DNVEdge( 0, DNVEdge.DEFAULT_RESTING_DISTANCE, false, tempNode, tempNode2, graph );
      graph.addNode( 0, tempEdge );
      if( ( i + 1 ) % 10000 == 0 )
      {
        timer.setEnd();
        System.out.println( "edge " + ( i + 1 ) + " - Total time: " + timer.getTotalTime( Timer.SECONDS ) + " seconds. Last segment: "
View Full Code Here


      graph.addNode( 0, tempNode );
    }

    int degreeBy2 = meanDegree / 2;
    DNVNode tempNode2;
    DNVEdge tempEdge;
    int edgeId = numberOfNodes;
    HashMap<String, DNVEdge> edgeMap = new HashMap<String, DNVEdge>();
    System.out.println( "Generating nodes and edges..." );
    for( int i = 0; i < numberOfNodes; i++ )
    {
      if( i % 10000 == 0 )
      {
        System.out.println( 1 + " : " + i );
      }
      tempNode = (DNVNode)graph.getNodeById( i );
      for( int j = i - degreeBy2; j <= i + degreeBy2; j++ )
      {
        int index = j % numberOfNodes;
        if( index < 0 )
        {
          index += numberOfNodes;
        }
        if( index != i )
        {
          tempNode2 = (DNVNode)graph.getNodeById( index );
          tempEdge = edgeMap.get( i + "_" + index );
          if( tempEdge == null )
          {
            tempEdge = edgeMap.get( index + "_" + i );
            if( tempEdge == null )
            {
              tempEdge = new DNVEdge( tempNode, tempNode2, graph );
              tempEdge.setId( edgeId++ );
              graph.addNode( 0, tempEdge );
              edgeMap.put( i + "_" + index, tempEdge );
              edgeMap.put( index + "_" + i, tempEdge );
            }
          }
        }
      }
    }

    System.out.println( "Rewiring edges..." );
    for( int i = 0; i < numberOfNodes; i++ )
    {
      if( i % 10000 == 0 )
      {
        System.out.println( 2 + " : " + i );
      }
      tempNode = (DNVNode)graph.getNodeById( i );
      for( int j = i + 1; j < numberOfNodes; j++ )
      {
        if( Math.random() < rewireProbability )
        {
          tempEdge = edgeMap.remove( i + "_" + j );
          edgeMap.remove( j + "_" + i );
          if( tempEdge != null )
          {
            graph.removeNode( 0, tempEdge );
            int index = (int)( Math.random() * numberOfNodes );
            while( index == i )
              index = (int)( Math.random() * numberOfNodes );
            tempNode2 = (DNVNode)graph.getNodeById( index );
            tempEdge = new DNVEdge( tempNode, tempNode2, graph );
            tempEdge.setId( edgeId++ );
            graph.addNode( 0, tempEdge );
          }
        }
      }
    }
View Full Code Here

  private static double addEdge( DNVNode nFrom, DNVNode nTo, DNVGraph graph, double totalConnectivity,
      Map<Integer, List<DNVNode>> nodesByConnectivity )
  {
    removeNodeFromConnectivityMap( nodesByConnectivity, nFrom );
    removeNodeFromConnectivityMap( nodesByConnectivity, nTo );
    DNVEdge e = new DNVEdge( nFrom, nTo, graph );
    e.setLevel( 0 );
    e.setRestingDistance( (float)Math.random() * 10.0f );
    graph.addNode( 0, e );

    addNodeToConnectivityMap( nodesByConnectivity, nFrom );
    addNodeToConnectivityMap( nodesByConnectivity, nTo );

View Full Code Here

    String to;

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

    while( ( line = br.readLine() ) != null )
    {
      from = line.substring( 0, line.indexOf( "\t" ) ).trim();
      to = line.substring( line.indexOf( "\t" ) + 2 ).trim();
      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 );
    return graph;
View Full Code Here

        {
          DNVNode fromNode = (DNVNode)graph.getNodeByBbId( edge.getFrom().getLabel() );
          DNVNode toNode = (DNVNode)graph.getNodeByBbId( edge.getTo().getLabel() );
          if( fromNode != null && toNode != null )
          {
            DNVEdge newEdge = new DNVEdge( fromNode, toNode, graph );
            newEdge.setBbId( fromNode.getLabel() + "->" + toNode.getLabel() );
            newEdge.setType( "likes" );
            graph.addEntity( 0, newEdge );
          }
        }
      }
     
      if( generateFriendEdges )
      {
        DNVNode tempUserNode = (DNVNode)tempGraph.getNodesByType( 0, "user" ).get( 0 );
        if( tempUserNode != null )
        {
          DNVNode userNode = (DNVNode)graph.getNodeByBbId( tempUserNode.getLabel() );
          Map<Integer,DNVEntity> friends = tempGraph.getNodesByType( 0, "friend" );
          for( DNVEntity friend : friends.values() )
          {
            DNVNode friendNode = (DNVNode)graph.getNodeByBbId( friend.getLabel() );
            DNVEdge newEdge = new DNVEdge( userNode, friendNode, graph );
            newEdge.setBbId( userNode.getLabel() + "->" + friendNode.getLabel() );
            newEdge.setType( "friendEdge" );
            graph.addEntity( 0, newEdge );
          }
        }
      }
    }
View Full Code Here

    file = new File( path, co_occurenceFile );
    fr = new FileReader( file );
    csv = new CSVReader( fr );
    DNVNode node1;
    DNVNode node2;
    DNVEdge edge;
    long time;
    while( (line=csv.readNext()) != null )
    {
      if( !line[0].equals( "" ) )
      {
        node1 = (DNVNode)graph.getNodeByBbId( line[0] );
        node2 = (DNVNode)graph.getNodeByBbId( line[1] );
        if( !node1.getNeighborMap().containsKey( node2.getId() ) )
        {
          edge = new DNVEdge( node1, node2, graph );
          edge.setBbId( node1.getBbId() + "->" + node2.getBbId() );
          time = convertTimeStampToLong( line[3] );
          if( time != -1 )
          {
            edge.setProperty( "time", "" + time );
          }
         
          graph.addEntity( 0, edge );
        }
      }
View Full Code Here

   */
  public static DNVEdge getEdgeToNodeOfType( DNVGraph graph, DNVNode node, String type )
  {
    Iterator<DNVEdge> edges;
    DNVNode neighbor;
    DNVEdge edge;
    try
    {
      edges = node.getFromEdges().iterator();
      while( edges.hasNext() )
      {
        edge = edges.next();
        neighbor = edge.getTo();
        if( neighbor.getType().equals( type ) )
        {
          return edge;
        }
      }
    }
    catch( NullPointerException npe )
    {}

    try
    {
      edges = node.getToEdges().iterator();
      while( edges.hasNext() )
      {
        edge = edges.next();
        neighbor = edge.getFrom();
        if( neighbor.getType().equals( type ) )
        {
          return edge;
        }
      }
View Full Code Here

      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);       
      }

      for(DNVNode n : nodes){
        if(n.getProperty("dktime") == null){
View Full Code Here

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

   *             Signals that an I/O exception has occurred.
   */
  private static void writeEdges( FileWriter fw, DNVGraph graph ) throws IOException
  {
    Iterator<DNVEdge> edges = graph.getEdges( 0 ).iterator();
    DNVEdge tempEdge;
    while( edges.hasNext() )
    {
      counter++;
      tempEdge = edges.next();
      tempEdge.setId( counter );
      fw.write( "            <edge id=\"" + counter + "\" source=\"" + tempEdge.getFrom().getId() + "\" target=\"" + tempEdge.getTo().getId()
          + "\">\n" );
      fw.write( "              <attributes>\n" );
      fw.write( "                <attribute index=\"1\" name=\"Thickness\" type=\"Integer\" value=\"1\"/>\n" );
      fw.write( "                <attribute index=\"2\" name=\"Edge_Style\" type=\"Integer\" value=\"0\"/>\n" );
      fw.write( "              </attributes>\n" );
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.