Package primitives.cluster

Examples of primitives.cluster.ClusterHead


        if (a_subject.size() == 0) {
            return 0.0;
        }
        GeneType type = (GeneType) a_subject.getApplicationData();

        ClusterHead ch = TreeTranslator.getTree(a_subject, tree);

        double fitness;

        if (type == GeneType.STACK) {
            ArrayList<StackInstructionGene> prog = new ArrayList<StackInstructionGene>();
View Full Code Here



        StackInterpreter interp = new StackInterpreter(p, tree.deepCopy());


        ClusterHead evaluated = interp.run();
        double fitness = evaluate(evaluated);
        if (punishesWastage()) {
            fitness = scaleWastage(fitness, interp.getWastage());
        }
View Full Code Here

                    }
                }
            }
        }

        ClusterHead ch = new ClusterHead();
        Map<Integer, ClusterNode> parents = new HashMap<Integer, ClusterNode>();
        Set<Node> nodes = originalTree.getNodes();
        for (int i = 0; i < assignments.size(); i++) {
            int parentNumber = assignments.get(i).intValue();
            Node cur = nodenumbers.get(i + 1);



            if (cur == null) {
                throw new RuntimeException(String.format("ERROR: Missing node %d, known nodes: %s", i, nodenumbers.keySet()));
            }
            ClusterNode parent = parents.get(parentNumber);
            if (parent == null) {
                parent = new ClusterNode();
                parent.setID(parentNumber);
                ch.addChild(parent);
                parents.put(parentNumber, parent);
            }
            parent.addNode(cur);
            nodes.remove(cur);
View Full Code Here

                    }
                }
            }
        }
       
        ClusterHead newTree = new ClusterHead();
        Map<Integer,ClusterNode> treenodes = new HashMap<Integer,ClusterNode>();
        treenodes.put(0,newTree);
               
        //allocate each node to its parent:
        for(int i = 0; i<originalTree.getNodes().size(); i++){
            int parent = assignments.get(i);
            ClusterNode parentNode = treenodes.get(parent);
            if(parentNode == null){
                parentNode = new ClusterNode();
                treenodes.put(parent, parentNode);
            }
            parentNode.addNode(nodenumbers.get(i+1));
           
        }
        //state is now that there are loads of clusters with the children they need.
        //build the tree:
        int treeSize = originalTree.getNodes().size();
        for(int i = 0; i<assignments.size() - treeSize; i++){
            int parent = assignments.get(i + treeSize); //pull parent id for child i from the array.
            if(parent == i+1){
                //Logger.getLogger(TreeTranslator.class.getName()).log(Level.INFO, "Attempted to make a child a parent of itself {0} from {1}",new Object[]{parent,i});
                parent = 0;
            }
            ClusterNode parentNode = treenodes.get(parent); //parent is whatever that value was
            if(parentNode == null){
                //add intermediate parent that didn't have any nodes in it:
                parentNode = new ClusterNode();
                treenodes.put(parent,parentNode);
            }
            ClusterNode childNode = treenodes.get(i + 1); //i starts 0..n-1, they're numbered 1..n (0 is always reserved for the child).
            if(childNode == null){
                childNode = new ClusterNode();
                treenodes.put(i+1, childNode);
            }
            parentNode.addChild(childNode);
            if(ClusterUtils.isCyclic(parentNode)){
                parentNode.deleteChild(childNode);
                //Logger.getLogger(TreeTranslator.class.getName()).log(Level.INFO, "{0} was cyclic so the child {1} was removed", new Object[]{parentNode, childNode});
               
            }
        }
       
        Set<ClusterNode> orphans = new HashSet<ClusterNode>();
       

        for(ClusterNode n : treenodes.values()){
            if(n != newTree && ClusterUtils.findParent(n, newTree) == null){
                orphans.add(n);
            }
        }

       
        for (Iterator<ClusterNode> it = orphans.iterator(); it.hasNext();) {
            ClusterNode clusterNode = it.next();
           
            boolean remove = false;
            for(ClusterNode cn : orphans){
                if(cn != clusterNode && ClusterUtils.findParent(clusterNode, cn) != null){
                    //if the current clusterNode can be found in any of the "trees" of the orphans
                    //then it isn't an orphan proper, just an orphan of the main ClusterHead - we can
                    //fix this problem by adopting its parent, so we remove it from our fixups.
                    remove = true;
                    break;
                }
            }
            if(removeit.remove();
        }
       

        //orphans should now contain all clusters that need to be adopted:
        for(ClusterNode cn : orphans){
            if(ClusterUtils.isCyclic(cn)){
                throw new RuntimeException("A cyclic orphan was detected.");  
            }
            newTree.addChild(cn);
        }
        if(ClusterUtils.isCyclic(newTree)){
            Logger.getLogger(TreeTranslator.class.getName()).log(Level.WARNING, "Cyclic tree detected!");
            throw new RuntimeException("There was a cyclic tree so I stopped.");
        }
        //ClusterUtils.prettyPrintTree(newTree);
        Set<Node> oNodes = originalTree.getNodes();
        Set<Node> tNodes = newTree.getNodes();
       
       
        if(!oNodes.containsAll(tNodes) || !tNodes.containsAll(oNodes)){
            Logger.getLogger(TreeTranslator.class.getName()).log(Level.INFO, "Converting a HCLUST: not all nodes were copied, Have {0} nodes but needed {1}.", new Object[]{tNodes.size(), oNodes.size()});
            oNodes.removeAll(tNodes);
View Full Code Here

    g.addNode(outsideOut);
   
    leaf1 = new ClusterLeaf();
    leaf2 = new ClusterLeaf();
    leaf3 = new ClusterLeaf();
    head = new ClusterHead(g);
    body = new ClusterNode();
   
    leaf1.addNode(b);

    leaf2.addNode(a);
View Full Code Here

    g.addNode(b);
    g.addNode(c);
    g.addNode(d);
    g.addNode(e);
    g.addNode(f);
    tree = new ClusterHead(g);
  }
View Full Code Here

    g.addNode(b);
    g.addNode(c);
    g.addNode(d);
    g.addNode(e);
    g.addNode(f);
    ch = new ClusterHead(g);
    IClusterLevel c1, c2;
    try {
      // c1 = ClusterUtils.lookup(ch, 0);
      // c2 = ClusterUtils.lookup(ch, 1);
      // ClusterUtils.merge(ch, c1, c2);
View Full Code Here

    g = new Graph();

    g.addNode(a);
    g.addNode(b);

    n = new ClusterHead(g);

  }
View Full Code Here

    };


    StackInterpreter instance = new StackInterpreter(Arrays.asList(l), n);
    System.out.println("execute");
    ClusterHead r = instance.run();
    // TODO review the generated test code and remove the default call to fail.
    ClusterUtils.prettyPrintTree(r);
   
    assertTrue(r.contains(a));
    assertTrue(r.contains(b));
   
    assertTrue(ClusterUtils.validTree(r, g));
   
    assertEquals(r.getChildren().size(), 1);
   
   
   
  }
View Full Code Here

    };


    StackInterpreter instance = new StackInterpreter(Arrays.asList(l), n);
    System.out.println("execute");
    ClusterHead r = instance.run();
    // TODO review the generated test code and remove the default call to fail.
    ClusterUtils.prettyPrintTree(r);
   
    assertTrue(r.contains(a));
    assertTrue(r.contains(b));
   
    assertTrue(ClusterUtils.validTree(r, g));
   
    assertEquals(r.getChildren().size(), 1);
   
   
   
  }
View Full Code Here

TOP

Related Classes of primitives.cluster.ClusterHead

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.