/** * 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 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())))); }
/** * 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)); } }
public ExecutableDungTheory next(Collection<? extends Perceivable> percepts) { double bestUtility = Double.NEGATIVE_INFINITY; DungTheory e = new DungTheory(); for(Graph<Argument> subgraph: this.theory.getSubgraphs()){ DungTheory sub = new DungTheory(subgraph); Double d = this.util.getUtility(sub, this.semantics); if(d > bestUtility){ bestUtility = d; e = sub; } } return new ExecutableDungTheory(e); }
/** * Checks whether the given set of divisions is exhaustive wrt. the given theory. * @param divisions a set of divisions. * @param theory some aaf. * @param semantics some semantics * @return "true" if the given set of divisions is exhaustive. */ public static boolean isExhaustive(Collection<Division> divisions, DungTheory theory, Semantics semantics){ Collection<Graph<Argument>> subgraphs = theory.getSubgraphs(); // convert to Dung theories Collection<DungTheory> subtheories = new HashSet<DungTheory>(); for(Graph<Argument> g: subgraphs) subtheories.add(new DungTheory(g)); for(Division d: divisions){ subtheories.removeAll(d.getDividers(theory, semantics)); } return subtheories.isEmpty(); }
@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; } }
/** * Returns the dividers for this formula, i.e. all sub-theories of the given * theory such that this formula is satisfied by this sub-theory. * @param theory some argumentation framework * @param semantics some semantics * @return the set of dividers of this formula */ public Collection<DungTheory> getDividers(DungTheory theory, Semantics semantics){ Collection<DungTheory> result = new HashSet<DungTheory>(); for(Graph<Argument> g: theory.getSubgraphs()){ DungTheory sub = new DungTheory(g); LdoInterpretation i = new LdoInterpretation(sub,semantics); if(i.satisfies(this)) result.add(sub); } return result; }
@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; }
@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; }
/** * 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; }
@Override public double getUtility(DialogueTrace<Argument,Extension> trace) { DungTheory theory = new DungTheory(this.theory.getRestriction(trace.getElements())); Extension groundedExtension = new SimpleGroundedReasoner().getModel(theory); return this.getUtility(groundedExtension, trace); }
@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; }
/** * @return a Dung Theory derived from this ABA theory */ public DungTheory asDungTheory() { if (!isFlat()) throw new RuntimeException("Only flat ABA theories can be transformed into Dung theories."); Collection<Deduction<T>> ds = getAllDeductions(); int id = 0; DungTheory dt = new DungTheory(); Map<Deduction<T>, Argument> argmap = new HashMap<>(); for (Deduction<T> d : ds) { Argument arg = d.getRule() instanceof Assumption<?> ? new Argument(d.getConclusion().toString()) : new Argument("arg_" + id++); dt.add(arg); argmap.put(d, arg); } for (Deduction<T> atter : ds) for (Deduction<T> atted : ds) for (T ass : atted.getAssumptions()) if (attacks(atter, ass)) { dt.add(new Attack(argmap.get(atter), argmap.get(atted))); break; } return dt; }
@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); }
/** * Returns the dividers for this division, i.e. all sub-theories of the given * theory such that this division is in that sub-theories set of divisions. * @param theory some argumentation framework * @param semantics some semantics * @return the set of dividers of this devision */ public Collection<DungTheory> getDividers(DungTheory theory, Semantics semantics){ Collection<DungTheory> result = new HashSet<DungTheory>(); Collection<Graph<Argument>> subtheories = theory.getSubgraphs(); for(Graph<Argument> g: subtheories){ DungTheory sub = new DungTheory(g); for(Division d: Division.getDivisions(AbstractExtensionReasoner.getSimpleReasonerForSemantics(semantics).getModels(sub), sub)){ if(d.getFirst().equals(this.getFirst())){ Extension e = new Extension(this.getSecond()); e.retainAll(sub); if(e.equals(d.getSecond())) result.add(sub); } } } return result; }
@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; }
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()); }
/** * This method translates this delp into an abstract Dung theory. All arguments, that can * be built in this theory are interpreted as abstract arguments. The attack relation is built using * the dialectical proof theory of delp. * @return the abstract Dung theory induced by this delp. */ public DungTheory getDungTheory(){ DungTheory dungTheory = new DungTheory(); for (DelpArgument arg1 : getArguments()) { //add arguments dungTheory.add(new Argument(arg1.toString())); //add attacks for (DelpArgument arg2 : getArguments()) { if (arg1.getDisagreementSubargument(arg2.getConclusion(), this) != null) { dungTheory.add(new Attack(new Argument(arg2.toString()), new Argument(arg1.toString()))); } } } return dungTheory; }
public static void main(String[] args){ // create some Dung theory DungTheory theory = new DungTheory(); Argument a = new Argument("a"); Argument b = new Argument("b"); Argument c = new Argument("c"); Argument d = new Argument("d"); //Argument e = new Argument("e"); theory.add(a); theory.add(b); theory.add(c); theory.add(d); //theory.add(e); theory.add(new Attack(a,b)); theory.add(new Attack(b,a)); theory.add(new Attack(b,c)); theory.add(new Attack(c,b)); theory.add(new Attack(d,c)); theory.add(new Attack(c,d)); StratifiedLabelingReasoner reasoner = new StratifiedLabelingReasoner(Semantics.STABLE_SEMANTICS); for(StratifiedLabeling labeling: reasoner.getModels(theory)){ System.out.println(labeling); } } }
public static void main(String[] args){ // create some Dung theory DungTheory theory = new DungTheory(); Argument a = new Argument("a"); Argument b = new Argument("b"); Argument c = new Argument("c"); Argument d = new Argument("d"); Argument e = new Argument("e"); Argument f = new Argument("f"); theory.add(a); theory.add(b); theory.add(c); theory.add(d); theory.add(e); theory.add(f); theory.add(new Attack(a,b)); theory.add(new Attack(b,c)); theory.add(new Attack(c,d)); theory.add(new Attack(d,e)); theory.add(new Attack(e,a)); theory.add(new Attack(e,f)); SimpleCF2Reasoner reasoner = new SimpleCF2Reasoner(); for(Extension ext: reasoner.getModels(theory)){ System.out.println(ext); } } }