Logo Search packages:      
Sourcecode: cdk version File versions  Download package

List org::openscience::cdk::structgen::stochastic::operator::CrossoverMachine::doCrossover ( IAtomContainer  dad,
IAtomContainer  mom 
) throws CDKException [inline]

Performs the n point crossover of two MolChromosome supplied by the CrossInfo.parents class and stores the resulting chromosomes in CrossInfo.children.

Returns:
an object storing information generated by the operator.
Exceptions:
IllegalArgumentExceptionif some of the crosspoints defined are greater than the size of the corresponding chromosome.

Definition at line 87 of file CrossoverMachine.java.

References org::openscience::cdk::interfaces::IAtomContainer::add(), org::openscience::cdk::interfaces::IAtomContainer::bonds(), org::openscience::cdk::interfaces::IBond::contains(), org::openscience::cdk::interfaces::IAtomContainer::getAtom(), org::openscience::cdk::interfaces::IChemObject::getBuilder(), org::openscience::cdk::interfaces::IChemObjectBuilder::newAtomContainer(), numatoms, org::openscience::cdk::math::RandomNumbersTool::randomInt(), org::openscience::cdk::interfaces::IAtomContainer::removeBond(), org::openscience::cdk::structgen::stochastic::PartialFilledStructureMerger::setAtomContainer(), SPLIT_MODE_DEPTH_FIRST, SPLIT_MODE_RADNDOM, and splitMode.

    {
            int dim = dad.getAtomCount();
            
            /***randomly divide atoms into two parts: redAtoms and blueAtoms.***/
            redAtoms.clear();
            blueAtoms.clear();            
            
          if (splitMode==SPLIT_MODE_RADNDOM)
            {
                  /*better way to randomly divide atoms into two parts: redAtoms and blueAtoms.*/
                  for (int i = 0; i < dim; i++)
                        redAtoms.add(Integer.valueOf(i));
                  for (int i = 0; i < (dim - numatoms); i++)
                  {   int ranInt = RandomNumbersTool.randomInt(0,redAtoms.size()-1);
                        redAtoms.remove(ranInt);
                        blueAtoms.add(Integer.valueOf(ranInt));
                  }
                         
            }
            else
            {
                  /*split graph using depth/breadth first traverse*/
                  ChemGraph graph = new ChemGraph(dad);
                  graph.setNumAtoms(numatoms);
                  if (splitMode==SPLIT_MODE_DEPTH_FIRST)
                  {
                        redAtoms = graph.pickDFgraph();
                  }
                  else
                        redAtoms = graph.pickBFgraph();
                        
                  for (int i = 0; i < dim; i++){
                        Integer element = Integer.valueOf(i);
                        if (!(redAtoms.contains(element)))
                        {
                              blueAtoms.add(element);
                        }     
                  }
            }           
            /*** dividing over ***/
            
            
            redChild[0] = dad.getBuilder().newAtomContainer(dad); 
            blueChild[0] = dad.getBuilder().newAtomContainer(dad); 
            redChild[1] = dad.getBuilder().newAtomContainer(mom); 
            blueChild[1] = dad.getBuilder().newAtomContainer(mom); 
            
            
            for (int j = 0; j < blueAtoms.size(); j++)
            {
                  Iterator bonds = redChild[1].bonds().iterator();
                  while (bonds.hasNext()) {
                        IBond bond = (IBond)bonds.next();
                        if (bond.contains(redChild[0].getAtom(((Integer)blueAtoms.get(j)).intValue())))
                        {
                              redChild[0].removeBond(bond);
                        }
                  }
            }


            for (int j = 0; j < blueAtoms.size(); j++)
            {
                  Iterator bonds = redChild[1].bonds().iterator();
                  while (bonds.hasNext()) {
                        IBond bond = (IBond)bonds.next();
                        if (bond.contains(redChild[1].getAtom(((Integer)blueAtoms.get(j)).intValue())))
                        {
                              bonds.remove(); // this removes it from redChild[1] too
                        }
                  }
            }


            for (int j = 0; j < redAtoms.size(); j++)
            {
                  Iterator bonds = blueChild[0].bonds().iterator();
                  while (bonds.hasNext()) {
                        IBond bond = (IBond)bonds.next();
                        if (bond.contains(blueChild[0].getAtom(((Integer)redAtoms.get(j)).intValue())))
                        {
                              bonds.remove();
                        }
                  }
            }


            for (int j = 0; j < redAtoms.size(); j++) {
                  Iterator bonds = blueChild[1].bonds().iterator();
                  while (bonds.hasNext()) {
                        IBond bond = (IBond)bonds.next();
                        if (bond.contains(blueChild[1].getAtom(((Integer)redAtoms.get(j)).intValue())))
                        {
                              bonds.remove();
                        }
                  }
            }

            
            redChild[0].add(blueChild[1]);
            if (children.size()==2)
            {
                  redChild[1].add(blueChild[0]);
            }
            
            
            
            for (int f = 0; f < children.size(); f++)
            {
                  pfsm.setAtomContainer(redChild[f]);
                  children.add(f, pfsm.generate());
            }
        return children;                  
    } 

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index