Passed
Push — master ( 785027...2ca559 )
by Alessandro
07:25
created

choose()   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
dl 0
loc 14
rs 10
c 1
b 0
f 0
1
package it.cnr.istc.pst.platinum.ai.deliberative.heuristic;
2
3
import java.util.HashSet;
4
import java.util.List;
5
import java.util.Set;
6
7
import it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.ex.NoFlawFoundException;
8
import it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.flaw.Flaw;
9
import it.cnr.istc.pst.platinum.ai.framework.microkernel.resolver.ex.UnsolvableFlawException;
10
11
/**
12
 * 
13
 * @author anacleto
14
 *
15
 */
16
public class CompleteFlawSelectionHeuristic extends FlawSelectionHeuristic
17
{
18
	/**
19
	 * 
20
	 */
21
	protected CompleteFlawSelectionHeuristic() {
22
		super("RandomFlawSelectionHeuristic");
23
	}
24
	
25
	/**
26
	 * 
27
	 */
28
	@Override
29
	public Set<Flaw> choose() 
30
			throws UnsolvableFlawException, NoFlawFoundException {
31
		
32
		// detect flaws
33
		List<Flaw> flaws = this.pdb.detectFlaws();
34
		// check flaws found
35
		if (flaws.isEmpty()) {
36
			// throw exception
37
			throw new NoFlawFoundException("No flaw has been found in the current plan");
38
		}
39
		
40
		// consider all flaws for plan refinement
41
		return new HashSet<>(flaws);
42
	}
43
44
	/**
45
	 * 
46
	 */
47
	@Override
48
	public Set<Flaw> check() {
49
		// check flaws
50
		return new HashSet<>(this.pdb.checkFlaws());
51
	}
52
	
53
	
54
}
55