for (AbstractTCGEdge edge : atcg.getInitialNode().getOutgoing()) {
stack.add(new Pair(edge, new Integer(0)));
}
AbstractTCGNode currentNode = atcg.getInitialNode();
Pair currentEdge;
Path currentPath = TestCaseGraphRuntimeFactory.eINSTANCE.createPath();
while (!stack.isEmpty()
&& (result.size() <= maxNoPaths || maxNoPaths == -1)) {
currentEdge = stack.removeFirst();
// backtrack
while (currentEdge.getSecond() != currentPath.getEdges().size()) {
// System.out.println("BACKTRACK");
EList<AbstractTCGEdge> l = currentPath.getEdges();
AbstractTCGEdge e = l.remove(l.size() - 1);
currentNode = e.getSource();
if (currentNode.getOutgoing().size() >= 2) {
passedDecisions--;
}
}
passedDecisions = (passedDecisions < 0 ? 0 : passedDecisions);
currentNode = currentEdge.getFirst().getTarget();
currentPath.getEdges().add(currentEdge.getFirst());
if (currentPath.getEdges().size() <= maxDepth || maxDepth == -1) {
// check every 3 or 4 decisions whether the path is still
// feasible
if (currentNode.getOutgoing().size() >= 2) {
passedDecisions++;
if (passedDecisions > uncheckedSteps) {
passedDecisions = 0;
ampl.loadData(Path2AMPLData.transform(currentPath));
SolveResult solved = SolveResult.Solved;
try {
solved = ampl.solve();
} catch (IOException e) {
ampl = new JamplBuilder().solver(solver)
.model(ActTCG2AMPLModel.transform(atcg))
.data(Path2AMPLData.transform(currentPath))
.build();
System.out.println("RESET!!!");
try {
solved = ampl.solve();
} catch (IOException e1) {
e1.printStackTrace();
break;
}
}
totalSolves++;
if (solved == SolveResult.Solved) {
System.out.print(",");
}
if (solved == SolveResult.Infeasible) {
infeasibleSolves++;
System.out.print(".");
continue;
}
if (solved == SolveResult.Failure) {
System.out.println("FAILURE!!!!!!!");
infeasibleSolves++;
continue;
}
}
} // System.out.println("Adding Next STEP");
// add child nodes to Stack
for (AbstractTCGEdge outgoing : currentNode.getOutgoing()) {
stack.addFirst(new Pair(outgoing, new Integer(currentPath
.getEdges().size())));
}
}
if (currentNode.getOutgoing().size() == 0) {
// found final node -> Add path to result
// fill witness with data.
Witness witness = generateWitness(currentPath, atcg);
if (witness != null) {
result.put(currentPath, witness);
Logging.trace("found test case " + new Date(), this);
Path newCurrentPath = TestCaseGraphRuntimeFactory.eINSTANCE
.createPath();
for (AbstractTCGEdge e : currentPath.getEdges()) {
newCurrentPath.getEdges().add(e);
}
currentPath = newCurrentPath;
if (monitor != null) {
monitor.worked(5);
}