19package denoptim.fragspace;
21import java.util.ArrayList;
22import java.util.HashMap;
23import java.util.Iterator;
25import java.util.NoSuchElementException;
26import java.util.logging.Level;
28import denoptim.constants.DENOPTIMConstants;
29import denoptim.exception.DENOPTIMException;
30import denoptim.graph.APClass;
31import denoptim.graph.AttachmentPoint;
32import denoptim.graph.DGraph;
33import denoptim.graph.SymmetricAPs;
34import denoptim.graph.SymmetricVertexes;
35import denoptim.graph.Vertex;
36import denoptim.utils.GraphUtils;
64 new ArrayList<IdFragmentAndAP>();
72 new ArrayList<IdFragmentAndAP>();
78 new HashMap<IdFragmentAndAP,ArrayList<IdFragmentAndAP>>();
83 private ArrayList<Integer>
nextIds =
new ArrayList<Integer>();
135 long vIdx = v.getVertexId();
136 int vMolId = v.getBuildingBlockId();
137 Vertex.BBType vMolTyp = v.getBuildingBlockType();
140 boolean keepThisVertex =
true;
144 keepThisVertex =
false;
145 boolean isInSymSet =
false;
153 if (ss.indexOf(v) == 0)
155 keepThisVertex =
true;
162 keepThisVertex =
true;
172 if (!ap.isAvailable())
176 int apIdx = v.getIndexOfAP(ap);
178 boolean keepThisAP =
true;
181 && v.hasSymmetricAP())
184 boolean isInSymSet =
false;
196 if (ss.indexOf(ap) == 0)
214 vMolTyp, apIdx, -1, -1);
222 Vertex.BBType fTyp = candSrcAp.getVertexMolType();
223 int fIdx = candSrcAp.getVertexMolId();
224 int apId = candSrcAp.getApId();
230 ArrayList<IdFragmentAndAP> candsForThisSrc =
231 new ArrayList<IdFragmentAndAP>();
234 ArrayList<IdFragmentAndAP> compatFragAps =
242 compatApId.getVertexMolId(),
244 compatApId.getApId(),
248 candsForThisSrc.add(trgFrgAp);
256 if (capApCls !=
null)
264 for (Integer i : capGrpIds)
273 candsForThisSrc.add(trgFrgAp);
285 candsForThisSrc.add(trgFrgAp);
290 if (candsForThisSrc.size() > 0)
306 StringBuilder sb =
new StringBuilder();
307 sb.append(
"Initializing iterator over combs of frags:"+
EOL);
310 sb.append(
" -> Possibilities for "+candSrcAp+
EOL);
313 sb.append(
" ---> " + i+
EOL);
318 boolean emptySets =
true;
319 for (
int curSrcApIdx=0; curSrcApIdx<
actvSrcAps.size(); curSrcApIdx++)
330 for (
int srcApIdx=0; srcApIdx<
actvSrcAps.size(); srcApIdx++)
365 for (
int i=0; i<
nextIds.size(); i++)
398 throw new NoSuchElementException();
410 ArrayList<Integer> currentIds =
new ArrayList<Integer>();
412 for (
int curSrcApIdx=0; curSrcApIdx<
actvSrcAps.size(); curSrcApIdx++)
416 ArrayList<IdFragmentAndAP> locCandsList =
candFragsPerAP.get(src);
419 fap.setVrtSymSetId(curSrcApIdx);
422 int locCurCandId =
nextIds.get(curSrcApIdx);
424 msg =
"Setting frag for AP " + curSrcApIdx +
" (" + src +
")";
429 boolean changeCurIdx =
true;
430 for (
int fIdx=curSrcApIdx+1; fIdx<
actvSrcAps.size(); fIdx++)
434 changeCurIdx =
false;
444 msg =
"Non-last src AP; fixed on " + locCurCandId;
446 currentIds.add(locCurCandId);
447 currentComb.put(src,locCandsList.get(locCurCandId));
451 if (locCurCandId+1 < locTotCands)
455 nextIds.set(curSrcApIdx,locCurCandId);
457 StringBuilder sb =
new StringBuilder();
458 for (
int futureSrcAp=curSrcApIdx+1;
461 sb.append(
"Restart idx on src AP " + futureSrcAp +
EOL);
465 sb.append(
"Non-last src AP; new idx = " + locCurCandId);
468 currentIds.add(locCurCandId);
469 currentComb.put(src,locCandsList.get(locCurCandId));
478 nextIds.set(curSrcApIdx,locCurCandId);
480 msg =
"Step BACK from src AP " + curSrcApIdx;
482 currentIds.remove(currentIds.size()-1);
483 curSrcApIdx = curSrcApIdx - 2;
488 else if ((curSrcApIdx+1) ==
actvSrcAps.size())
490 msg =
"Last src AP; new idx = " + locCurCandId;
493 currentIds.add(locCurCandId);
494 currentComb.put(src,locCandsList.get(locCurCandId));
496 nextIds.set(curSrcApIdx,locCurCandId);
500 for (
int i=0; i<
nextIds.size(); i++)
503 if (i == curSrcApIdx)
520 StringBuilder sb =
new StringBuilder();
521 sb.append(
"Combination before applying symmetry: ");
524 sb.append(
" "+entry);
532 Map<IdFragmentAndAP,IdFragmentAndAP> pairsToAdd =
533 new HashMap<IdFragmentAndAP,IdFragmentAndAP>();
538 long srcVrtId = srcFrgAp.getVertexId();
539 int srcApId = srcFrgAp.getApId();
548 if (ss.contains(srcAP))
557 for (
int i=1; i<ss.size(); i++)
569 srcFrgAp.getVrtSymSetId(),
580 pairsToAdd.put(symSrcFrgAp, symTrgFrgAp);
589 pairsToAdd.entrySet())
591 currentComb.put(entry.getKey(), entry.getValue());
600 long srcVrtId = srcFrgAp.getVertexId();
602 Iterator<SymmetricVertexes> it =
607 if (ss.contains(srcVrt))
610 for (
int i=1; i<ss.size(); i++)
612 Vertex symVertex = ss.get(i);
620 srcFrgAp.getVrtSymSetId(),
632 pairsToAdd.put(symSrcFrgAp,symTrgFrgAp);
641 pairsToAdd.entrySet())
643 currentComb.put(entry.getKey(), entry.getValue());
649 StringBuilder sb2 =
new StringBuilder();
650 sb2.append(
"Final combination of frags/APs: ");
653 sb2.append(
" "+entry);
General set of constants used in DENOPTIM.
static final String EOL
new line character
Vertex getVertexFromLibrary(Vertex.BBType bbType, int bbIdx)
Returns a clone of the requested building block.
ArrayList< Integer > getCappingGroupsWithAPClass(APClass capApCls)
Set< APClass > getForbiddenEndList()
APClass getAPClassOfCappingVertex(APClass srcApClass)
boolean imposeSymmetryOnAPsOfClass(APClass apClass)
Checks if the symmetry settings impose use of symmetry on attachment points of the given AP class.
ArrayList< IdFragmentAndAP > getFragAPsCompatibleWithClass(APClass aPC1)
Returns the list of attachment points found in the fragment space and that are compatible with a give...
Parameters defining the fragment space.
boolean enforceSymmetry
Flag enforcing constitutional symmetry.
boolean symmetryConstraints
Flag for application of selected constitutional symmetry constraints.
FragmentSpace getFragmentSpace()
Data structure identifying a combination of one or more pairs of attachment points located on specifi...
Factory of combination of fragments.
int getNumGeneratedCombs()
FragsCombination next()
Generate the next combination of fragments.
FragmentSpaceParameters settings
Parameters defining the fragment space.
Map< IdFragmentAndAP, ArrayList< IdFragmentAndAP > > getCandidatesMap()
ArrayList< IdFragmentAndAP > actvSrcAps
List of attachment points on the root graph (source APs) for which there are one or more candidate de...
ArrayList< Integer > totCandsPerAP
Sizes of the candidates set for each source AP.
ArrayList< Integer > getNextIds()
Returns the list of indeces used to calculate the next iteration.
void setStartingPoint(ArrayList< Integer > nextIds)
Sets the starting point for the iterator.
ArrayList< Integer > nextIds
Set of indeces for the next iteration.
Map< IdFragmentAndAP, ArrayList< IdFragmentAndAP > > candFragsPerAP
Map of all possible matches for each source AP.
int numbGenCombs
Current number of generated combinations.
DGraph rootGraph
The root graph (may be a single fragment or an extended graph)
ArrayList< IdFragmentAndAP > allSrcAps
List of all attachment points on the root graph (source APs)
int totCombs
Total number of combinations.
boolean finished
Flag defining whether at list one more combination can be produced.
FragsCombinationIterator(FragmentSpaceParameters settings, DGraph rootGraph)
Constructs a new factory for generating all the combination of fragments that can be attached on a gi...
ArrayList< Integer > getSizesOfCandidateSets()
Data structure containing information that identifies a single AP of a vertex/fragment.
BBType getVertexMolType()
void setVrtSymSetId(int vSymSetId)
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
APClass getAPClass()
Returns the Attachment Point class.
boolean isAvailable()
Check availability of this attachment point.
Container for the list of vertices and the edges that connect them.
Vertex getVertexWithId(long vid)
Searches for a vertex with the given identifier.
Iterator< SymmetricVertexes > getSymSetsIterator()
Get an iterator for the sets of symmetrically related vertices.
List< Vertex > getVertexList()
A collection of AttachmentPoints that are related by a relation that we call "symmetry",...
A collection of Vertexs that are related by a relation that we call "symmetry", even though this clas...
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Vertex.BBType getBuildingBlockType()
abstract List< AttachmentPoint > getAttachmentPoints()
abstract List< SymmetricAPs > getSymmetricAPSets()
Logger getLogger()
Get the name of the program specific logger.
static synchronized long getUniqueVertexIndex()
Unique counter for the number of graph vertices generated.
The type of building block.