@Override public DungTheory next() { Argument a = new Argument("a"); return this.next(a); }
/** * Returns an argument representation (in Dung-style) * of this LdoArgument. * @return an argument representation (in Dung-style) * of this LdoArgument. */ public Argument getArgument(){ return new Argument(this.getName()); }
/** * Returns a collection view of the given set of arguments * * @param s * some string in the format "[arg1,...,argn]". * @return a collection view of the given arguments */ public static Extension parseArgumentList(String s) { s = s.trim(); if (!s.startsWith("[") || !s.endsWith("]")) throw new IllegalArgumentException("Expected list of arguments but encountered " + s); String s2 = s.substring(1, s.length() - 1); StringTokenizer tokenizer = new StringTokenizer(s2, ","); Extension args = new Extension(); while (tokenizer.hasMoreTokens()) args.add(new Argument(tokenizer.nextToken().trim())); return args; }
@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 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 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; }
/** * 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; }
@Override public DungSignature getSignature() { DungSignature reval = new DungSignature(); reval.add(new Argument(this.predicate.getName())); return reval; }
@Override public Boolean query(ABATheory<T> beliefbase, Assumption<T> query, InferenceMode inferenceMode) { Argument arg = new Argument(query.getConclusion().toString()); DungTheory dt = beliefbase.asDungTheory(); AbstractExtensionReasoner aer = AbstractExtensionReasoner.getSimpleReasonerForSemantics(semantics); return aer.query(dt,arg,inferenceMode); }
/** * @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; }
/** * 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 Extension getModel(DungTheory bbase) { // returns the first found model PlBeliefSet prop = this.getPropositionalCharacterisation(bbase); PossibleWorld w = (PossibleWorld) this.solver.getWitness(prop); if(w == null) return null; Extension ext = new Extension(); for(Proposition p: w){ if(p.getName().startsWith("in_")) ext.add(new Argument(p.getName().substring(3))); } return ext; } }
@Override public Collection<Extension> getModels(DungTheory bbase) { PlBeliefSet prop = this.getPropositionalCharacterisation(bbase); // get some labeling from the solver, then add the negation of this to the program and repeat // to obtain all labelings Set<Extension> result = new HashSet<Extension>(); Extension ext; do{ PossibleWorld w = (PossibleWorld) this.solver.getWitness(prop); if(w == null) break; ext = new Extension(); for(Proposition p: w){ if(p.getName().startsWith("in_")) ext.add(new Argument(p.getName().substring(3))); } result.add(ext); // add the newly found extension in negative form to prop // so the next witness cannot be the same Collection<PropositionalFormula> f = new HashSet<PropositionalFormula>(); for(Proposition p: w) f.add(p); prop.add(new Negation(new Conjunction(f))); }while(true); return result; }
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); } } }
@Override public GroundedGameSystem generate(SimulationParameters params) { log.info("Starting to generate a grounded game system"); Argument arg = new Argument("A"); DungTheory theory = this.gen.next(arg); log.trace("Generated Dung theory with " + this.gen + ":\n" +
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 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; }
@Override public LotteryGameSystem generate(SimulationParameters params) { DungTheory theory; if(this.ensureArg){ Argument arg = new Argument("A"); theory = this.gen.next(arg); params.put(LotteryGameGenerator.PARAM_ARGUMENT, arg); }else{ theory = this.gen.next(); } params.put(LotteryGameGenerator.PARAM_SEM, this.semantics); params.put(LotteryGameGenerator.PARAM_UNIVERSALTHEORY, theory); // random utility function UtilityFunction util = new UtilityFunction(); for(Division d: Division.getStandardDivisions(theory)) util.put(d, random.nextDouble()); params.put(LotteryGameGenerator.PARAM_LOT_UTIL, util); // random probability function SubgraphProbabilityFunction prob = new SubgraphProbabilityFunction(theory); for(DungTheory t: prob.keySet()) prob.put(t, new Probability(random.nextDouble())); prob.normalize(); params.put(LotteryGameGenerator.PARAM_LOT_PROB, prob); // sample some random theory params.put(LotteryGameGenerator.PARAM_DUMMY_THEORY, prob.sample(this.random)); return new LotteryGameSystem(theory); }