Update update = ((InsertAction) action).getUpdate(); this.beliefUpdates.add(update); this.beliefQueries.add(update.toQuery()); this.insertUpdates.add(update); Update update = ((DeleteAction) action).getUpdate(); this.beliefUpdates.add(update); this.beliefQueries.add(update.toQuery()); this.deleteUpdates.add(update); this.goalQueries.add(((AdoptAction) action).getUpdate().toQuery()); this.adoptUpdates.add(((AdoptAction) action).getUpdate()); this.goalQueries.add(((DropAction) action).getUpdate().toQuery()); this.dropUpdates.add(((DropAction) action).getUpdate());
/** * Drops all goals that entail the goal to be dropped. * * @param dropgoal * goal to be dropped. * @return A (possibly empty) list of goals that have been dropped. * @throws MSTDatabaseException */ Result drop(Update dropgoal) throws MSTQueryException, MSTDatabaseException { // Gather the actual goals matching the update List<SingleGoal> goalsToBeDropped = new LinkedList<>(); for (SingleGoal goal : this.goals) { Set<Substitution> dropCheck = goal.query(dropgoal.toQuery()); if (!dropCheck.isEmpty()) { goalsToBeDropped.add(goal); } } // Actually remove the goals (from the collection & clean-up themselves) Result result = this.owner.createResult(BASETYPE.GOALBASE, getName()); for (SingleGoal goal : goalsToBeDropped) { result.merge(remove(goal)); } return result; }
/** * Implements the blind commitment strategy of a GOAL agent. It removes * goals when they are believed to be achieved completely. * * @return list of goals achieved and removed (per goalbase) * @throws MSTDatabaseException * @throws MSTQueryException */ List<Result> updateGoalState() throws MSTQueryException, MSTDatabaseException { List<Result> results = new LinkedList<>(); for (GoalBase goalbase : this.goalBases) { // Gather the actual goals matching the update in this base List<SingleGoal> goalsToBeRemoved = new LinkedList<>(); for (SingleGoal goal : goalbase.getGoals()) { Set<Substitution> check = this.mentalBases.get(BASETYPE.BELIEFBASE).query(goal.getGoal().toQuery()); if (!check.isEmpty()) { goalsToBeRemoved.add(goal); } } // Actually remove the goals (if any) if (!goalsToBeRemoved.isEmpty()) { Result result = this.owner.createResult(BASETYPE.GOALBASE, goalbase.getName()); for (SingleGoal goal : goalsToBeRemoved) { result.merge(goalbase.remove(goal)); } results.add(result); } } return results; }
/** * Extracts relevant info for validation. */ private void processInfo() { // Extract relevant info from referenced files. this.knowledge.addAll(this.program.getKnowledge()); this.beliefs.addAll(this.program.getBeliefs()); // Extract relevant info from action specifications. for (UserSpecAction action : this.program.getActionSpecifications()) { for (MentalLiteral literal : getBeliefLiterals(action.getPrecondition())) { this.beliefQueries.add(literal.getFormula()); } if (action.getPositivePostcondition() != null) { this.beliefQueries.add(action.getPositivePostcondition().getPostCondition().toQuery()); } if (action.getNegativePostcondition() != null) { this.beliefQueries.add(action.getNegativePostcondition().getPostCondition().toQuery()); } } } }
/** * Returns the precondition of this {@link AdoptAction}. * * <p> * An adopt action can be performed if the agent does not believe that the goal * that is adopted has already been achieved, i.e., believes it already to be * the case, and the goal does not follow from one of the goals that are already * present in the goal base. * </p> * * @return A {@link MentalStateCondition} that represents the action's * precondition. */ @Override public MentalStateCondition getPrecondition() { // Get the goal this action should add Query query = getUpdate().toQuery(); List<MentalFormula> formulalist = new ArrayList<>(2); // Construct the belief part of the query: NOT(BEL(query)). formulalist.add(new BelLiteral(false, getSelector(), query, null, getSourceInfo())); // Construct the goal part of the query: NOT(GOAL(query)). formulalist.add(new GoalLiteral(false, getSelector(), query, null, getSourceInfo())); // Combine both parts. return new MentalStateCondition(formulalist, query.getSourceInfo()); }
goal.getGoal().toQuery(), null, null); List<MentalFormula> formulas = new ArrayList<>(1); formulas.add(literal);
@Override public DatabaseFormula convertMessage(Message message) throws MSTTranslationException { PrologCompound content = ((PrologQuery) message.getContent().toQuery()).getCompound(); switch (message.getMood()) { case IMPERATIVE: content = PrologImplFactory.getCompound("imp", new Term[] { content }, content.getSourceInfo()); break; case INTERROGATIVE: content = PrologImplFactory.getCompound("int", new Term[] { content }, content.getSourceInfo()); break; default: } Term sender = convert(message.getSender()); PrologCompound compound = PrologImplFactory.getCompound("received", new Term[] { sender, content }, content.getSourceInfo()); return PrologImplFactory.getDBFormula(compound); }