Examples of DNVGraph


Examples of net.wigis.graph.dnv.DNVGraph

    compressedGraph.writeGraph(Settings.GRAPHS_PATH + "fb1000_level1.dnv");
    System.out.println("this level contains " + compressedGraph.getGraphSize(0) + " nodes " + compressedGraph.getEdges(0).size() + " edges");
  }
  public static void main(String[] args){
    GraphsPathFilter.init();
    DNVGraph graph = new DNVGraph( Settings.GRAPHS_PATH + "fb1000.dnv" );
    System.out.println("this level contains " + graph.getGraphSize(0) + " nodes " + graph.getEdges(0).size() + " edges");
    cluster(graph, 0);
  }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

    InputStream inp = new FileInputStream("/Users/scarlettteng/Dropbox/terrorisim_study/IrelandNorthernIrelandGB.xlsx");
      //InputStream inp = new FileInputStream("/Users/scarlettteng/Dropbox/terrorisim_study/sample.xlsx");
      Workbook wb = WorkbookFactory.create(inp);
      Sheet sheet = wb.getSheetAt(0);
     
      DNVGraph graph = new DNVGraph();
      HashMap<String, String> countryHash = new HashMap<String,String>();
      HashMap<String, String> attacktypeHash = new HashMap<String,String>();
      HashMap<String, String> targettypeHash = new HashMap<String,String>();
      HashMap<String, String> propertyLossHash = new HashMap<String,String>();
     
      HashSet<String> countrySet = new HashSet<String>();
      String minTime = null;
      String maxTime = null;
      for(int rowCnt = 2; rowCnt < sheet.getPhysicalNumberOfRows(); rowCnt++){
        Row row = sheet.getRow(rowCnt);
        DNVNode node = new DNVNode(graph);
        //time
        Cell timeCell = row.getCell(0);
        timeCell.setCellType(Cell.CELL_TYPE_STRING);
        String timeString = timeCell.getStringCellValue().substring(0, 8);
        node.setProperty("time", timeString);
       
        if(rowCnt == 2){
          minTime = timeString;
          maxTime = timeString;
        }else{
          if(minTime.compareTo(timeString) > 0){
            minTime = timeString;
          }
          if(maxTime.compareTo(timeString) < 0){
            maxTime = timeString;
          }
        }
       
       
        //country
        Cell countryCell = row.getCell(7);
        countryCell.setCellType(Cell.CELL_TYPE_STRING);
        countrySet.add(row.getCell(8).getStringCellValue());
        node.setProperty("country", row.getCell(8).getStringCellValue());
       
        //city
        Cell cityCell = row.getCell(12);
        cityCell.setCellType(Cell.CELL_TYPE_STRING);
        node.setProperty("city", cityCell.getStringCellValue());
        node.setLabel(cityCell.getStringCellValue() + " " + timeString);
        //System.out.println(cityCell.getStringCellValue());
       
        //whether the attack is successful or not
        Cell successCell = row.getCell(24);
        if(successCell.getNumericCellValue() == 1)
          node.setProperty("success","successful");
        else{
          node.setProperty("success","failed");
        }
       
        //attack type, up to three attack types
        Cell attacktype1Cell = row.getCell(26);
        attacktype1Cell.setCellType(Cell.CELL_TYPE_STRING);
        String attacktype1 = attacktype1Cell.getStringCellValue();
        attacktypeHash.put(attacktype1, row.getCell(27).getStringCellValue());
        String attacktype = row.getCell(27).getStringCellValue();//attacktype1;
       
        Cell attacktype2Cell = row.getCell(28);
        if(attacktype2Cell != null){
          attacktype2Cell.setCellType(Cell.CELL_TYPE_STRING);
          attacktype += "\t" + attacktypeHash.get(attacktype2Cell.getStringCellValue());//attacktype2Cell.getStringCellValue();
        }

        Cell attacktype3Cell = row.getCell(30);
        if(attacktype3Cell != null){
          attacktype3Cell.setCellType(Cell.CELL_TYPE_STRING);
          attacktype += "\t" + attacktypeHash.get(attacktype3Cell.getStringCellValue());//attacktype3Cell.getStringCellValue();
        }
        node.setProperty("attacktype", attacktype);
        //System.out.println("attacktype " + attacktype);
       
        //target type, up to three target types
        Cell targettype1Cell = row.getCell(32);
        targettype1Cell.setCellType(Cell.CELL_TYPE_STRING);
        String targettype1 = targettype1Cell.getStringCellValue();
        targettypeHash.put(targettype1, row.getCell(33).getStringCellValue());
        String targettype = row.getCell(33).getStringCellValue();//targettype1;       
       
        Cell targettype2Cell = row.getCell(38);
        if(targettype2Cell != null){
          targettype2Cell.setCellType(Cell.CELL_TYPE_STRING);
          targettype += "\t" + targettypeHash.get(targettype2Cell.getStringCellValue());
        }
       
        Cell targettype3Cell = row.getCell(44);
        if(targettype3Cell != null){
          targettype3Cell.setCellType(Cell.CELL_TYPE_STRING);
          targettype += "\t" + targettypeHash.get(targettype3Cell.getStringCellValue());
        }
        node.setProperty("targettype", targettype);
        //System.out.println("targettype " + targettype);
       
        //number of victims
        int numberVictims = -10;
        Cell numberKilledCell = row.getCell(92);
        if(numberKilledCell != null && numberKilledCell.getNumericCellValue() > 0){
          numberVictims = (int) numberKilledCell.getNumericCellValue();
        }
        Cell numberWoundedCell = row.getCell(95);
        if(numberWoundedCell != null && numberWoundedCell.getNumericCellValue() > 0){
          if(numberVictims < 0)
            numberVictims = (int) numberWoundedCell.getNumericCellValue();
          else
            numberVictims += (int) numberWoundedCell.getNumericCellValue();
        }
        if(numberVictims < 0){
          node.setRadius(3);
          node.setProperty("numberOfVictims", "unknown");
        }else{
          node.setRadius((float) (3 + Math.log10(numberVictims)));
          node.setProperty("numberOfVictims", String.valueOf(numberVictims));
        }//System.out.println("number of victims " + numberVictims);
       
        //property loss
        Cell propertyLoss = row.getCell(99);
        if(propertyLoss != null){
          propertyLoss.setCellType(Cell.CELL_TYPE_STRING);
          node.setProperty("propertyLoss", row.getCell(100).getStringCellValue());
          propertyLossHash.put(propertyLoss.getStringCellValue(), row.getCell(100).getStringCellValue());
          //System.out.println("property loss " + row.getCell(100).getStringCellValue());
        }
        //System.out.println();
        graph.addNode(0, node);
      }
      String countryHashString = "";
      for(String key : countrySet){
        countryHashString += key + "\t";
      }
      System.out.println();
      String attacktypeHashString = "";
      for(String key : attacktypeHash.keySet()){
        attacktypeHashString += attacktypeHash.get(key) + "\t";
      }
      System.out.println();
      String targettypeHashString = "";
      for(String key : targettypeHash.keySet()){
        targettypeHashString += targettypeHash.get(key) + "\t";
      }
      System.out.println();
      String propertyLossHashString = "";
      for(String key : propertyLossHash.keySet()){
        propertyLossHashString += propertyLossHash.get(key) + "\t";
      }
      Random generator = new Random();
    for(DNVNode node : graph.getNodes(0)){
      node.setPosition(generator.nextFloat() * 2 - 1, generator.nextFloat() * 2 - 1);
    }
      String propertyList = "country" + "\t" + "success" + "\t" + "attacktype" + "\t" + "targettype" + "\t" + "propertyLoss";
      graph.setProperty("propertyList", propertyList);
      graph.setProperty("country", countryHashString);
      graph.setProperty("success", "successful"+"\t"+"failed");
      graph.setProperty("attacktype", attacktypeHashString);
      graph.setProperty("targettype", targettypeHashString);
      graph.setProperty("properLoss", propertyLossHashString);
     
      graph.setProperty("minTime", minTime);
      graph.setProperty("maxTime", maxTime);
     
      System.out.println("minTime  " + minTime + "  maxTime  " + maxTime);
      graph.writeGraph("/Users/scarlettteng/dev/graphs/" + "terrorism.dnv");
  }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

   *            the arguments
   */
  public static void main( String args[] )
  {
    GraphsPathFilter.init();
    DNVGraph graph = new DNVGraph( Settings.GRAPHS_PATH + Settings.DEFAULT_GRAPH );
    System.out.println( graph.getNodes( 0 ).size() );
    cluster( graph, 0 );
    System.out.println( graph.getNodes( 0 ).size() );
    System.out.println( graph.getNodes( 1 ).size() );
    graph.writeGraph( Settings.GRAPHS_PATH + Settings.DEFAULT_GRAPH + "_clustered.dnv" );
  }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

    String line;
    String from;
    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 );
    return graph;
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

   * @throws IOException
   *             Signals that an I/O exception has occurred.
   */
  public static void main( String args[] ) throws IOException
  {
    DNVGraph graph = convert( Settings.GRAPHS_PATH + "dep.dot" );
    graph.writeGraph( Settings.GRAPHS_PATH + "dep.dot.dnv" );
  }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

  /**
   *
   */
  private static void generate()
  {
    DNVGraph graph = new DNVGraph();
   
    String nodeColor = "#6666FF";
   
    makeLetter( graph, nodeColor, "W", wPositions );
    makeLetter( graph, nodeColor, "i1", i1Positions );
    makeLetter( graph, nodeColor, "i1_dot", i1_dotPositions );
    makeLetter( graph, nodeColor, "i2", i2Positions );
    makeLetter( graph, nodeColor, "i2_dot", i2_dotPositions );
    makeLetter( graph, nodeColor, "s", sPositions );
    List<DNVNode> nodes = generateSeries( graph, 7, nodeColor, "G" );
    DNVNode node = addNode( graph, nodeColor, "G", nodes );
    addEdge( graph, "G", nodes.get( 5 ), node );
    applyPositions( gPositions, nodes );
   
    graph.writeGraph( Settings.GRAPHS_PATH + "WiGis.dnv" );
  }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

    File file = new File( outputFileName );
    try
    {
      FileWriter fw = new FileWriter( file );
      fw.write( "Filename, Part, Number of Nodes, Number of Edges, Average Time in Milliseconds, Maximum Depth, Number of Iterations\n" );
      DNVGraph graph;
      Vector2D movement = new Vector2D();
      int maxDepth = Integer.MAX_VALUE;
      int level = 0;
      double globalMaxY;
      double globalMinY;
      double globalMaxX;
      double globalMinX;
      DNVNode movedNode;
      int graphSize;
      int tempIndex;
      String tempFileName;
      Timer[] selectionTimers = new Timer[fileNames.length];
      Timer[] movementTimers = new Timer[fileNames.length];
      for( int i = 0; i < fileNames.length; i++ )
      {
        graph = new DNVGraph( fileNames[i] );
        globalMaxY = GraphFunctions.getMaxYPosition( graph, level, false );
        globalMinY = GraphFunctions.getMinYPosition( graph, level, false );
        globalMaxX = GraphFunctions.getMaxXPosition( graph, level, false );
        globalMinX = GraphFunctions.getMinXPosition( graph, level, false );
        if( globalMinY == globalMaxY )
        {
          globalMinY -= 10;
          globalMaxY += 10;
        }
        if( globalMinX == globalMaxX )
        {
          globalMinX -= 10;
          globalMaxX += 10;
        }
        movement.setX( getRandomSign() * (float)( globalMaxX - globalMinX ) / 3.0f );
        movement.setY( getRandomSign() * (float)( globalMaxY - globalMinY ) / 3.0f );
        graphSize = graph.getGraphSize( level );
        System.out.print( "---------------------------------------------------------------------------------------\n" );
        System.out.print( "Results for " + fileNames[i] + "\n" );
        for( int k = 0; k < maxDepths.length; k++ )
        {
          maxDepth = maxDepths[k];
          selectionTimers[i] = new Timer( Timer.NANOSECONDS );
          movementTimers[i] = new Timer( Timer.NANOSECONDS );
          for( int j = 0; j < numberOfIterationsPerGraph; j++ )
          {
            movedNode = graph.getNodes( level ).get( (int)( Math.random() * graphSize ) );

            selectionTimers[i].setStart();
            simulateSelection( movedNode, graph, level, maxDepth );
            selectionTimers[i].setEnd();

            movementTimers[i].setStart();
            simulateMovement( movedNode, graph, movement, level );
            movementTimers[i].setEnd();
          }

          System.out.print( "With maxDepth set as " + maxDepth + ":\n" );
          System.out.print( "Average selection time: " + selectionTimers[i].getAverageTime( Timer.MILLISECONDS ) + " milliseconds.\n" );
          System.out.print( "Average movement time:  " + movementTimers[i].getAverageTime( Timer.MILLISECONDS ) + " milliseconds.\n" );
          System.out.print( "Average total time:     "
              + ( movementTimers[i].getAverageTime( Timer.MILLISECONDS ) + selectionTimers[i].getAverageTime( Timer.MILLISECONDS ) )
              + " milliseconds.\n" );
          System.out.println();
          fw.write( fileNames[i] + ",selection," + graphSize + "," + graph.getEdges( level ).size() + ","
              + selectionTimers[i].getAverageTime( Timer.MILLISECONDS ) + "," + maxDepth + "," + numberOfIterationsPerGraph + "\n" );
          fw.write( fileNames[i] + ",movement," + graphSize + "," + graph.getEdges( level ).size() + ","
              + movementTimers[i].getAverageTime( Timer.MILLISECONDS ) + "," + maxDepth + "," + numberOfIterationsPerGraph + "\n" );
          fw.write( fileNames[i] + ",total," + graphSize + "," + graph.getEdges( level ).size() + ","
              + ( movementTimers[i].getAverageTime( Timer.MILLISECONDS ) + selectionTimers[i].getAverageTime( Timer.MILLISECONDS ) )
              + "," + maxDepth + "," + numberOfIterationsPerGraph + "\n" );
        }
        System.out.print( "---------------------------------------------------------------------------------------\n\n" );

        tempIndex = fileNames[i].lastIndexOf( "." );
        tempFileName = fileNames[i].substring( 0, tempIndex ) + "_interp" + fileNames[i].substring( tempIndex );
        graph.writeGraph( tempFileName );
      }

      fw.close();
    }
    catch( IOException e )
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

   * @param args
   *            the arguments
   */
  public static void main( String args[] )
  {
    DNVGraph graph;
    String graphs[] = { "13-33-07-2.dnv" };

    for( int j = 0; j < graphs.length; j++ )
    {
      graph = new DNVGraph( Settings.GRAPHS_PATH + graphs[j] );
      Iterator<DNVNode> i = graph.getNodeMap( 0 ).values().iterator();
      while( i.hasNext() )
      {
        i.next().setPosition( (float)Math.random(), (float)Math.random() );
      }

      graph.writeGraph( Settings.GRAPHS_PATH + graphs[j] );
    }
  }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

    final int EDGE_ID_OFFSET = 1000000;

    Map<String, DNVNode> nodeIdMap = new HashMap<String, DNVNode>();
    // create a DNV graph to store the citeseer data

    DNVGraph g = new DNVGraph();

    // TODO Auto-generated method stub
    try
    {
      DOMParser parser = new DOMParser();
      parser.parse( filetoparse );
      Document doc = parser.getDocument();

      NodeList nodes = doc.getElementsByTagName( "object" );
      System.out.println( "There are " + nodes.getLength() + "  nodes." );
      NodeList nl = doc.getElementsByTagName( "*" );
      Node n;
      String fromid = "";
      String toid = "";
      int edgeID = EDGE_ID_OFFSET;
      String uuid = "";
      DNVNode dnvnode = null;
      for( int i = 0; i < nl.getLength(); i++ )
      {
        n = nl.item( i );

        if( n.getNodeName().equals( "uuid" ) )
        {
          dnvnode = new DNVNode( g );
          uuid = clean( n.getTextContent() );
          g.addNode( 0, dnvnode );
          nodeIdMap.put( uuid, dnvnode );
        }
        // transformation case
        else if( n.getNodeName().equals( "name" ) )
        {
          System.out.println( n.getNodeName() + " " );
          dnvnode.setLabel( "TRANS: " + clean( n.getTextContent() ) );
          dnvnode.setRadius( 2 );
          dnvnode.setPosition( (float)Math.random(), (float)Math.random() );
          dnvnode.setColor( new Vector3D( 0.1f, 0.5f, 0.9f ) );
          System.out.println( n.getTextContent() + " " );
        }
        // file case
        else if( n.getNodeName().equals( "localId" ) )
        {
          System.out.println( n.getNodeName() + " " );
          dnvnode.setLabel( "FILE: " + clean( n.getTextContent() ) );
          dnvnode.setRadius( 3 );
          dnvnode.setPosition( (float)Math.random(), (float)Math.random() );
          dnvnode.setColor( new Vector3D( 0.0f, 0.9f, 0.1f ) );
          System.out.println( n.getTextContent() + " " );
        }

        else if( n.getNodeName().equals( "from" ) )
        {
          fromid = clean( n.getTextContent() );
        }
        else if( n.getNodeName().equals( "to" ) )
        {
          toid = clean( n.getTextContent() );
          Logger.write( "Fromid is: " + fromid );
          Logger.write( "toid is: " + toid );
          DNVEdge dnvedge = new DNVEdge( 0, 1.0f, false, ( nodeIdMap.get( fromid ) ), nodeIdMap.get( toid ), g );
          dnvedge.setId( edgeID );
          edgeID++;
          g.addNode( 0, dnvedge );
        }

      }

    }
