/*
* needs to be refactored into smaller methods
*/
protected List<List<String>> generateQuestions(DirectedSparseGraph model, OrigStatePair pair){
Vertex q = pair.getQ();
Vertex r = pair.getR();
if(q==null || r ==null)
return new ArrayList<List<String>>();
boolean accepted = DeterministicDirectedSparseGraph.isAccept(q);
if(accepted == false)
return new ArrayList<List<String>>();
List<String> sp = null;
Set<List<String>> w =null;
if(!hasAcceptedNeighbours(q)){
sp = getShortPrefix(model, q);
w = getShortSuffixes(model, r);
}
else{
sp = getShortPrefix(model, r);// shortest sequence to the red state
w = getSuffixes(model,q, accepted);
}
Iterator<List<String>> wIt;
ArrayList<List<String>> questions = new ArrayList<List<String>>();
Set<String>loopLabels = new HashSet<String>();
boolean loopToR = r.getSuccessors().contains(r);
boolean redAndBlueNeighbours = r.getNeighbors().contains(q);
if(loopToR||redAndBlueNeighbours){ //there either exists a loop to r or will do if r and b merge
if(loopToR){
Edge e = findEdge(r, r);
HashSet<String> labels = (HashSet<String>)e.getUserDatum(JUConstants.LABEL);
loopLabels.addAll(labels);
}
if(redAndBlueNeighbours){
Edge e = findEdge(r,q);
HashSet<String> labels = (HashSet<String>)e.getUserDatum(JUConstants.LABEL);
loopLabels.addAll(labels);
}
}
wIt = w.iterator();
while(wIt.hasNext()){
List<String> suffix = wIt.next();
Iterator<String> labelIt = loopLabels.iterator();
if(!loopLabels.isEmpty()){
while(labelIt.hasNext()){
List<String> newQuestion = new ArrayList<String>();
newQuestion.addAll(sp);
newQuestion.add(labelIt.next());
newQuestion.addAll(suffix);
Vertex v = getVertex(model, newQuestion);
if(v==null)
questions.add(newQuestion);
}
}
List<String> newQuestion = new ArrayList<String>();
newQuestion.addAll(sp);
newQuestion.addAll(suffix);
Vertex v = getVertex(model, newQuestion);
if(v==null)
questions.add(newQuestion);
}
return questions;
}