/** * Computes all possible attacks. * @param arguments some set of arguments * @return the set of all possible attacks. */ private List<Attack> generatePossibleAttacks(Set<Argument> arguments){ List<Attack> result = new LinkedList<Attack>(); for(Argument a: arguments) for(Argument b: arguments) result.add(new Attack(a,b)); return result; }
/** * Checks whether this theory contains the given attack. * @param att some attack * @return "true" iff this theory contains the given attack. */ public boolean containsAttack(Attack att) { if(this.parents.get(att.getAttacked()) == null) return false; return this.parents.get(att.getAttacked()).contains(att.getAttacker()); }
/** * returns the attacking argument of this attack relation. * @return the attacking argument of this attack relation. */ public Argument getAttacker() { return this.getNodeA(); }
/** * returns the attacked argument of this attack relation. * @return the attacked argument of this attack relation. */ public Argument getAttacked() { return this.getNodeB(); }
/** * Returns all attacks of this theory. * @return all attacks of this theory. */ public Set<Attack> getAttacks(){ Set<Attack> attacks = new HashSet<Attack>(); for(Argument a: this) { if(this.children.containsKey(a)) { for(Argument b: this.children.get(a)) attacks.add(new Attack(a,b)); } } return attacks; }
/** * Removes the given attack from this Dung theory. * @param attack an attack * @return "true" if the set of attacks has been modified. */ public boolean remove(Attack attack){ boolean result = false; if(parents.containsKey(attack.getAttacked())) result |= parents.get(attack.getAttacked()).remove(attack.getAttacker()); if(children.containsKey(attack.getAttacker())) result |= children.get(attack.getAttacker()).remove(attack.getAttacked()); return result; }
@Override public Edge<Argument> getEdge(Argument a, Argument b) { if(this.isAttackedBy(b, a)) return new Attack(a, b); return null; }
/** * Adds the given attack to this dung theory. * @param attack an attack * @return "true" if the set of attacks has been modified. */ public boolean add(Attack attack){ return this.addAttack(attack.getAttacker(), attack.getAttacked()); }
theory.add(new Argument("a" + attacker)); theory.add(new Argument("a" + attacked)); theory.add(new Attack(new Argument("a" + attacker),new Argument("a" + attacked)));
public boolean equals(Object o){ if(!o.getClass().equals(this.getClass())) return false; if(!this.getAttacker().equals(((Attack)o).getAttacker())) return false; if(!this.getAttacked().equals(((Attack)o).getAttacked())) return false; return true; }
@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; }
/** * Return true if the given argument is in this attack relation. * @param argument some argument * @return true if the given argument is in this attack relation. */ public boolean contains(Argument argument){ return this.getAttacked().equals(argument) || this.getAttacker().equals(argument); }
@Override public Set<Perceivable> execute(Executable action) { if(!(action instanceof Extension)) throw new IllegalArgumentException("SasEnvironment expects action of type 'Extension'."); Extension e = (Extension) action; if(!(this.saf.containsAll(e))) throw new IllegalArgumentException("Action contains unknown arguments."); this.commonView.addAll(e); for(Argument a: this.commonView){ for(Argument b: this.commonView) if(saf.isAttackedBy(a, b)) this.commonView.add(new Attack(b,a)); } return this.getPercepts(null); }
public String toString(){ return "("+this.getAttacker().toString()+","+this.getAttacked().toString()+")"; }
/** * 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 int hashCode(){ return this.getAttacked().hashCode() + 7 * this.getAttacker().hashCode(); }
theory.add(b); theory.add(c); theory.add(new Attack(b,c)); theory.add(new Attack(c,b)); theory.add(new Attack(b,arg)); theory.add(new Attack(c,arg)); theory.add(bn); theory.add(cn); theory.add(new Attack(bn,b)); theory.add(new Attack(cn,c)); b = new Argument("b" + idx); c = new Argument("c" + idx); theory.add(b); theory.add(c); theory.add(new Attack(b,bn)); theory.add(new Attack(b,cn)); theory.add(new Attack(b,c)); theory.add(new Attack(c,b)); theory.add(new Attack(c,bn)); theory.add(new Attack(c,cn)); idx++; theory.add(new Attack(d,b)); theory.add(new Attack(d,c)); return theory;
@Override public void write(DungTheory aaf, File f) throws IOException { PrintWriter writer = new PrintWriter(f, "UTF-8"); writer.println("p af " + aaf.size() + " " + aaf.getAttacks().size()); Map<Argument,Integer> map = new HashMap<Argument,Integer>(); int idx = 1; for(Argument arg: aaf) map.put(arg, idx++); for(Attack att: aaf.getAttacks()) writer.println(map.get(att.getAttacker()) + " -" + map.get(att.getAttacked()) + " 0"); writer.close(); } }
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); } } }
@Override public void write(DungTheory aaf, File f) throws IOException { PrintWriter writer = new PrintWriter(f, "UTF-8"); for(Argument a: aaf) writer.println(a.getName()); writer.println("#"); for(Attack att: aaf.getAttacks()) writer.println(att.getAttacker().getName() + " " + att.getAttacked().getName()); writer.close(); }