View Full Code Here

Examples of net.wigis.graph.dnv.DNVGraph

    // line
    // --------------------------
    ArrayList<String> currentLineArray;
    String currentLine;
    String currentChunkType;
    DNVGraph dnvGraph = new DNVGraph();
    int fromId;
    int toId;
    DNVNode fromNode;
    DNVNode toNode;
    for( int i = 0; i < allChunks.size(); i++ )
    {
      currentChunk = allChunks.get( i );
      currentChunkType = chunkTypes.get( i );
      currentOffset = offsets.get( i );
      currentColor = chunkColors.get( i );
      currentSize = chunkSizes.get( i );

      for( int j = 0; j < currentChunk.size(); j++ )
      {
        currentLine = currentChunk.get( j );
        currentLineArray = parseLine( currentLine, delim );
        if( currentChunkType.equals( "@NODES" ) )
        {
          DNVNode dnvNode = new DNVNode( new Vector2D( (float)Math.random(), (float)Math.random() ), dnvGraph );
          dnvNode.setLevel( 0 );
          dnvNode.setId( Integer.parseInt( currentLineArray.get( 0 ) ) );
          dnvNode.setLabel( currentLineArray.get( 1 ) );
          dnvNode.setColor( currentColor );
          dnvNode.setRadius( (float)currentSize );
          dnvGraph.addNode( 0, dnvNode );
        }
        else if( currentChunkType.equals( "@EDGES" ) )
        {
          fromId = Integer.parseInt( currentLineArray.get( 0 ) );
          toId = Integer.parseInt( currentLineArray.get( 1 ) );
          DNVEdge dnvEdge = new DNVEdge( dnvGraph );
          dnvEdge.setLevel( 0 );
          dnvEdge.setId( currentOffset + j );
          fromNode = (DNVNode)dnvGraph.getNodeById( fromId );
          toNode = (DNVNode)dnvGraph.getNodeById( toId );
          dnvEdge.setFrom( fromNode );
          dnvEdge.setTo( toNode );
          dnvGraph.addNode( 0, dnvEdge );
        }
      }
    }

    return dnvGraph;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.