1 /*********************************************************************
2 Copyright 2012, Ralph Ronnquist.
4 This file is part of GORITE.
6 GORITE is free software: you can redistribute it and/or modify it
7 under the terms of the Lesser GNU General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GORITE is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the Lesser GNU General Public
17 License along with GORITE. If not, see <http://www.gnu.org/licenses/>.
18 **********************************************************************/
20 package com.intendico.gorite;
22 import com.intendico.data.Query;
23 import com.intendico.data.Ref;
25 import java.util.HashSet;
26 import java.util.Iterator;
27 import java.util.Vector;
30 * A RepeatGoal is achieved by means of achieving all its
31 * instantiations in parallel, where each instantiation is achieved by
32 * achieving the given sub goals in sequence. The goal definition
33 * includes a context specification, which enumerates the
34 * instantiations of the goal arising. Each instantiation refers to
35 * the same sequence of sub goals, but with different focus in the
38 * <p> The following code snippet illustrates the use of a RepeatGoal
39 * to process a multi-valued data element (named "options" in the
43 * new RepeatGoal( "process options", new Goal [] {
44 * // This goal sequence has its "options" data focussed
45 * // on one of the (previosuly multi-valued) options.
46 * new BDIGoal( "do this with options" ),
47 * new BDIGoal( "do that with options" ),
48 * new BDIGoal( "do more with options" ),
49 * } ) {{ control = "options"; }} // Replicate for all the values of "options"
55 public class RepeatGoal extends BranchingGoal {
58 * Constructor with a given control name, goal name and sub goals.
60 public RepeatGoal(String c,String n,Goal [] sg) {
66 * Constructor with a given goal name and sub goals.
68 public RepeatGoal(String n,Goal [] sg) {
73 * Convenience constructor without sub goals.
75 public RepeatGoal(String n) {
80 * Creates and returns an instance object for achieving
83 public Instance instantiate(String head,Data d) {
84 return new RepeatInstance( head );
88 * Implements re-instatiation of this goal relative something.
90 public class RepeatInstance extends MultiInstance {
95 public RepeatInstance(String h) {
100 * To decide whether yet another branch should be made.
102 public boolean more(int i,Data d) {
103 return i < d.size( getGoalControl() );
107 * The branch is created be instantiating this goal as a
110 public Instance getBranch(int i,String head,Data d) {
111 Goal g = new SequenceGoal( getGoalName(), getGoalSubgoals() );
112 g.setGoalControl( getGoalControl() );
113 g.setGoalGroup( getGoalGroup() );
114 return g.instantiate( head, d );