public void addSomeLinks(int num) {
   for (int i = 0; i < num; i++) {
     int randomSource = random.nextInt(idCounter);
     int randomSink = random.nextInt(idCounter);
     while (randomSink == randomSource) {
       randomSink = random.nextInt(idCounter);
     }
     Node source = ns.getNode(randomSource);
     Node sink = ns.getNode(randomSink);
     int randomCategory = random.nextInt(linkCategoryPool.size());
     PamNode lcn = (PamNode) linkCategoryPool.get(randomCategory);
     lcn.setId(categoryIdCounter++);
     ns.addDefaultLink(source, sink, lcn, 1.0, -1.0);
   }
 }
 public void addSomeNodes(int num) {
   for (int i = 0; i < num; i++) {
     Node foo = factory.getNode();
     foo.setId(idCounter++);
     ns.addDefaultNode(foo);
   }
 }
  public void test1() {
    int seed = 23434535;
    random = new Random(seed);
    ns = new NodeStructureImpl();

    int nodes = 10000;
    int linkCategories = 1000;
    double nodeLinkRatio = 5.0;

    int links = (int) (nodes / nodeLinkRatio);
    System.out.println("Creating NS with " + nodes + " nodes, " + links + " links");

    createLinkCategoryPool(linkCategories);
    addSomeNodes(nodes);
    addSomeLinks(links);
    System.out.println("Copying NS\n");

    long start = System.currentTimeMillis();
    ns.copy();
    long finish = System.currentTimeMillis();
    System.out.println("time: " + (finish - start) + " ms");
    System.out.println("ms per linkable : " + (finish - start) / (1.0 * ns.getLinkableCount()));
    System.out.println("total linkables " + ns.getLinkableCount());
  }
Пример #4
0
  public static void printType(NodeType type) {
    if (type instanceof NodeSynonym) {
      System.out.println("NodeSynonym: " + ((NodeSynonym) type).getID());
    } // System.out.println("NodeSynonym: " + ((NodeSynonym)type).getType());
    else if (type instanceof NodePLType) {
      System.out.println("PLType: " + ((NodePLType) type).getType());
    } else if (type instanceof NodePointer) {
      System.out.println("Puntero a");
      System.out.print("  ");
      printType(((NodePointer) type).getType());
    } else if (type instanceof NodeArray) {
      System.out.print("Arreglo de tamaño " + ((NodeArray) type).getSize() + " de tipo: ");
      printType(((NodeArray) type).getType());
    } else if (type instanceof NodeStructure) {
      NodeStructure structure = (NodeStructure) type;
      // List<NodeElement>	elements =	record.getElements(); CHANGE
      List<NodeElement> elements = structure.getElements();
      Iterator<NodeElement> iter = elements.iterator();

      // System.out.println("Estructura: " + "Nombre: " + record.getName()); CHANGE
      System.out.println("Estructura: " + "Nombre: " + structure.getName());

      int i = 1;
      NodeElement element;

      while (iter.hasNext()) {
        element = iter.next();

        System.out.println("Campo " + i + ": ");
        i++;

        // System.out.println("Nombre: " + (element.getName())); CHANGE
        System.out.println("Nombre: " + (element.getID()));
        System.out.print("Tipo: ");
        printType(element.getType());
      }
    } else if (type instanceof NodeList) {
      NodeList list = (NodeList) type;
      // List<NodeField>		fields	=	list.getFields(); CHANGE
      List<NodeElement> fields = list.getFields();
      // Iterator<NodeField> iter	= fields.iterator(); CHANGE
      Iterator<NodeElement> iter = fields.iterator();

      System.out.println("Lista");
      System.out.println("Nombre: " + list.getName());
      System.out.println("LinkType: " + list.getLinkType());
      System.out.println("LinkNexName: " + list.getLinkNextName());

      if (list.getLinkPrevName() != null) {
        System.out.println("LinkPrevName: " + list.getLinkPrevName());
      }

      int i = 1;

      NodeElement field;
      while (iter.hasNext()) {
        field = iter.next();
        System.out.println("Campo " + i + ":");
        i++;
        // System.out.println("Nombre: " + (field.getName())); CHANGE
        System.out.println("Nombre: " + (field.getID()));
        System.out.print("Tipo: ");
        printType(field.getType());
      }
      // if (list.getMemalloc() != null ) CHANGE
      if (list.getMemAlloc() != null) {
        System.out.println("MemallocFunction: ");
        // System.out.println(list.getMemalloc()); CHANGE
        System.out.println(list.getMemAlloc());
      }
    } else if (type instanceof NodeFile) {
      NodeFile file = (NodeFile) type;

      System.out.println("Archivo");
      System.out.println("Nombre: " + file.getName());
      System.out.println("Ruta: " + file.getPath());
      System.out.println("Delimitador: " + file.getDelimiter());

      if (file.getEof() != null) {
        System.out.println("EOF: " + file.getEof());
      }
      if (file.getEol() != null) {
        System.out.println("EOL: " + file.getEol());
      }
      if (file.getStructure() != null) {
        System.out.println("Estructura: " + file.getStructure());
      }
    } else if (type instanceof NodeDB) {
      NodeDB db = (NodeDB) type;
      List<NodeDBColumn> regs = db.getColumns();
      Iterator<NodeDBColumn> iter = regs.iterator();

      System.out.println("Base de Datos");
      System.out.println("DBMS: " + db.getDBMSID());
      // System.out.println("connectionID "		+ db.getConnID()); CHANGE
      System.out.println("connectionID " + db.getConnectionID());

      // System.out.println("Table name: "		+ db.getTable()); CHANGE
      System.out.println("Table name: " + db.getTableName());
      System.out.println("Registros:");

      int i = 1;

      while (iter.hasNext()) {
        NodeDBColumn rec = iter.next();
        System.out.println(
            "Registro " + i + ": " + rec.getColType() + " tipo: " + rec.getColType());
        i++;
      }
    }
  }