Skip to content

Commit cc647cc

Browse files
author
“jklein94”
committed
Added missing javadoc EafReasonerExample.java
1 parent c872a0c commit cc647cc

1 file changed

Lines changed: 115 additions & 100 deletions

File tree

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/examples/EafReasonerExample.java

Lines changed: 115 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -35,108 +35,123 @@
3535

3636

3737
/**
38-
*
38+
* Demonstrates the use of {@link EpistemicArgumentationFramework} (EAF) with various
39+
* logical constraints and how they affect argument justification under different semantics.
40+
*
41+
* <p>This example includes:
42+
* <ul>
43+
* <li>Defining a shared Dung theory with several mutually attacking arguments</li>
44+
* <li>Creating multiple EAFs with different epistemic constraints</li>
45+
* <li>Computing epistemic labelling sets under stable, grounded, and preferred semantics</li>
46+
* <li>Using simple EAF reasoners to compute extensions and argument justification statuses</li>
47+
* <li>Checking constraint strength and its impact on the resulting labelling sets</li>
48+
* </ul>
49+
*
50+
* <p>This class illustrates both declarative modeling of agent beliefs and procedural
51+
* reasoning using the provided reasoners.
3952
*/
4053
public class EafReasonerExample {
4154

42-
/**
43-
* @param args
44-
* @throws IOException
45-
* @throws ParserException
46-
*/
47-
public static void main(String[] args) throws ParserException, IOException {
48-
Argument a = new Argument("a");
49-
Argument b = new Argument("b");
50-
Argument c = new Argument("c");
51-
Argument d = new Argument("d");
52-
53-
String constEAF1 = "<>(in(b))";
54-
String constEAF2 = "[](in(a))||[](in(b))";
55-
String constEAF3 = "<>(in(c))=>[](in(a))";
56-
String constEAF4 = "(<>(in(c))=>[](in(a))) && [](in(d))";
57-
String constEAF5 = "(<>(in(c))=>[](in(a))) && [](in(d)) && [](out(a))";
58-
String constEAF6 = "[](und(b))";
59-
60-
61-
DungTheory af = new DungTheory();
62-
63-
af.add(a);
64-
af.add(b);
65-
af.add(c);
66-
af.add(d);
67-
68-
69-
af.addAttack(a,b);
70-
af.addAttack(b,a);
71-
af.addAttack(c,b);
72-
af.addAttack(c,d);
73-
af.addAttack(d,c);
74-
75-
76-
//Create EAFs
77-
EpistemicArgumentationFramework eaf1 = new EpistemicArgumentationFramework(af, constEAF1);
78-
EpistemicArgumentationFramework eaf2 = new EpistemicArgumentationFramework(af, constEAF2);
79-
EpistemicArgumentationFramework eaf3 = new EpistemicArgumentationFramework(af, constEAF3);
80-
EpistemicArgumentationFramework eaf4 = new EpistemicArgumentationFramework(af, constEAF4);
81-
EpistemicArgumentationFramework eaf5 = new EpistemicArgumentationFramework(af, constEAF5);
82-
EpistemicArgumentationFramework eaf6 = new EpistemicArgumentationFramework(af, constEAF6);
83-
84-
//Get epistemic labelling sets for specified semantics
85-
86-
System.out.print("The EAF: \n"+ eaf1.prettyPrint() +"\n\nhas the following stable labelling set:");
87-
System.out.println(eaf1.getWEpistemicLabellingSets(Semantics.ST));
88-
System.out.print("and the following grounded labelling set:");
89-
System.out.println(eaf1.getWEpistemicLabellingSets(Semantics.GR));
90-
91-
System.out.print("\nThe EAF with the same underlying AF and the constraint "+ eaf2.getConstraint()+" has the following stable labelling sets:");
92-
System.out.println(eaf2.getWEpistemicLabellingSets(Semantics.ST));
93-
System.out.print("and the following grounded labelling set:");
94-
System.out.println(eaf2.getWEpistemicLabellingSets(Semantics.GR));
95-
96-
System.out.print("\nThe EAF with the same underlying AF and the constraint "+ eaf3.getConstraint()+" has the following stable labelling sets:");
97-
System.out.println(eaf3.getWEpistemicLabellingSets(Semantics.ST));
98-
System.out.print("and the following grounded labelling set:");
99-
System.out.println(eaf3.getWEpistemicLabellingSets(Semantics.GR));
100-
101-
System.out.print("\nThe EAF with the same underlying AF and the constraint "+ eaf4.getConstraint()+" has the following stable labelling sets:");
102-
System.out.println(eaf4.getWEpistemicLabellingSets(Semantics.ST));
103-
System.out.print("and the following grounded labelling set:");
104-
System.out.println(eaf4.getWEpistemicLabellingSets(Semantics.GR));
105-
106-
System.out.print("\nThe EAF with the same underlying AF and the constraint "+ eaf5.getConstraint()+" has the following stable labelling sets:");
107-
System.out.println(eaf5.getWEpistemicLabellingSets(Semantics.ST));
108-
109-
System.out.print("The EAF with the same underlying AF and the constraint "+ eaf6.getConstraint()+" has the following preferred labelling sets:");
110-
System.out.println(eaf6.getWEpistemicLabellingSets(Semantics.PR));
111-
112-
113-
System.out.println("\n\nSimple Reasoners for different semantics can be used to find extensions, that satisfy the underlying constraint of an EAF.");
114-
System.out.println("Note that Reasoners do not return epistemic labelling sets.");
115-
116-
117-
//Reasoners can be created using the abstract superclass
118-
AbstractEAFReasoner eafReasoner = AbstractEAFReasoner.getSimpleReasonerForSemantics(EAFSemantics.EAF_PR);
119-
//Or by instantiating a reasoner for the required semantics
120-
SimpleEAFPreferredReasoner eafPr = new SimpleEAFPreferredReasoner();
121-
Collection<Extension<EpistemicArgumentationFramework>> eafPrSets = eafReasoner.getModels(eaf1);
122-
System.out.print("The extensions of the EAF that satisfy its constraint "+ eaf1.getConstraint()+" are:");
123-
System.out.println(eafPrSets);
124-
System.out.println("\nSimple Reasoners can also be used to compute the acceptance status of an argument");
125-
System.out.println("Credulous justification status of each argument under preferred semantics:");
126-
for(Argument arg: eaf1) {
127-
System.out.println(arg +": " + eafPr.query(eaf1, arg, InferenceMode.CREDULOUS));
128-
}
129-
130-
131-
//You can check whether a constraint is stronger, than the underlying constraint of an eaf.
132-
//A constraint φ₁ is stronger than φ₂ if it holds that whenever a set of labelings SL satisfies φ₁, it also satisfies φ₂.
133-
System.out.print("\n\nThe constraint " + constEAF5 +" is stronger than " + constEAF4+":");
134-
System.out.println(eaf4.isStrongerConstraint(constEAF5, Semantics.ST));
135-
System.out.println("Introducing a stronger constraint thus eliminates elements of epistemic labeling sets");
136-
System.out.print("\nThe EAF with the weaker constraint "+ eaf4.getConstraint()+" has the following stable labelling sets:");
137-
System.out.println(eaf4.getWEpistemicLabellingSets(Semantics.ST));
138-
System.out.print("The EAF with the stronger constraint "+ eaf5.getConstraint()+" has the following stable labelling sets:");
139-
System.out.println(eaf5.getWEpistemicLabellingSets(Semantics.ST));
140-
}
55+
/**
56+
* Entry point of the example program demonstrating epistemic argumentation reasoning.
57+
*
58+
* <p>Creates several epistemic argumentation frameworks (EAFs) based on a common Dung theory
59+
* and evaluates how different logical constraints affect the argument labellings. It uses:
60+
* <ul>
61+
* <li>{@link EpistemicArgumentationFramework#getWEpistemicLabellingSets(Semantics)} to compute labellings</li>
62+
* <li>{@link AbstractEAFReasoner} and {@link SimpleEAFPreferredReasoner} to compute extensions and acceptance statuses</li>
63+
* <li>{@link EpistemicArgumentationFramework#isStrongerConstraint(String, Semantics)} to compare constraint strength</li>
64+
* </ul>
65+
*
66+
* @param args command-line arguments (not used)
67+
* @throws IOException if an error occurs while parsing the EAF constraints
68+
* @throws ParserException if any constraint formula is invalid or cannot be parsed
69+
*/
70+
public static void main(String[] args) throws ParserException, IOException {
71+
Argument a = new Argument("a");
72+
Argument b = new Argument("b");
73+
Argument c = new Argument("c");
74+
Argument d = new Argument("d");
14175

76+
String constEAF1 = "<>(in(b))";
77+
String constEAF2 = "[](in(a))||[](in(b))";
78+
String constEAF3 = "<>(in(c))=>[](in(a))";
79+
String constEAF4 = "(<>(in(c))=>[](in(a))) && [](in(d))";
80+
String constEAF5 = "(<>(in(c))=>[](in(a))) && [](in(d)) && [](out(a))";
81+
String constEAF6 = "[](und(b))";
82+
83+
DungTheory af = new DungTheory();
84+
af.add(a);
85+
af.add(b);
86+
af.add(c);
87+
af.add(d);
88+
af.addAttack(a, b);
89+
af.addAttack(b, a);
90+
af.addAttack(c, b);
91+
af.addAttack(c, d);
92+
af.addAttack(d, c);
93+
94+
// Create EAFs
95+
EpistemicArgumentationFramework eaf1 = new EpistemicArgumentationFramework(af, constEAF1);
96+
EpistemicArgumentationFramework eaf2 = new EpistemicArgumentationFramework(af, constEAF2);
97+
EpistemicArgumentationFramework eaf3 = new EpistemicArgumentationFramework(af, constEAF3);
98+
EpistemicArgumentationFramework eaf4 = new EpistemicArgumentationFramework(af, constEAF4);
99+
EpistemicArgumentationFramework eaf5 = new EpistemicArgumentationFramework(af, constEAF5);
100+
EpistemicArgumentationFramework eaf6 = new EpistemicArgumentationFramework(af, constEAF6);
101+
102+
// Print labelling sets for various semantics
103+
System.out.print("The EAF: \n" + eaf1.prettyPrint() + "\n\nhas the following stable labelling set: ");
104+
System.out.println(eaf1.getWEpistemicLabellingSets(Semantics.ST));
105+
System.out.print("and the following grounded labelling set: ");
106+
System.out.println(eaf1.getWEpistemicLabellingSets(Semantics.GR));
107+
108+
System.out.print("\nThe EAF with constraint " + eaf2.getConstraint() + " has the following stable labelling sets: ");
109+
System.out.println(eaf2.getWEpistemicLabellingSets(Semantics.ST));
110+
System.out.print("and the following grounded labelling set: ");
111+
System.out.println(eaf2.getWEpistemicLabellingSets(Semantics.GR));
112+
113+
System.out.print("\nThe EAF with constraint " + eaf3.getConstraint() + " has the following stable labelling sets: ");
114+
System.out.println(eaf3.getWEpistemicLabellingSets(Semantics.ST));
115+
System.out.print("and the following grounded labelling set: ");
116+
System.out.println(eaf3.getWEpistemicLabellingSets(Semantics.GR));
117+
118+
System.out.print("\nThe EAF with constraint " + eaf4.getConstraint() + " has the following stable labelling sets: ");
119+
System.out.println(eaf4.getWEpistemicLabellingSets(Semantics.ST));
120+
System.out.print("and the following grounded labelling set: ");
121+
System.out.println(eaf4.getWEpistemicLabellingSets(Semantics.GR));
122+
123+
System.out.print("\nThe EAF with constraint " + eaf5.getConstraint() + " has the following stable labelling sets: ");
124+
System.out.println(eaf5.getWEpistemicLabellingSets(Semantics.ST));
125+
126+
System.out.print("The EAF with constraint " + eaf6.getConstraint() + " has the following preferred labelling sets: ");
127+
System.out.println(eaf6.getWEpistemicLabellingSets(Semantics.PR));
128+
129+
System.out.println("\n\nSimple Reasoners for different semantics can be used to find extensions that satisfy the EAF constraint.");
130+
System.out.println("Note that Reasoners do not return epistemic labelling sets.");
131+
132+
// Use Reasoners
133+
AbstractEAFReasoner eafReasoner = AbstractEAFReasoner.getSimpleReasonerForSemantics(EAFSemantics.EAF_PR);
134+
SimpleEAFPreferredReasoner eafPr = new SimpleEAFPreferredReasoner();
135+
136+
Collection<Extension<EpistemicArgumentationFramework>> eafPrSets = eafReasoner.getModels(eaf1);
137+
System.out.print("The extensions of the EAF that satisfy its constraint " + eaf1.getConstraint() + " are: ");
138+
System.out.println(eafPrSets);
139+
140+
System.out.println("\nSimple Reasoners can also compute the acceptance status of individual arguments.");
141+
System.out.println("Credulous justification status of each argument under preferred semantics:");
142+
for (Argument arg : eaf1) {
143+
System.out.println(arg + ": " + eafPr.query(eaf1, arg, InferenceMode.CREDULOUS));
144+
}
145+
146+
// Check constraint strength
147+
System.out.print("\n\nThe constraint " + constEAF5 + " is stronger than " + constEAF4 + ": ");
148+
System.out.println(eaf4.isStrongerConstraint(constEAF5, Semantics.ST));
149+
150+
System.out.println("Introducing a stronger constraint eliminates elements of the epistemic labelling set.");
151+
System.out.print("\nThe EAF with the weaker constraint " + eaf4.getConstraint() + " has the following stable labelling sets: ");
152+
System.out.println(eaf4.getWEpistemicLabellingSets(Semantics.ST));
153+
System.out.print("The EAF with the stronger constraint " + eaf5.getConstraint() + " has the following stable labelling sets: ");
154+
System.out.println(eaf5.getWEpistemicLabellingSets(Semantics.ST));
155+
}
142156
}
157+

0 commit comments

Comments
 (0)