01 package dk.deepthought.sidious.planner;
02 
03 import java.util.Collection;
04 
05 import org.apache.commons.logging.Log;
06 import org.apache.commons.logging.LogFactory;
07 
08 import dk.deepthought.sidious.planner.graph.AStarGraph;
09 import dk.deepthought.sidious.planner.graph.Graph;
10 import dk.deepthought.sidious.supportsystem.Adjustable;
11 import dk.deepthought.sidious.supportsystem.State;
12 import dk.deepthought.sidious.supportsystem.SuperLinkID;
13 
14 /**
15  * The graph factory.
16  
17  @author Deepthought
18  
19  */
20 public class GraphFactory {
21 
22     private static final Log logger = LogFactory.getLog(GraphFactory.class);
23 
24     /**
25      * This method is a factory for creating a <code>Graph</code>.
26      <p>
27      * The input states (<code>source</code> and <code>goal</code>) must:
28      <li> have same dimension
29      <li> operate in the same state space
30      
31      @param requester
32      *            the id of the originating <code>PlanRequester</code>
33      @param source
34      *            the beginning of any path in the graph
35      @param goal
36      *            the end of any path in the graph
37      @return a graph
38      */
39     public static Graph makeGraph(SuperLinkID requester, State source,
40             State goal) {
41         if (logger.isDebugEnabled()) {
42             logger.debug("makeGraph() - start");
43         }
44         if (requester == null || source == null || goal == null) {
45             logger.error("makeGraph(SuperLinkID requester=" + requester
46                     ", State source=" + source + ", State goal=" + goal
47                     ") - not valid input");
48             throw new IllegalArgumentException("null not valid input");
49         }
50         Collection<Adjustable> adjustables = PlannerEngine
51                 .getAdjustables(requester);
52         Heuristic greenhouseHeuristic = new GreenhouseHeuristic(requester,
53                 source, goal);
54         Graph returnGraph = new AStarGraph(source, goal, adjustables,
55                 greenhouseHeuristic, requester);
56         if (logger.isDebugEnabled()) {
57             logger.debug("makeGraph() - end - return value=" + returnGraph);
58         }
59         return returnGraph;
60     }
61 }