01 package dk.deepthought.sidious.planner;
02 
03 import org.apache.commons.logging.Log;
04 import org.apache.commons.logging.LogFactory;
05 
06 import dk.deepthought.sidious.planner.graph.Graph;
07 import dk.deepthought.sidious.planner.graph.Vertex;
08 import dk.deepthought.sidious.supportsystem.Step;
09 
10 /**
11  * This class is responsible for generating a plan from a already searched
12  * graph.
13  
14  @author Deepthought
15  
16  */
17 public class PlanGenerator {
18 
19     /**
20      * Logger for this class.
21      */
22     private static final Log logger = LogFactory.getLog(PlanGenerator.class);
23 
24     /**
25      * This method traverses the <code>Graph</code> and generates a
26      <code>Plan</code> from that result.
27      */
28     public static Plan generatePlan(Graph graph) {
29         if (logger.isDebugEnabled()) {
30             logger.debug("generatePlan(Graph graph=" + graph + ") - start");
31         }
32         Plan plan = new Plan();
33         Vertex vertex = graph.getGoalVertex();
34         Step step = vertex.getStepToThis();
35         while (vertex.getPredecessorVertex() != null) {
36             plan.add(step);
37             vertex = vertex.getPredecessorVertex();
38             step = vertex.getStepToThis();
39         }
40         plan.setId(graph.getId());
41         if (logger.isDebugEnabled()) {
42             logger.debug("generatePlan(Graph graph=" + graph
43                     ") - end - return value=" + plan);
44         }
45         return plan;
46     }
47 
48 }