@Override public Graph<Argument> getRestriction(Collection<Argument> arguments) { DungTheory theory = new DungTheory(); theory.addAll(arguments); for (Attack attack: this.getAttacks()) if(arguments.contains(attack.getAttacked()) && arguments.contains(attack.getAttacker())) theory.add(attack); return theory; }
@Override public double getUtility(DialogueTrace<Argument,Extension> trace, Set<Argument> additionalArguments, Set<Attack> additionalAttacks){ DungTheory theory = new DungTheory(this.theory.getRestriction(trace.getElements())); theory.addAll(additionalArguments); theory.addAllAttacks(additionalAttacks); Extension groundedExtension = new SimpleGroundedReasoner().getModel(theory); return this.getUtility(groundedExtension, trace); }
/** * Checks whether "arg1" indirectly attacks "arg2", i.e. whether there * is an odd-length path from "arg1" to "arg2". * @param arg1 an AbstractArgument. * @param arg2 an AbstractArgument. * @param visited already visited arguments. * @return "true" iff "arg1" indirectly attacks "arg2". */ private boolean isIndirectAttack(Argument arg1, Argument arg2, Set<Argument> visited){ if(this.isAttackedBy(arg2,arg1)) return true; visited.add(arg1); Set<Argument> attackedArguments = this.getAttacked(arg1); attackedArguments.removeAll(visited); for(Argument attacked : attackedArguments){ if(this.isSupport(attacked, arg2)) return true; } return false; }
/** * Adds all arguments and attacks of the given theory to * this theory * @param theory some Dung theory * @return "true" if this Dung Theory has been modified */ public boolean add(DungTheory theory){ boolean b1 = this.addAll(theory); boolean b2 = this.addAllAttacks(theory.getAttacks()); return b1 || b2 ; }
/** * Returns the view of the universal Dung theory restricted to * the given set of arguments. * @param arguments a set of arguments. * @return the projection of the universal theory. */ public DungTheory getPerceivedDungTheory(Extension arguments){ return new DungTheory(this.universalTheory.getRestriction(arguments)); } }
@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; }
@Override public DungTheory next() { if(this.params.enforceTreeShape) return this.generateTreeShape(new Argument("a")); DungTheory theory = new DungTheory(); for(int i = 0; i < this.params.numberOfArguments; i++) theory.add(new Argument("a" + i)); for(Argument a: theory) for(Argument b: theory){ if(a == b && this.params.avoidSelfAttacks) continue; if(this.random.nextDouble() <= this.params.attackProbability) theory.add(new Attack(a,b)); } return theory; }
for(Argument a: theory){ for(Argument b: theory){ if(!theory.isAttackedBy(b, a)){ DungTheory newTheory = new DungTheory(); newTheory.addAll(theory); newTheory.addAllAttacks(theory.getAttacks()); newTheory.add(new Attack(a,b)); if(!this.isIsomorphic(newTheory, newTheories)) newTheories.add(newTheory); DungTheory theory = new DungTheory(); for(int i = 0; i < this.cntArguments; i++) theory.add(new Argument("A"+i)); this.currentTheories.clear(); this.currentTheories.add(theory);
@Override public ExecutableDungTheory next(Collection<? extends Perceivable> percepts) { List<Graph<Argument>> allSub = new LinkedList<Graph<Argument>>(this.theory.getSubgraphs()); Random rand = new Random(); return new ExecutableDungTheory(new DungTheory(allSub.get(rand.nextInt(allSub.size())))); }
@Override public DungTheory parse(Reader reader) throws IOException { DungTheory theory = new DungTheory(); BufferedReader in = new BufferedReader(reader); String row = null; boolean argumentSection = true; Map<String,Argument> arguments = new HashMap<String,Argument>(); while ((row = in.readLine()) != null) { if(row.trim().equals("")) continue; if(row.trim().equals("#")){ argumentSection = false; continue; } if(argumentSection) { Argument a = new Argument(row.trim()); arguments.put(a.getName(), a); theory.add(a); } else{ theory.addAttack(arguments.get(row.substring(0, row.indexOf(" ")).trim()),arguments.get(row.substring(row.indexOf(" ")+1,row.length()).trim())); } } in.close(); return theory; } }
@Override public DungTheory parse(Reader reader) throws IOException { DungTheory theory = new DungTheory(); int numArgs = -1; int numAtt = -1; attacker = row.substring(0,row.indexOf(" ")).trim(); attacked = row.substring(row.indexOf("-")+1, row.lastIndexOf("0")).trim(); theory.add(new Argument("a" + attacker)); theory.add(new Argument("a" + attacked)); theory.add(new Attack(new Argument("a" + attacker),new Argument("a" + attacked))); if(theory.size() != numArgs || theory.getAttacks().size() != numAtt) throw new IOException("Illegal number of arguments and/or attacks."); return theory;
@Override public DungTheory getComplementGraph(int selfloops) { DungTheory comp = new DungTheory(); for(Argument node: this) comp.add(node); for(Argument node1: this) for(Argument node2: this) if(node1 == node2){ if(selfloops == Graph.INVERT_SELFLOOPS){ if(!this.isAttackedBy(node2, node1)) comp.add(new Attack(node1, node2)); }else if(selfloops == Graph.IGNORE_SELFLOOPS){ if(this.isAttackedBy(node2, node1)) comp.add(new Attack(node1, node2)); } }else if(!this.isAttackedBy(node2, node1)) comp.add(new Attack(node1, node2)); return comp; }
@Override public DungTheory next() { if(this.attacks == null){ this.currentSize = 1; this.arguments = new HashSet<Argument>(); arguments.add(new Argument("A1")); this.possibleAttacks = this.generatePossibleAttacks(arguments); this.attacks = new BitSet(this.possibleAttacks.size()); }else{ if(this.addOneToBitSet(this.attacks, this.possibleAttacks.size())){ this.currentSize++; this.arguments = new HashSet<Argument>(); for(int i = 0; i < this.currentSize;i++) arguments.add(new Argument("A"+i)); this.possibleAttacks = this.generatePossibleAttacks(this.arguments); this.attacks = new BitSet(this.possibleAttacks.size()); } } DungTheory theory = new DungTheory(); theory.addAll(this.arguments); for(int i = 0; i < this.possibleAttacks.size(); i++) if(this.attacks.get(i)) theory.add(this.possibleAttacks.get(i)); return theory; }
/** * Generates a Dung theory with a tree shape where the given argument * is the root. * @param arg some argument. * @return a Dung theory. */ private DungTheory generateTreeShape(Argument arg){ DungTheory theory = new DungTheory(); theory.add(arg); int numOfArguments = 1; Queue<Argument> q = new LinkedList<Argument>(); q.add(arg); while(numOfArguments < this.params.numberOfArguments){ Argument a = new Argument("a" + numOfArguments++); theory.add(new Attack(a, (Argument)theory.toArray()[this.random.nextInt(numOfArguments-1)])); theory.add(a); } return theory; }
public Double getUtility(Agent agent){ DungTheory theory = new DungTheory(); // get theory of audience for(Agent b: this.getMultiAgentSystem()) if(b instanceof DummyLotteryAgent){ theory.addAll(((DummyLotteryAgent)b).getTheory()); theory.addAllAttacks(((DummyLotteryAgent)b).getTheory().getAttacks()); break; } // get disclosed arguments and attacks for(DungTheory action: ((LotteryArgumentationEnvironment)this.getMultiAgentSystem().getEnvironment()).getDialogueTrace().getElements()){ theory.addAll(action); theory.addAllAttacks(action.getAttacks()); } // get utility return ((AbstractLotteryAgent)agent).getUtility(theory, ((AbstractLotteryAgent)agent).getSemantics()); }
public static void main(String[] args){ DungTheory theory = new DungTheory(); Argument a = new Argument("a"); Argument b = new Argument("b"); Argument f = new Argument("f"); Argument g = new Argument("g"); theory.add(a); theory.add(b); theory.add(c); theory.add(d); theory.add(e); theory.add(f); theory.add(g); theory.add(new Attack(d,c)); theory.add(new Attack(c,a)); theory.add(new Attack(a,b)); theory.add(new Attack(b,a)); theory.add(new Attack(e,b)); theory.add(new Attack(f,e)); theory.add(new Attack(g,e)); for(int m = 1; m < theory.size(); m++) for(int n = 1; n < theory.size(); n++) System.out.println(m + "," + n + " : " + reasoner.getAllMNCompleteExtensions(theory,m, n));
@Override public DungTheory next(Argument arg){ DungTheory theory = new DungTheory(); if(this.params.enforceTreeShape){ boolean inExtension = false; do{ theory = this.generateTreeShape(arg); inExtension = new SimpleGroundedReasoner().query(theory,arg); }while(!inExtension); return theory; } theory.add(arg); for(int i = 1; i < this.params.numberOfArguments; i++) theory.add(new Argument("a" + i)); for(Argument a: theory) for(Argument b: theory){ if(a == b && this.params.avoidSelfAttacks) continue; if(this.random.nextDouble() <= this.params.attackProbability){ Attack att = new Attack(a,b); theory.add(att); //Check whether this makes the argument out if(!new SimpleGroundedReasoner().query(theory,arg)) theory.remove(att); } } return theory; }
DungTheory af = new DungTheory(); af.add(new SimplePlLogicArgument(derivation)); for (Argument arga : af.getNodes()){ for (Argument argb: af.getNodes()){ SimplePlLogicArgument larga = (SimplePlLogicArgument)arga; SimplePlLogicArgument largb = (SimplePlLogicArgument)argb; af.add(new Attack(arga, argb)); for (PropositionalFormula p : r.getPremise()){ if (!solver.isConsistent((PropositionalFormula)(larga.getClaim()).combineWithAnd(p))){ af.add(new Attack(arga, argb));
DungTheory subTheory = (DungTheory) theory.getRestriction(sccs.get(idx)); subTheory.removeAll(out); subTheory.add(aux); subTheory.add(new Attack(aux,aux)); for(Argument a: subTheory) if(theory.isAttacked(a, new Extension(undec))) subTheory.add(new Attack(aux,a)); new_in.addAll(ext); for(Argument a: ext) attacked.addAll(theory.getAttacked(a)); new_out.addAll(attacked); for(Argument a: subTheory)
refArgsUpper.add(a.getArgument()); if(formula instanceof LdoGraphBoxModality){ for(Graph<Argument> t: theory.getSubgraphs()){ DungTheory th = new DungTheory(t); if(th.containsAll(refArgsLower) && refArgsUpper.containsAll(th)){ LdoInterpretation i = new LdoInterpretation(th, this.ext, this.sem); if(!i.satisfies(innerFormula)) for(Graph<Argument> t: theory.getSubgraphs()){ DungTheory th = new DungTheory(t); if(th.containsAll(refArgsLower) && refArgsUpper.containsAll(th)){ LdoInterpretation i = new LdoInterpretation(th, this.ext, this.sem); if(i.satisfies(innerFormula)) LdoFormula left = ((LdoRelation)formula).getLeft(); LdoFormula right = ((LdoRelation)formula).getRight(); for(Graph<Argument> t: theory.getSubgraphs()){ for(Attack a: theory.getAttacks()){ if(t.contains(a.getAttacked()) && t.contains(a.getAttacker())){ if(!t.areAdjacent(a.getAttacker(), a.getAttacked())){ DungTheory th = new DungTheory(t); LdoInterpretation i = new LdoInterpretation(th,this.ext,this.sem); if(i.satisfies(left) && !i.satisfies(right))