1
|
|
|
package it.cnr.istc.pst.platinum.ai.deliberative; |
2
|
|
|
|
3
|
|
|
import it.cnr.istc.pst.platinum.ai.deliberative.heuristic.pipeline.PipelineFlawSelectionHeuristic; |
4
|
|
|
import it.cnr.istc.pst.platinum.ai.deliberative.solver.PseudoControllabilityAwareSolver; |
5
|
|
|
import it.cnr.istc.pst.platinum.ai.deliberative.solver.SearchSpaceNode; |
6
|
|
|
import it.cnr.istc.pst.platinum.ai.deliberative.solver.Solver; |
7
|
|
|
import it.cnr.istc.pst.platinum.ai.deliberative.strategy.DepthFirstSearchStrategy; |
8
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.domain.component.PlanDataBase; |
9
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.FrameworkObject; |
10
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.annotation.cfg.FrameworkLoggerConfiguration; |
11
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.annotation.cfg.deliberative.FlawSelectionHeuristicsConfiguration; |
12
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.annotation.cfg.deliberative.PlannerSolverConfiguration; |
13
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.annotation.cfg.deliberative.SearchStrategyConfiguration; |
14
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.annotation.inject.deliberative.PlannerSolverPlaceholder; |
15
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.annotation.inject.framework.PlanDataBasePlaceholder; |
16
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.ex.NoSolutionFoundException; |
17
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.plan.PlanControllabilityType; |
18
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.plan.SolutionPlan; |
19
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.utils.log.FrameworkLoggingLevel; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* @author anacleto |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
@PlannerSolverConfiguration( |
29
|
|
|
solver = PseudoControllabilityAwareSolver.class, |
30
|
|
|
timeout = 180000 |
31
|
|
|
) |
32
|
|
|
@FlawSelectionHeuristicsConfiguration( |
33
|
|
|
heuristics = PipelineFlawSelectionHeuristic.class |
34
|
|
|
) |
35
|
|
|
@SearchStrategyConfiguration( |
36
|
|
|
strategy = DepthFirstSearchStrategy.class |
37
|
|
|
) |
38
|
|
|
@FrameworkLoggerConfiguration( |
39
|
|
|
// set logging level |
40
|
|
|
level = FrameworkLoggingLevel.INFO |
41
|
|
|
) |
42
|
|
|
public class Planner extends FrameworkObject |
43
|
|
|
{ |
44
|
|
|
@PlanDataBasePlaceholder |
45
|
|
|
protected PlanDataBase pdb; |
46
|
|
|
|
47
|
|
|
@PlannerSolverPlaceholder |
48
|
|
|
protected Solver solver; |
49
|
|
|
|
50
|
|
|
protected SearchSpaceNode currentSolution; // current solution found |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
protected Planner() { |
56
|
|
|
super(); |
57
|
|
|
this.currentSolution = null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Display the current plan |
62
|
|
|
*/ |
63
|
|
|
public void display() { |
64
|
|
|
// display the current plan |
65
|
|
|
this.pdb.display(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The method starts the planning process and return the solution plan if any. |
70
|
|
|
* |
71
|
|
|
* If no solution plan is found the method throws an exception |
72
|
|
|
* |
73
|
|
|
* @return |
74
|
|
|
* @throws NoSolutionFoundException |
75
|
|
|
*/ |
76
|
|
|
public SolutionPlan plan() |
77
|
|
|
throws NoSolutionFoundException |
78
|
|
|
{ |
79
|
|
|
// get time |
80
|
|
|
long start = System.currentTimeMillis(); |
81
|
|
|
// find a solution to the planning problem |
82
|
|
|
this.currentSolution = this.solver.solve(); |
83
|
|
|
|
84
|
|
|
// extract solution plan |
85
|
|
|
SolutionPlan plan = this.pdb.getSolutionPlan(); |
86
|
|
|
plan.setControllability(PlanControllabilityType.PSEUDO_CONTROLLABILITY); |
87
|
|
|
|
88
|
|
|
// check solving time |
89
|
|
|
long time = System.currentTimeMillis() - start; |
90
|
|
|
plan.setSolvingTime(time); |
91
|
|
|
// get the solution plan |
92
|
|
|
return plan; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* The method returns a structure representing the current plan. |
97
|
|
|
* |
98
|
|
|
* @return |
99
|
|
|
*/ |
100
|
|
|
public SolutionPlan getCurrentPlan() { |
101
|
|
|
// get current plan |
102
|
|
|
return this.pdb.getSolutionPlan(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* |
107
|
|
|
* @return |
108
|
|
|
*/ |
109
|
|
|
public SearchSpaceNode getCurrentNode() { |
110
|
|
|
return this.currentSolution; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* |
115
|
|
|
* @return |
116
|
|
|
*/ |
117
|
|
|
@Override |
118
|
|
|
public String toString() { |
119
|
|
|
// get a description of the plan data base |
120
|
|
|
return this.pdb.toString(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* |
125
|
|
|
*/ |
126
|
|
|
public void clear() { |
127
|
|
|
// clear solver |
128
|
|
|
this.solver.clear(); |
129
|
|
|
// clear current solution |
130
|
|
|
this.currentSolution = null; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|