Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //----------------------------------------------------------------------------
  // Copyright (C) 2003  Rafael H. Bordini, Jomi F. Hubner, et al.
  // 
  // This library is free software; you can redistribute it and/or
  // modify it under the terms of the GNU Lesser General Public
  // License as published by the Free Software Foundation; either
  // version 2.1 of the License, or (at your option) any later version.
  // 
  // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 // 
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 // 
 // To contact the authors:
 // http://www.inf.ufrgs.br/~bordini
 // http://www.das.ufsc.br/~jomi
 //----------------------------------------------------------------------------
 
 
 package jason.stdlib;
 
 

Internal action: .resume(G).

Description: resume goals G that were suspended by .suspend.

Example:

  • .resume(go(1,3)): resume the goal of going to location 1,3.

 
 public class resume extends DefaultInternalAction {
 
     @Override public int getMinArgs() { return 1; }
     @Override public int getMaxArgs() { return 1; }
 
     @Override protected void checkArguments(Term[] argsthrows JasonException {
         super.checkArguments(args); // check number of arguments
         if (!args[0].isLiteral())
             throw JasonException.createWrongArgument(this,"first argument must be a literal");
     }
 
     @Override
     public Object execute(TransitionSystem tsUnifier unTerm[] argsthrows Exception {
         checkArguments(args);
 
         Trigger      g = new Trigger(.., (Literal)args[0]);
         Circumstance C = ts.getC();
         
         // Search the goal in PI
         Iterator<Stringik = C.getPendingIntentions().keySet().iterator();
         while (ik.hasNext()) {
             String k = ik.next();
             if (k.startsWith(.)) {
                 Intention i = C.getPendingIntentions().get(k);
                 if (i.hasTrigger(gun)) {
                     i.setSuspended(false);
                     ik.remove();
                     
                     // remove the IA .suspend in case of self-suspend
                     if (k.startsWith(.))
                         i.peek().removeCurrentStep();
                     
                     // add it back in I if not in PA
                    if (! C.getPendingActions().containsKey(i.getId()))
                        C.resumeIntention(i);
                    
                    //System.out.println("res "+g+" from I "+i.getId());
                }
            }
        }
        
        // Search the goal in PE
        ik = C.getPendingEvents().keySet().iterator();
        while (ik.hasNext()) {
            String k = ik.next();
            if (k.startsWith(.)) {
                Event e = C.getPendingEvents().get(k);
                Intention i = e.getIntention();
                if (un.unifies(ge.getTrigger()) || (i != null && i.hasTrigger(gun))) {
                    ik.remove();
                    C.addEvent(e);                    
                    if (i != null
                        i.setSuspended(false);                
                    //System.out.println("res "+g+" from E "+e.getTrigger());
                }
            }
        }
        return true;
    }        
    
New to GrepCode? Check out our FAQ X