@Override public Collection<Argument> getParents(Node node) { if(!(node instanceof Argument)) throw new IllegalArgumentException("Node of type argument expected"); return this.getAttackers((Argument)node); }
@Override public Collection<Argument> getNeighbors(Argument node) { Set<Argument> neighbours = new HashSet<Argument>(); neighbours.addAll(this.getAttacked(node)); neighbours.addAll(this.getAttackers(node)); return neighbours; }
/** * Depth-First-Search to find a cycle in the theory. Auxiliary method to determine if the theory is well-founded * @param i current node * @param arguments list of all nodes (arguments) * @param dfn array which keeps track whether a node has been visited * @param inProgress array which keeps track which nodes are currently being processed * @return true iff the theory contains a cycle */ private boolean dfs(int i, List<Argument> arguments, boolean[] dfn, boolean[] inProgress){ dfn[i] = true; inProgress[i] = true; Set<Argument> attackers = getAttackers(arguments.get(i)); Iterator<Argument> it = attackers.iterator(); while(it.hasNext()){ Argument argument = (Argument) it.next(); if(inProgress[arguments.indexOf(argument)]) return true; else if(!dfn[arguments.indexOf(argument)]) if(dfs(arguments.indexOf(argument),arguments,dfn,inProgress)) return true; } inProgress[i] = false; return false; }
/** * Implements the graded defense function from Def. 5, i.e. * gradedDefense_m_n(X) = { x | there are not more than m different y s.t. * y attacks x and there are not more than n different z s.t. z attacks * y and z is in X} * @param theory a Dung theory * @param args some set of arguments * @param m some integer (indicating the number of attackers) * @param n some integer (indicating the number of attackers of attackers) * @return the set of arguments mn-defended by the given set of arguments */ public Collection<Argument> gradedDefense(DungTheory theory, Collection<Argument> args, int m, int n){ Collection<Argument> result = new HashSet<>(); for(Argument arg: theory){ int num_attackers = 0; for(Argument attacker: theory.getAttackers(arg)) if(this.numOfAttackers(theory,attacker, args) < n) num_attackers++; if(num_attackers < m) result.add(arg); } return result; }
/** * returns true if every attacker on <source>argument</source> is attacked by some * accepted argument wrt. the given theory. * @param argument an argument * @param dungTheory a Dung theory (the knowledge base) * @return true if every attacker on <source>argument</source> is attacked by some * accepted argument wrt. the given theory. */ public boolean isAcceptable(Argument argument, DungTheory dungTheory){ Set<Argument> attackers = dungTheory.getAttackers(argument); Iterator<Argument> it = attackers.iterator(); while (it.hasNext()) if(!dungTheory.isAttacked(it.next(),this.getArgumentsOfStatus(ArgumentStatus.IN))) return false; return true; }
@Override protected PlBeliefSet getPropositionalCharacterisationBySemantics(DungTheory aaf, Map<Argument, Proposition> in, Map<Argument, Proposition> out, Map<Argument, Proposition> undec) { PlBeliefSet beliefSet = new PlBeliefSet(); // an argument is in iff all attackers are out for(Argument a: aaf){ if(aaf.getAttackers(a).isEmpty()){ beliefSet.add(((PropositionalFormula)in.get(a))); }else{ Collection<PropositionalFormula> attackersAnd = new HashSet<PropositionalFormula>();//new Tautology(); Collection<PropositionalFormula> attackersOr = new HashSet<PropositionalFormula>();//new Contradiction(); Collection<PropositionalFormula> attackersNotAnd = new HashSet<PropositionalFormula>();//new Tautology(); Collection<PropositionalFormula> attackersNotOr = new HashSet<PropositionalFormula>();//new Contradiction(); for(Argument b: aaf.getAttackers(a)){ attackersAnd.add(out.get(b)); attackersOr.add(in.get(b)); attackersNotAnd.add((PropositionalFormula)in.get(b).complement()); attackersNotOr.add((PropositionalFormula)out.get(b).complement()); } beliefSet.add(((PropositionalFormula)out.get(a).complement()).combineWithOr(new Disjunction(attackersOr))); beliefSet.add(((PropositionalFormula)in.get(a).complement()).combineWithOr(new Conjunction(attackersAnd))); beliefSet.add(((PropositionalFormula)undec.get(a).complement()).combineWithOr(new Conjunction(attackersNotAnd))); beliefSet.add(((PropositionalFormula)undec.get(a).complement()).combineWithOr(new Disjunction(attackersNotOr))); } } return beliefSet; } }
@Override protected PlBeliefSet getPropositionalCharacterisationBySemantics(DungTheory aaf, Map<Argument, Proposition> in, Map<Argument, Proposition> out, Map<Argument, Proposition> undec) { PlBeliefSet beliefSet = new PlBeliefSet(); // an argument is in iff all attackers are out, and // no argument is undecided for(Argument a: aaf){ PropositionalFormula attackersAnd = new Tautology(); PropositionalFormula attackersOr = new Contradiction(); PropositionalFormula attackersNotAnd = new Tautology(); PropositionalFormula attackersNotOr = new Contradiction(); for(Argument b: aaf.getAttackers(a)){ attackersAnd = attackersAnd.combineWithAnd(out.get(b)); attackersOr = attackersOr.combineWithOr(in.get(b)); attackersNotAnd = attackersNotAnd.combineWithAnd(in.get(b).complement()); attackersNotOr = attackersNotOr.combineWithOr(out.get(b).complement()); } beliefSet.add(((PropositionalFormula)out.get(a).complement()).combineWithOr(attackersOr)); beliefSet.add(((PropositionalFormula)in.get(a).complement()).combineWithOr(attackersAnd)); beliefSet.add((PropositionalFormula)undec.get(a).complement()); } return beliefSet; } }
for(Argument a: ((DungTheory)params.get(GroundedGameGenerator.PARAM_UNIVERSALTHEORY)).getAttackers(rec.getPreimage(vArg))){ if(arguments.contains(a)) if(this.getRandom().nextDouble() <= this.config.percentageVirtualAttacks)