Skip to content

Commit 728fa49

Browse files
Refactor SimpleEAFReasoners and Bugfixes
1 parent 1b31bbb commit 728fa49

9 files changed

Lines changed: 91 additions & 141 deletions

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ public static void main(String[] args) throws Exception {
4949

5050
String constEAF1 = "[](in(a))";
5151
String constEAF2 = "[](und(a))";
52+
53+
5254
EpistemicArgumentationFramework eaf1 = new EpistemicArgumentationFramework(af, constEAF1);
53-
EpistemicArgumentationFramework eaf2 = new EpistemicArgumentationFramework(af, constEAF2);
55+
EpistemicArgumentationFramework eaf2 = new EpistemicArgumentationFramework(af, constEAF2);
56+
5457

5558
EAFAgreementReasoner agreementReasoner = new EAFAgreementReasoner(eaf1);
5659

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public static void main(String[] args) throws ParserException, IOException {
112112

113113
System.out.println("\n\nSimple Reasoners for different semantics can be used to find extensions, that satisfy the underlying constraint of an EAF.");
114114
System.out.println("Note that Reasoners do not return epistemic labelling sets.");
115+
116+
115117
//Reasoners can be created using the abstract superclass
116118
AbstractEAFReasoner eafReasoner = AbstractEAFReasoner.getSimpleReasonerForSemantics(EAFSemantics.EAF_PR);
117119
//Or by instantiating a reasoner for the required semantics

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/AbstractEAFReasoner.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
package org.tweetyproject.arg.eaf.reasoner;
2020

2121
import java.util.Collection;
22+
import java.util.HashSet;
2223

24+
import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner;
2325
import org.tweetyproject.arg.dung.semantics.Extension;
26+
import org.tweetyproject.arg.dung.semantics.Semantics;
2427
import org.tweetyproject.arg.dung.syntax.Argument;
28+
import org.tweetyproject.arg.dung.syntax.DungTheory;
2529
import org.tweetyproject.arg.eaf.semantics.EAFSemantics;
2630
import org.tweetyproject.arg.eaf.syntax.EpistemicArgumentationFramework;
2731
import org.tweetyproject.commons.InferenceMode;
@@ -85,6 +89,51 @@ public static AbstractEAFReasoner getSimpleReasonerForSemantics(EAFSemantics sem
8589
default -> throw new IllegalArgumentException("Unknown semantics.");
8690
};
8791
}
92+
93+
/**
94+
* Computes all admissible extensions that satisfy the epistemic constraint of the EAF for the specified semantics.
95+
*
96+
* @param bbase the epistemic argumentation framework
97+
* @param semantics the desired semantics
98+
* @return A collection of all admissible extensions that satisfy the constraint.
99+
*/
100+
public Collection<Extension<EpistemicArgumentationFramework>> getModels(EpistemicArgumentationFramework bbase, Semantics semantics) {
101+
//get all admissible Sets of the underlying DungTheory
102+
AbstractExtensionReasoner dungReasoner = AbstractExtensionReasoner.getSimpleReasonerForSemantics(semantics);
103+
Collection<Extension<DungTheory>> semExtensions = dungReasoner.getModels(bbase);
104+
Collection<Extension<EpistemicArgumentationFramework>> eafSemExtensions = new HashSet<>();
105+
106+
//find sets that satisfy the constraint
107+
for (Extension<DungTheory> semSet : semExtensions) {
108+
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
109+
eafExtension.addAll(semSet);
110+
if (bbase.satisfiesConstraint(semSet)) eafSemExtensions.add(eafExtension);
111+
}
112+
return eafSemExtensions;
113+
}
114+
115+
/**
116+
* Computes one extension that satisfies the epistemic constraint of the EAF for the specified semantics.
117+
*
118+
* @param bbase the constrained argumentation framework
119+
* @param semantics the desired semantics
120+
* @return An admissible extension that satisfies the constraint.
121+
*/
122+
public Extension<EpistemicArgumentationFramework> getModel(EpistemicArgumentationFramework bbase, Semantics semantics) {
123+
// return the first C-Admissible Set
124+
//get all extensions of the underlying DungTheory based on semantics
125+
AbstractExtensionReasoner dungReasoner = AbstractExtensionReasoner.getSimpleReasonerForSemantics(semantics);
126+
Collection<Extension<DungTheory>> semExtensions = dungReasoner.getModels(bbase);
127+
128+
//find sets that are also C-Admissible
129+
for (Extension<DungTheory> semSet : semExtensions) {
130+
Extension<EpistemicArgumentationFramework> cafExtension = new Extension<>();
131+
cafExtension.addAll(semSet);
132+
if (bbase.satisfiesConstraint(semSet)) return cafExtension;
133+
134+
}
135+
throw new RuntimeException("No Extension found that satisfies constraint.");
136+
}
88137

89138

90139

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/EAFAgreementReasoner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public EAFAgreementReasoner(EpistemicArgumentationFramework eaf) {
6060
public boolean addEAF(EpistemicArgumentationFramework eaf) throws Exception {
6161
// Check whether underlying AFs are the same
6262
DungTheory underlyingAF = new DungTheory(eaf);
63-
if (!this.af.getSignature().equals(underlyingAF.getSignature()))
63+
if (!this.af.equals(underlyingAF))
6464
throw new Exception("underlying AF does not match AF for this Agreement Reasoner");
6565
this.eafs.add(eaf);
6666
return true;

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/SimpleEAFAdmissibleReasoner.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.tweetyproject.arg.dung.reasoner.SimpleAdmissibleReasoner;
2525
import org.tweetyproject.arg.dung.semantics.Extension;
26+
import org.tweetyproject.arg.dung.semantics.Semantics;
2627
import org.tweetyproject.arg.dung.syntax.DungTheory;
2728
import org.tweetyproject.arg.eaf.syntax.EpistemicArgumentationFramework;
2829

@@ -37,46 +38,23 @@
3738
public class SimpleEAFAdmissibleReasoner extends AbstractEAFReasoner{
3839

3940
/**
40-
* Computes all admissible extensions that satify the epistemic constraint of the EAF.
41+
* Computes all admissible extensions that satisfy the epistemic constraint of the EAF.
4142
*
4243
* @param bbase the epistemic argumentation framework
43-
* @return A collection of all admissible extensions that satify the constraint.
44+
* @return A collection of all admissible extensions that satisfy the constraint.
4445
*/
4546
public Collection<Extension<EpistemicArgumentationFramework>> getModels(EpistemicArgumentationFramework bbase) {
46-
//get all admissible Sets of the underlying DungTheory
47-
SimpleAdmissibleReasoner dungReasoner = new SimpleAdmissibleReasoner();
48-
Collection<Extension<DungTheory>> admExtensions = dungReasoner.getModels(bbase);
49-
Collection<Extension<EpistemicArgumentationFramework>> eafAdmExtensions = new HashSet<>();
50-
51-
//find sets that satify the constraint
52-
for (Extension<DungTheory> admSet : admExtensions) {
53-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
54-
eafExtension.addAll(admSet);
55-
if (bbase.satisfiesConstraint(admSet)) eafAdmExtensions.add(eafExtension);
56-
}
57-
return eafAdmExtensions;
47+
return super.getModels(bbase, Semantics.ADM);
5848
}
5949

6050
/**
61-
* Computes one admissible extension that satifies the epistemic constraint of the EAF.
51+
* Computes one admissible extension that satisfies the epistemic constraint of the EAF.
6252
*
6353
* @param bbase the constrained argumentation framework
64-
* @return An admissible extension that satifies the constraint.
54+
* @return An admissible extension that satisfies the constraint.
6555
*/
6656
public Extension<EpistemicArgumentationFramework> getModel(EpistemicArgumentationFramework bbase) {
67-
// return the first C-Admissible Set
68-
//get all admissible Sets of the underlying DungTheory
69-
SimpleAdmissibleReasoner dungReasoner = new SimpleAdmissibleReasoner();
70-
Collection<Extension<DungTheory>> admExtensions = dungReasoner.getModels(bbase);
71-
72-
//find sets that are also C-Admissible
73-
for (Extension<DungTheory> admSet : admExtensions) {
74-
Extension<EpistemicArgumentationFramework> cafExtension = new Extension<>();
75-
cafExtension.addAll(admSet);
76-
if (bbase.satisfiesConstraint(admSet)) return cafExtension;
77-
78-
}
79-
throw new RuntimeException("No Admissible Extension found that satisfies constraint.");
57+
return super.getModel(bbase, Semantics.ADM);
8058
}
8159

8260
}

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/SimpleEAFCompleteReasoner.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.tweetyproject.arg.dung.reasoner.SimpleCompleteReasoner;
2525
import org.tweetyproject.arg.dung.semantics.Extension;
26+
import org.tweetyproject.arg.dung.semantics.Semantics;
2627
import org.tweetyproject.arg.dung.syntax.DungTheory;
2728
import org.tweetyproject.arg.eaf.syntax.EpistemicArgumentationFramework;
2829

@@ -37,45 +38,23 @@
3738
public class SimpleEAFCompleteReasoner extends AbstractEAFReasoner{
3839

3940
/**
40-
* Computes all complete extensions that satify the epistemic constraint of the EAF.
41+
* Computes all complete extensions that satisfy the epistemic constraint of the EAF.
4142
*
4243
* @param bbase the epistemic argumentation framework
43-
* @return A collection of all complete extensions that satify the constraint.
44+
* @return A collection of all complete extensions that satisfy the constraint.
4445
*/
4546
public Collection<Extension<EpistemicArgumentationFramework>> getModels(EpistemicArgumentationFramework bbase) {
46-
//get all complete Sets of the underlying DungTheory
47-
SimpleCompleteReasoner dungReasoner = new SimpleCompleteReasoner();
48-
Collection<Extension<DungTheory>> comExtensions = dungReasoner.getModels(bbase);
49-
Collection<Extension<EpistemicArgumentationFramework>> eafComExtensions = new HashSet<>();
50-
51-
//find sets that satify the constraint
52-
for (Extension<DungTheory> comSet : comExtensions) {
53-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
54-
eafExtension.addAll(comSet);
55-
if (bbase.satisfiesConstraint(comSet)) eafComExtensions.add(eafExtension);
56-
}
57-
return eafComExtensions;
47+
return super.getModels(bbase, Semantics.CO);
5848
}
5949

6050
/**
61-
* Computes one complete extension that satifies the epistemic constraint of the EAF.
51+
* Computes one complete extension that satisfies the epistemic constraint of the EAF.
6252
*
6353
* @param bbase the constrained argumentation framework
64-
* @return A complete extension that satifies the constraint.
54+
* @return A complete extension that satisfies the constraint.
6555
*/
6656
public Extension<EpistemicArgumentationFramework> getModel(EpistemicArgumentationFramework bbase) {
67-
//get all complete Sets of the underlying DungTheory
68-
SimpleCompleteReasoner dungReasoner = new SimpleCompleteReasoner();
69-
Collection<Extension<DungTheory>> comExtensions = dungReasoner.getModels(bbase);
70-
71-
//find a sets that satifies the constraint
72-
for (Extension<DungTheory> comSet : comExtensions) {
73-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
74-
eafExtension.addAll(comSet);
75-
if (bbase.satisfiesConstraint(comSet)) return eafExtension;
76-
77-
}
78-
throw new RuntimeException("No Complete Extension found that satisfies constraint.");
57+
return super.getModel(bbase, Semantics.CO);
7958
}
8059

8160
}

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/SimpleEAFGroundedReasoner.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.tweetyproject.arg.dung.reasoner.SimpleGroundedReasoner;
2525
import org.tweetyproject.arg.dung.semantics.Extension;
26+
import org.tweetyproject.arg.dung.semantics.Semantics;
2627
import org.tweetyproject.arg.dung.syntax.DungTheory;
2728
import org.tweetyproject.arg.eaf.syntax.EpistemicArgumentationFramework;
2829

@@ -37,43 +38,23 @@
3738
public class SimpleEAFGroundedReasoner extends AbstractEAFReasoner{
3839

3940
/**
40-
* Computes all grounded extensions that satify the epistemic constraint of the EAF.
41+
* Computes all grounded extensions that satisfy the epistemic constraint of the EAF.
4142
*
4243
* @param bbase the epistemic argumentation framework
43-
* @return A collection of all grounded extensions that satify the constraint.
44+
* @return A collection of all grounded extensions that satisfy the constraint.
4445
*/
4546
public Collection<Extension<EpistemicArgumentationFramework>> getModels(EpistemicArgumentationFramework bbase) {
46-
//get all grounded Sets of the underlying DungTheory
47-
SimpleGroundedReasoner dungReasoner = new SimpleGroundedReasoner();
48-
Collection<Extension<DungTheory>> grExtensions = dungReasoner.getModels(bbase);
49-
Collection<Extension<EpistemicArgumentationFramework>> eafGrExtensions = new HashSet<>();
50-
51-
//find sets that satify the constraint
52-
for (Extension<DungTheory> grSet : grExtensions) {
53-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
54-
eafExtension.addAll(grSet);
55-
if (bbase.satisfiesConstraint(grSet)) eafGrExtensions.add(eafExtension);
56-
}
57-
return eafGrExtensions;
47+
return super.getModels(bbase, Semantics.GR);
5848
}
5949

6050
/**
61-
* Computes one grounded extension that satifies the epistemic constraint of the EAF.
51+
* Computes one grounded extension that satisfies the epistemic constraint of the EAF.
6252
*
6353
* @param bbase the constrained argumentation framework
64-
* @return A grounded extension that satifies the constraint.
54+
* @return A grounded extension that satisfies the constraint.
6555
*/
6656
public Extension<EpistemicArgumentationFramework> getModel(EpistemicArgumentationFramework bbase) {
67-
//get all grounded Sets of the underlying DungTheory
68-
SimpleGroundedReasoner dungReasoner = new SimpleGroundedReasoner();
69-
Extension<DungTheory> grExtension = dungReasoner.getModel(bbase);
70-
71-
//check if grounded extension satisfies constraint
72-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
73-
eafExtension.addAll(grExtension);
74-
if (bbase.satisfiesConstraint(grExtension)) return eafExtension;
75-
76-
throw new RuntimeException("No Grounded Extension found that satisfies constraint.");
57+
return super.getModel(bbase, Semantics.GR);
7758
}
7859

7960
}

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/SimpleEAFPreferredReasoner.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner;
2525
import org.tweetyproject.arg.dung.semantics.Extension;
26+
import org.tweetyproject.arg.dung.semantics.Semantics;
2627
import org.tweetyproject.arg.dung.syntax.DungTheory;
2728
import org.tweetyproject.arg.eaf.syntax.EpistemicArgumentationFramework;
2829

@@ -37,44 +38,22 @@
3738
public class SimpleEAFPreferredReasoner extends AbstractEAFReasoner{
3839

3940
/**
40-
* Computes all preferred extensions that satify the epistemic constraint of the EAF.
41+
* Computes all preferred extensions that satisfy the epistemic constraint of the EAF.
4142
*
4243
* @param bbase the epistemic argumentation framework
43-
* @return A collection of all preferred extensions that satify the constraint.
44+
* @return A collection of all preferred extensions that satisfy the constraint.
4445
*/
4546
public Collection<Extension<EpistemicArgumentationFramework>> getModels(EpistemicArgumentationFramework bbase) {
46-
//get all preferred Sets of the underlying DungTheory
47-
SimplePreferredReasoner dungReasoner = new SimplePreferredReasoner();
48-
Collection<Extension<DungTheory>> prExtensions = dungReasoner.getModels(bbase);
49-
Collection<Extension<EpistemicArgumentationFramework>> eafPrExtensions = new HashSet<>();
50-
51-
//find sets that satify the constraint
52-
for (Extension<DungTheory> prSet : prExtensions) {
53-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
54-
eafExtension.addAll(prSet);
55-
if (bbase.satisfiesConstraint(prSet)) eafPrExtensions.add(eafExtension);
56-
}
57-
return eafPrExtensions;
47+
return super.getModels(bbase, Semantics.PR);
5848
}
5949

6050
/**
61-
* Computes one preferred extension that satifies the epistemic constraint of the EAF.
51+
* Computes one preferred extension that satisfies the epistemic constraint of the EAF.
6252
*
6353
* @param bbase the constrained argumentation framework
64-
* @return A preferred extension that satifies the constraint.
54+
* @return A preferred extension that satisfies the constraint.
6555
*/
6656
public Extension<EpistemicArgumentationFramework> getModel(EpistemicArgumentationFramework bbase) {
67-
//get all preferred Sets of the underlying DungTheory
68-
SimplePreferredReasoner dungReasoner = new SimplePreferredReasoner();
69-
Collection<Extension<DungTheory>> prExtensions = dungReasoner.getModels(bbase);
70-
71-
//find a sets that satifies the constraint
72-
for (Extension<DungTheory> prSet : prExtensions) {
73-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
74-
eafExtension.addAll(prSet);
75-
if (bbase.satisfiesConstraint(prSet)) return eafExtension;
76-
77-
}
78-
throw new RuntimeException("No Preferred Extension found that satisfies constraint.");
57+
return super.getModel(bbase, Semantics.PR);
7958
}
8059
}

org-tweetyproject-arg-eaf/src/main/java/org/tweetyproject/arg/eaf/reasoner/SimpleEAFStableReasoner.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.tweetyproject.arg.dung.reasoner.SimpleStableReasoner;
2525
import org.tweetyproject.arg.dung.semantics.Extension;
26+
import org.tweetyproject.arg.dung.semantics.Semantics;
2627
import org.tweetyproject.arg.dung.syntax.DungTheory;
2728
import org.tweetyproject.arg.eaf.syntax.EpistemicArgumentationFramework;
2829

@@ -37,44 +38,22 @@
3738
public class SimpleEAFStableReasoner extends AbstractEAFReasoner{
3839

3940
/**
40-
* Computes all stable extensions that satify the epistemic constraint of the EAF.
41+
* Computes all stable extensions that satisfy the epistemic constraint of the EAF.
4142
*
4243
* @param bbase the epistemic argumentation framework
43-
* @return A collection of all stable extensions that satify the constraint.
44+
* @return A collection of all stable extensions that satisfy the constraint.
4445
*/
4546
public Collection<Extension<EpistemicArgumentationFramework>> getModels(EpistemicArgumentationFramework bbase) {
46-
//get all stable Sets of the underlying DungTheory
47-
SimpleStableReasoner dungReasoner = new SimpleStableReasoner();
48-
Collection<Extension<DungTheory>> stExtensions = dungReasoner.getModels(bbase);
49-
Collection<Extension<EpistemicArgumentationFramework>> eafStExtensions = new HashSet<>();
50-
51-
//find sets that satify the constraint
52-
for (Extension<DungTheory> stSet : stExtensions) {
53-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
54-
eafExtension.addAll(stSet);
55-
if (bbase.satisfiesConstraint(stSet)) eafStExtensions.add(eafExtension);
56-
}
57-
return eafStExtensions;
47+
return super.getModels(bbase, Semantics.ST);
5848
}
5949

6050
/**
61-
* Computes one stable extension that satifies the epistemic constraint of the EAF.
51+
* Computes one stable extension that satisfies the epistemic constraint of the EAF.
6252
*
6353
* @param bbase the constrained argumentation framework
64-
* @return An stable extension that satifies the constraint.
54+
* @return An stable extension that satisfies the constraint.
6555
*/
6656
public Extension<EpistemicArgumentationFramework> getModel(EpistemicArgumentationFramework bbase) {
67-
//get all stable Sets of the underlying DungTheory
68-
SimpleStableReasoner dungReasoner = new SimpleStableReasoner();
69-
Collection<Extension<DungTheory>> stExtensions = dungReasoner.getModels(bbase);
70-
71-
//find a sets that satifies the constraint
72-
for (Extension<DungTheory> stSet : stExtensions) {
73-
Extension<EpistemicArgumentationFramework> eafExtension = new Extension<>();
74-
eafExtension.addAll(stSet);
75-
if (bbase.satisfiesConstraint(stSet)) return eafExtension;
76-
77-
}
78-
throw new RuntimeException("No Stable Extension found that satisfies constraint.");
57+
return super.getModel(bbase, Semantics.ST);
7958
}
8059
}

0 commit comments

Comments
 (0)