|
1
|
|
|
package it.cnr.istc.pst.platinum.ai.framework.microkernel.resolver.timeline.behavior.planning; |
|
2
|
|
|
|
|
3
|
|
|
import java.util.ArrayList; |
|
4
|
|
|
import java.util.List; |
|
5
|
|
|
|
|
6
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.domain.component.ComponentValue; |
|
7
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.domain.component.Decision; |
|
8
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.flaw.FlawSolution; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @author anacleto |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
public class GapCompletion extends FlawSolution |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
private Decision left; |
|
18
|
|
|
private Decision right; |
|
19
|
|
|
private List<ComponentValue> path; |
|
20
|
|
|
private boolean complex; // true if at least one of the values of the the path is complex |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* |
|
25
|
|
|
* @param gap |
|
26
|
|
|
* @param path |
|
27
|
|
|
* @param cost |
|
28
|
|
|
*/ |
|
29
|
|
|
protected GapCompletion(Gap gap, List<ComponentValue> path, double cost) { |
|
30
|
|
|
super(gap, cost); |
|
31
|
|
|
this.left = gap.getLeftDecision(); |
|
32
|
|
|
this.right = gap.getRightDecision(); |
|
33
|
|
|
this.path = new ArrayList<>(path); |
|
34
|
|
|
// set complex flag |
|
35
|
|
|
this.complex = false; |
|
36
|
|
|
// check if complex |
|
37
|
|
|
for (ComponentValue value : path) { |
|
38
|
|
|
if (value.isComplex()) { |
|
39
|
|
|
complex = true; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* |
|
46
|
|
|
* @return |
|
47
|
|
|
*/ |
|
48
|
|
|
public boolean isComplex() { |
|
49
|
|
|
return complex; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* |
|
54
|
|
|
* @return |
|
55
|
|
|
*/ |
|
56
|
|
|
public Decision getLeftDecision() { |
|
57
|
|
|
return left; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* @return |
|
63
|
|
|
*/ |
|
64
|
|
|
public Decision getRightDecision() { |
|
65
|
|
|
return right; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* |
|
70
|
|
|
* @return |
|
71
|
|
|
*/ |
|
72
|
|
|
public List<ComponentValue> getPath() { |
|
73
|
|
|
return path; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* |
|
78
|
|
|
* @param o |
|
79
|
|
|
* @return |
|
80
|
|
|
*/ |
|
81
|
|
|
@Override |
|
82
|
|
|
public int compareTo(FlawSolution o) { |
|
83
|
|
|
// get other gap completion flaw |
|
84
|
|
|
GapCompletion sol = (GapCompletion) o; |
|
85
|
|
|
return this.path.size() < sol.path.size() ? -1 : this.path.size() > sol.path.size() ? 1 : 0; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* |
|
90
|
|
|
*/ |
|
91
|
|
|
@Override |
|
92
|
|
|
public String toString() { |
|
93
|
|
|
// JSON style object description |
|
94
|
|
|
return "{ \"type\": \"GAP_COMPLETION\", " |
|
95
|
|
|
+ "\"left\": " + this.left + ", " |
|
96
|
|
|
+ "\"right\": " + this.right + ", " |
|
97
|
|
|
+ "\"path\": " + this.path.toString() + " }"; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|