01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.strategy.feature;
12:
13: import de.uka.ilkd.key.logic.PosInOccurrence;
14: import de.uka.ilkd.key.proof.Goal;
15: import de.uka.ilkd.key.rule.RuleApp;
16: import de.uka.ilkd.key.strategy.RuleAppCost;
17: import de.uka.ilkd.key.strategy.TopRuleAppCost;
18: import de.uka.ilkd.key.util.Debug;
19:
20: /**
21: * A feature that computes the sum of a given list (vector) of features
22: */
23: public class SumFeature implements Feature {
24:
25: public RuleAppCost compute(RuleApp app, PosInOccurrence pos,
26: Goal goal) {
27: // We require that there is at least one feature (in method
28: // <code>createSum</code>)
29: RuleAppCost res = features[0].compute(app, pos, goal);
30:
31: for (int i = 1; i < features.length
32: && !(res instanceof TopRuleAppCost); i++)
33: res = res.add(features[i].compute(app, pos, goal));
34:
35: return res;
36: }
37:
38: private SumFeature(Feature[] p_features) {
39: features = p_features;
40: }
41:
42: public static Feature createSum(Feature[] fs) {
43: Debug.assertFalse(fs.length == 0,
44: "Cannot compute the sum of zero features");
45: final Feature[] fsCopy = new Feature[fs.length];
46: System.arraycopy(fs, 0, fsCopy, 0, fs.length);
47: return new SumFeature(fsCopy);
48: }
49:
50: private final Feature[] features;
51: }
|