2929 * is possible.
3030 *
3131 * @author samagra
32+ * @author Ruediger Lunde
3233 */
3334public class GraphPlanAlgorithm {
3435
@@ -96,19 +97,18 @@ private List<List<ActionSchema>> extractSolution(Graph graph, List<Literal> goal
9697 if (nogoods .contains (numLevel ))
9798 return null ;
9899
99- int level = ( graph . numLevels () - 1 ) / 2 ;
100+ List < Literal > goalsCurr = new ArrayList <>( goals ) ;
100101 List <List <ActionSchema >> solution = new ArrayList <>();
101- Level currLevel = graph .getLevels (). get ( 2 * level );
102- while ( level > 0 ) {
102+ for ( int level = ( graph .numLevels () - 1 ) / 2 ; level > 0 ; level --) {
103+ Level currLevel = graph . getLevels (). get ( 2 * level );
103104 List <List <ActionSchema >> setOfPossibleActions = new ArrayList <>();
104105 HashMap <Object , List <Object >> mutexLinks = currLevel .getPrevLevel ().getMutexLinks ();
105- for (Literal literal : goals ) {
106- List <ActionSchema > possiBleActionsPerLiteral = new ArrayList <>();
107- for (Object action :
108- currLevel .getPrevLinks ().get (literal )) {
109- possiBleActionsPerLiteral .add ((ActionSchema ) action );
106+ for (Literal literal : goalsCurr ) {
107+ List <ActionSchema > possibleActionsPerLiteral = new ArrayList <>();
108+ for (Object action : currLevel .getPrevLinks ().get (literal )) {
109+ possibleActionsPerLiteral .add ((ActionSchema ) action );
110110 }
111- setOfPossibleActions .add (possiBleActionsPerLiteral );
111+ setOfPossibleActions .add (possibleActionsPerLiteral );
112112 }
113113 List <List <ActionSchema >> allPossibleSubSets = generateCombinations (setOfPossibleActions );
114114 boolean validSet ;
@@ -125,24 +125,21 @@ private List<List<ActionSchema>> extractSolution(Graph graph, List<Literal> goal
125125 }
126126 }
127127 if (validSet ) {
128+ // This is too simple. Completeness is lost. Search would be required... (RLu)
128129 setToBeTaken = possibleSet ;
129130 break ;
130131 }
131132 }
132133 if (setToBeTaken == null ) {
133- nogoods .put (level , goals );
134+ nogoods .put (level , goalsCurr );
134135 return null ;
135136 }
136-
137- level --;
138- currLevel = graph .getLevels ().get (2 * level );
139- goals .clear ();
140137 solution .add (setToBeTaken );
138+ goalsCurr .clear ();
141139 for (ActionSchema action : setToBeTaken ) {
142- for (Literal literal :
143- action .getPrecondition ()) {
144- if (!goals .contains (literal )) {
145- goals .add (literal );
140+ for (Literal literal : action .getPrecondition ()) {
141+ if (!goalsCurr .contains (literal )) {
142+ goalsCurr .add (literal );
146143 }
147144 }
148145 }
0 commit comments