From 7fa3a4e8dae38c25668bd3b4676e6a4684b69592 Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Fri, 8 May 2026 11:46:39 +0200 Subject: [PATCH 01/43] refactored bipolar argumentation --- .../bipolar/analysis/AbstractAnalysis.java | 204 ------- .../arg/bipolar/analysis/Analysis.java | 20 - .../arg/bipolar/analysis/AnalysisResult.java | 90 --- .../arg/bipolar/analysis/AnalysisType.java | 110 ---- .../arg/bipolar/analysis/ApproxAnalysis.java | 73 --- .../analysis/ConcurrentApproxAnalysis.java | 171 ------ .../analysis/ConcurrentExactAnalysis.java | 95 --- .../arg/bipolar/analysis/ExactAnalysis.java | 89 --- .../ProbabilisticJustificationAnalysis.java | 27 - .../extensions/AbstractExtensionAnalysis.java | 92 --- .../extensions/ExtensionAnalysis.java | 42 -- .../analysis/extensions/GroundedAnalysis.java | 41 -- .../extensions/PreferredAnalysis.java | 40 -- .../examples/AllPEAFInducerExample.java | 93 --- ...proximateJustificationAnalysisExample.java | 134 ----- .../CheckIfSelfSupportingExample.java | 100 ---- .../examples/DeductiveArgumentation.java | 104 ---- .../DeductiveBipolarArgumentation.java | 73 +++ .../arg/bipolar/examples/EAFExample.java | 90 --- .../arg/bipolar/examples/EasyPEAFExample.java | 75 --- .../examples/EvidentialAcceptability.java | 97 --- .../examples/EvidentialArgumentation.java | 83 --- .../examples/EvidentialArgumentation2.java | 73 --- .../arg/bipolar/examples/ExpandMCExample.java | 98 ---- .../JustificationAnalysisExample.java | 87 --- .../examples/LiThesisPage21EAFExample.java | 76 --- .../bipolar/examples/MeetingPEAFExample.java | 122 ---- .../examples/NecessityArgumentation.java | 75 --- .../NecessityBipolarArgumentation.java | 74 +++ .../examples/OrenEtAl2010Figure2Example.java | 66 --- .../examples/SomePEAFInducerExample.java | 82 --- .../bipolar/examples/admissibleExample.java | 73 --- .../bipolar/inducers/AbstractPEAFInducer.java | 140 ----- .../bipolar/inducers/ApproxPEAFInducer.java | 175 ------ .../bipolar/inducers/ExactPEAFInducer.java | 243 -------- .../bipolar/inducers/LiExactPEAFInducer.java | 210 ------- .../arg/bipolar/inducers/PEAFInducer.java | 37 -- .../arg/bipolar/io/EdgeListWriter.java | 190 ------ .../arg/bipolar/io/eaf/EAFToDAFConverter.java | 255 -------- .../AbstractBipolarExtensionReasoner.java | 87 ++- .../reasoner/SimpleCoalitionReasoner.java | 72 +++ .../SimpleCoherentAdmissibleReasoner.java | 62 ++ .../reasoner/SimpleCoherentReasoner.java | 61 ++ .../reasoner/SimpleDeductiveReasoner.java | 67 +++ .../reasoner/SimpleNecessityReasoner.java | 62 ++ .../SimpleStronglyConflictFreeReasoner.java | 54 ++ .../deductive/CAdmissibleReasoner.java | 56 -- .../reasoner/deductive/ClosureReasoner.java | 71 --- .../deductive/ConflictFreeReasoner.java | 64 -- .../deductive/DAdmissibleReasoner.java | 68 --- .../reasoner/deductive/SafetyReasoner.java | 86 --- .../evidential/AdmissibleReasoner.java | 74 --- .../reasoner/evidential/CompleteReasoner.java | 71 --- .../evidential/ConflictFreeReasoner.java | 79 --- .../reasoner/evidential/GroundedReasoner.java | 61 -- .../evidential/PreferredReasoner.java | 76 --- .../evidential/SelfSupportingReasoner.java | 71 --- .../reasoner/evidential/StableReasoner.java | 115 ---- .../necessity/AdmissibleReasoner.java | 83 --- .../reasoner/necessity/CompleteReasoner.java | 83 --- .../reasoner/necessity/GroundedReasoner.java | 73 --- .../reasoner/necessity/PreferredReasoner.java | 88 --- .../reasoner/necessity/StableReasoner.java | 79 --- .../arg/bipolar/semantics/Semantics.java | 93 +++ .../syntax/AbstractBipolarFramework.java | 456 --------------- .../arg/bipolar/syntax/AbstractEAFTheory.java | 306 ---------- .../arg/bipolar/syntax/ArgumentSet.java | 333 ----------- .../arg/bipolar/syntax/Attack.java | 61 -- .../arg/bipolar/syntax/BArgument.java | 104 ---- .../arg/bipolar/syntax/BinaryAttack.java | 120 ---- .../arg/bipolar/syntax/BinarySupport.java | 128 ---- .../syntax/BipolarArgumentationFramework.java | 421 +++++++++++++ ...olarEntity.java => CoalitionArgument.java} | 92 +-- .../arg/bipolar/syntax/CyclicException.java | 24 - .../DeductiveArgumentationFramework.java | 487 --------------- .../arg/bipolar/syntax/EAFTheory.java | 305 ---------- .../arg/bipolar/syntax/EAttack.java | 137 ----- .../EvidentialArgumentationFramework.java | 553 ------------------ .../arg/bipolar/syntax/InducibleEAF.java | 259 -------- .../arg/bipolar/syntax/NamedPEAFTheory.java | 241 -------- .../NecessityArgumentationFramework.java | 424 -------------- .../arg/bipolar/syntax/PEAFTheory.java | 139 ----- .../arg/bipolar/syntax/PEEAFTheory.java | 548 ----------------- .../arg/bipolar/syntax/SetAttack.java | 134 ----- .../arg/bipolar/syntax/SetSupport.java | 152 ----- .../arg/bipolar/syntax/Support.java | 204 ++++--- .../bipolar/syntax/WeightedSetSupport.java | 48 -- .../arg/bipolar/BasicFunctionalityTest.java | 117 ---- .../bipolar/DeductiveArgumentationTest.java | 70 --- .../bipolar/EvidentialArgumentationTest.java | 159 ----- .../bipolar/NecessityArgumentationTest.java | 123 ---- .../arg/bipolar/TranslationTest.java | 121 ---- ...stractBipolarExtensionReasonerFactory.java | 34 +- .../AbstractBipolarFrameworkFactory.java | 20 +- .../BipolarArgumentationFrameworkType.java | 27 - .../bipolar/BipolarReasonerCalleeFactory.java | 4 +- .../BipolarReasonerGetModelCallee.java | 10 +- .../BipolarReasonerGetModelsCallee.java | 10 +- .../services/bipolar/BipolarSemantics.java | 46 +- .../RequestControllerBipolarTest.java | 26 +- 100 files changed, 1363 insertions(+), 10955 deletions(-) delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AbstractAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/Analysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisResult.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisType.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ApproxAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentApproxAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentExactAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ExactAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ProbabilisticJustificationAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/AbstractExtensionAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/ExtensionAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/GroundedAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/PreferredAnalysis.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/AllPEAFInducerExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ApproximateJustificationAnalysisExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/CheckIfSelfSupportingExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveArgumentation.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveBipolarArgumentation.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EAFExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EasyPEAFExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialAcceptability.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation2.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ExpandMCExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/JustificationAnalysisExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/LiThesisPage21EAFExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/MeetingPEAFExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityArgumentation.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityBipolarArgumentation.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/OrenEtAl2010Figure2Example.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/SomePEAFInducerExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/admissibleExample.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/AbstractPEAFInducer.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ApproxPEAFInducer.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ExactPEAFInducer.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/LiExactPEAFInducer.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/PEAFInducer.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/EdgeListWriter.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/eaf/EAFToDAFConverter.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoalitionReasoner.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentAdmissibleReasoner.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentReasoner.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleDeductiveReasoner.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleNecessityReasoner.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleStronglyConflictFreeReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/CAdmissibleReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ClosureReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ConflictFreeReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/DAdmissibleReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/SafetyReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/AdmissibleReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/CompleteReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/ConflictFreeReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/GroundedReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/PreferredReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/SelfSupportingReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/StableReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/AdmissibleReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/CompleteReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/GroundedReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/PreferredReasoner.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/StableReasoner.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/semantics/Semantics.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractBipolarFramework.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractEAFTheory.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/ArgumentSet.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Attack.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BArgument.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinaryAttack.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinarySupport.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java rename org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/{BipolarEntity.java => CoalitionArgument.java} (51%) delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CyclicException.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/DeductiveArgumentationFramework.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAFTheory.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAttack.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EvidentialArgumentationFramework.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/InducibleEAF.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NamedPEAFTheory.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NecessityArgumentationFramework.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEAFTheory.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEEAFTheory.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetAttack.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetSupport.java delete mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/WeightedSetSupport.java delete mode 100644 org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/BasicFunctionalityTest.java delete mode 100644 org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/DeductiveArgumentationTest.java delete mode 100644 org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/EvidentialArgumentationTest.java delete mode 100644 org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/NecessityArgumentationTest.java delete mode 100644 org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/TranslationTest.java delete mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarArgumentationFrameworkType.java diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AbstractAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AbstractAnalysis.java deleted file mode 100644 index 6eced8739..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AbstractAnalysis.java +++ /dev/null @@ -1,204 +0,0 @@ -package org.tweetyproject.arg.bipolar.analysis; - - -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.arg.bipolar.io.eaf.EAFToDAFConverter; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * AbstractAnalysis provides utility functions for concrete implementations - * - * @author Taha Dogan Gunes - */ -public abstract class AbstractAnalysis implements Analysis { - - - /** - * The PEAF theory to be analyzed - */ - protected PEAFTheory peafTheory; - /** - * The extension reasoner that analysis will be based on - */ - protected final AbstractExtensionReasoner extensionReasoner; - /** - * The type of the analysis - */ - protected final AnalysisType analysisType; - - /** - * The default constructor - * - * @param peafTheory The PEAF Theory - * @param extensionReasoner The extension reasoner - * @param analysisType The type of the analysis - */ - public AbstractAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, AnalysisType analysisType) { - this.peafTheory = peafTheory; - this.extensionReasoner = extensionReasoner; - this.analysisType = analysisType; - } - - - /** - * Setter for peafTheory - * @param peafTheory theory - */ - public void setPEAFTheory(PEAFTheory peafTheory) { - this.peafTheory = peafTheory; - } - - /** - * It's called when the analysis is complete. - * - * @param probability the result value found as a result - * @param noIterations the number of iterations done for the analysis - * @param totalProbability computed for correctness (in exact analysis) - * @return an Analysis object - */ - protected AnalysisResult createResult(double probability, long noIterations, double totalProbability) { - return new AnalysisResult(probability, noIterations, this.analysisType, totalProbability); - } - - /** - * Computes the contribution of an induced EAF to the justification analysis. - *

- * Before computing the contribution with extensions, several checks are done. - * 1. If the queried args are not found in the EAF, return 0. - * 2. If there are no attacks, return 1.0. - * 3. If the queried args have no attack, return 1.0 - * 4. Otherwise, convert EAF to DAF and run the given extension reasoner. - * - If one of the extension has the query, return 1.0. - * - * @param args the query as a set of arguments - * @param inducibleEAF an induced EAF object - * @return the contribution for the analysis - */ - protected double computeContributionOfAniEAF(Set args, InducibleEAF inducibleEAF) { - EAFTheory eafTheory = inducibleEAF.toNewEAFTheory(); - - // If Q is not a subset of A, the contribution is zero - if (!eafTheory.getArgumentsAsSet().containsAll(args)) { - return 0.0; - } - - // If R^F_a is empty, then directly return 1.0 - if (eafTheory.getAttacks().isEmpty()) { - return 1.0; - } - - // Create Q' (this is set of nodes that have attack relation) - // If Q' equals to \emptyset (then return 1.0); - Set Q_prime = this.getAttackQueries(eafTheory, args); - - if (Q_prime.isEmpty()) { - return 1.0; - } - - // Create a DAF from arguments that are involved in an attack - DungTheory dungTheory = EAFToDAFConverter.convert(eafTheory); - - // Solve () - Collection> extensions = extensionReasoner.getModels(dungTheory); - - for (Extension extension : extensions) { - Set extensionArgs = new HashSet<>(); - - for (Argument argument : extension) { - String mainArgName = argument.getName(); - if (mainArgName.contains("_")) { - // Must contain all subArgsNames from an extension - String[] subArgsNames = mainArgName.split("_"); - Collections.addAll(extensionArgs, subArgsNames); - } else { - extensionArgs.add(mainArgName); - } - } - - if (extensionArgs.containsAll(Q_prime) && !extension.isEmpty()) { - return 1.0; - } - } - - return 0.0; - } - - /** - * The helper function that return arguments (the query) that has an attack as a set - * - * @param eafTheory the converted iEAF to EAF object - * @param args the query - * @return the names of the arguments that has an attack - */ - private Set getAttackQueries(EAFTheory eafTheory, Set args) { - Set Q_prime = new HashSet(); - - Set attacks = eafTheory.getAttacks(); - for (Attack attack : attacks) { - BipolarEntity froms = attack.getAttacker(); - BipolarEntity tos = attack.getAttacked(); - - for (BArgument arg : args) { - if (froms.contains(arg) || tos.contains(arg)) { - Q_prime.add(arg.getName()); - } - } - } - return Q_prime; - } - - /** - * Creates a virtual DAF from EAFTheory without including the support links - * This is not a great conversion method, however works good for queries. - *

- * FIXME: this assumes that the internal structure when attacks exist does not have a support link inside the subgraph - * - * @param eafTheory an EAFTheory object - * @return a DungTheory object - */ - @Deprecated - protected DungTheory createDAF(EAFTheory eafTheory) { - Map argumentsInAttack = new HashMap(); - DungTheory dungTheory = new DungTheory(); - for (Attack attack : eafTheory.getAttacks()) { - String from = this.convertEArgumentsToDAFArgumentName(attack.getAttacker()); - - if (!argumentsInAttack.containsKey(from)) { - Argument fromArg = new Argument(from); - argumentsInAttack.put(from, fromArg); - dungTheory.add(fromArg); - } - - String to = this.convertEArgumentsToDAFArgumentName(attack.getAttacked()); - if (!argumentsInAttack.containsKey(to)) { - Argument toArg = new Argument(to); - argumentsInAttack.put(to, toArg); - dungTheory.add(toArg); - } - - dungTheory.addAttack(argumentsInAttack.get(from), argumentsInAttack.get(to)); - } - return dungTheory; - } - - /** - * Joins EArguments' names with a delimiter to create a new name for the conversion from EAF to DAF - * - * @param eArguments a set of arguments - * @return the joint (sorted) name of arguments - */ - private String convertEArgumentsToDAFArgumentName(BipolarEntity eArguments) { - return ((ArgumentSet) eArguments).stream() - .map(BArgument::getName) - .sorted() - .collect(Collectors.joining("_")); - } - - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/Analysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/Analysis.java deleted file mode 100644 index 6a046af02..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/Analysis.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tweetyproject.arg.bipolar.analysis; - -import org.tweetyproject.arg.bipolar.syntax.BArgument; - -import java.util.Set; - -/** - * The interface of the analyses in arg.peaf - * - * @author Taha Dogan Gunes - */ -public interface Analysis { - /** - * Creates an AnalysisResult to store the results of the analysis - * - * @param args the set of arguments necessary for the query - * @return an AnalysisResult object - */ - AnalysisResult query(Set args); -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisResult.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisResult.java deleted file mode 100644 index f0391d6eb..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisResult.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.tweetyproject.arg.bipolar.analysis; - -/** - * Represents the result of an analysis, including performance metrics and analysis type. - *

- * This class encapsulates details about the analysis result such as the result value, number of iterations, - * analysis type, and total probability. It provides methods to retrieve these values and to print the results - * for debugging purposes. - *

- * - * @author Taha Dogan Gunes - */ -public class AnalysisResult { - - /** The result value of the analysis. */ - private final double result; - - /** The number of iterations performed during the analysis. */ - private final long noIterations; - - /** The type of analysis conducted. */ - private final AnalysisType type; - - /** The total probability calculated during the analysis. */ - private final double totalProbability; - - /** - * Constructs an {@code AnalysisResult} with the specified parameters. - * - * @param result the result of the analysis - * @param noIterations the number of iterations performed - * @param type the type of analysis conducted - * @param totalProbability the total probability calculated - */ - public AnalysisResult(double result, long noIterations, AnalysisType type, double totalProbability) { - this.result = result; - this.noIterations = noIterations; - this.type = type; - this.totalProbability = totalProbability; - } - - /** - * Returns the result of the analysis. - * - * @return the result value - */ - public double getResult() { - return result; - } - - /** - * Returns the number of iterations performed during the analysis. - * - * @return the number of iterations - */ - public long getNoIterations() { - return noIterations; - } - - /** - * Returns the type of analysis conducted. - * - * @return the type of analysis - */ - public AnalysisType getType() { - return type; - } - - /** - * Returns the total probability calculated during the analysis. - * - * @return the total probability - */ - public double getTotalProbability() { - return totalProbability; - } - - /** - * Prints the details of the analysis result to the standard output. - *

- * The output includes the type of analysis, result value, number of iterations, and total probability. - *

- */ - public void print() { - System.out.println("Type: " + this.type + - ", Result: " + this.getResult() + - ", Iterations: " + this.getNoIterations() + - ", Total Probability: " + this.getTotalProbability()); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisType.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisType.java deleted file mode 100644 index 0ea2848b8..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/AnalysisType.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.tweetyproject.arg.bipolar.analysis; - -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * The types of analysis supported by arg.peaf - * - * @author Taha Dogan Gunes - */ -public enum AnalysisType { - /** - * see ExactAnalysis - */ - EXACT("exact"), - /** - * see ApproxAnalysis - */ - APPROX("approx"), - /** - * see ConcurrentApproxAnalysis - */ - CONCURRENT_APPROX("con_approx"), - /** - * see ConcurrentExactAnalysis - */ - CONCURRENT_EXACT("con_exact"), - /** - * see PreferredAnalysis - */ - PREFERRED("preferred"), - - /** - * see GroundedAnalysis - */ - GROUNDED("grounded"), - - /** - * see org.tweetyproject.arg.peaf.analysis.voi.TargetOutputAnalysis - */ - VOI_TARGET_OUTPUT("voi_target_output"), - - /** - * see org.tweetyproject.arg.peaf.analysis.voi.MinimiseEntropyAnalysis - */ - VOI_MINIMISE_ENTROPY("voi_min_entropy"), - - /** - * see org.tweetyproject.arg.peaf.analysis.voi.MaximiseChangeAnalysis - */ - VOI_MAXIMISE_CHANGE("voi_max_change"), - - /** - * see org.tweetyproject.arg.peaf.analysis.voi.KLDivergenceAnalysis - */ - VOI_KL_DIVERGENCE("voi_kl_divergence"); - - - /** - * Internal map for string enumeration - */ - private static final Map ENUM_MAP; - - static { - Map map = new ConcurrentHashMap<>(); - for (AnalysisType instance : AnalysisType.values()) { - map.put(instance.getName().toLowerCase(), instance); - } - ENUM_MAP = Collections.unmodifiableMap(map); - } - - /** - * The keyword of the analysis - */ - private final String text; - - /** - * Creates an AnalysisType object - * - * @param text the keyword - */ - AnalysisType(final String text) { - this.text = text; - } - - /** - * Get the AnalysisType by giving the keyword - * - * @param name the keyword in string - * @return the AnalysisType - */ - public static AnalysisType get(String name) { - return ENUM_MAP.get(name.toLowerCase()); - } - - @Override - public String toString() { - return text; - } - - /** - * Return the keyword of the AnalysisType - * - * @return the keyword in string - */ - private String getName() { - return text; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ApproxAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ApproxAnalysis.java deleted file mode 100644 index f053e000f..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ApproxAnalysis.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.tweetyproject.arg.bipolar.analysis; - -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.bipolar.inducers.ApproxPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.Set; - -/** - * This class implements approximate probabilistic justification of a set of queries using Monte Carlo Sampling of - * induced EAFs from a PEAF. - * see Li, Hengfei. Probabilistic argumentation. 2015. PhD Thesis. Aberdeen University. - * - * @author Taha Dogan Gunes - */ -public class ApproxAnalysis extends AbstractAnalysis implements ProbabilisticJustificationAnalysis { - - /** - * The error level defines how much the computed result is tolerated for deviation. - *

- * Example: If errorLevel is 0.1, then the result will be in the range [x - 0.1, x + 0.1]. - */ - private final double errorLevel; - - /** - * Creates an ApproxAnalysis object - * - * @param peafTheory The PEAFTheory object - * @param extensionReasoner An extension reasoner object - * @param errorLevel the error level in double - */ - public ApproxAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, double errorLevel) { - super(peafTheory, extensionReasoner, AnalysisType.APPROX); - this.errorLevel = errorLevel; - } - - /** - * Computes approximately what is probabilistic justification of the given set of arguments in the PEAF given error - * level - * - * @param args the set of arguments necessary for the query - * @return the result of the analysis - */ - @Override - public AnalysisResult query(Set args) { - final double[] M = {0.0}; - final double[] N = {0.0}; - final double[] metric = {0.0}; - final double[] p_i = {0.0}; - final long[] i = {0}; - final double[] total = {0.0}; - - do { - ApproxPEAFInducer approxPEAFInducer = new ApproxPEAFInducer(this.peafTheory); - approxPEAFInducer.induce(iEAF -> { - double contribution = 0; - - contribution = computeContributionOfAniEAF(args, iEAF); - - total[0] += contribution; - M[0] = M[0] + contribution; - N[0] = N[0] + 1.0; - i[0] += 1; - p_i[0] = (M[0] + 2) / (N[0] + 4); - metric[0] = ((4.0 * p_i[0] * (1.0 - p_i[0])) / Math.pow(errorLevel, 2)) - 4.0; - }); - } while (N[0] <= metric[0]); - - - return this.createResult(M[0] / N[0], i[0], total[0]); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentApproxAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentApproxAnalysis.java deleted file mode 100644 index 67cc1ecd1..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentApproxAnalysis.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis; - -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.bipolar.inducers.ApproxPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * This class implements approximate probabilistic justification of a set of queries using Monte Carlo Sampling of - * induced EAFs from a PEAF. The computation is done in batches, the main thread checks the condition of when to stop - * after each batch. - * - * @author Taha Dogan Gunes - */ -public class ConcurrentApproxAnalysis extends AbstractAnalysis implements ProbabilisticJustificationAnalysis { - /** - * The error level defines how much the computed result is tolerated for deviation. - *

- * Example: If errorLevel is 0.1, then the result will be in the range [x - 0.1, x + 0.1]. - */ - private final double errorLevel; - /** - * The fixed thread pool to run the contributions in parallel - */ - private final ExecutorService executorService; - /** - * The number of jobs to be completed for checking when to stop. - * This is to reduce the effect of one thread stalling all the batch - * (increasing too much would create unnecessary iterations) - */ - private final int batchSize; - - /** - * Constructs ConcurrentApproxAnalysis with noThreads equal to availableProcessors - 1 - * - * @param peafTheory the PEAFTheory to be analyzed - * @param extensionReasoner the extension reasoner - * @param errorLevel the error level in double - */ - public ConcurrentApproxAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, double errorLevel) { - this(peafTheory, extensionReasoner, errorLevel, Runtime.getRuntime().availableProcessors() - 1); - } - - /** - * Constructs ConcurrentApproxAnalysis with batchSize equal to noThreads*2 - * - * @param peafTheory the PEAFTheory to be analyzed - * @param extensionReasoner the extension reasoner - * @param errorLevel the error level in double - * @param noThreads the number of threads - */ - public ConcurrentApproxAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, double errorLevel, int noThreads) { - this(peafTheory, extensionReasoner, errorLevel, noThreads, noThreads * 2); - } - - /** - * The default constructor for ConcurrentApproxAnalysis - * - * @param peafTheory the PEAFTheory to be analyzed - * @param extensionReasoner the extension reasoner - * @param errorLevel the error level in double - * @param noThreads the number of threads - * @param batchSize the number jobs to be completed for checking when to stop - */ - public ConcurrentApproxAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, double errorLevel, int noThreads, int batchSize) { - super(peafTheory, extensionReasoner, AnalysisType.CONCURRENT_APPROX); - this.errorLevel = errorLevel; - this.executorService = Executors.newFixedThreadPool(noThreads); - this.batchSize = batchSize; - } - /** Total */ - public double total = 0.0; - /** - * Computes approximately what is probabilistic justification of the given set of arguments in the PEAF given error - * level concurrently. - * - * @param args the set of arguments necessary for the query - * @return an AnalysisResult object - */ - @Override - public AnalysisResult query(Set args) { - - // tests for cyclic - new ApproxPEAFInducer(peafTheory); - - final double[] M = {0.0}; - final double[] N = {0.0}; - final double[] metric = {0.0}; - final double[] p_i = {0.0}; - final long[] i = {0}; - this.total = 0.0; - AtomicInteger poolAvailability = new AtomicInteger(this.batchSize); - List> futures = new ArrayList>(); - - - do { - // Submit a group of threads - if (poolAvailability.get() > 0) { - Future future = executorService.submit(() -> { - poolAvailability.decrementAndGet(); - double[] contribution = {0.0}; - ApproxPEAFInducer approxPEAFInducer = new ApproxPEAFInducer(peafTheory); - approxPEAFInducer.induce(iEAF -> { - contribution[0] = computeContributionOfAniEAF(args, iEAF); - - this.total = contribution[0]; - }); - return contribution[0]; - }); - futures.add(future); - } - - // Make sure all the batch is completed. - ListIterator> iter = futures.listIterator(); - while (iter.hasNext()) { - Future future = iter.next(); - - double contribution = 0; - try { - // future.get() stalls the main thread - contribution = future.get(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - M[0] = M[0] + contribution; - N[0] = N[0] + 1.0; - i[0] += 1; - p_i[0] = (M[0] + 2) / (N[0] + 4); - metric[0] = ((4.0 * p_i[0] * (1.0 - p_i[0])) / Math.pow(errorLevel, 2)) - 4.0; - - poolAvailability.incrementAndGet(); - iter.remove(); - } - - } while (N[0] <= metric[0]); - - - // The condition is now satisfied, we don't need to run all the tasks now. - executorService.shutdownNow(); - - return this.createResult(M[0] / N[0], i[0], total); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentExactAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentExactAnalysis.java deleted file mode 100644 index 04f9a85ff..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ConcurrentExactAnalysis.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.tweetyproject.arg.bipolar.analysis; - - -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.bipolar.inducers.LiExactPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -/** - * This class implements exact probabilistic justification of a set of queries by generating all possible - * induces EAFs from a PEAF in parallel. - * - * @author Taha Dogan Gunes - */ -public class ConcurrentExactAnalysis extends AbstractAnalysis implements ProbabilisticJustificationAnalysis { - /** - * The fixed thread pool to run the contributions in parallel - */ - private final ExecutorService executorService; - - /** - * Constructs ConcurrentExactAnalysis with noThreads equal to availableProcessors - 1 - * - * @param peafTheory the PEAFTheory to be analyzed - * @param extensionReasoner the extension reasoner - */ - public ConcurrentExactAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner) { - this(peafTheory, extensionReasoner, Runtime.getRuntime().availableProcessors() - 1); - } - - /** - * Constructs ConcurrentExactAnalysis with given noThreads - * - * @param peafTheory the PEAFTheory to be analyzed - * @param extensionReasoner the extension reasoner - * @param noThreads the number of threads - */ - public ConcurrentExactAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, int noThreads) { - super(peafTheory, extensionReasoner, AnalysisType.CONCURRENT_EXACT); - this.executorService = Executors.newFixedThreadPool(noThreads); - } - - /** Total */ - public Double total = Double.valueOf(0.0); - /** P */ - public Double p = Double.valueOf(0.0); - /** - * Computes exactly what is probabilistic justification of the given set of arguments in the PEAF. - *

- * Warning: It is intractable when the number of arguments in PEAF is above 15. - * - * @param args the set of arguments necessary for the query - * @return the result of the analysis - * @see ConcurrentApproxAnalysis for larger PEAFs - */ - @Override - public AnalysisResult query(Set args) { - LiExactPEAFInducer exactPEAFInducer = new LiExactPEAFInducer(this.peafTheory); - this.total = 0.0; - this.p = 0.0; - AtomicLong i = new AtomicLong(0); - - - - exactPEAFInducer.induce(iEAF -> - executorService.submit((Callable) () -> { - double contribution = computeContributionOfAniEAF(args, iEAF); - this.total += contribution; - this.p += contribution * iEAF.getInducePro(); - i.incrementAndGet(); - return null; - })); - - try { - executorService.shutdown(); - } finally { - try { - //noinspection ResultOfMethodCallIgnored - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - return this.createResult(p.doubleValue(), i.get(), total.doubleValue()); - } - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ExactAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ExactAnalysis.java deleted file mode 100644 index 1f32d0dbe..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ExactAnalysis.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis; - - -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.bipolar.inducers.LiExactPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.Set; - -/** - * This class implements exact probabilistic justification of a set of queries by generating all possible - * induces EAfs from a PEAF. - * - * See - * - * Li, Hengfei. Probabilistic argumentation. 2015. PhD Thesis. Aberdeen University. - * - * @author Taha Dogan Gunes - */ -public class ExactAnalysis extends AbstractAnalysis implements ProbabilisticJustificationAnalysis { - - /** - * Creates an ExactAnalysis object - * - * @param peafTheory The PEAFTheory object - * @param extensionReasoner An extension reasoner object - */ - public ExactAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner) { - super(peafTheory, extensionReasoner, AnalysisType.EXACT); - } - - /** - * Computes exactly what is probabilistic justification of the given set of arguments in the PEAF. - *

- * Warning: It is intractable when the number of arguments in PEAF is above 12. - * - * @param args the set of arguments necessary for the query - * @return the result of the analysis - * @see ApproxAnalysis for larger PEAFs - */ - @Override - public AnalysisResult query(Set args) { - - LiExactPEAFInducer exactPEAFInducer = new LiExactPEAFInducer(this.peafTheory); - - final double[] p = {0.0}; - final double[] total = {0.0}; - final long[] i = {0}; - - - exactPEAFInducer.induce(iEAF -> { - double contribution = 0; - - contribution = computeContributionOfAniEAF(args, iEAF); - -// if (iEAF.getInducePro() > 0.0 && contribution > 0.0) { -// System.out.println(iEAF + " c:" +contribution); -// } - - - p[0] += contribution * iEAF.getInducePro(); - total[0] += iEAF.getInducePro(); - i[0] += 1; - - }); -// System.out.println("Total is: " + total[0]); - - return this.createResult(p[0], i[0], total[0]); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ProbabilisticJustificationAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ProbabilisticJustificationAnalysis.java deleted file mode 100644 index ac028a982..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/ProbabilisticJustificationAnalysis.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis; - -/** - * probablisitic justification analysis - * @author Matthias Thimm - * - */ -public interface ProbabilisticJustificationAnalysis { -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/AbstractExtensionAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/AbstractExtensionAnalysis.java deleted file mode 100644 index 6e746ecd4..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/AbstractExtensionAnalysis.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis.extensions; - -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.arg.bipolar.analysis.AbstractAnalysis; -import org.tweetyproject.arg.bipolar.analysis.AnalysisResult; -import org.tweetyproject.arg.bipolar.analysis.AnalysisType; -import org.tweetyproject.arg.bipolar.io.eaf.EAFToDAFConverter; -import org.tweetyproject.arg.bipolar.syntax.EAFTheory; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.NamedPEAFTheory; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * An abstract class for performing extension analysis on a PEAF (Process-Entity-Attribute-Function) theory. - *

- * This class is designed to convert a PEAF theory into an EAF (Extended Argumentation Framework) theory, - * then into a Dung theory, and finally use an extension reasoner to compute the extensions of the Dung theory. - *

- */ -public abstract class AbstractExtensionAnalysis extends AbstractAnalysis implements ExtensionAnalysis { - /** - * The default constructor - * - * @param peafTheory The PEAF Theory - * @param extensionReasoner The extension reasoner - * @param analysisType The type of the analysis - */ - public AbstractExtensionAnalysis(PEAFTheory peafTheory, AbstractExtensionReasoner extensionReasoner, AnalysisType analysisType) { - super(peafTheory, extensionReasoner, analysisType); - } - - @Override - public List> getExtensions() { - // Convert peaf -> eaf -> daf, then run jargsemsat - EAFTheory eafTheory = EAFTheory.newEAFTheory(peafTheory); - DungTheory dungTheory = EAFToDAFConverter.convert(eafTheory); - Collection> extensions = extensionReasoner.getModels(dungTheory); - - NamedPEAFTheory namedPEAFTheory = (NamedPEAFTheory) this.peafTheory; - List> results = new ArrayList>(); - for (Extension extension : extensions) { - Set extensionWithNames = new HashSet(); - for (Argument argument : extension) { - - String[] argumentNames = argument.getName().split("_"); - - for (String argumentName : argumentNames) { - BArgument eArgument = namedPEAFTheory.getArguments().get(Integer.parseInt(argumentName)); - String name = namedPEAFTheory.getNameOfArgument(eArgument); - - extensionWithNames.add(name); - } - - } - results.add(extensionWithNames); - } - - return results; - } - - @Override - public AnalysisResult query(Set args) { - return null; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/ExtensionAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/ExtensionAnalysis.java deleted file mode 100644 index dcd6fe704..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/ExtensionAnalysis.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis.extensions; - -import java.util.List; -import java.util.Set; - -/** - * The `ExtensionAnalysis` interface provides a contract for analyzing and retrieving extensions - * in the context of argumentation frameworks, particularly within the domain of bipolar argumentation. - */ -public interface ExtensionAnalysis { - - /** - * Computes and returns a list of extensions. - * - *

- * Each extension is represented as a set of strings, where each string corresponds to an argument - * in the argumentation framework. The method returns all extensions that are found according to - * the specific analysis performed by the implementing class. - *

- * - * @return a list of sets, where each set contains strings representing an extension of the argumentation framework. - */ - List> getExtensions(); -} \ No newline at end of file diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/GroundedAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/GroundedAnalysis.java deleted file mode 100644 index 5147ceb8d..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/GroundedAnalysis.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis.extensions; - -import org.tweetyproject.arg.bipolar.analysis.AnalysisType; -import org.tweetyproject.arg.dung.reasoner.SimpleGroundedReasoner; -import org.tweetyproject.arg.bipolar.syntax.NamedPEAFTheory; - -/** - * Computes the preferred extension of the given PEAF - *

- * Uses `jargsemsat` for computing extensions. - * - * @author Taha Dogan Gunes - */ -public class GroundedAnalysis extends AbstractExtensionAnalysis { - /** - * Construct a GroundedAnalysis - * @param peaf a PEAF theory - */ - public GroundedAnalysis(NamedPEAFTheory peaf) { - super(peaf, new SimpleGroundedReasoner(), AnalysisType.GROUNDED); - } - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/PreferredAnalysis.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/PreferredAnalysis.java deleted file mode 100644 index f8c984006..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/analysis/extensions/PreferredAnalysis.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.analysis.extensions; - -import org.tweetyproject.arg.bipolar.analysis.AnalysisType; -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.bipolar.syntax.NamedPEAFTheory; - -/** - * Computes the preferred extension of the given PEAF - *

- * Uses `jargsemsat` for computing extensions. - * - * @author Taha Dogan Gunes - */ -public class PreferredAnalysis extends AbstractExtensionAnalysis { - /** - * Constructor - * @param peaf NamedPEAFTheory - */ - public PreferredAnalysis(NamedPEAFTheory peaf) { - super(peaf, new SimplePreferredReasoner(), AnalysisType.PREFERRED); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/AllPEAFInducerExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/AllPEAFInducerExample.java deleted file mode 100644 index 320b7a900..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/AllPEAFInducerExample.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.inducers.LiExactPEAFInducer; -import org.tweetyproject.arg.bipolar.io.EdgeListWriter; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.concurrent.atomic.AtomicInteger; - - -/** - * Example class demonstrating the use of the PEAF (Preference-based Argumentation Framework) inducer. - *

- * This example sets up a PEAF theory with a specified number of arguments, adds various support and attack relationships - * between the arguments, and then uses the `LiExactPEAFInducer` to induce new EAF (Argumentation Framework) theories from the - * given PEAF theory. The results are printed and saved to files. - *

- */ -public class AllPEAFInducerExample { - /** - * Main method to run the example. - *

- * This method initializes a PEAF theory with a set number of arguments, defines support and attack relationships, - * and uses the `LiExactPEAFInducer` to induce new EAF theories. It prints each induced EAF and saves it to a file. - *

- * - * @param args Command line arguments (not used in this example). - */ - public static void main(String[] args) { - int numOfArgs = 8; - - - PEAFTheory peafTheory = new PEAFTheory(); - - for (int i = 0; i < numOfArgs; i++) { - peafTheory.addArgument(i); - } - - peafTheory.addSupport(new HashSet(), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), 1.0); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), 0.3); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), 0.8); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), 0.9); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(4)))), 0.85); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), 0.5); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(6)))), 0.6); - HashSet myArgs = new HashSet(); - myArgs.add(peafTheory.getArguments().get(5)); - myArgs.add(peafTheory.getArguments().get(4)); - peafTheory.addSupport(myArgs, new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(7)))), 0.4); - - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(4))))); - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(6))))); - - peafTheory.prettyPrint(); - - EdgeListWriter.write("0.peaf", peafTheory); - - AtomicInteger i = new AtomicInteger(); - LiExactPEAFInducer inducer = new LiExactPEAFInducer(peafTheory); - - inducer.induce(ind -> { - int n = i.getAndIncrement(); - System.out.println(ind); - EdgeListWriter.write(n + ".eaf", ind.toNewEAFTheory()); - - }); - - } - - /** Default Constructor */ - public AllPEAFInducerExample(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ApproximateJustificationAnalysisExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ApproximateJustificationAnalysisExample.java deleted file mode 100644 index 13b485237..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ApproximateJustificationAnalysisExample.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.analysis.AnalysisResult; -import org.tweetyproject.arg.bipolar.analysis.ApproxAnalysis; -import org.tweetyproject.arg.bipolar.analysis.ExactAnalysis; -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Demonstrates the use of exact and approximate justification analysis on a PEAFTheory. - *

- * This example sets up a PEAFTheory with a number of arguments, defines supports and attacks among them, - * and then performs exact and approximate analyses to justify a specific argument. - *

- */ -public class ApproximateJustificationAnalysisExample { - - /** - * Example - * @param args the args - */ - public static void main(String[] args) { - int numOfArgs = 7; // Number of arguments to add to the PEAFTheory - PEAFTheory peafTheory = new PEAFTheory(); - - // Add arguments to the theory - for (int i = 0; i < numOfArgs; i++) { - peafTheory.addArgument(i); - } - - // Define supports among arguments with associated probabilities - peafTheory.addSupport( - new HashSet<>(), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(0))), - 1.0 - ); - peafTheory.addSupport( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(0))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(2))), - 0.6 - ); - peafTheory.addSupport( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(0))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(1))), - 0.7 - ); - peafTheory.addSupport( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(0))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(3))), - 0.9 - ); - peafTheory.addSupport( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(0))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(4))), - 0.3 - ); - peafTheory.addSupport( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(3))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(5))), - 0.5 - ); - - // Define supports involving multiple arguments - Set argSet = new HashSet<>(); - argSet.add(peafTheory.getArguments().get(3)); - argSet.add(peafTheory.getArguments().get(4)); - peafTheory.addSupport( - argSet, - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(6))), - 0.9 - ); - - // Define attack relationships among arguments - peafTheory.addAttack( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(5))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(2))) - ); - peafTheory.addAttack( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(5))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(1))) - ); - peafTheory.addAttack( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(1))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(5))) - ); - peafTheory.addAttack( - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(1))), - new HashSet<>(Arrays.asList(peafTheory.getArguments().get(6))) - ); - - // Define the query for analysis - Set query = new HashSet<>(); - query.add(peafTheory.getArguments().get(0)); - - // Perform exact analysis - ExactAnalysis exactAnalysis = new ExactAnalysis(peafTheory, new SimplePreferredReasoner()); - AnalysisResult exactResult = exactAnalysis.query(query); - exactResult.print(); - - // Perform approximate analysis - ApproxAnalysis approxAnalysis = new ApproxAnalysis(peafTheory, new SimplePreferredReasoner(), 0.1); - AnalysisResult approxResult = approxAnalysis.query(query); - approxResult.print(); - } - - /** Default Constructor */ - public ApproximateJustificationAnalysisExample() {} -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/CheckIfSelfSupportingExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/CheckIfSelfSupportingExample.java deleted file mode 100644 index ce2c20bb3..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/CheckIfSelfSupportingExample.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.syntax.EAFTheory; -import org.tweetyproject.arg.bipolar.syntax.BArgument; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * This class demonstrates the use of the {@link EAFTheory} class to check for self-supporting sets of arguments. - * - * In this example, an extended argumentation framework (EAF) is created with a set of arguments and supports/attacks between them. - * The goal is to check whether certain sets of arguments are self-supporting using the {@code checkIsSelfSupporting} method - * of the {@link EAFTheory} class. - * - * @author Your Name - */ -public class CheckIfSelfSupportingExample { - - /** - * The entry point of the example program that sets up an {@link EAFTheory} instance, - * adds arguments, defines supports and attacks, and checks whether various sets of arguments - * are self-supporting. - * - * @param args command-line arguments (not used) - */ - public static void main(String[] args) { - EAFTheory eafTheory = new EAFTheory(); - for (int i = 0; i < 4; i++) { - eafTheory.addArgument(i); - } - - // Arguments: - // eta = 0, a = 1, b = 2, c = 3 - - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(Arrays.asList(eafTheory.getArguments().get(1)))); - eafTheory.addSupport(new HashSet(Arrays.asList(eafTheory.getArguments().get(0))), new HashSet(Arrays.asList(eafTheory.getArguments().get(2)))); - eafTheory.addAttack(new HashSet(Arrays.asList(eafTheory.getArguments().get(2))), new HashSet(Arrays.asList(eafTheory.getArguments().get(1)))); - eafTheory.addSupport(new HashSet(Arrays.asList(eafTheory.getArguments().get(1))), new HashSet(Arrays.asList(eafTheory.getArguments().get(3)))); - - List eArguments = eafTheory.getArguments(); - Set selfSupported = new HashSet<>(); - - // Various checks for self-supporting sets of arguments - selfSupported.add(eArguments.get(0)); - System.out.println("{eta} is " + eafTheory.checkIsSelfSupporting(selfSupported) + ", but must be true"); - selfSupported.clear(); - - selfSupported.add(eArguments.get(2)); - System.out.println("{b} is " + eafTheory.checkIsSelfSupporting(selfSupported) + ", but must be false"); - selfSupported.clear(); - - selfSupported.add(eArguments.get(1)); - selfSupported.add(eArguments.get(2)); - System.out.println("{a, b} is " + eafTheory.checkIsSelfSupporting(selfSupported) + ", but must be false"); - selfSupported.clear(); - - selfSupported.add(eArguments.get(0)); - selfSupported.add(eArguments.get(1)); - selfSupported.add(eArguments.get(3)); - System.out.println("{eta, a, c} is " + eafTheory.checkIsSelfSupporting(selfSupported) + ", but must be true"); - selfSupported.clear(); - - selfSupported.add(eArguments.get(0)); - selfSupported.add(eArguments.get(2)); - System.out.println("{eta, b} is " + eafTheory.checkIsSelfSupporting(selfSupported) + ", but must be true"); - - selfSupported.add(eArguments.get(0)); - selfSupported.add(eArguments.get(3)); - System.out.println("{eta, c} is " + eafTheory.checkIsSelfSupporting(selfSupported) + ", but must be false"); - } - - /** - * Default constructor for the {@code CheckIfSelfSupportingExample} class. - * Initializes an instance of this class, though it currently has no specific initialization logic. - */ - public CheckIfSelfSupportingExample() {} -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveArgumentation.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveArgumentation.java deleted file mode 100644 index 05df978fe..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveArgumentation.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - - -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.reasoner.deductive.*; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.tweetyproject.arg.dung.reasoner.SimpleCompleteReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleGroundedReasoner; -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleStableReasoner; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.logics.pl.sat.Sat4jSolver; -import org.tweetyproject.logics.pl.sat.SatSolver; - -/** - * Demonstrates the construction of deductive argumentation frameworks and the computation of their extensions. - *

- * This example uses the Deductive Argumentation Framework to create an argumentation framework, add arguments and relationships, - * and then compute various types of extensions. The example framework and its associated Dung theory are used to compute extensions - * using different reasoners. - *

- * The example is based on the work by Cayrol and Lagasquie-Schiex on bipolarity in argumentation graphs. - */ -public class DeductiveArgumentation { - - /** - * The entry point of the example program. Constructs a deductive argumentation framework, adds arguments, attacks, and supports, - * and computes various types of extensions using different reasoners. - *

- * The following steps are performed in the main method: - *

    - *
  1. Create a {@link DeductiveArgumentationFramework} instance.
  2. - *
  3. Add four arguments to the framework.
  4. - *
  5. Add one attack and two support relationships between the arguments.
  6. - *
  7. Obtain the associated Dung theory and meta-framework for the deductive argumentation framework.
  8. - *
  9. Set the default SAT solver to {@link Sat4jSolver}.
  10. - *
  11. Compute and print the closed extensions and safe extensions using the {@link ClosureReasoner} and {@link SafetyReasoner}.
  12. - *
  13. Compute and print the preferred, grounded, and stable extensions for the Dung theory using the {@link SimplePreferredReasoner}, {@link SimpleGroundedReasoner}, and {@link SimpleStableReasoner}.
  14. - *
  15. Compute and print the complete extensions for both the Dung theory and the meta-framework using the {@link SimpleCompleteReasoner}.
  16. - *
- * - * @param args command-line arguments (not used) - */ - public static void main(String[] args) { - // Example from Cayrol, Lagasquie-Schiex. Bipolarity in argumentation graphs: Towards a better understanding. 2013 - DeductiveArgumentationFramework at = new DeductiveArgumentationFramework(); - BArgument a = new BArgument("a"); - BArgument b = new BArgument("b"); - BArgument c = new BArgument("c"); - BArgument x = new BArgument("x"); - at.add(a); - at.add(b); - at.add(c); - at.add(x); - - Attack att1 = new BinaryAttack(x, c); - at.add(att1); - - Support supp1 = new BinarySupport(a, x); - Support supp2 = new BinarySupport(b, c); - at.add(supp1); - at.add(supp2); - - DungTheory dt = at.getCompleteAssociatedDungTheory(); - DungTheory mt = at.getMetaFramework(); - - SatSolver.setDefaultSolver(new Sat4jSolver()); - - System.out.println("Closed extensions at: " + new ClosureReasoner().getModels(at)); - System.out.println("Safe extensions at: " + new SafetyReasoner().getModels(at)); - - System.out.println("Preferred extensions: " + new SimplePreferredReasoner().getModels(dt)); - System.out.println("Grounded extensions: " + new SimpleGroundedReasoner().getModels(dt)); - System.out.println("Stable extensions: " + new SimpleStableReasoner().getModels(dt)); - - System.out.println("Complete extensions dt: " + new SimpleCompleteReasoner().getModels(dt)); - System.out.println("Complete extensions mt: " + new SimpleCompleteReasoner().getModels(mt)); - } - - /** - * Default constructor for the {@code DeductiveArgumentation} class. - * Initializes an instance of this class, though it currently has no specific initialization logic. - */ - public DeductiveArgumentation() {} -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveBipolarArgumentation.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveBipolarArgumentation.java new file mode 100644 index 000000000..ca7dcc65c --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/DeductiveBipolarArgumentation.java @@ -0,0 +1,73 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.examples; + +import org.tweetyproject.arg.bipolar.reasoner.SimpleDeductiveReasoner; +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.bipolar.syntax.Support; +import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; +import org.tweetyproject.arg.dung.semantics.Semantics; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +/** + * Demonstrates the construction of deductive argumentation frameworks and the computation of their extensions. + * + * @author Lars Bengel + */ +public class DeductiveBipolarArgumentation { + + /** + * The entry point of the example program. Constructs a deductive argumentation framework, adds arguments, attacks, and supports, + * and computes extensions using different reasoners. + * + * @param args command-line arguments (not used) + */ + public static void main(String[] args) { + // Example from Cayrol, Lagasquie-Schiex. Bipolarity in argumentation graphs: Towards a better understanding. 2013 + BipolarArgumentationFramework at = new BipolarArgumentationFramework(); + Argument a = new Argument("a"); + Argument b = new Argument("b"); + Argument c = new Argument("c"); + Argument x = new Argument("x"); + at.add(a); + at.add(b); + at.add(c); + at.add(x); + + at.addAttack(x,c); + at.addSupport(a,x); + at.addSupport(b,c); + + DungTheory dt = at.getAssociatedTheory(Support.Type.DEDUCTIVE); + + System.out.println(at.prettyPrint()); + + // Computing the preferred extensions directly or via the associated abstract argumentation framework should yield the same result + System.out.println("Preferred extensions of at: " + new SimpleDeductiveReasoner(Semantics.PR).getModels(at)); + System.out.println("Preferred extensions of dt: " + new SimplePreferredReasoner().getModels(dt)); + } + + /** + * Default constructor for the {@code DeductiveBipolarArgumentation} class. + * Initializes an instance of this class, though it currently has no specific initialization logic. + */ + public DeductiveBipolarArgumentation() {} +} + diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EAFExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EAFExample.java deleted file mode 100644 index c62c84cd9..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EAFExample.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - -import org.tweetyproject.arg.bipolar.io.EdgeListWriter; -import org.tweetyproject.arg.bipolar.syntax.*; - -/** - * Provides an example of constructing an Argumentation Framework (EAFTheory) and saving its representation to a file. - *

- * This example demonstrates the creation of an argumentation framework with eight arguments, setting up various support - * and attack relationships between these arguments, and finally writing the resulting framework to a file. - */ -public class EAFExample { - - /** - * The entry point of the example program. Constructs an {@link EAFTheory} instance, adds arguments, support, and attack - * relationships, and writes the framework to a file. - *

- * The following steps are performed in the main method: - *

    - *
  1. Create an instance of {@link EAFTheory}.
  2. - *
  3. Add eight arguments to the framework.
  4. - *
  5. Define support relationships between various sets of arguments.
  6. - *
  7. Define attack relationships between specific arguments.
  8. - *
  9. Print the string representation of the framework to the console.
  10. - *
  11. Write the framework to a file named "eaf.txt" using {@link EdgeListWriter}.
  12. - *
- * - * @param _args command-line arguments (not used in this example) - */ - public static void main(String[] _args) { - int numOfArgs = 8; - - EAFTheory eafTheory = new EAFTheory(); - - for (int i = 0; i < numOfArgs; i++) { - eafTheory.addArgument(i); - } - - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(1))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(3))))); - HashSet args1 = new HashSet(); - args1.add(eafTheory.getArguments().get(1)); - args1.add(eafTheory.getArguments().get(3)); - eafTheory.addSupport(args1, new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(3))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(5))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(6))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(6)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(7))))); - HashSet args2 = new HashSet(); - args2.add(eafTheory.getArguments().get(5)); - args2.add(eafTheory.getArguments().get(7)); - eafTheory.addSupport(args2, new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(4))))); - - eafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(5)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(4))))); - eafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(6))))); - - System.out.println(eafTheory.toString()); - - EdgeListWriter.write("eaf.txt", eafTheory); - } - - /** - * Default constructor for the {@code EAFExample} class. - * Initializes an instance of this class. This constructor does not perform any specific initialization. - */ - public EAFExample() {} -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EasyPEAFExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EasyPEAFExample.java deleted file mode 100644 index c8fb33454..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EasyPEAFExample.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - -import org.tweetyproject.arg.bipolar.inducers.LiExactPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; -/** - * Provides an example of constructing a Probabilistic Argumentation Framework (PEAFTheory), adding support relationships, - * and inducing extensions using a specific inducer. - *

- * This example demonstrates the creation of a PEAFTheory instance with two arguments, setting up support relationships - * with specified probabilities, and then inducing extensions of the framework using the {@link LiExactPEAFInducer}. - */ -public class EasyPEAFExample { - - /** - * The entry point of the example program. Constructs a {@link PEAFTheory} instance, adds arguments, defines support - * relationships with associated probabilities, prints the framework, and induces extensions using the - * {@link LiExactPEAFInducer}. - *

- * The following steps are performed in the main method: - *

    - *
  1. Create an instance of {@link PEAFTheory}.
  2. - *
  3. Add two arguments to the framework.
  4. - *
  5. Define support relationships between the arguments with specified probabilities.
  6. - *
  7. Print the framework in a human-readable format using {@link PEAFTheory#prettyPrint()}.
  8. - *
  9. Induce extensions of the framework using {@link LiExactPEAFInducer} and print each induced extension.
  10. - *
- * - * @param args command-line arguments (not used in this example) - */ - public static void main(String[] args) { - PEAFTheory peafTheory = new PEAFTheory(); - peafTheory.addArgument(0); - peafTheory.addArgument(1); - - - peafTheory.addSupport(new HashSet(), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), 1.0); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), 0.3); - - - peafTheory.prettyPrint(); - LiExactPEAFInducer inducer = new LiExactPEAFInducer(peafTheory); - - inducer.induce(ind -> { - System.out.println(ind); - - - }); - } - - /** Default Constructor */ - public EasyPEAFExample(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialAcceptability.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialAcceptability.java deleted file mode 100644 index 351825fcf..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialAcceptability.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - - -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.HashSet; -import java.util.Set; - -/** - * Demonstrates the use of evidential argumentation frameworks. - *

- * This example shows how to construct an instance of {@link EvidentialArgumentationFramework}, - * add arguments, support, and attack relationships, and check the acceptability of arguments - * with respect to a given set of arguments. - * It also prints the framework in a human-readable format. - */ -public class EvidentialAcceptability { - - /** - * The entry point of the example program. Constructs an {@link EvidentialArgumentationFramework} instance, - * adds arguments, defines support and attack relationships, specifies prima facie arguments, and checks - * the acceptability of various arguments with respect to a specified set of arguments. - * - * @param args command-line arguments (not used in this example) - */ - public static void main(String[] args) { - EvidentialArgumentationFramework et = new EvidentialArgumentationFramework(); - BArgument a = new BArgument("a"); - BArgument b = new BArgument("b"); - BArgument c = new BArgument("c"); - BArgument d = new BArgument("d"); - BArgument e = new BArgument("e"); - BArgument f = new BArgument("f"); - et.add(a); - et.add(b); - et.add(c); - et.add(d); - et.add(e); - et.add(f); - SetAttack att1 = new SetAttack(a, f); - SetAttack att2 = new SetAttack(b, e); - SetAttack att3 = new SetAttack(d, c); - SetAttack att4 = new SetAttack(c, e); - SetSupport supp1 = new SetSupport(f, b); - SetSupport supp2 = new SetSupport(d, e); - et.add(att1); - et.add(att2); - et.add(att3); - et.add(att4); - et.add(supp1); - et.add(supp2); - - - et.addPrimaFacie(a); - et.addPrimaFacie(c); - et.addPrimaFacie(d); - et.addPrimaFacie(f); - - - System.out.println(et.prettyPrint()); - - Set s1 = new HashSet<>(); - s1.add(et.getEta()); - s1.add(a); - s1.add(d); - - System.out.println("Argument a is acceptable wrt. " + s1 + ": " + et.isAcceptable(a, s1)); - System.out.println("Argument b is acceptable wrt. " + s1 + ": " + et.isAcceptable(b, s1)); - System.out.println("Argument c is acceptable wrt. " + s1 + ": " + et.isAcceptable(c, s1)); - System.out.println("Argument d is acceptable wrt. " + s1 + ": " + et.isAcceptable(d, s1)); - System.out.println("Argument e is acceptable wrt. " + s1 + ": " + et.isAcceptable(e, s1)); - System.out.println("Argument f is acceptable wrt. " + s1 + ": " + et.isAcceptable(f, s1)); - - } - - /** Default Constructor */ - public EvidentialAcceptability(){} -} \ No newline at end of file diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation.java deleted file mode 100644 index a1cba9c96..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - - -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.reasoner.evidential.*; -import org.tweetyproject.arg.bipolar.syntax.*; - -/** - * More examples for evidential argumentation frameworks. - */ -public class EvidentialArgumentation { - - /** - * Example - * @param args the args - */ - public static void main(String[] args) { - // Example from Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - EvidentialArgumentationFramework et = new EvidentialArgumentationFramework(); - BArgument a = new BArgument("a"); - BArgument b = new BArgument("b"); - BArgument c = new BArgument("c"); - BArgument d = new BArgument("d"); - BArgument e = new BArgument("e"); - BArgument f = new BArgument("f"); - et.add(a); - et.add(b); - et.add(c); - et.add(d); - et.add(e); - et.add(f); - - SetAttack att1 = new SetAttack(b, a); - SetAttack att2 = new SetAttack(b, c); - SetAttack att3 = new SetAttack(c, b); - SetAttack att4 = new SetAttack(c, d); - SetAttack att5 = new SetAttack(d, f); - SetAttack att6 = new SetAttack(f, f); - et.add(att1); - et.add(att2); - et.add(att3); - et.add(att4); - et.add(att5); - et.add(att6); - - SetSupport supp1 = new SetSupport(d, e); - et.add(supp1); - - et.addPrimaFacie(b); - et.addPrimaFacie(c); - et.addPrimaFacie(d); - et.addPrimaFacie(f); - - System.out.println("Self-Supporting extensions: " + new SelfSupportingReasoner().getModels(et)); - System.out.println("Conflict-Free extensions: " + new ConflictFreeReasoner().getModels(et)); - System.out.println("Admissible extensions: " + new AdmissibleReasoner().getModels(et)); - System.out.println("Grounded extensions: " + new GroundedReasoner().getModels(et)); - System.out.println("Complete extensions: " + new CompleteReasoner().getModels(et)); - System.out.println("Preferred extensions: " + new PreferredReasoner().getModels(et)); - System.out.println("Stable extensions: " + new StableReasoner().getModels(et)); - } - - /** Default Constructor */ - public EvidentialArgumentation(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation2.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation2.java deleted file mode 100644 index f9a793892..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/EvidentialArgumentation2.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.reasoner.evidential.*; -import org.tweetyproject.arg.bipolar.syntax.*; - -/** - * More examples for evidential argumentation frameworks. - */ -public class EvidentialArgumentation2 { - /** - * Example - * @param args the args - */ - public static void main(String[] args) { - // Example from Oren, Norman. Semantics for Evidence-Based Argumentation. 2008 - EvidentialArgumentationFramework et = new EvidentialArgumentationFramework(); - BArgument a = new BArgument("a"); - BArgument b = new BArgument("b"); - BArgument c = new BArgument("c"); - BArgument x = new BArgument("x"); - et.add(a); - et.add(b); - et.add(c); - et.add(x); - - Attack att1 = new SetAttack(a, c); - Attack att2 = new BinaryAttack(a, b); - Attack att3 = new BinaryAttack(c, x); - et.add(att1); - et.add(att2); - et.add(att3); - - SetSupport supp1 = new SetSupport(b, x); - et.add(supp1); - - et.addPrimaFacie(a); - et.addPrimaFacie(b); - et.addPrimaFacie(c); - et.addPrimaFacie(x); - - System.out.println(et.prettyPrint()); - - System.out.println("Self-Supporting extensions: " + new SelfSupportingReasoner().getModels(et)); - System.out.println("Conflict-Free extensions: " + new ConflictFreeReasoner().getModels(et)); - System.out.println("Admissible extensions: " + new AdmissibleReasoner().getModels(et)); - System.out.println("Grounded extensions: " + new GroundedReasoner().getModels(et)); - System.out.println("Complete extensions: " + new CompleteReasoner().getModels(et)); - System.out.println("Preferred extensions: " + new PreferredReasoner().getModels(et)); - System.out.println("Stable extensions: " + new StableReasoner().getModels(et)); - } - - /** Default Constructor */ - public EvidentialArgumentation2(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ExpandMCExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ExpandMCExample.java deleted file mode 100644 index 0a46fcc90..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/ExpandMCExample.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - -import org.tweetyproject.arg.bipolar.inducers.ExactPEAFInducer; -import org.tweetyproject.arg.bipolar.inducers.LiExactPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -/** - * Demonstrates the use of various PEAF (Probabilistic Evidential Argumentation Framework) - * inducers to compute and display argumentation frameworks and their associated probabilities. - *

- * This example constructs a {@link PEAFTheory} with a set of arguments and support relationships, - * prints the framework, and uses different inducers to process the framework and output the results. - */ -public class ExpandMCExample { - - /** - * The entry point of the example program. Constructs a {@link PEAFTheory} instance, - * adds arguments and support relationships, and utilizes two types of inducers to process - * the framework. It prints the framework and the results obtained from using the - * {@link LiExactPEAFInducer} and {@link ExactPEAFInducer}. - *

- * The following steps are performed in the main method: - *

    - *
  1. Create an instance of {@link PEAFTheory}.
  2. - *
  3. Add four arguments to the framework.
  4. - *
  5. Define and add support relationships between the arguments with associated probabilities.
  6. - *
  7. Print the framework using {@link PEAFTheory#prettyPrint()}.
  8. - *
  9. Create an instance of {@link LiExactPEAFInducer} and use it to induce and print the - * results along with the accumulated probability.
  10. - *
  11. Reset the probability and repeat the induction process with {@link ExactPEAFInducer}, - * printing the results and the accumulated probability.
  12. - *
- * - * @param args command-line arguments (not used in this example) - */ - public static void main(String[] args) { - PEAFTheory peafTheory = new PEAFTheory(); - for(int i = 0; i < 4; i++) { - peafTheory.addArgument(i); - } - - peafTheory.addSupport(new HashSet(), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), 1.0); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), 0.8); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), 0.9); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), 0.9); - - peafTheory.prettyPrint(); - - System.out.println("The LiExactPEAFInducer:"); - System.out.println(); - final double[] p = {0.0}; - LiExactPEAFInducer inducer = new LiExactPEAFInducer(peafTheory); - inducer.induce(inducibleEAF -> { - System.out.println(inducibleEAF); - p[0] += inducibleEAF.getInducePro(); - }); - - System.out.println("The result is: " + p[0]); - p[0] = 0.0; - - System.out.println(); - System.out.println("The ExactPEAFInducer:"); - System.out.println(); - ExactPEAFInducer inducer2 = new ExactPEAFInducer(peafTheory); - inducer2.induce(inducibleEAF -> { - System.out.println(inducibleEAF); - p[0] += inducibleEAF.getInducePro(); - }); - - System.out.println("The result is: " + p[0]); - } - - /** Default Constructor */ - public ExpandMCExample(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/JustificationAnalysisExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/JustificationAnalysisExample.java deleted file mode 100644 index 613ca2081..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/JustificationAnalysisExample.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.analysis.AnalysisResult; -import org.tweetyproject.arg.bipolar.analysis.ExactAnalysis; -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -/** - * JustificationAnalysisExample class - */ -public class JustificationAnalysisExample { - /** - * Example - * @param s string array - */ - public static void main(String[] s) { - int numOfArgs = 7; - PEAFTheory peafTheory = new PEAFTheory(); - - for (int i = 0; i < numOfArgs; i++) { - peafTheory.addArgument(i); - } - - - peafTheory.addSupport(new HashSet(), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), 1.0); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), 0.6); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), 0.7); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), 0.9); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(4)))), 0.3); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), 0.5); - HashSet arg3And4 = new HashSet(); - arg3And4.add(peafTheory.getArguments().get(3)); - arg3And4.add(peafTheory.getArguments().get(4)); - peafTheory.addSupport(arg3And4, new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(6)))), 0.9); - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2))))); - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1))))); - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5))))); - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(6))))); - - List args = peafTheory.getArguments(); -// args.get(0).setName("eta"); -// args.get(1).setName("b"); -// args.get(2).setName("d"); -// args.get(3).setName("e"); -// args.get(4).setName("f"); -// args.get(5).setName("a"); -// -// -// args.get(6).setName("c"); - - Set query = new HashSet<>(); -// query.add(args.get(0)); - query.add(args.get(1)); - query.add(args.get(6)); - - ExactAnalysis analysis = new ExactAnalysis(peafTheory, new SimplePreferredReasoner()); - AnalysisResult result = analysis.query(query); - result.print(); - - - } - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/LiThesisPage21EAFExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/LiThesisPage21EAFExample.java deleted file mode 100644 index cd89da0f4..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/LiThesisPage21EAFExample.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - -/** - * LiThesisPage21EAFExample class - */ -public class LiThesisPage21EAFExample { - - /** - * Example - * @param args the args - */ - public static void main(String[] args) { - EAFTheory eafTheory = new EAFTheory(); - for(int i = 0; i< 9; i++) { - eafTheory.addArgument(i); - } - - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(1))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(3))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(4))))); - HashSet arg3And4 = new HashSet(); - arg3And4.add(eafTheory.getArguments().get(3)); - arg3And4.add(eafTheory.getArguments().get(4)); - eafTheory.addSupport(arg3And4, new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(7))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(5))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(5)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(8))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(6))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(6)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(8))))); - - eafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(5))))); - eafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(6)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(3))))); - - - DungTheory dungTheory = eafTheory.convertToDAFNaively(); - - System.out.println("EAF Theory Pretty Print:"); - eafTheory.prettyPrint(); - - System.out.println("DAF Theory Pretty Print:"); - System.out.println(dungTheory.prettyPrint()); - - System.out.println("SimplePreferredReasoner:"); - SimplePreferredReasoner reasoner1 = new SimplePreferredReasoner(); - for (Extension model : reasoner1.getModels(dungTheory)) { - System.out.println(model); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/MeetingPEAFExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/MeetingPEAFExample.java deleted file mode 100644 index d828283bd..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/MeetingPEAFExample.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.inducers.ExactPEAFInducer; -import org.tweetyproject.arg.bipolar.inducers.LiExactPEAFInducer; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.HashSet; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * MeetingPEAFExample class - */ -public class MeetingPEAFExample { - - /** total */ - static double total = 0; - - /** - * Example - * @param s args - */ - public static void main(String[] s) { - int numOfArgs = 7; - - - PEAFTheory peafTheory = new PEAFTheory(); - - for (int i = 0; i < numOfArgs; i++) { - peafTheory.addArgument(i); - } - HashSet arg0 = new HashSet(); - arg0.add(peafTheory.getArguments().get(0)); - HashSet arg1 = new HashSet(); - arg1.add(peafTheory.getArguments().get(1)); - HashSet arg2 = new HashSet(); - arg2.add(peafTheory.getArguments().get(2)); - HashSet arg3 = new HashSet(); - arg3.add(peafTheory.getArguments().get(3)); - HashSet arg4 = new HashSet(); - arg4.add(peafTheory.getArguments().get(4)); - HashSet arg5 = new HashSet(); - arg5.add(peafTheory.getArguments().get(5)); - HashSet arg6 = new HashSet(); - arg6.add(peafTheory.getArguments().get(6)); - - peafTheory.addSupport(new HashSet(), arg0 , 1.0); - peafTheory.addSupport(arg0, arg2, 1.0); - peafTheory.addSupport(arg0, arg1, 1.0); - peafTheory.addSupport(arg0, arg3, 1.0); - peafTheory.addSupport(arg0, arg4, 1.0); - peafTheory.addSupport(arg3, arg5, 1.0); -// peafTheory.addSupport(new int[]{3, 4}, new int[]{6}, 0.9); - - peafTheory.addAttack(arg5, arg2); - peafTheory.addAttack(arg5, arg1); - peafTheory.addAttack(arg1, arg5); - peafTheory.addAttack(arg1, arg6); - - - List args = peafTheory.getArguments(); - args.get(0).setName("eta"); - args.get(1).setName("b"); - args.get(2).setName("d"); - args.get(3).setName("e"); - args.get(4).setName("f"); - args.get(5).setName("a"); - args.get(6).setName("c"); - peafTheory.prettyPrint(); -// EdgeListWriter.write("/Users/tdgunes/Projects/DrawPrEAF/input/0.peaf", peafTheory); - - System.out.println("LiExactPEAFInducer: "); - AtomicInteger i = new AtomicInteger(); - LiExactPEAFInducer inducer = new LiExactPEAFInducer(peafTheory); - total = 0; - inducer.induce(ind -> { - int n = i.getAndIncrement(); - System.out.println(n + ". " + ind); - String probability = String.format("%.04f", ind.getInducePro()); - probability = probability.replace(".", "_"); -// EdgeListWriter.write("/Users/tdgunes/Projects/DrawPrEAF/input/" + n + "" + "_" + result + ".eaf", ind.toNewEAFTheory()); - total += ind.getInducePro(); - }); - System.out.println("Total result: " + total); - - System.out.println(); - System.out.println("The ExactPEAFInducer:"); - System.out.println(); - AtomicInteger i1 = new AtomicInteger(); - ExactPEAFInducer inducer2 = new ExactPEAFInducer(peafTheory); - total = 0; - inducer2.induce(ind -> { - int n = i1.getAndIncrement(); - System.out.println(n + ". " + ind); - String probability = String.format("%.04f", ind.getInducePro()); - probability = probability.replace(".", "_"); -// EdgeListWriter.write("/Users/tdgunes/Projects/DrawPrEAF/input/" + n + "" + "_" + result + ".eaf", ind.toNewEAFTheory()); - total += ind.getInducePro(); - }); - System.out.println("Total result: " + total); - - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityArgumentation.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityArgumentation.java deleted file mode 100644 index d4b603210..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityArgumentation.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2020 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import java.util.HashSet; - -import org.tweetyproject.arg.bipolar.reasoner.necessity.*; -import org.tweetyproject.arg.bipolar.syntax.*; - -/** - * Examples for necessity argumentation frameworks. - */ -public class NecessityArgumentation { - - /** - * Example - * @param args args - */ - public static void main(String[] args) { - // Example from Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - NecessityArgumentationFramework nt = new NecessityArgumentationFramework(); - BArgument a = new BArgument("a"); - BArgument b = new BArgument("b"); - BArgument c = new BArgument("c"); - BArgument d = new BArgument("d"); - BArgument e = new BArgument("e"); - nt.add(a); - nt.add(b); - nt.add(c); - nt.add(d); - nt.add(e); - - ArgumentSet aS1 = new ArgumentSet(); - aS1.add(b); - aS1.add(d); - Attack att1 = new BinaryAttack(b, a); - Attack att2 = new BinaryAttack(e, a); - Attack att3 = new BinaryAttack(c, d); - Support supp1 = new BinarySupport(a, c); - Support supp2 = new BinarySupport(b, b); - HashSet eSet = new HashSet(); - eSet.add(e); - Support supp3 = new SetSupport(aS1, eSet); - nt.add(att1); - nt.add(att2); - nt.add(att3); - nt.add(supp1); - nt.add(supp2); - nt.add(supp3); - - System.out.println(nt.prettyPrint()); - - System.out.println("Admissible extensions: " + new AdmissibleReasoner().getModels(nt)); - System.out.println("Grounded extensions: " + new GroundedReasoner().getModels(nt)); - System.out.println("Complete extensions: " + new CompleteReasoner().getModels(nt)); - System.out.println("Preferred extensions: " + new PreferredReasoner().getModels(nt)); - System.out.println("Stable extensions: " + new StableReasoner().getModels(nt)); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityBipolarArgumentation.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityBipolarArgumentation.java new file mode 100644 index 000000000..279f02613 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/NecessityBipolarArgumentation.java @@ -0,0 +1,74 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.examples; + +import org.tweetyproject.arg.bipolar.reasoner.SimpleNecessityReasoner; +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.bipolar.syntax.Support; +import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; +import org.tweetyproject.arg.dung.semantics.Semantics; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +/** + * Examples for necessity argumentation frameworks. + * + * @author Lars Bengel + */ +public class NecessityBipolarArgumentation { + + /** + * Example + * @param args args + */ + public static void main(String[] args) { + // Modified Example from Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 + BipolarArgumentationFramework nt = new BipolarArgumentationFramework(); + 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"); + nt.add(a,b,c,d,e); + + nt.addAttack(b,a); + nt.addAttack(e,a); + nt.addAttack(c,d); + nt.addSupport(a,c); + nt.addSupport(b,b); + + System.out.println("BAF:"); + System.out.println(nt.prettyPrint()); + + DungTheory dt = nt.getAssociatedTheory(Support.Type.NECESSITY); + + System.out.println("Associated AF:"); + System.out.println(dt.prettyPrint()); + + // Computing the preferred extensions directly or via the associated abstract argumentation framework should yield the same result + System.out.println("Preferred extensions of at: " + new SimpleNecessityReasoner(Semantics.PR).getModels(nt)); + System.out.println("Preferred extensions of dt: " + new SimplePreferredReasoner().getModels(dt)); + } + + /** + * Default constructor for the {@code NecessityBipolarArgumentation} class. + * Initializes an instance of this class, though it currently has no specific initialization logic. + */ + public NecessityBipolarArgumentation() {} +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/OrenEtAl2010Figure2Example.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/OrenEtAl2010Figure2Example.java deleted file mode 100644 index af8bbf4b5..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/OrenEtAl2010Figure2Example.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.DungTheory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.EAFTheory; - -/** - * OrenEtAl2010Figure2Example class - */ -public class OrenEtAl2010Figure2Example { - /** - * Example - * @param args args - */ - public static void main(String[] args) { - EAFTheory eafTheory = new EAFTheory(); - for(int i = 0; i< 4 ; i++) { - eafTheory.addArgument(i); - } - - - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(1))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2))))); - eafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(1))))); - eafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(eafTheory.getArguments().get(3))))); - - DungTheory dungTheory = eafTheory.convertToDAFNaively(); - - System.out.println("EAF Theory Pretty Print:"); - eafTheory.prettyPrint(); - - System.out.println("DAF Theory Pretty Print:"); - System.out.println(dungTheory.prettyPrint()); - - System.out.println("SimplePreferredReasoner:"); - SimplePreferredReasoner reasoner1 = new SimplePreferredReasoner(); - for (Extension model : reasoner1.getModels(dungTheory)) { - System.out.println(model); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/SomePEAFInducerExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/SomePEAFInducerExample.java deleted file mode 100644 index faa294979..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/SomePEAFInducerExample.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.io.EdgeListWriter; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.InducibleEAF; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - -/** - * SomePEAFInducerExample class - */ -public class SomePEAFInducerExample { - /** - * Example - * @param args args - */ - public static void main(String[] args) { - int numOfArgs = 8; - - - PEAFTheory peafTheory = new PEAFTheory(); - - for (int i = 0; i < numOfArgs; i++) { - peafTheory.addArgument(i); - } - - peafTheory.addSupport(new HashSet(), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), 1.0); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), 0.3); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), 0.8); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(1)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), 0.9); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(4)))), 0.85); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), 0.5); - peafTheory.addSupport(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(3)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(6)))), 0.6); - HashSet arg5And4 = new HashSet(); - arg5And4.add(peafTheory.getArguments().get(5)); - arg5And4.add(peafTheory.getArguments().get(4)); - peafTheory.addSupport(arg5And4, new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(7)))), 0.4); - - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(5)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(4))))); - peafTheory.addAttack(new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(2)))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(6))))); - - System.out.println(peafTheory.toString()); - - EdgeListWriter.write("peaf.networkx", peafTheory); - - AtomicInteger i = new AtomicInteger(); - - - Consumer consumer = new Consumer() { - @Override - public void accept(InducibleEAF inducibleEAF) { - int n = i.getAndIncrement(); - System.out.println(inducibleEAF); - } - }; - - - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/admissibleExample.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/admissibleExample.java deleted file mode 100644 index 92334eb99..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/examples/admissibleExample.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.examples; - -import org.tweetyproject.arg.bipolar.reasoner.deductive.*; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.DeductiveArgumentationFramework; - -/** - * A demonstration class for showing how to use the Deductive Argumentation - * Framework - * with different admissible reasoners. This example sets up a simple - * argumentation - * framework, adds arguments and their relationships, and then prints the - * results - * of admissible reasoning. - */ -public class admissibleExample { - /** - * Main method to run the example. - *

- * This method initializes a deductive argumentation framework with three - * arguments, - * adds attacks and supports between them, and then uses two different - * admissible reasoners - * to compute and print the admissible extensions. - *

- * - * @param args Command line arguments (not used in this example). - */ - public static void main(String[] args) { - DeductiveArgumentationFramework theory = new DeductiveArgumentationFramework(); - BArgument a = new BArgument("a"); - BArgument b = new BArgument("b"); - BArgument h = new BArgument("h"); - - theory.add(a); - theory.add(b); - theory.add(h); - - theory.addAttack(h, b); - theory.addSupport(a, b); - - System.out.println(theory.prettyPrint()); - - System.out.print("d-admissible extensions: "); - System.out.println(new DAdmissibleReasoner().getModels(theory)); - - System.out.print("c-admissible extensions: "); - System.out.println(new CAdmissibleReasoner().getModels(theory)); - } - - /** Default Constructor */ - public admissibleExample() { - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/AbstractPEAFInducer.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/AbstractPEAFInducer.java deleted file mode 100644 index a6e7b89f1..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/AbstractPEAFInducer.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.inducers; - - - -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - -/** - * AbstractPEAFInducer includes helper functions for concrete implementations - * - * @author Taha Dogan Gunes - */ -public abstract class AbstractPEAFInducer implements PEAFInducer { - - /** - * PEAFTheory that will be induced. - */ - protected PEAFTheory peafTheory; - - /** - * Default constructor (checks if the given PEAF is cyclic or not.) - *

- * Cyclic in PEAF support links is forbidden in PEAF specification. - * - * @param peafTheory a PEAFTheory object - */ - public AbstractPEAFInducer(PEAFTheory peafTheory) { - this.peafTheory = peafTheory; - - if (isSupportLinksCyclic()) { - throw new CyclicException("This PEAF can not be induced, because a cyclic was found."); - } - } - - /** - * Check if the given PEAFTheory has cyclic or not in the support links. - * - * @return true if there is a cyclic - */ - private boolean isSupportLinksCyclic() { - // Adapted from https://www.geeksforgeeks.org/detect-cycle-in-a-graph/ - // Mark all the vertices as not visited and - // not part of recursion stack - - Map visited = new HashMap(); - Map recStack = new HashMap(); - for (BArgument argument : peafTheory.getArguments()) { - visited.put(argument, false); - recStack.put(argument, false); - } - - // Call the recursive helper function to - // detect cycle in different DFS trees - for (BArgument arg : this.peafTheory.getArguments()) { - if (isCyclicUtil(arg, visited, recStack)) - return true; - } - - return false; - } - - /** - * Induce n times - * @param consumer a inducible eaf consumer - * @param n number of iterations - */ - public void induceNTimes(Consumer consumer, int n) { - while (n > 0) { - this.induce(consumer); - n--; - } - } - - /** - * Returns the used PEAFTheory in inducer - * - * @return the given PEAFTheory object - */ - public PEAFTheory getPeafTheory() { - return peafTheory; - } - - /** - * Recursive DFS to find some cyclics in the PEAF - *

- * This function is a variation of DFSUtil() in - * https://www.geeksforgeeks.org/archives/18212 - * - * @param arg starting EArgument to explore - * @param visited the map stores if the argument is explored or not - * @param recStack recursion stack - * @return return true if it is a cyclic - */ - private boolean isCyclicUtil(BArgument arg, Map visited, - Map recStack) { - // Mark the current node as visited and - // part of recursion stack - if (recStack.get(arg)) - return true; - - if (visited.get(arg)) - return false; - - visited.put(arg, true); - recStack.put(arg, true); - Set set = peafTheory.getSupports(arg); - - for (Support c : set) { - for (BArgument to : c.getSupported()) { - if (isCyclicUtil(to, visited, recStack)) - return true; - } - } - recStack.put(arg, false); - - return false; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ApproxPEAFInducer.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ApproxPEAFInducer.java deleted file mode 100644 index 146faef11..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ApproxPEAFInducer.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.inducers; - -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Stack; -import java.util.concurrent.ThreadLocalRandom; -import java.util.function.Consumer; - -/** - * ApproxPEAFInducer induces a set of random EAFs from a PEAF - * - * @author Taha Dogan Gunes - */ -public class ApproxPEAFInducer extends AbstractPEAFInducer { - /** - * Internal intermediate data structure to expand an EAF in the inducer - * - * @see ExactPEAFInducer.EAF_F - */ - class EAF_F { - /** - * Arguments of the EAF - */ - Set eArguments; - /** - * Supports of the EAF - */ - Set eSupports; - /** - * The next arguments to add to the EAF - */ - Set newEArguments; - - /** - * @param eArguments - * @param eSupports - * @param newEArguments - */ - public EAF_F(Set eArguments, - Set eSupports, - Set newEArguments) { - this.eArguments = eArguments; - this.eSupports = eSupports; - this.newEArguments = newEArguments; - } - - /** - * For compatibility this re-implementation maps to InducibleEAF - * - * @return an InducibleEAF - * @see InducibleEAF - */ - public InducibleEAF convertToInducible() { - List supportList = new ArrayList(); - for (Support eSupport : eSupports) { - supportList.add((Support) eSupport); - } - HashSet args = new HashSet<>(); - HashSet> lists = new HashSet>(); - args.addAll(eArguments); - lists.add(supportList); - - InducibleEAF inducibleEAF = new InducibleEAF(args, - new HashSet<>(supportList), - new HashSet<>(), - new HashSet<>(), - 0, 0); - - inducibleEAF.addAttackLinks(); - - return inducibleEAF; - } - - /** - * Makes a direct copy of this EAF_F - * - * @return a copied EAF_F - */ - public EAF_F copy() { - return new EAF_F(this.eArguments, this.eSupports, this.newEArguments); - } - } - - /** - * The default constructor for the ApproxPEAFInducer - * - * @param peafTheory a theory - */ - public ApproxPEAFInducer(PEAFTheory peafTheory) { - super(peafTheory); - } - - /** - * Inducer induces inducibleEAFs and gives to a consumer function - * - * @param consumer the function that consumes InducibleEAFs - */ - @Override - public void induce(Consumer consumer) { - Stack stack = new Stack<>(); - - // eta is added, Algorithm 8 Line 2 EAF_F <- {eta}, {}, {} - stack.push(new EAF_F(new HashSet<>(), new HashSet(new ArrayList(Arrays.asList(peafTheory.getSupports().iterator().next()))), new HashSet(new ArrayList(Arrays.asList(peafTheory.getArguments().get(0)))))); - - // Turn recursive random induce to sequential - while (!stack.isEmpty()) { - EAF_F eaf = stack.pop(); - - // compute expanding supports (ES) - // if ES.isEmpty - // return eaf; - Set expandingSupports = new HashSet(); - for (BArgument newArgument : eaf.newEArguments) { - // These new arguments have these supports -// System.out.println(newEArgument.getSupports()); - expandingSupports.addAll(this.peafTheory.getSupports(newArgument)); - } - // these are cleared such that new ones can be added - // System.out.println("Add new arguments: " + eaf.newEArguments); - eaf.eArguments.addAll(eaf.newEArguments); - eaf.newEArguments.clear(); - - if (expandingSupports.isEmpty()) { - consumer.accept(eaf.convertToInducible()); - return; - } - - // Line 6-7 - EAF_F eaf_c = eaf.copy(); - - // Line 8-14 - for (Support eSupport : expandingSupports) { - double r = ThreadLocalRandom.current().nextDouble(); - if (r <= ((SetSupport) eSupport).getConditionalProbability()) { - eaf_c.eSupports.add(eSupport); - - // This is to eliminate visiting same nodes again - for (BArgument to : eSupport.getSupported()) { - if (!eaf_c.eArguments.contains(to)) { - eaf_c.newEArguments.add(to); - } - } - } - } - - // Line 15 - // This is omitted since attacks are not supported. - - stack.push(eaf_c); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ExactPEAFInducer.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ExactPEAFInducer.java deleted file mode 100644 index 49f9d48fa..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/ExactPEAFInducer.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.inducers; - -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Stack; -import java.util.function.Consumer; - -/** - * ExactPEAFInducer generates all possible EAFs that can be generated from a PEAF. - * Computationally, this implementation is not great since the all variations of EAFs increase by the number of - * arguments and links exponentially. It is good to use for small PEAFs. - * FIXME: In some instances, probabilities are found to be more than 1. - * - * @author Taha Dogan Gunes - */ -public class ExactPEAFInducer extends AbstractPEAFInducer { - - /** - * Used internally for debugging the inducer - * TODO: Could be removed and migrated to a proper logging module. - * - * @param message a string - */ - private void debugPrint(Object message) { - boolean INTERNAL_DEBUG_MESSAGES = false; - if (INTERNAL_DEBUG_MESSAGES) { - System.out.println(message); - } - } - - /** - * Inducer induces inducibleEAFs and gives to a consumer function - * - * @param consumer the function that consumes InducibleEAFs - */ - @Override - public void induce(Consumer consumer) { - Stack stack = new Stack<>(); - - stack.push(new EAF_F(new HashSet<>(), new HashSet(peafTheory.getSupports()), new HashSet<>(new ArrayList<>(Arrays.asList(peafTheory.getEta()))), 1.0)); - - while (!stack.isEmpty()) { - EAF_F eaf = stack.pop(); - - double po = 1.0; - - // line 3, page 80 - // FIXME: This query can be improved by reducing this set at each iteration - // FIXME: This can be done by storing NAS inside iEAF object - - Set supportsLeft = new HashSet(peafTheory.getSupports()); - supportsLeft.removeAll(eaf.eSupports); - Set args = new HashSet(); - args.addAll(eaf.eArguments); - args.addAll(eaf.newEArguments); - - for (Support support : supportsLeft) { - if ( eaf.eArguments.size() == 1) { - continue; - } - - BArgument notIn = null; - - for (BArgument from : support.getSupporter()) { - // R_S - R_S^F - if (!args.contains(from)) { - notIn = from; - break; - } - } - - if (notIn == null) { - po *= (1.0 - support.getConditionalProbability()); - } - - debugPrint(support); - debugPrint("Not in: " + notIn); - debugPrint("EAF Args: " + eaf.eArguments); - debugPrint("po is: " + po); - } - - debugPrint("po: " + po); - double npi = eaf.pi; - - debugPrint("eaf pi (before): " + eaf.pi); - eaf.pi = eaf.pi * po; - - debugPrint("eaf pi (after): " + eaf.pi); - Set expandingSupports = new HashSet(); - debugPrint(" New arguments: " + eaf.newEArguments); - - for (BArgument newEArgument : eaf.newEArguments) { - expandingSupports.addAll(this.peafTheory.getSupports(newEArgument)); - } - - eaf.eArguments.addAll(eaf.newEArguments); - eaf.newEArguments.clear(); - - consumer.accept(eaf.convertToInducible()); - - debugPrint(eaf.convertToInducible()); - - for (Set eSupports : this.peafTheory.powerSet(expandingSupports)) { - - EAF_F eaf_c = eaf.copy(); - double xpi = npi; - for (Support eSupport : eSupports) { - eaf_c.eSupports.add(eSupport); - - // This is to eliminate visiting same nodes again - for (BArgument to : eSupport.getSupported()) { - if (!eaf_c.eArguments.contains(to)) { - eaf_c.newEArguments.add(to); - } - } - - xpi *= ((Support) eSupport).getConditionalProbability(); - } - - if (!eSupports.isEmpty()) { - eaf_c.pi = xpi; - debugPrint(eSupports); - stack.push(eaf_c); - - } - } - - } - } - - /** - * The default constructor for the ExactPEAFInducer - * - * @param peafTheory a theory - */ - public ExactPEAFInducer(PEAFTheory peafTheory) { - super(peafTheory); - } - - /** - * Simpler re-implementation of InducibleEAF (It is a temporary data structure that helps to expand an induced - * EAF. - */ - class EAF_F { - /** - * Arguments of the EAF - */ - Set eArguments; - /** - * Supports of the EAF - */ - Set eSupports; - /** - * The next arguments to add to the EAF - */ - Set newEArguments; - /** - * Reference to EAFs that originate this EAF - */ - List createdFrom = new ArrayList(); - /** - * The result value of the EAF (notation from the thesis) - */ - double pi; - - /** - * The default constructor for the EAF_F - * - * @param eArguments the set of arguments - * @param eSupports the set of supports - * @param newEArguments the new arguments after this EAF - * @param pi the result value - */ - public EAF_F(Set eArguments, - Set eSupports, - Set newEArguments, double pi) { - this.eArguments = eArguments; - this.eSupports = eSupports; - this.newEArguments = newEArguments; - this.pi = pi; - } - - /** - * For compatibility this re-implementation maps to InducibleEAF - * - * @return an InducibleEAF - * @see InducibleEAF - */ - public InducibleEAF convertToInducible() { - List supportList = new ArrayList(); - for (Support eSupport : eSupports) { - supportList.add((Support) eSupport); - } - - - InducibleEAF inducibleEAF = new InducibleEAF(new HashSet<>(eArguments), - new HashSet<>(supportList), - new HashSet<>(), - new HashSet<>(), - 0, Math.log(this.pi)); - - - inducibleEAF.addAttackLinks(); - - return inducibleEAF; - } - - /** - * Makes a direct copy of this EAF_F - * - * @return a copied EAF_F - */ - public EAF_F copy() { - EAF_F i = new EAF_F(new HashSet<>(this.eArguments), new HashSet<>(this.eSupports), new HashSet<>(this.newEArguments), this.pi); - i.createdFrom.add(this); - return i; - } - } - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/LiExactPEAFInducer.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/LiExactPEAFInducer.java deleted file mode 100644 index 173da2d94..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/LiExactPEAFInducer.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.inducers; - - -import org.tweetyproject.arg.bipolar.syntax.ArgumentSet; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.BipolarEntity; -import org.tweetyproject.arg.bipolar.syntax.InducibleEAF; -import org.tweetyproject.arg.bipolar.syntax.PEAFTheory; -import org.tweetyproject.arg.bipolar.syntax.Support; - -import java.util.*; -import java.util.function.Consumer; - -/** - * This is a direct re-implementation of the Hengfei Li's ruby code in Java. - * see Li, Hengfei. Probabilistic argumentation. 2015. PhD Thesis. Aberdeen University. - * The comments also have the ruby code equivalent. - * LiExactPEAFInducer generates all possible EAFs that can be generated from a PEAF. - - * FIXME: This is to be used in @see Runner of the module. It is a great reference implementation. - * - * @author Taha Dogan Gunes - */ -@Deprecated -public class LiExactPEAFInducer extends AbstractPEAFInducer { - - /** - * The default constructor for the inducer - * - * @param peafTheory a PEAFObject reference - */ - @Deprecated - public LiExactPEAFInducer(PEAFTheory peafTheory) { - super(peafTheory); - } - - /** - * Inducer induces inducibleEAFs and gives to a consumer function - * - * @param consumer the function that consumes InducibleEAFs - */ - @Deprecated - public void induce(Consumer consumer) { - InducibleEAF f = new InducibleEAF(new HashSet<>(), - new HashSet<>(), - new HashSet<>(), - new HashSet<>(), Math.log(1.0), Math.log(1.0)); - - // Store inducible that need to expand - List expansion = new ArrayList<>(); - expansion.add(f); - while (!expansion.isEmpty()) { - - InducibleEAF toExpand = expansion.remove(0); - // Before accepting explore all the attacks and add these links (traverse all the tree) - toExpand.addAttackLinks(); - System.out.println(toExpand.arguments.toString()); - consumer.accept(toExpand); - - - Map, Map> expandingArgs = expand(toExpand); - - if (expandingArgs.isEmpty()) { - continue; - } - - - int noCombinations = 1 << expandingArgs.size(); - - for (int i = 1; i < noCombinations; i++) { - List newArgs = new ArrayList<>(); - List supports = new ArrayList<>(); - - double pInside = toExpand.getpInside(); - int n = i; - - for (Map.Entry, Map> entry : expandingArgs.entrySet()) { - Set argIds = entry.getKey(); - Map map = entry.getValue(); - - if ((n & 1) == 1) { - newArgs.addAll(argIds); - supports.addAll((Collection) map.get("supports")); - pInside += Math.log(1.0 - Math.exp((double) map.get("pro"))); - } - n = n >> 1; - } - List args = new ArrayList<>(); - args.addAll(toExpand.getArguments()); - args.addAll(newArgs); - supports.addAll(toExpand.getSupports()); - - double pOutside = Math.log(1.0); - - for (Support sr : this.peafTheory.getSupports()) { - if (supports.contains(sr)) { - continue; - } - - BArgument notIn = null; - - for (BArgument fa : sr.getSupporter()) { - if (!args.contains(fa)) { - notIn = fa; - break; - } - } - - if (notIn == null) { - pOutside += Math.log(1.0 - sr.getConditionalProbability()); -// System.out.println(Math.exp(pOutside)); - } - } - - double induceP = pInside + pOutside; - InducibleEAF indu = new InducibleEAF(new HashSet(args), new HashSet(supports), new HashSet(), new HashSet(newArgs), pInside, induceP); - - expansion.add(indu); - } - - } - - } - - /** - * Internal function to expand the InducibleEAF - * - * @param indu an InducibleEAF object - * @return a map of all possible ways that the InducibleEAF can be expanded - */ - private Map, Map> expand(InducibleEAF indu) { - Map, Map> expandable = new HashMap<>(); - - for (Support sr : this.peafTheory.getSupports()) { - - // next if indu.supports.include?(sr.id) - if (indu.getSupports().contains(sr)) { - continue; - } - - boolean foundNotIn = false; - boolean foundNewSup = false; - - - // sr.from.each { |fa| - // found_not_in = true if !indu.arguments.include?(fa.id) - // break if found_not_in - // found_new_sup = true if indu.new_args.include?(fa.id) - // } - for (BArgument fa : sr.getSupporter()) { - if (!indu.getArguments().contains(fa)) { - foundNotIn = true; - break; - } - if (indu.getNewArguments().contains(fa)) { - foundNewSup = true; - } - } - - //if !found_not_in and (found_new_sup or indu.new_args.empty?) - // if expandable.has_key?(sr.to.id) - // expandable[sr.to.id][:supports].push(sr.id) - // expandable[sr.to.id][:pro] *= (1 - sr.cp) - // else - // expandable[sr.to.id] = {:supports => [sr.id], :pro => (1 - sr.cp)} - // end - // end - if (!foundNotIn && (foundNewSup || indu.getNewArguments().isEmpty())) { - if (expandable.containsKey(sr.getSupported())) { - Map map = expandable.get(sr.getSupported()); - - List supports = (List) map.get("supports"); - supports.add(sr); - - double probability = (double) map.get("pro"); - map.replace("pro", probability + Math.log(1.0 - sr.getConditionalProbability())); - } else { - Map map = new HashMap<>(); - List supports = new ArrayList<>(); - supports.add(sr); - map.put("supports", supports); - map.put("pro", Math.log(1.0 - sr.getConditionalProbability())); - expandable.put( ((ArgumentSet) sr.getSupported()).getArguments(), map); - } - - } - - } - - return expandable; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/PEAFInducer.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/PEAFInducer.java deleted file mode 100644 index 9cd60066c..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/inducers/PEAFInducer.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.inducers; - -import org.tweetyproject.arg.bipolar.syntax.InducibleEAF; - -import java.util.function.Consumer; - -/** - * The interface for PEAFInducers, these create a subset of the graph that is generated from the given PEAF - * - * @author Taha Dogan Gunes - */ -public interface PEAFInducer { - /** - * Inducer induces inducibleEAFs and gives to a consumer function - * - * @param consumer the function that consumes InducibleEAFs - */ - void induce(Consumer consumer); -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/EdgeListWriter.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/EdgeListWriter.java deleted file mode 100644 index 22eb49991..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/EdgeListWriter.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.io; - -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.io.FileWriter; -import java.io.IOException; -import java.util.Set; -import java.util.StringJoiner; - - -/** - * The EdgeList writer is a utility class for testing purposes to write networkx compatible EdgeList file format. - *

- * More details are at @see EdgeListReader. - * - * @author Taha Dogan Gunes - */ -public class EdgeListWriter { - - /** - * Writes a PEAFTheory in EdgeList format - * - * @param path the path in string - * @param peafTheory the PEAFTheory object - */ - public static void write(String path, PEAFTheory peafTheory) { - try { - FileWriter writer = new FileWriter(path); - - write(peafTheory, writer); - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - /** - * Writes a PEAFTheory and the query to a EdgeList format given the path - * - * @param path the path in string - * @param peafTheory the PEAFTheory object - * @param query a set of arguments for query - */ - public static void write(String path, PEAFTheory peafTheory, Set query) { - try { - FileWriter writer = new FileWriter(path); - - writer.write("# Query: "); - boolean first = true; - for (BArgument argument : query) { - if (first) { - first = false; - } else { - writer.write(" "); - } - writer.write(argument.getName()); - } - writer.write(System.lineSeparator()); - - write(peafTheory, writer); - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Write EAFTheory to EdgeList file format - * - * @param path the path in string - * @param eafTheory the EAFTheory object - */ - public static void write(String path, EAFTheory eafTheory) { - try { - FileWriter writer = new FileWriter(path); - - for (Support o : eafTheory.getSupports()) { - StringBuilder builder = getStringBuilder((ArgumentSet) o.getSupporter(), (ArgumentSet) o.getSupported()); - if (builder != null) { - builder.append(" {'color': 'green'}"); - writer.write(builder.toString()); - writer.write(System.lineSeparator()); - } - } - - - for (Attack o : eafTheory.getAttacks()) { - StringBuilder builder = getStringBuilder((ArgumentSet) o.getAttacker(), (ArgumentSet) o.getAttacked()); - if (builder != null) { - builder.append(" {'color': 'red'}"); - writer.write(builder.toString()); - writer.write(System.lineSeparator()); - } - } - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Combines arguments and builds the first line - * - * @param froms a set of arguments that originate the link - * @param tos a set of arguments that gets targeted - * @param fromToDelimiter the delimiter for froms argument to tos argument - * @return StringBuilder object - */ - public static StringBuilder getStringBuilder(ArgumentSet froms, ArgumentSet tos, String fromToDelimiter) { - StringBuilder builder = new StringBuilder(); - StringJoiner joiner = new StringJoiner("-"); - for (BArgument from : froms) { - joiner.add(from.getName()); - } - if (froms.isEmpty()) { - joiner.add("E"); - return null; - } - builder.append(joiner); - builder.append(fromToDelimiter); - joiner = new StringJoiner("-"); - for (BArgument from : tos) { - joiner.add(from.getName()); - } - builder.append(joiner); - return builder; - } - - /** - * Utility method for getStringBuilder - * - * @param froms a set of arguments that originate the link - * @param tos a set of arguments that gets targets - * @return StringBuilder object - */ - public static StringBuilder getStringBuilder(ArgumentSet froms, ArgumentSet tos) { - return EdgeListWriter.getStringBuilder(froms, tos, " "); - } - - /** - * Utility method for writing PEAFTheory to a file - * - * @param peafTheory PEAFTheory object - * @param writer writes to a file - * @throws IOException when writing to a file fails, this exception is thrown. - */ - private static void write(PEAFTheory peafTheory, FileWriter writer) throws IOException { - for (Support o : peafTheory.getSupports()) { - StringBuilder builder = getStringBuilder((ArgumentSet) o.getSupporter(), (ArgumentSet) o.getSupported()); - if (builder != null) { - builder.append(" {'color': 'green', 'weight': ").append(o.getConditionalProbability()).append(" }"); - writer.write(builder.toString()); - writer.write(System.lineSeparator()); - } - } - for (Attack o : peafTheory.getAttacks()) { - StringBuilder builder = getStringBuilder((ArgumentSet) o.getAttacker(), (ArgumentSet) o.getAttacked()); - if (builder != null) { - builder.append(" {'color': 'red' }"); - writer.write(builder.toString()); - writer.write(System.lineSeparator()); - } - } - } - - /** Default Constructor */ - public EdgeListWriter(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/eaf/EAFToDAFConverter.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/eaf/EAFToDAFConverter.java deleted file mode 100644 index cb0ffb497..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/io/eaf/EAFToDAFConverter.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.io.eaf; - - -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.arg.bipolar.syntax.EAFTheory; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.BipolarEntity; -import org.tweetyproject.arg.bipolar.syntax.Support; -import org.tweetyproject.commons.util.Pair; - -import java.util.*; - -/** - * converts EAF to DAF - * @author Sebastian Franke - * - */ -public class EAFToDAFConverter { - - /** - * - * Return a dungtheory version of the input - * @param eafTheory a theory - * @return a dungtheory version of the input - */ - public static DungTheory convert(EAFTheory eafTheory) { - DungTheory dungTheory = new DungTheory(); - // Keeping track of which arguments are discovered - Set discovered = new HashSet(); - // Stores which EArgument corresponds to which dafArguments (one-to-many) - Map> mapping = new HashMap>(); - - BArgument startingPoint = eafTheory.getEta(); - bfsTraverse(dungTheory, startingPoint, discovered, mapping, eafTheory); - - // Once the traversal is finished - System.out.println(mapping); - - for (BArgument from : eafTheory.getArguments()) { - for (org.tweetyproject.arg.bipolar.syntax.Attack attack : eafTheory.getAttacks()) { - if(attack.contains(from)) { - Set edgeArguments = new HashSet(); - - findEdgeNodes(attack.getAttacked(), edgeArguments, eafTheory); - - Set dafAttackers = mapping.get(from); - - - System.out.println("Edge arguments: " + edgeArguments); - if (dafAttackers == null) { - System.err.println("dafAttackers is null: " + from); - } - - if (edgeArguments.isEmpty()) { - System.err.println("dafAttackeds is null: " + edgeArguments); - } - - if (edgeArguments.isEmpty() || dafAttackers == null) { - return null; - } - - - for (Argument dafAttacker : dafAttackers) { - for (BArgument attacked : edgeArguments) { - if (mapping.get(attacked) == null) { - continue; - } - for (Argument argument : mapping.get(attacked)) { - dungTheory.addAttack(dafAttacker, argument); - } - } - } - } - } - } - - System.out.println(dungTheory.prettyPrint()); - return dungTheory; - } - - /** - * - * @param bipolarEntity an argument - * @param edgeArguments an edge argument - * @param eafTheory the eafTheory - */ - private static void findEdgeNodes(BipolarEntity bipolarEntity, Set edgeArguments, EAFTheory eafTheory) { - Map> supportsToArgs = new HashMap>(); - - for(Support s : eafTheory.getSupports()) { - for(BArgument a : eafTheory.getArguments()) { - if(s.contains(a)) { - if(supportsToArgs.get(a) != null) { - supportsToArgs.get(a).add(s); - - } - else { - supportsToArgs.put(a, new HashSet(new ArrayList(Arrays.asList(s)))); - } - } - } - - } - for (BArgument child : bipolarEntity) { - if (supportsToArgs.get(child).size() == 0) { - edgeArguments.add(child); - } else { - edgeArguments.add(child); - for (Support support : supportsToArgs.get(child)) { - findEdgeNodes(support.getSupported(), edgeArguments, eafTheory); - } - } - } - } - - /** - * - * @param dungTheory a dungtheory - * @param startingPoint an argument to start at - * @param discovered a set of arguments - * @param mapping mapping of Arguments to sets of arguments - * @param eafTheory a theory - */ - private static void bfsTraverse(DungTheory dungTheory, BArgument startingPoint, Set discovered, Map> mapping, EAFTheory eafTheory) { - Map> supportsToArgs = new HashMap>(); - Map> attacksToArgs = new HashMap>(); - Map> incomingAttacksToArgs = new HashMap>(); - - for(BArgument a : eafTheory.getArguments()) { - for(Support s : eafTheory.getSupports()) { - if(s.contains(a)) { - if(supportsToArgs.get(a) != null) { - supportsToArgs.get(a).add(s); - - } - else { - supportsToArgs.put(a, new HashSet(new ArrayList(Arrays.asList(s)))); - } - } - } - for(org.tweetyproject.arg.bipolar.syntax.Attack s : eafTheory.getAttacks()) { - if(s.contains(a)) { - if(attacksToArgs.get(a) != null) { - attacksToArgs.get(a).add( s); - - } - else { - attacksToArgs.put(a, new HashSet(new ArrayList(Arrays.asList(s)))); - } - } - if(s.getAttacked().contains(a)) { - if(incomingAttacksToArgs.get(a) != null) { - incomingAttacksToArgs.get(a).add( s); - - } - else { - incomingAttacksToArgs.put(a, new HashSet(new ArrayList(Arrays.asList(s)))); - } - } - } - - } - Queue>> queue = new LinkedList<>(); - - if (discovered.contains(startingPoint)) { - return; - } - discovered.add(startingPoint); - queue.add(new Pair<>(startingPoint, new ArrayList(Arrays.asList(startingPoint)))); - - - while (!queue.isEmpty()) { - Pair> pair = queue.poll(); - BArgument v = pair.getFirst(); - - System.out.println("h1: " + pair.getSecond()); - if (supportsToArgs.get(v).size() > 0) { - for (Support support : supportsToArgs.get(v)) { - for (BArgument to : support.getSupported()) { -// FIXME: since the support structure is a tree perhaps we can avoid this -// if (!discovered.contains(to)) { -// discovered.add(to); - List newList = new ArrayList(); - newList.addAll(pair.getSecond()); - newList.add(to); - queue.add(new Pair<>(to, newList)); -// } - } - } - } else { - addDAFArgument(dungTheory, mapping, pair); - } - - if (attacksToArgs.get(v).size() > 0) { -// System.out.println("h2: " + pair.getSecond()); - addDAFArgument(dungTheory, mapping, pair); - } - - if (incomingAttacksToArgs.get(v).size() > 0) { - addDAFArgument(dungTheory, mapping, pair); - } - - - } - - } - - /** - * - * @param dungTheory a theory - * @param mapping a mapping of argument to sets of arguments - * @param pair argument and lis of arguments - */ - private static void addDAFArgument(DungTheory dungTheory, Map> mapping, Pair> pair) { - List args = new ArrayList(); - for (BArgument eArgument : pair.getSecond()) { - args.add(eArgument.getName()); - } - - Argument dafArgument = new Argument(String.join("_", args)); - dungTheory.add(dafArgument); - - BArgument eArgument = pair.getSecond().get(pair.getSecond().size() - 1); - if (!mapping.containsKey(eArgument)) { - mapping.put(eArgument, new HashSet<>()); - } - mapping.get(eArgument).add(dafArgument); - - - } - - - - /** Default Constructor */ - public EAFToDAFConverter(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/AbstractBipolarExtensionReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/AbstractBipolarExtensionReasoner.java index 8fb0ba8dd..f4f578367 100644 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/AbstractBipolarExtensionReasoner.java +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/AbstractBipolarExtensionReasoner.java @@ -1,65 +1,100 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ package org.tweetyproject.arg.bipolar.reasoner; -import org.tweetyproject.arg.bipolar.syntax.AbstractBipolarFramework; -import org.tweetyproject.arg.bipolar.syntax.BArgument; +import org.tweetyproject.arg.bipolar.semantics.Semantics; +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.syntax.Argument; import org.tweetyproject.commons.InferenceMode; +import org.tweetyproject.commons.ModelProvider; +import org.tweetyproject.commons.QualitativeReasoner; +import org.tweetyproject.commons.postulates.PostulateEvaluatable; import java.util.Collection; /** - * Abstract Reasoner for Bipolar Argumentation + * Abstract class for reasoners for bipolar argumentation * * @author Lars Bengel */ -public abstract class AbstractBipolarExtensionReasoner { +public abstract class AbstractBipolarExtensionReasoner implements ModelProvider>, PostulateEvaluatable, QualitativeReasoner { + /** - * Compute all extensions of this semantics - * @param baf some bipolar AF - * @return the set of extensions + * Default constructor */ - public abstract Collection> getModels(AbstractBipolarFramework baf); + public AbstractBipolarExtensionReasoner() { + super(); + } + /** - * Compute a single extension of this semantics - * @param baf some bipolar AF - * @return some extension + * Return a reasoner for the given semantics + * @param semantics some semantics + * @return reasoner for the semantics */ - public Collection getModel(AbstractBipolarFramework baf) { - return getModels(baf).iterator().next(); + public static AbstractBipolarExtensionReasoner getSimpleReasonerForSemantics(Semantics semantics) { + return switch (semantics) { + case BCF -> new SimpleStronglyConflictFreeReasoner(); + case BCOH -> new SimpleCoherentReasoner(); + case BAD -> new SimpleCoherentAdmissibleReasoner(); + default -> throw new IllegalArgumentException("Unknown semantics."); + }; } - /** - * Queries the given BAF for the given argument using the given - * skeptical inference. - * @param beliefbase a BAF - * @param formula a single argument - * @return "true" if the argument is accepted + /* (non-Javadoc) + * @see org.tweetyproject.arg.dung.reasoner.AbstractDungReasoner#query(org.tweetyproject.arg.dung.syntax.DungTheory, org.tweetyproject.arg.dung.syntax.Argument) */ - public Boolean query(AbstractBipolarFramework beliefbase, BArgument formula) { + @Override + public Boolean query(BipolarArgumentationFramework beliefbase, Argument formula) { return this.query(beliefbase, formula, InferenceMode.SKEPTICAL); } /** - * Queries the given BAF for the given argument using the given + * Queries the given AAF for the given argument using the given * inference type. - * @param beliefbase a BAF + * @param beliefbase an AAF * @param formula a single argument * @param inferenceMode either InferenceMode.SKEPTICAL or InferenceMode.CREDULOUS * @return "true" if the argument is accepted */ - public Boolean query(AbstractBipolarFramework beliefbase, BArgument formula, InferenceMode inferenceMode) { - Collection> extensions = this.getModels(beliefbase); + public Boolean query(BipolarArgumentationFramework beliefbase, Argument formula, InferenceMode inferenceMode) { + Collection> extensions = this.getModels(beliefbase); if(inferenceMode.equals(InferenceMode.SKEPTICAL)){ - for(Collection e: extensions) + for(Extension e: extensions) if(!e.contains(formula)) return false; return true; } // so its credulous semantics - for(Collection e: extensions){ + for(Extension e: extensions){ if(e.contains(formula)) return true; } return false; } + + /** + * the solver is natively installed and is therefore always installed + */ + @Override + public boolean isInstalled() { + return true; + } } diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoalitionReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoalitionReasoner.java new file mode 100644 index 000000000..6ffcb1255 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoalitionReasoner.java @@ -0,0 +1,72 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.reasoner; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.bipolar.syntax.CoalitionArgument; +import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.semantics.Semantics; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +import java.util.Collection; +import java.util.HashSet; + +/** + * Reasoner for bipolar argumentation frameworks based on the coalition approach. + * A coalition is defined as a maximal set of arguments that is conflict-free and connected via the support relation. + * + * @see "Cayrol, C. and M.-C. Lagasquie-Schiex. 'Coalitions of arguments: a tool for handling bipolar + * argumentation frameworks'. International Journal of Intelligent Systems, 25(1):83–109, 2010." + * + * @author Lars Bengel + */ +public class SimpleCoalitionReasoner extends AbstractBipolarExtensionReasoner { + /** The underlying reasoner */ + private final AbstractExtensionReasoner reasoner; + + /** + * Initializes a new coalition reasoner for the given semantics + * @param semantics some semantics + */ + public SimpleCoalitionReasoner(Semantics semantics) { + this.reasoner = AbstractExtensionReasoner.getSimpleReasonerForSemantics(semantics); + } + + @Override + public Collection> getModels(BipolarArgumentationFramework bbase) { + Collection> result = new HashSet<>(); + DungTheory coalitionGraph = bbase.getCoalitionGraph(); + Collection> extensions = reasoner.getModels(coalitionGraph); + for (Extension ext: extensions) { + Extension extension = new Extension<>(); + for (Argument arg: ext) { + extension.addAll(((CoalitionArgument) arg).getArguments()); + } + result.add(extension); + } + return result; + } + + @Override + public Extension getModel(BipolarArgumentationFramework bbase) { + return getModels(bbase).iterator().next(); + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentAdmissibleReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentAdmissibleReasoner.java new file mode 100644 index 000000000..ebeb1cd08 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentAdmissibleReasoner.java @@ -0,0 +1,62 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.reasoner; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +import java.util.Collection; +import java.util.HashSet; + +/** + * Reasoner for coherent admissible sets (also called s-admissible sets) in bipolar argumentation. + * + * @see "Cayrol, C. and M.-C. Lagasquie-Schiex. 'On the acceptability of arguments in bipolar argumentation frameworks'. ECSQARU’05, pp. 378–389, 2005" + * + * @author Lars Bengel + */ +public class SimpleCoherentAdmissibleReasoner extends AbstractBipolarExtensionReasoner { + @Override + public Collection> getModels(BipolarArgumentationFramework bbase) { + Collection> result = new HashSet<>(); + + for (Extension ext: new SimpleCoherentReasoner().getModels(bbase)) { + boolean defended = true; + for (Argument arg: ext) { + DungTheory theory = bbase.getAssociatedTheory(); + Collection attackers = theory.getAttackers(arg); + attackers.removeAll(theory.getAttacked(ext)); + if (!attackers.isEmpty()) { + defended = false; + break; + } + } + if (defended) + result.add(ext); + } + return result; + } + + @Override + public Extension getModel(BipolarArgumentationFramework bbase) { + return getModels(bbase).iterator().next(); + } +} \ No newline at end of file diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentReasoner.java new file mode 100644 index 000000000..64a3948ac --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleCoherentReasoner.java @@ -0,0 +1,61 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.reasoner; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.reasoner.SimpleConflictFreeReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +import java.util.Collection; +import java.util.HashSet; + +/** + * A reasoner for coherent sets in bipolar argumentation under a default support interpretation. + * A Set of arguments is coherent iff it is strongly conflict-free and does not support and attack some argument at the same time + * + * @author Lars Bengel + */ +public class SimpleCoherentReasoner extends AbstractBipolarExtensionReasoner { + + @Override + public Collection> getModels(BipolarArgumentationFramework bbase) { + Collection> result = new HashSet<>(); + + DungTheory theory = new DungTheory(); + theory.addAll(bbase.getNodes()); + theory.addAllAttacks(bbase.getSupportedAttacks()); + theory.addAllAttacks(bbase.getIndirectAttacks()); + + for (Extension ext: new SimpleConflictFreeReasoner().getModels(theory)) { + Collection supported = new HashSet<>(ext); + supported.addAll(bbase.getSupported(ext)); + Collection intersect = new HashSet<>(theory.getAttacked(ext)); + intersect.retainAll(supported); + if (intersect.isEmpty()) result.add(new Extension<>(ext)); + } + return result; + } + + @Override + public Extension getModel(BipolarArgumentationFramework bbase) { + return getModels(bbase).iterator().next(); + } +} \ No newline at end of file diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleDeductiveReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleDeductiveReasoner.java new file mode 100644 index 000000000..653ba0fe0 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleDeductiveReasoner.java @@ -0,0 +1,67 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.reasoner; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.semantics.Semantics; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +import java.util.Collection; +import java.util.HashSet; + +/** + * Reasoner for bipolar argumentation under the deductive support interpretation. + * Under this interpretation we account for mediated attacks. + * + * @see "Boella, G., Dov Gabbay, L. van der Torre, and S. Villata. 'Support in abstract argumentation'. COMMA’10, 2010." + * + * @author Lars Bengel + */ +public class SimpleDeductiveReasoner extends AbstractBipolarExtensionReasoner { + + /** the underlying reasoner */ + private final AbstractExtensionReasoner reasoner; + + /** + * Initializes a new reasoner based on the given semantics + * @param semantics some semantics + */ + public SimpleDeductiveReasoner(Semantics semantics) { + this.reasoner = AbstractExtensionReasoner.getSimpleReasonerForSemantics(semantics); + } + + @Override + public Collection> getModels(BipolarArgumentationFramework bbase) { + DungTheory theory = new DungTheory(); + theory.addAll(bbase.getNodes()); + theory.addAllAttacks(bbase.getMediatedAttacks()); + Collection> result = new HashSet<>(); + for (Extension ext: reasoner.getModels(theory)) { + result.add(new Extension<>(ext)); + } + return result; + } + + @Override + public Extension getModel(BipolarArgumentationFramework bbase) { + return getModels(bbase).iterator().next(); + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleNecessityReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleNecessityReasoner.java new file mode 100644 index 000000000..121e0bc6b --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleNecessityReasoner.java @@ -0,0 +1,62 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.reasoner; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.bipolar.syntax.Support; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.semantics.Semantics; + +import java.util.Collection; + +/** + * Reasoner for bipolar argumentation under the deductive support interpretation. + * + * @see "F. Nouioua and V. Risch. 'Argumentation frameworks with necessities'. SUM’11, pp. 163–176, 2011" + * + * @author Lars Bengel + */ +public class SimpleNecessityReasoner extends AbstractBipolarExtensionReasoner { + /** the underlying semantics */ + private final Semantics semantics; + + /** + * Initializes a new reasoner with the given semantics + * @param semantics some semantics + */ + public SimpleNecessityReasoner(Semantics semantics) { + this.semantics = semantics; + } + + @Override + public Collection> getModels(BipolarArgumentationFramework bbase) { + BipolarArgumentationFramework theory = new BipolarArgumentationFramework(); + theory.addAll(bbase.getNodes()); + theory.addAllAttacks(bbase.getAttacks()); + for (Support supp: bbase.getSupports()) { + theory.addSupport(supp.getSupported(), supp.getSupporter()); + } + return new SimpleDeductiveReasoner(semantics).getModels(theory); + } + + @Override + public Extension getModel(BipolarArgumentationFramework bbase) { + return getModels(bbase).iterator().next(); + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleStronglyConflictFreeReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleStronglyConflictFreeReasoner.java new file mode 100644 index 000000000..25f50bb9e --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/SimpleStronglyConflictFreeReasoner.java @@ -0,0 +1,54 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.reasoner; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.reasoner.SimpleConflictFreeReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.syntax.DungTheory; + +import java.util.Collection; +import java.util.HashSet; + +/** + * Reasoner for conflict-freeness in bipolar argumentation under a default support interpretation. + * A set of arguments is strongly conflict-free iff it contains no conflict wrt. the classical attacks as well as supported and indirect attacks + * + * @author Lars Bengel + */ +public class SimpleStronglyConflictFreeReasoner extends AbstractBipolarExtensionReasoner { + + @Override + public Collection> getModels(BipolarArgumentationFramework bbase) { + DungTheory theory = new DungTheory(); + theory.addAll(bbase.getNodes()); + theory.addAllAttacks(bbase.getSupportedAttacks()); + theory.addAllAttacks(bbase.getIndirectAttacks()); + Collection> result = new HashSet<>(); + for (Extension ext: new SimpleConflictFreeReasoner().getModels(theory)) { + result.add(new Extension<>(ext)); + } + return result; + } + + @Override + public Extension getModel(BipolarArgumentationFramework bbase) { + return new Extension<>(); + } +} \ No newline at end of file diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/CAdmissibleReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/CAdmissibleReasoner.java deleted file mode 100644 index a278be87a..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/CAdmissibleReasoner.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.reasoner.deductive; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.*; - -/** - * reasoner for admissibility in bipolar argumentation frameworks with deductive support interpretation - * a set of arguments is c-admissible iff it is admissible wrt. the complex attacks in the framework and closed wrt. - * the support relation - */ -public class CAdmissibleReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(DeductiveArgumentationFramework bbase) { - Collection> extensions = new HashSet<>(); - for (Collection ext: new DAdmissibleReasoner().getModels(bbase)) { - if (bbase.isClosed(new ArgumentSet(ext))) { - extensions.add(ext); - } - } - return extensions; - } - - /** Default Constructor */ - public CAdmissibleReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - return this.getModels((DeductiveArgumentationFramework) baf); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ClosureReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ClosureReasoner.java deleted file mode 100644 index e2d031646..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ClosureReasoner.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.deductive; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.tweetyproject.commons.util.SetTools; - -import java.util.*; - -/** - * a set of arguments S is closed under the support relation iff all arguments supported by an element of S are in S. - * - * @author Lars Bengel - * - */ -public class ClosureReasoner extends AbstractBipolarExtensionReasoner { - - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(DeductiveArgumentationFramework bbase) { - Set> extensions = new HashSet<>(); - // Check all subsets - for(Set ext: new SetTools().subsets(bbase)) - if(bbase.isClosed(new ArgumentSet(ext))) - extensions.add(new ArgumentSet(ext)); - return extensions; - } - - /** - * Returns a model - * @param bbase a belief base - * @return a ArgumentSet - */ - public ArgumentSet getModel(DeductiveArgumentationFramework bbase) { - // as the empty set is always closed we return that one. - return new ArgumentSet(); - } - - /** Default Constructor */ - public ClosureReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof DeductiveArgumentationFramework) { - return this.getModels((DeductiveArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ConflictFreeReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ConflictFreeReasoner.java deleted file mode 100644 index c23cbabe6..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/ConflictFreeReasoner.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - - -package org.tweetyproject.arg.bipolar.reasoner.deductive; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.tweetyproject.arg.dung.reasoner.SimpleConflictFreeReasoner; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.DungTheory; - -import java.util.*; - -/** - * reasoner for conflict-freeness in bipolar argumentation frameworks with a deductive support interpretation - * a set of arguments is conflict-free iff it is conflict-free in regards to the complex attacks in the framework - */ -public class ConflictFreeReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(DeductiveArgumentationFramework bbase) { - // get a dung theory containing all direct and complex attacks in the given bipolar argumentation framework - DungTheory theory = bbase.getCompleteAssociatedDungTheory(); - - Collection> result = new HashSet<>(); - for (Extension ext: new SimpleConflictFreeReasoner().getModels(theory)) { - result.add(new ArgumentSet(ext)); - } - return result; - } - - /** Default Constructor */ - public ConflictFreeReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof DeductiveArgumentationFramework) { - return this.getModels((DeductiveArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/DAdmissibleReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/DAdmissibleReasoner.java deleted file mode 100644 index 4401e6bd5..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/DAdmissibleReasoner.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.reasoner.deductive; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.*; - -/** - * reasoner for admissibility in bipolar argumentation frameworks with deductive support interpretation - * a set of arguments is d-admissible iff it is admissible wrt. the complex attacks in the framework - */ -public class DAdmissibleReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(DeductiveArgumentationFramework bbase) { - Collection> extensions = new HashSet<>(); - for (Collection ext: new ConflictFreeReasoner().getModels(bbase)) { - for (BArgument arg: ext) { - boolean defending = true; - for (BipolarEntity attacker: bbase.getAttackers(arg)) { - if (!bbase.isAttacked((BArgument) attacker, new HashSet<>(ext))) { - defending = false; - break; - } - } - if (defending) { - extensions.add(ext); - } - } - } - return extensions; - } - - /** Default Constructor */ - public DAdmissibleReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof DeductiveArgumentationFramework) { - return this.getModels((DeductiveArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/SafetyReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/SafetyReasoner.java deleted file mode 100644 index 15a324945..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/deductive/SafetyReasoner.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.deductive; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.tweetyproject.arg.dung.reasoner.SimpleConflictFreeReasoner; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.DungTheory; - -import java.util.*; - -/** - * a set of arguments S is safe wrt. the complex attacks iff there are no arguments a, b of S and argument c such that: - * b supports c or c is in S and - * there is a complex attack from a to c. - * - * @author Lars Bengel - * - */ -public class SafetyReasoner extends AbstractBipolarExtensionReasoner { - - /** - * - * @param bbase arg framework - * @return models - */ - public Collection> getModels(DeductiveArgumentationFramework bbase) { - Set> extensions = new HashSet<>(); - // Check only conflict-free subsets - SimpleConflictFreeReasoner cfReasoner = new SimpleConflictFreeReasoner(); - for(Extension ext: cfReasoner.getModels(bbase.getCompleteAssociatedDungTheory())){ - ArgumentSet argSet = new ArgumentSet(ext); - Set supported = bbase.getSupported(argSet); - supported.removeAll(argSet); - boolean isSafe = true; - for (BArgument a: argSet) { - for (BArgument c: supported) { - if (bbase.isAttackedBy(c, a) || bbase.isSupportedAttack(a, c) || - bbase.isMediatedAttack(a, c) || bbase.isSuperMediatedAttack(a, c)) { - isSafe = false; - } - } - } - if (isSafe) - extensions.add(argSet); - } - - return extensions; - } - - /** - * - * @param bbase arg framework - * @return model - */ - public ArgumentSet getModel(DeductiveArgumentationFramework bbase) { - // as the empty set is always safe we return that one. - return new ArgumentSet(); - } - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof DeductiveArgumentationFramework) { - return this.getModels((DeductiveArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/AdmissibleReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/AdmissibleReasoner.java deleted file mode 100644 index b5f9a6a41..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/AdmissibleReasoner.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.ArgumentSet; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.EvidentialArgumentationFramework; - -import java.util.*; - -/** - * a set of arguments S is admissible iff it is conflict-free and all elements of S are acceptable wrt. S. - * - * @author Lars Bengel - * - */ -public class AdmissibleReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Set extensions = new HashSet(); - // Check all conflict-free subsets - ConflictFreeReasoner cfReasoner = new ConflictFreeReasoner(); - for(ArgumentSet ext: cfReasoner.getModels(bbase)){ - // every admissible set S has to contain Eta, since every argument in S has to be e-supported by S - if (!ext.contains(bbase.getEta())) { - continue; - } - boolean admissible = true; - for (BArgument argument : ext) { - if (!bbase.isAcceptable(argument, ext)) { - admissible = false; - break; - } - } - if (admissible) - extensions.add(new ArgumentSet(ext)); - } - return extensions; - } - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - // as the empty set is always admissible we return that one. - return new ArgumentSet(); - } - - /** Default Constructor */ - public AdmissibleReasoner(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/CompleteReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/CompleteReasoner.java deleted file mode 100644 index 96f7d4061..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/CompleteReasoner.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.*; -import java.util.*; - -/** - * a set of arguments S is complete iff it is admissible and all arguments acceptable wrt. S are in S. - * - * @author Lars Bengel - * - */ -public class CompleteReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Set extensions = new HashSet(); - // Check all admissible subsets - AdmissibleReasoner admissibleReasoner = new AdmissibleReasoner(); - for(ArgumentSet ext: admissibleReasoner.getModels(bbase)){ - boolean complete = true; - Set otherArguments = new HashSet<>(bbase); - otherArguments.removeAll(ext); - for (BArgument argument : otherArguments) { - if (bbase.isAcceptable(argument, ext)) { - complete = false; - break; - } - } - if (complete) - extensions.add(new ArgumentSet(ext)); - } - return extensions; - } - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - // as the set only containing epsilon is always complete we return that one. - ArgumentSet ext = new ArgumentSet(); - ext.add(bbase.getEta()); - return ext; - } - - /** Default Constructor */ - public CompleteReasoner(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/ConflictFreeReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/ConflictFreeReasoner.java deleted file mode 100644 index 5f81f1599..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/ConflictFreeReasoner.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.ArgumentSet; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.EvidentialArgumentationFramework; -import org.tweetyproject.commons.util.SetTools; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * a set of arguments S is conflict-free iff there exists no attack between a subset of S and an element of S. - * - * @author Lars Bengel - * - */ -public class ConflictFreeReasoner { - /**constructor*/ - public ConflictFreeReasoner() { - } - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Set extensions = new HashSet<>(); - Set> subsets = new SetTools().subsets(bbase); - - for (Set ext: subsets) { - boolean conflict = false; - for (BArgument argument: ext) { - Set> subExtensions = new SetTools().subsets(ext); - for (Set subExt: subExtensions) { - if (bbase.isAttackedBy(argument, new ArgumentSet(subExt))) { - conflict = true; - break; - } - } - if (conflict) - break; - } - if (!conflict) - extensions.add(new ArgumentSet(ext)); - } - - return extensions; - } - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - return new ArgumentSet(); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/GroundedReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/GroundedReasoner.java deleted file mode 100644 index 3877cf6f2..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/GroundedReasoner.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.ArgumentSet; -import org.tweetyproject.arg.bipolar.syntax.EvidentialArgumentationFramework; -import java.util.*; - -/** - * the grounded extension of bbase is the least fixed point of the characteristic function. - * - * @author Lars Bengel - * - */ -public class GroundedReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Collection extensions = new HashSet<>(); - extensions.add(this.getModel(bbase)); - return extensions; - } - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - ArgumentSet ext = new ArgumentSet(); - int size; - do{ - size = ext.size(); - ext = bbase.faf(ext); - }while(size!=ext.size()); - return ext; - } - - /** Default Constructor */ - public GroundedReasoner(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/PreferredReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/PreferredReasoner.java deleted file mode 100644 index 1d6d5fd07..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/PreferredReasoner.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.ArgumentSet; -import org.tweetyproject.arg.bipolar.syntax.EvidentialArgumentationFramework; - -import java.util.*; - -/** - * a set of arguments S is preferred iff it is maximal wrt. set inclusion admissible. - * - * @author Lars Bengel - * - */ -public class PreferredReasoner { - /** - * - * @param bbase argumentation framework - * @return models - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Collection completeExtensions = new CompleteReasoner().getModels(bbase); - Set result = new HashSet<>(); - boolean maximal; - for(ArgumentSet e1: completeExtensions){ - maximal = true; - for(ArgumentSet e2: completeExtensions) - if(e1 != e2 && e2.containsAll(e1)){ - maximal = false; - break; - } - if(maximal) - result.add(e1); - } - return result; - } - /** - * - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - // just return the first found preferred extension - Collection completeExtensions = new CompleteReasoner().getModels(bbase); - boolean maximal; - for(ArgumentSet e1: completeExtensions){ - maximal = true; - for(ArgumentSet e2: completeExtensions) - if(e1 != e2 && e2.containsAll(e1)){ - maximal = false; - break; - } - if(maximal) - return e1; - } - // this should not happen - throw new RuntimeException("Hmm, did not find a maximal set in a finite number of sets. Should not happen."); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/SelfSupportingReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/SelfSupportingReasoner.java deleted file mode 100644 index f2b57ac84..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/SelfSupportingReasoner.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.ArgumentSet; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.EvidentialArgumentationFramework; -import org.tweetyproject.commons.util.SetTools; -import java.util.*; - -/** - * a set of arguments S is self-supporting iff all arguments in S are - * e-supported by S. - * - * @author Lars Bengel - * - */ -public class SelfSupportingReasoner { - /** - * Computes all self-supporting argument sets from the given evidential - * argumentation framework. - * - * @param bbase The evidential argumentation framework containing arguments and - * support relations. - * @return A collection of self-supporting argument sets. - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Set extensions = new HashSet(); - // Check all subsets - for (Set ext : new SetTools().subsets(bbase)) { - boolean selfSupporting = true; - for (BArgument argument : ext) { - if (!bbase.hasEvidentialSupport(argument, ext)) { - selfSupporting = false; - break; - } - } - if (selfSupporting) - extensions.add(new ArgumentSet(ext)); - } - return extensions; - } - - /** - * - * Return a model - * - * @param bbase arg framework - * @return a model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - // as the empty set is always self-supporting we return that one. - return new ArgumentSet(); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/StableReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/StableReasoner.java deleted file mode 100644 index e12ab05a0..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/evidential/StableReasoner.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.evidential; - -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.*; - - -/** - * a set of arguments S is stable iff it is conflict-free, self-supporting and for any argument a e-supported by bbase, - * where a is not in S, S e-support attacks either a or every set of arguments minimally e-supporting a. - * - * @author Lars Bengel - * - */ -public class StableReasoner { - /** - * - * @param bbase argumentation framework - * @return models - */ - public Collection getModels(EvidentialArgumentationFramework bbase) { - Collection preferredExtensions = new PreferredReasoner().getModels(bbase); - Set result = new HashSet<>(); - for(ArgumentSet ext: preferredExtensions){ - Set eSupportedArguments = bbase.getEvidenceSupportedArguments(); - eSupportedArguments.removeAll(ext); - boolean attacksAllESupportedArguments = true; - for (BArgument argument: eSupportedArguments){ - if (bbase.isEvidenceSupportedAttack(ext, argument)) { - continue; - } - boolean attacksAllESupporters = true; - for (Set supporter: bbase.getMinimalEvidentialSupporters(argument)) { - boolean attacksSupporter = false; - for (BArgument arg: supporter) { - if (bbase.isEvidenceSupportedAttack(ext, arg)) { - attacksSupporter = true; - break; - } - } - if (!attacksSupporter) { - attacksAllESupporters = false; - break; - } - } - if (!attacksAllESupporters) { - attacksAllESupportedArguments = false; - break; - } - } - - if (attacksAllESupportedArguments) - result.add(ext); - } - return result; - } - /** - * - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(EvidentialArgumentationFramework bbase) { - Collection preferredExtensions = new PreferredReasoner().getModels(bbase); - for(ArgumentSet ext: preferredExtensions){ - Set eSupportedArguments = bbase.getEvidenceSupportedArguments(); - eSupportedArguments.removeAll(ext); - boolean attacksAllESupportedArguments = true; - for (BArgument argument: eSupportedArguments){ - if (bbase.isEvidenceSupportedAttack(ext, argument)) { - continue; - } - boolean attacksAllESupporters = true; - for (Set supporter: bbase.getMinimalEvidentialSupporters(argument)) { - boolean attacksSupporter = false; - for (BArgument arg: supporter) { - if (bbase.isEvidenceSupportedAttack(ext, arg)) { - attacksSupporter = true; - break; - } - } - if (!attacksSupporter) { - attacksAllESupporters = false; - break; - } - } - if (!attacksAllESupporters) { - attacksAllESupportedArguments = false; - break; - } - } - - if (attacksAllESupportedArguments) - return ext; - } - return null; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/AdmissibleReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/AdmissibleReasoner.java deleted file mode 100644 index c3b351952..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/AdmissibleReasoner.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.necessity; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.tweetyproject.commons.util.SetTools; - -import java.util.*; - -/** - * a set of arguments S is admissible iff it is strongly coherent and defends all of its arguments. - * - * @author Lars Bengel - * - */ -public class AdmissibleReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(NecessityArgumentationFramework bbase) { - Set> extensions = new HashSet<>(); - Set> subsets = new SetTools().subsets(bbase); - - for (Set ext: subsets) { - if (!bbase.isStronglyCoherent(ext)) { - continue; - } - boolean admissible = true; - for (BArgument argument : ext) { - if (!bbase.isAcceptable(argument, ext)) { - admissible = false; - break; - } - } - if (admissible) - extensions.add(new ArgumentSet(ext)); - } - return extensions; - } - - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(NecessityArgumentationFramework bbase) { - // as the empty set is always self-supporting we return that one. - return new ArgumentSet(); - } - - /** Default Constructor */ - public AdmissibleReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof NecessityArgumentationFramework) { - return this.getModels((NecessityArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/CompleteReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/CompleteReasoner.java deleted file mode 100644 index dc4a7ef09..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/CompleteReasoner.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.necessity; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * a set of arguments S is complete iff it is admissible and all arguments defended by S are in S. - * - * @author Lars Bengel - * - */ -public class CompleteReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(NecessityArgumentationFramework bbase) { - Set> extensions = new HashSet<>(); - // Check all admissible subsets - AdmissibleReasoner admissibleReasoner = new AdmissibleReasoner(); - for(Collection ext: admissibleReasoner.getModels(bbase)){ - boolean complete = true; - Set otherArguments = new HashSet(bbase); - otherArguments.removeAll(ext); - for (BArgument argument : otherArguments) { - if (bbase.isAcceptable(argument, ext)) { - complete = false; - break; - } - } - if (complete) - extensions.add(new ArgumentSet(ext)); - } - return extensions; - } - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(NecessityArgumentationFramework bbase) { - // as the empty set is always complete we return that one. - ArgumentSet ext = new ArgumentSet(); - return ext; - } - - /** Default Constructor */ - public CompleteReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof NecessityArgumentationFramework) { - return this.getModels((NecessityArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/GroundedReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/GroundedReasoner.java deleted file mode 100644 index 3d1d1516b..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/GroundedReasoner.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.necessity; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.Collection; -import java.util.HashSet; - -/** - * the grounded extension of bbase is the least fixed point of the characteristic function. - * - * @author Lars Bengel - * - */ -public class GroundedReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * Return models - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(NecessityArgumentationFramework bbase) { - Collection> extensions = new HashSet<>(); - extensions.add(this.getModel(bbase)); - return extensions; - } - - /** - * - * Return model - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(NecessityArgumentationFramework bbase) { - ArgumentSet ext = new ArgumentSet(); - int size; - do{ - size = ext.size(); - ext = bbase.faf(ext); - }while(size!=ext.size()); - return ext; - } - - /** Default Constructor */ - public GroundedReasoner(){} - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof NecessityArgumentationFramework) { - return this.getModels((NecessityArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/PreferredReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/PreferredReasoner.java deleted file mode 100644 index 53ab6e202..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/PreferredReasoner.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.necessity; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * a set of arguments S is preferred iff it is maximal wrt set inclusion admissible. - * - * @author Lars Bengel - * - */ -public class PreferredReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(NecessityArgumentationFramework bbase) { - Collection> completeExtensions = new CompleteReasoner().getModels(bbase); - Set> result = new HashSet<>(); - boolean maximal; - for(Collection e1: completeExtensions){ - maximal = true; - for(Collection e2: completeExtensions) - if(e1 != e2 && e2.containsAll(e1)){ - maximal = false; - break; - } - if(maximal) - result.add(e1); - } - return result; - } - - /** - * - * @param bbase argumentation framework - * @return model - */ - public Collection getModel(NecessityArgumentationFramework bbase) { - // just return the first found preferred extension - Collection> completeExtensions = new CompleteReasoner().getModels(bbase); - boolean maximal; - for(Collection e1: completeExtensions){ - maximal = true; - for(Collection e2: completeExtensions) - if(e1 != e2 && e2.containsAll(e1)){ - maximal = false; - break; - } - if(maximal) - return e1; - } - // this should not happen - throw new RuntimeException("Hmm, did not find a maximal set in a finite number of sets. Should not happen."); - } - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof NecessityArgumentationFramework) { - return this.getModels((NecessityArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/StableReasoner.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/StableReasoner.java deleted file mode 100644 index 3bcab4deb..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/reasoner/necessity/StableReasoner.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.reasoner.necessity; - -import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.*; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * a set of arguments S is stable iff the set of arguments deactivated by S equals A\S, - * where A is the set of all arguments in the argumentation framework. - * - * @author Lars Bengel - * - */ -public class StableReasoner extends AbstractBipolarExtensionReasoner { - /** - * - * @param bbase argumentation framework - * @return models - */ - public Collection> getModels(NecessityArgumentationFramework bbase) { - Collection> preferredExtensions = new PreferredReasoner().getModels(bbase); - Set> result = new HashSet<>(); - for(Collection ext: preferredExtensions){ - Set deactivatedArguments = bbase.getDeactivatedArguments(ext); - Set arguments = new HashSet<>(bbase); - arguments.removeAll(ext); - if (deactivatedArguments.equals(arguments)) - result.add(ext); - } - return result; - } - - /** - * - * @param bbase argumentation framework - * @return model - */ - public ArgumentSet getModel(NecessityArgumentationFramework bbase) { - Collection> preferredExtensions = new PreferredReasoner().getModels(bbase); - for(Collection ext: preferredExtensions){ - Set deactivatedArguments = bbase.getDeactivatedArguments(ext); - Set arguments = new HashSet<>(bbase); - arguments.removeAll(ext); - if (deactivatedArguments.equals(arguments)) - return new ArgumentSet(ext); - } - return null; - } - - @Override - public Collection> getModels(AbstractBipolarFramework baf) { - if (baf instanceof NecessityArgumentationFramework) { - return this.getModels((NecessityArgumentationFramework) baf); - } else { - throw new IllegalArgumentException("Unsupported Framework type"); - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/semantics/Semantics.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/semantics/Semantics.java new file mode 100644 index 000000000..4bffb5509 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/semantics/Semantics.java @@ -0,0 +1,93 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.semantics; + +/** + * Enum of semantics for bipolar argumentation + * + * @author Lars Bengel + */ +public enum Semantics { + /** + * CF + */ + BCF("conflict-free semantics", "B-CF"), + /** + * COH + */ + BCOH("coherent semantics", "B-COH"), + /** + * ADM + */ + BAD("admissible semantics", "B-AD"), + /** + * diverse + */ + diverse("diverse semantics", "div"); + /** + * all semantics + */ + @SuppressWarnings("javadoc") + public static final Semantics + /** CONFLICT_FREE SEMANTICS*/ + B_CONFLICT_FREE_SEMANTICS = BCF, + /** COHERENT SEMANTICS*/ + B_COHERENT_SEMANTICS = BCOH, + /** COHERENT_ADMISSIBLE SEMANTICS */ + B_ADMISSIBLE_SEMANTICS = BAD; + + /** + * The description of the semantics. + */ + private String description; + /** + * The abbreviation of the semantics. + */ + private String abbreviation; + + /** + * Creates a new semantics. + * + * @param description some description + * @param abbreviation an abbreviation + */ + private Semantics(String description, String abbreviation) { + this.description = description; + this.abbreviation = abbreviation; + } + + /** + * Returns the description of the semantics. + * + * @return the description of the semantics. + */ + public String description() { + return this.description; + } + + /** + * Returns the abbreviation of the semantics. + * + * @return the abbreviation of the semantics. + */ + public String abbreviation() { + return this.abbreviation; + } +} + diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractBipolarFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractBipolarFramework.java deleted file mode 100644 index 8502466f8..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractBipolarFramework.java +++ /dev/null @@ -1,456 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungSignature; -import org.tweetyproject.commons.BeliefSet; -import org.tweetyproject.commons.Signature; -import org.tweetyproject.graphs.*; -import org.tweetyproject.math.matrix.Matrix; - -import java.util.*; - -/** - * This class implements a bipolar abstract argumentation framework with attack and support relations. - * Both relations need to have the form (BipolarEntity, BArgument) - * - * @author Lars Bengel - * - */ -public abstract class AbstractBipolarFramework extends BeliefSet implements Graph { - /** - * For archiving sub graphs - */ - private static Map>> archivedSubgraphs = new HashMap<>(); - - /** - * explicit listing of direct supporters and supported (for efficiency reasons) - */ - protected Map> supportParents = new HashMap<>(); - - /** explicit listing of direct supporters and supported (for efficiency reasons) */ - protected Map> supportChildren = new HashMap<>(); - - /** - * explicit listing of direct attackers and attackees (for efficiency reasons) - */ - protected Map> attackParents = new HashMap<>(); - - /** - * explicit listing of direct attackers and attackees (for efficiency reasons) - */ - protected Map> attackChildren = new HashMap<>(); - - /** - * Computes the set {A | (A,argument) in supports}. - * @param argument an argument - * @return the set of all bipolar entities that support argument. - */ - public Set getDirectSupporters(BArgument argument){ - if(!this.supportParents.containsKey(argument)) - return new HashSet<>(); - return new HashSet(this.supportParents.get(argument)); - } - - /** - * Computes the set {A | (argument,A) in supports}. - * @param arg an instance of bipolar entity - * @return the set of all arguments that are supported by argument. - */ - public Set getDirectSupported(BipolarEntity arg){ - if(!this.supportChildren.containsKey(arg)) { - return new HashSet<>(); - } - return new HashSet<>(this.supportChildren.get(arg)); - } - - /** - * Computes the set {A | (A,argument) in attacks}. - * @param argument an argument - * @return the set of all bipolar entities that attack argument. - */ - public Set getAttackers(BArgument argument){ - if(!this.attackParents.containsKey(argument)) - return new HashSet<>(); - return new HashSet<>(this.attackParents.get(argument)); - } - - /** - * Computes the set {A | (argument,A) in attacks}. - * @param arg an instance of bipolar entity - * @return the set of all arguments that are attacked by argument. - */ - public Set getAttacked(BipolarEntity arg){ - if(!this.attackChildren.containsKey(arg)) - return new HashSet<>(); - return new HashSet<>(this.attackChildren.get(arg)); - } - - /** - * checks whether argument is acceptable wrt. ext - * @param argument some argument - * @param ext a set of arguments - * @return "true" if argument is acceptable wrt. ext - */ - public abstract boolean isAcceptable(BArgument argument, Collection ext); - - /** - * The characteristic function of an bipolar argumentation framework: F_AF(S) = {A|A is acceptable wrt. S}. - * @param extension an extension (a set of arguments). - * @return an extension (a set of arguments). - */ - public ArgumentSet faf(ArgumentSet extension){ - ArgumentSet newExtension = new ArgumentSet(); - for (BArgument argument : this) { - if (this.isAcceptable(argument, extension)) - newExtension.add(argument); - } - return newExtension; - } - - /** - * Checks whether arg1 is directly supported by arg2. - * @param arg1 an argument. - * @param arg2 a bipolar entity - * @return "true" if arg1 is directly supported by arg2 - */ - public boolean isDirectSupportedBy(BArgument arg1, BipolarEntity arg2){ - if(!this.supportParents.containsKey(arg1)) - return false; - return this.supportParents.get(arg1).contains(arg2); - } - - /** - * Checks whether arg1 is attacked by arg2. - * @param arg1 an argument. - * @param arg2 a bipolar entity - * @return "true" if arg1 is directly attacked by arg2 - */ - public boolean isAttackedBy(BArgument arg1, BipolarEntity arg2){ - if(!this.attackParents.containsKey(arg1)) - return false; - return this.attackParents.get(arg1).contains(arg2); - } - - /** - * Returns all supports of this theory. - * @return all supports of this theory. - */ - public abstract Set getSupports(); - - /** - * Returns all attacks of this theory. - * @return all attacks of this theory. - */ - public abstract Set getAttacks(); - - /** - * Adds the given support to this argumentation framework. - * @param support a support - * @return "true" if the set of supports has been modified. - */ - public abstract boolean add(Support support); - - /** - * Adds the set of supports to this argumentation framework - * @param c a collection of supports - * @return "true" if this argumentation framework has been modified. - */ - public boolean addAllSupports(Collection c){ - boolean result = false; - for(Support supp: c) - result |= this.add(supp); - return result; - } - - /** - * Adds the given attack to this argumentation framework - * @param attack an attack - * @return "true" if the set of attacks has been modified. - */ - public abstract boolean add(Attack attack); - - /** - * Adds the set of attacks to this argumentation framework - * @param c a collection of attacks - * @return "true" if this argumentation framework has been modified. - */ - public boolean addAllAttacks(Collection c){ - boolean result = false; - for(Attack att: c) - result |= this.add(att); - return result; - } - - /** - * Adds all arguments, attacks and supports of the given argumentation framework to - * this framework - * @param theory some abstract support framework - * @return "true" if this framework has been modified - */ - protected boolean add(AbstractBipolarFramework theory){ - boolean b1 = this.addAll(theory); - boolean b2 = this.addAllAttacks(theory.getAttacks()); - boolean b3 = this.addAllSupports(theory.getSupports()); - return b1 || b2 || b3 ; - } - - /** - * Adds argument to this argumentation framework - * @param argument some argument - * @return "true" if this framework has been modified - */ - public boolean add(BArgument argument) { - return super.add(argument); - } - - /** - * Adds argument to this argumentation framework - * for better compatibility between dung theories and bipolar argumentation frameworks - * @param argument some argument - * @return "true" if this framework has been modified - */ - public boolean add(Argument argument) { - return this.add(new BArgument(argument)); - } - - /** - * Removes the given support from this argumentation framework. - * @param support a support - * @return "true" if the set of supports has been modified. - */ - public boolean remove(Support support){ - boolean result = false; - if(supportParents.containsKey(support.getSupported())) - result |= supportParents.get(support.getSupported()).remove(support.getSupporter()); - if(supportChildren.containsKey(support.getSupporter())) - result |= supportChildren.get(support.getSupporter()).remove(support.getSupported()); - return result; - } - - /** - * Removes the given attack from this argumentation framework. - * @param attack an attack - * @return "true" if the set of supports has been modified. - */ - public boolean remove(Attack attack){ - boolean result = false; - if(attackParents.containsKey(attack.getAttacked())) - result |= attackParents.get(attack.getAttacked()).remove(attack.getAttacker()); - if(attackChildren.containsKey(attack.getAttacker())) - result |= attackChildren.get(attack.getAttacker()).remove(attack.getAttacked()); - return result; - } - - /** - * Removes the argument and all its attacks and supports - * @param a some argument - * @return true if this structure has been changed - */ - public boolean remove(BArgument a){ - if(this.supportParents.get(a) != null){ - for(BipolarEntity b: this.supportParents.get(a)) - this.supportChildren.get(b).remove(a); - this.supportParents.remove(a); - } - Set supportKeys= new HashSet<>(this.supportChildren.keySet()); - for (BipolarEntity key: supportKeys) { - if (key.contains(a)) { - for(BArgument b: this.supportChildren.get(key)) - this.supportParents.get(b).remove(key); - this.supportChildren.remove(key); - } - } - if(this.attackParents.get(a) != null){ - for(BipolarEntity b: this.attackParents.get(a)) - this.attackChildren.get(b).remove(a); - this.attackParents.remove(a); - } - Set attackKeys = new HashSet<>(this.attackChildren.keySet()); - for (BipolarEntity key: attackKeys) { - if (key.contains(a)) { - for(BArgument b: this.attackChildren.get(key)) - this.attackParents.get(b).remove(key); - this.attackChildren.remove(key); - } - } - return super.remove(a); - } - - /* (non-Javadoc) - * @see org.tweetyproject.commons.BeliefSet#removeAll(java.util.Collection) - */ - public boolean removeAll(Collection c){ - boolean result = false; - for(Object a: c) - if(a instanceof BArgument) - result |= this.remove((BArgument) a); - else if(a instanceof Attack) - result |= this.remove((Attack)a); - else if(a instanceof BinarySupport) - result |= this.remove((Support)a); - return result; - } - - /** Pretty print of the framework. - * @return the pretty print of the framework. - */ - public String prettyPrint(){ - String output = new String(); - Iterator it = this.iterator(); - while(it.hasNext()) - output += "argument("+it.next().toString()+").\n"; - output += "\n"; - Iterator it2 = this.getAttacks().iterator(); - while(it2.hasNext()) - output += "attack"+it2.next().toString()+".\n"; - output += "\n"; - Iterator it3 = this.getSupports().iterator(); - while(it3.hasNext()) - output += "support"+it3.next().toString()+".\n"; - return output; - } - - @Override - protected DungSignature instantiateSignature() { - return new DungSignature(); - } - - @Override - public Signature getMinimalSignature() { - return new DungSignature(this); - } - - @Override - public boolean add(GeneralEdge edge) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection getNodes() { - return this; - } - - @Override - public int getNumberOfNodes() { - return this.size(); - } - - public int getNumberOfEdges() { - int num = 0; - for(Argument a: this.supportParents.keySet()) - num += this.supportParents.get(a).size(); - for(Argument a: this.attackParents.keySet()) - num += this.attackParents.get(a).size(); - return num; - } - - @Override - public boolean areAdjacent(BArgument a, BArgument b) { - return this.isAttackedBy(a, b) || this.isDirectSupportedBy(a, b); - } - - @Override - public Edge getEdge(BArgument a, BArgument b) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> getEdges() { - // edges can be between a set of nodes and a single node - throw new UnsupportedOperationException(); - } - - @Override - public Collection getChildren(Node node) { - if (!(node instanceof BipolarEntity)) { - throw new IllegalArgumentException("Node of type BArgument expected"); - } else { - Collection result = this.getAttacked((BipolarEntity) node); - result.addAll(this.getDirectSupported((BipolarEntity) node)); - return result; - } - } - - @Override - public Collection getParents(Node node) { - // parents can be arguments or sets of arguments - throw new UnsupportedOperationException(); - } - - @Override - public boolean existsDirectedPath(BArgument node1, BArgument node2) { - return DefaultGraph.existsDirectedPath(this, node1, node2); - } - - @Override - public Collection getNeighbors(BArgument node) { - //Neighbors can be arguments and sets of arguments - throw new UnsupportedOperationException(); - } - - @Override - public Matrix getAdjacencyMatrix() { - throw new UnsupportedOperationException(); - } - - @Override - public Graph getComplementGraph(int i) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> getConnectedComponents() { - return DefaultGraph.getConnectedComponents(this); - } - - @Override - public Collection> getStronglyConnectedComponents() { - return DefaultGraph.getStronglyConnectedComponents(this); - } - - @Override - public Collection> getSubgraphs() { - if (!archivedSubgraphs.containsKey(this)) { - archivedSubgraphs.put(this, DefaultGraph.getSubgraphs(this)); - } - - return (Collection)archivedSubgraphs.get(this); - } - - @Override - public Graph getRestriction(Collection collection) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean hasSelfLoops() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isWeightedGraph() { - return false; - } - - /** Default Constructor */ - public AbstractBipolarFramework(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractEAFTheory.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractEAFTheory.java deleted file mode 100644 index 6c6ce31c5..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/AbstractEAFTheory.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - - - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - - -/** - * A base class for implementing PEAFTheory and EAFTheory. - * - * @param the support link (ESupport or PSupport) - * @author Taha Dogan Gunes - */ -public abstract class AbstractEAFTheory extends AbstractBipolarFramework{ - - /** - * The root node of the EAFTheory - */ - protected BArgument eta; - /** - * Arguments stored in a set - */ - protected Set argumentsSet = new HashSet(); - - /** - * Arguments stored in a list - */ - protected ArrayList arguments = new ArrayList<>(); - /** - * Supports stored in a list - */ - protected ArrayList supports = new ArrayList<>(); - /** - * Attacks stored in a list - */ - protected ArrayList attacks = new ArrayList<>(); - - /** - * Add an argument - * - * @param argument an EArgument objects - */ - public void addArgument(BArgument argument) { - if (arguments.size() == 0) { - eta = argument; - } - arguments.add(argument); - argumentsSet.add(argument); - } - - - /** - * Add an attack - * - * @param attack an EAttack object - * @return true if successful - */ - public boolean addAttack(EAttack attack) { - return attacks.add(attack); - } - - /** - * Add a support - * - * @param support a T-Support object - * @return true if successful - */ - public boolean addSupport(S support) { - return supports.add(support); - } - - /** - * Creates an argument with a name - * - * @param name the name of the argument in string - * @return the created EArgument object - */ - protected BArgument createArgument(String name) { - return new BArgument(name); - } - - /** - * Add an attack with sets - * - * @param froms arguments that originates the attack - * @param tos arguments that receive the attack - */ - @SuppressWarnings("unchecked") - public void addAttack(BipolarEntity froms, BipolarEntity tos) { - int identifier = attacks.size(); - HashSet fromSet = new HashSet(); - HashSet toSet = new HashSet(); - if(froms instanceof BArgument) - fromSet.add((BArgument) froms); - if(froms instanceof HashSet) - fromSet = (HashSet) froms; - if(tos instanceof BArgument) - toSet.add((BArgument) tos); - if(tos instanceof HashSet) - toSet = (HashSet) tos; - EAttack attack = this.createAttack(Integer.toString(identifier), fromSet, toSet); - this.addAttack(attack); - } - - /** - * Add an attack with sets - * - * @param froms arguments that originates the attack - * @param tos arguments that receive the attack - */ - public void addAttack(Set froms, Set tos) { - int identifier = attacks.size(); - EAttack attack = this.createAttack(Integer.toString(identifier), froms, tos); - this.addAttack(attack); - } - - /** - * Creates an attack object (does not add to the internal abstract object) - * - * @param name the name of the attack - * @param froms the set of arguments that the attack originates from - * @param tos the set of arguments that the attack targets - * @return EAttack object - */ - protected EAttack createAttack(String name, Set froms, Set tos) { - if (tos.contains(eta)) { - throw new RuntimeException("Argument eta can't be attacked."); - } - EAttack attack = new EAttack( froms, tos); - - return attack; - } - - /** - * Create a set of arguments from the given indices - * - * @param fromIndices the indices of arguments requested - * @return the set of arguments - */ - protected Set createEmptyArgSet(int[] fromIndices) { - Set froms = new HashSet<>(fromIndices.length); - for (int fromIndex : fromIndices) { - froms.add(arguments.get(fromIndex)); - } - return froms; - } - - /** - * Create and add a new argument with identifier - * - * @param identifier integer identifier for the argument - * @return the created argument - */ - public BArgument addArgument(int identifier) { - BArgument argument = this.createArgument(Integer.toString(identifier)); - this.addArgument(argument); - return argument; - } - - /** - * Get all arguments - * - * @return a set of arguments - */ - public Set getArgumentsAsSet() { - return this.argumentsSet; - } - - /** - * - * Return a list of arguments - * @return a list of arguments - */ - public ArrayList getArguments() { - return arguments; - } - - /** - * Get all supports - * - * @return a list of supports - */ - public Set getSupports() { - return new HashSet(supports); - } - - /** - * Get all supports invloving argument arg - * @param arg an argument - * @return a list of supports - */ - public Set getSupports(BArgument arg) { - HashSet result = new HashSet(); - for(Support s : this.getSupports()) { - if(s.contains(arg)) - result.add(s); - } - return result; - } - - /** - * Get all attacks - * - * @return a list of attacks - */ - public Set getAttacks() { - return new HashSet(attacks); - } - /** - * Return the powerset - * @return the powerset - * - * @param type - * @param originalSet the input set - */ - public Set> powerSet(Set originalSet) { - Set> sets = new HashSet>(); - if (originalSet.isEmpty()) { - sets.add(new HashSet()); - return sets; - } - List list = new ArrayList(originalSet); - T head = list.get(0); - Set rest = new HashSet(list.subList(1, list.size())); - for (Set set : powerSet(rest)) { - Set newSet = new HashSet(); - newSet.add(head); - newSet.addAll(set); - sets.add(newSet); - sets.add(set); - } - return sets; - } - /** - * Pretty print of the EAFTheory - */ - public String toString() { - String result = ""; - result += ("-- Arguments --"); - int i = 0; - for (BArgument argument : this.getArguments()) { - result += (i + ". " + argument); - i++; - } - - result += "\n"; - result += ("-- Supports --"); - i = 0; - for (Support support : this.getSupports()) { - result += (i + ". " + support); - i++; - } - - result += ""; - result += ("-- Attacks --"); - i = 0; - for (Attack attack : this.getAttacks()) { - result += (i + ". " + attack); - i++; - } - - return result += ("\n"); - } - - /** - * Get all the number of arguments - * - * @return the number of arguments - */ - public int getNumberOfArguments() { - return arguments.size(); - } - - /** - * Get the eta (the root) argument - * - * @return eta argument - */ - public BArgument getEta() { - return eta; - } - - /** Default Constructor */ - public AbstractEAFTheory(){} -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/ArgumentSet.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/ArgumentSet.java deleted file mode 100644 index 52e0658ce..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/ArgumentSet.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; -import org.tweetyproject.arg.dung.semantics.Extension; -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.commons.Signature; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -/** - * This class models a set of arguments used in the context of bipolar abstract argumentation theory. - *

- * It provides functionalities for managing a collection of {@link BArgument} objects, including adding, removing, - * and comparing sets of arguments. The class implements the {@link BipolarEntity} interface, - * the {@link Collection} interface for managing arguments, and the {@link Comparable} interface for comparing argument sets. - *

- * - * @see BArgument - * @see BipolarEntity - * @see Collection - * @see Comparable - * - * - * @author Lars Bengel - */ -public class ArgumentSet implements BipolarEntity, Collection, Comparable { - private Set arguments; - - /** - * Constructs an empty {@code ArgumentSet}. - */ - public ArgumentSet() { - this(new HashSet<>()); - } - - /** - * Constructs an {@code ArgumentSet} and initializes it with the arguments from a given {@code Extension}. - * - * @param ext the extension containing arguments to initialize the set - */ - public ArgumentSet(Extension ext) { - this(); - for (Argument argument: ext) { - this.add(new BArgument(argument)); - } - } - - /** - * Constructs an {@code ArgumentSet} with a single argument. - * - * @param argument the argument to add to the set - */ - public ArgumentSet(BArgument argument) { - this(new HashSet<>()); - this.add(argument); - } - - /** - * Constructs an {@code ArgumentSet} initialized with a collection of arguments. - * - * @param arguments the collection of arguments to initialize the set - */ - public ArgumentSet(Collection arguments) { - this.arguments = new HashSet<>(arguments); - } - - /** - * Returns a string representation of the {@code ArgumentSet}. - * The arguments are enclosed in curly braces and separated by commas. - * - * @return a string representation of the argument set - */ - @Override - public String toString() { - String s = "{"; - boolean first = true; - Iterator var3 = this.iterator(); - - while(var3.hasNext()) { - BArgument a = var3.next(); - if (first) { - s = s + a; - first = false; - } else { - s = s + "," + a; - } - } - - return s + "}"; - } - - /** - * Returns the hash code value for this argument set. - * - * @return the hash code value - */ - @Override - public int hashCode() { - return 31 * 1 + (this.arguments == null ? 0 : this.arguments.hashCode()); - } - - /** - * Compares this {@code ArgumentSet} to another object for equality. - * - * @param obj the object to compare with - * @return {@code true} if the argument sets are equal, {@code false} otherwise - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - ArgumentSet other = (ArgumentSet)obj; - if (this.arguments == null) { - if (other.arguments != null) { - return false; - } - } else if (!this.arguments.equals(other.arguments)) { - return false; - } - return true; - } - } - - /** - * Returns the set of arguments contained in this {@code ArgumentSet}. - * - * @return the set of arguments - */ - public Set getArguments() { - return this.arguments; - } - - /** - * Adds an argument to this set. - * - * @param arg0 the argument to be added - * @return {@code true} if the set did not already contain the argument - */ - @Override - public boolean add(BArgument arg0) { - return this.arguments.add(arg0); - } - - /** - * Adds a collection of arguments to this set. - * - * @param arg0 the collection of arguments to be added - * @return {@code true} if the set changed as a result of the call - */ - @Override - public boolean addAll(Collection arg0) { - return this.arguments.addAll(arg0); - } - - /** - * Clears the set, removing all arguments. - */ - @Override - public void clear() { - this.arguments.clear(); - } - - /** - * Returns {@code true} if this set contains the specified argument. - * - * @param arg0 the argument to check for containment - * @return {@code true} if this set contains the specified argument - */ - @Override - public boolean contains(Object arg0) { - return this.arguments.contains(arg0); - } - - /** - * Returns {@code true} if this set contains all of the elements in the specified collection. - * - * @param arg0 the collection to check for containment - * @return {@code true} if this set contains all of the elements in the specified collection - */ - @Override - public boolean containsAll(Collection arg0) { - return this.arguments.containsAll(arg0); - } - - /** - * Returns {@code true} if this set contains no arguments. - * - * @return {@code true} if this set contains no arguments - */ - @Override - public boolean isEmpty() { - return this.arguments.isEmpty(); - } - - /** - * Returns an iterator over the arguments in this set. - * - * @return an iterator over the arguments in this set - */ - @Override - public Iterator iterator() { - return this.arguments.iterator(); - } - - /** - * Removes the specified argument from this set if it is present. - * - * @param arg0 the argument to be removed - * @return {@code true} if the set contained the specified argument - */ - @Override - public boolean remove(Object arg0) { - return this.arguments.remove(arg0); - } - - /** - * Removes from this set all of its elements that are contained in the specified collection. - * - * @param arg0 the collection of elements to be removed from this set - * @return {@code true} if the set changed as a result of the call - */ - @Override - public boolean removeAll(Collection arg0) { - return this.arguments.removeAll(arg0); - } - - /** - * Retains only the elements in this set that are contained in the specified collection. - * - * @param arg0 the collection containing elements to be retained in this set - * @return {@code true} if the set changed as a result of the call - */ - @Override - public boolean retainAll(Collection arg0) { - return this.arguments.retainAll(arg0); - } - - /** - * Returns the number of arguments in this set. - * - * @return the number of arguments in this set - */ - @Override - public int size() { - return this.arguments.size(); - } - - /** - * Returns an array containing all the arguments in this set. - * - * @return an array containing all the arguments in this set - */ - @Override - public Object[] toArray() { - return this.arguments.toArray(); - } - - /** - * Returns an array containing all the arguments in this set; the runtime type of the returned array is that of the specified array. - * - * @param the component type of the array to contain the arguments - * @param arg0 the array into which the arguments of this set are to be stored - * @return an array containing the arguments in this set - */ - @Override - public T[] toArray(T[] arg0) { - return this.arguments.toArray(arg0); - } - - /** - * Compares this {@code ArgumentSet} with another for order. The comparison is based on the hash codes of the sets. - * - * @param arg0 the other {@code ArgumentSet} to be compared - * @return a negative integer, zero, or a positive integer as this set is less than, equal to, or greater than the specified set - */ - @Override - public int compareTo(ArgumentSet arg0) { - if (this.hashCode() < arg0.hashCode()) { - return -1; - } else { - return this.hashCode() > arg0.hashCode() ? 1 : 0; - } - } - - - /** - * Retrieves the LdoFormula associated with this argument set. - * - * @return {@code null} as this implementation does not currently support LdoFormula - */ - @Override - public LdoFormula getLdoFormula() { - return null; - } - - /** - * Retrieves the signature of this argument set. - * - * @return {@code null} as this implementation does not currently support signatures - */ - @Override - public Signature getSignature() { - return null; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Attack.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Attack.java deleted file mode 100644 index af7e9b2a0..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Attack.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -/** - * This interface captures common methods of different interpretations of the attack relation in - * bipolar abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public interface Attack extends BipolarEntity{ - /** - * Returns the entity that is being attacked. - *

- * This method provides access to the argument or set of arguments that is the target of the attack. - *

- * - * @return the entity that is attacked - */ - BipolarEntity getAttacked(); - - /** - * Returns the entity that is initiating the attack. - *

- * This method provides access to the argument or set of arguments that is performing the attack. - *

- * - * @return the entity that is attacking - */ - BipolarEntity getAttacker(); - - /** - * Provides a string representation of the attack. - *

- * This method returns a string that describes the attack relation, typically including - * the identities of the attacker and the attacked entity. - *

- * - * @return a string representation of the attack - */ - - public String toString(); -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BArgument.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BArgument.java deleted file mode 100644 index 9614af26b..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BArgument.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import java.util.Iterator; -import org.tweetyproject.arg.dung.syntax.Argument; - -/** - * This class models an argument used by bipolar abstract argumentation theories. - * @author Lars Bengel - * - */ -public class BArgument extends org.tweetyproject.arg.dung.syntax.Argument implements BipolarEntity { - - /** - * Constructs a new bipolar argument with the specified name. - * - * @param name the name of the argument - */ - public BArgument(String name) { - super(name); - } - - /** - * Constructs a new bipolar argument from an existing argument. - * - * @param arg the argument to be converted - */ - public BArgument(Argument arg) { - super(arg.getName()); - } - - /** - * Checks if this argument is equal to the specified object. - *

- * This method checks for equality based on the argument's name. - *

- * - * @param arg0 the object to be compared - * @return {@code true} if this argument is equal to the specified object; - * {@code false} otherwise - */ - @Override - public boolean contains(Object arg0) { - return this.equals(arg0); - } - - /** - * Returns an iterator over the arguments in this set. - *

- * This method is not implemented for the current class and returns {@code null}. - * In a complete implementation, it would provide an iterator over a collection - * of arguments. - *

- * - * @return an iterator over the arguments - */ - @Override - public Iterator iterator() { - return null; - } - - /** - * Checks if this argument is supported by another argument in the given theory. - *

- * This method determines if there exists a support relation in the given - * {@link EAFTheory} where this argument is supported by the specified argument. - *

- * - * @param theory the theory in which to check for support - * @param x the argument that might support this argument - * @return {@code true} if this argument is supported by the specified argument in the theory; - * {@code false} otherwise - */ - public boolean isSupportedBy(EAFTheory theory, BipolarEntity x) { - for (Support support : theory.supports) { - BipolarEntity froms = support.getSupporter(); - BipolarEntity tos = support.getSupported(); - if (tos.contains(this) && froms.contains(x)) { - return true; - } - } - - return false; - } -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinaryAttack.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinaryAttack.java deleted file mode 100644 index 5869fc90a..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinaryAttack.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import java.util.Iterator; - -import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; -import org.tweetyproject.arg.dung.ldo.syntax.LdoNegation; -import org.tweetyproject.arg.dung.ldo.syntax.LdoRelation; -import org.tweetyproject.arg.dung.syntax.DungSignature; -import org.tweetyproject.commons.Signature; -import org.tweetyproject.graphs.DirectedEdge; - -/** - * This class models a binary attack relation between two arguments. It comprises of two attributes of Argument and is used by - * abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public class BinaryAttack extends DirectedEdge implements Attack { - /** - * Default constructor; initializes the two arguments used in this attack relation - * @param attacker the supporting argument - * @param attacked the supported argument - */ - public BinaryAttack(BArgument attacker, BArgument attacked) { - super(attacker, attacked); - } - - /** - * returns the attacked argument of this attack relation. - * @return the attacked argument of this attack relation. - */ - public BArgument getAttacked() { - return this.getNodeB(); - } - - /** - * returns the attacking argument of this attack relation. - * @return the attacking argument of this attack relation. - */ - public BArgument getAttacker() { - return this.getNodeA(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - String var10000 = this.getAttacker().toString(); - return "(" + var10000 + "," + this.getAttacked().toString() + ")"; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (!o.getClass().equals(this.getClass())) { - return false; - } else if (!this.getAttacker().equals(((BinaryAttack)o).getAttacker())) { - return false; - } else { - return this.getAttacked().equals(((BinaryAttack)o).getAttacked()); - } - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return this.getAttacked().hashCode() + 7 * this.getAttacker().hashCode(); - } - - @Override - public boolean contains(Object o) { - return this.getAttacked().equals(o) || this.getAttacker().equals(o); - } - - /* (non-Javadoc) - * @see org.tweetyproject.arg.dung.syntax.DungEntity#getLdoFormula() - */ - public LdoFormula getLdoFormula() { - return new LdoRelation(this.getAttacker().getLdoFormula(), new LdoNegation(this.getAttacked().getLdoFormula())); - } - - /* (non-Javadoc) - * @see org.tweetyproject.kr.Formula#getSignature() - */ - public Signature getSignature() { - DungSignature sig = new DungSignature(); - sig.add(this.getAttacked()); - sig.add(this.getAttacker()); - return sig; - } - - @Override - public Iterator iterator() { - return null; - } - - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinarySupport.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinarySupport.java deleted file mode 100644 index ff2060eeb..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BinarySupport.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import java.util.Iterator; - -import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; -import org.tweetyproject.arg.dung.ldo.syntax.LdoRelation; -import org.tweetyproject.arg.dung.syntax.DungSignature; -import org.tweetyproject.commons.*; -import org.tweetyproject.graphs.DirectedEdge; - -/** - * This class models a support between two arguments. It comprises of two attributes of Argument and is used by - * bipolar abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public class BinarySupport extends DirectedEdge implements Support{ - - /** - * Default constructor; initializes the two arguments used in this support relation - * @param supporter the supporting argument - * @param supported the supported argument - */ - public BinarySupport(BArgument supporter, BArgument supported){ - super(supporter,supported); - } - - /** - * returns the supported argument of this support relation. - * @return the supported argument of this support relation. - */ - public BArgument getSupported() { - return this.getNodeB(); - } - - /** - * returns the supporting argument of this support relation. - * @return the supporting argument of this support relation. - */ - public BArgument getSupporter() { - return this.getNodeA(); - } - - /* (non-Javadoc) - * @see org.tweetyproject.kr.Formula#getSignature() - */ - public Signature getSignature(){ - DungSignature sig = new DungSignature(); - sig.add(this.getSupported()); - sig.add(this.getSupporter()); - return sig; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString(){ - return "("+this.getSupporter().toString()+","+this.getSupported().toString()+")"; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o){ - if(!o.getClass().equals(this.getClass())) return false; - if(!this.getSupporter().equals(((BinarySupport)o).getSupporter())) return false; - if(!this.getSupported().equals(((BinarySupport)o).getSupported())) return false; - return true; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode(){ - return this.getSupported().hashCode() + 11 * this.getSupporter().hashCode(); - } - - /* (non-Javadoc) - * @see org.tweetyproject.arg.dung.syntax.DungEntity#getLdoFormula() - */ - public LdoFormula getLdoFormula() { - return new LdoRelation(this.getSupporter().getLdoFormula(), this.getSupported().getLdoFormula()); - } - - /* (non-Javadoc) - * @see java.lang.Object#contains(java.lang.Object) - */ - public boolean contains(Object o) { - return this.getSupported().equals(o) || this.getSupporter().equals(o); - } - - @Override - public Iterator iterator() { - return null; - } - - @Override - public void setConditionality(double c) { - //this class has not conditionality - - } - - @Override - public double getConditionalProbability() { - //this class has not conditionality - return 0; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java new file mode 100644 index 000000000..ef8d05749 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java @@ -0,0 +1,421 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ + +package org.tweetyproject.arg.bipolar.syntax; + +import org.tweetyproject.arg.dung.reasoner.SimpleConflictFreeReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.Attack; + +import org.tweetyproject.arg.dung.syntax.DungTheory; +import org.tweetyproject.commons.util.SetTools; +import org.tweetyproject.graphs.Graph; + +import java.util.*; + +/** + * This class implements a bipolar abstract argumentation theory with support and attack relation. + * + * @see "Cayrol C., A. Cohen, and M.-C. Lagasquie-Schiex. 'Higher-order interactions (bipolar or not) in abstract argumentation: A state of the art'. Handbook of Formal Argumentation Vol. 2, 2021." + * @see "Cohen A., S. Gottifredi, A. J. Garcia, and G. R. Simari. 'A survey of different approaches to support in argumentation systems'. Knowledge Engineering Review, 29(5):513–550, 2014." + * + * @author Lars Bengel + */ +public class BipolarArgumentationFramework extends DungTheory { + + /** + * explicit listing of direct supporters and supported (for efficiency reasons) + */ + protected Map> supportParents = new HashMap<>(); + protected Map> supportChildren = new HashMap<>(); + + /** + * Default constructor; initializes empty sets of arguments, attacks and supports + */ + public BipolarArgumentationFramework() { + super(); + } + + /** + * Determines whether 'args' is coherent, i.e., whether there exists no argument that is both (indirectly) supported and attacked (either supported or indirectly) by 'args' + * + * @param args some set of arguments + * @return "true" iff 'args' is coherent + */ + public boolean isCoherent(Collection args){ + Collection supported = new HashSet<>(args); + supported.addAll(getSupported(args)); + + DungTheory theory = getAssociatedTheory(); + + Collection intersect = new HashSet<>(theory.getAttacked(args)); + intersect.retainAll(supported); + return intersect.isEmpty(); + } + + /** + * Determines whether 'args' is strongly conflict-free, i.e., whether 'args' is conflict-free wrt. supported and indirect attacks + * + * @param args some set of arguments + * @return "true" iff 'args' is strongly conflict-free + */ + public boolean isStronglyConflictFree(Collection args) { + DungTheory theory = getAssociatedTheory(); + return theory.isConflictFree(args); + } + + /** + * Determines whether 'ext' strongly defends 'arg', i.e., whether 'arg' is defended under consideration of supported and indirect attacks + * @param ext some set of arguments + * @param arg some argument + * @return "true" iff 'arg' is strongly defended by 'ext' + */ + public boolean isStronglyDefendedBy(Collection ext, Argument arg) { + DungTheory theory = getAssociatedTheory(); + Collection attackers = theory.getAttackers(arg); + attackers.removeAll(theory.getAttacked(ext)); + return attackers.isEmpty(); + } + + /** + * Determines whether 'args' is coherent admissible, i.e., whether 'args' is coherent and strongly defends all its arguments + * + * @param args some set of arguments + * @return "true" iff 'args' is coherent admissible + */ + public boolean isCoherentAdmissible(Collection args) { + if (!isCoherent(args)) return false; + for (Argument arg: args) { + if (!isStronglyDefendedBy(args, arg)) return false; + } + return true; + } + + /** + * Determines whether 'args' is a coalition, i.e., whether 'args' is a maximal conflict-free set of arguments that is connected via the support relation. + * + * @param args some set of arguments + * @return "true" if 'args' is a coalition of this BAF + */ + public boolean isCoalition(Collection args) { + return getCoalitions().contains(args); + } + + /** + * Computes the set of all coalition of this BAF + * A coalition is a maximal conflict-free set of arguments that is connected via the support relation. + * + * @return the set of coalitions + */ + public Collection> getCoalitions() { + Collection> candidates = new HashSet<>(); + for (Argument arg: this) { + Extension ext = new Extension<>(); + ext.add(arg); + candidates.add(ext); + } + DungTheory supp_theory = new DungTheory(); + supp_theory.addAll(this.getNodes()); + for (Support supp: this.getSupports()) { + supp_theory.addAttack(supp.getSupporter(), supp.getSupported()); + } + Collection> components = supp_theory.getComponents(); + Collection> cfSets = new SimpleConflictFreeReasoner().getModels(this); + for (Graph component : components) { + for (Collection candidate : new SetTools().subsets(component.getNodes())) { + if (candidate.isEmpty()) continue; + DungTheory candidate_theory = (DungTheory) supp_theory.getRestriction(candidate); + if (candidate_theory.getComponents().size() == 1) { + if (cfSets.contains(new Extension(candidate))) { + candidates.add(new Extension(candidate)); + } + } + } + } + + Collection> coalitions = new HashSet<>(); + boolean maximal; + for(Collection e1: candidates){ + maximal = true; + for(Collection e2: candidates) + if(e1 != e2 && e2.containsAll(e1)){ + maximal = false; + break; + } + if(maximal) + coalitions.add(e1); + } + return coalitions; + } + + /** + * Computes the coalition graph for this BAF. + * A coalition is a maximal conflict-free set of arguments that is connected via the support relation. + * There is an attack between two coalitions iff there is an attack between members of each coalition. + * + * @return the coalition graph for this BAF + */ + public DungTheory getCoalitionGraph() { + DungTheory theory = new DungTheory(); + Collection> coalitions = getCoalitions(); + for (Collection coalition: coalitions) { + theory.add(new CoalitionArgument(coalition)); + } + for (Collection c1 : coalitions) { + for (Collection c2: coalitions) { + if (c1.equals(c2)) continue; + Collection attacked = getAttacked(c1); + attacked.retainAll(c2); + if (!attacked.isEmpty()) { + theory.addAttack(new CoalitionArgument(c1), new CoalitionArgument(c2)); + } + } + } + return theory; + } + + /** + * Returns the corresponding abstract argumentation framework where all supported and indirect attacks are included directly + * @return an argumentation framework + */ + public DungTheory getAssociatedTheory() { + return this.getAssociatedTheory(Support.Type.DEFAULT); + } + + /** + * Induces an argumentation framework by resolving the complex attacks of the given support interpretation + * + * @param type the support interpretation + * @return the argumentation framework induced via the given support interpretation + */ + public DungTheory getAssociatedTheory(Support.Type type) { + DungTheory theory = new DungTheory(); + theory.addAll(this.getNodes()); + switch (type) { + case DEFAULT -> { + theory.addAllAttacks(getSupportedAttacks()); + theory.addAllAttacks(getIndirectAttacks()); + } case SIMPLE_DEDUCTIVE -> { + theory.addAllAttacks(getMediatedAttacks()); + } case DEDUCTIVE -> { + theory.addAllAttacks(getSupportedAttacks()); + theory.addAllAttacks(getMediatedAttacks()); + } case NECESSITY -> { + BipolarArgumentationFramework comp_theory = new BipolarArgumentationFramework(); + comp_theory.addAll(this.getNodes()); + comp_theory.addAllAttacks(this.getAttacks()); + for (Support supp: this.getSupports()) { + comp_theory.addSupport(supp.getSupported(), supp.getSupporter()); + } + return comp_theory.getAssociatedTheory(Support.Type.DEDUCTIVE); + } case SIMPLE_NECESSITY -> { + BipolarArgumentationFramework comp_theory = new BipolarArgumentationFramework(); + comp_theory.addAll(this.getNodes()); + comp_theory.addAllAttacks(this.getAttacks()); + for (Support supp: this.getSupports()) { + comp_theory.addSupport(supp.getSupported(), supp.getSupporter()); + } + return comp_theory.getAssociatedTheory(Support.Type.SIMPLE_DEDUCTIVE); + } + } + return theory; + } + + public boolean isSupportedAttack(Argument arg1, Argument arg2) { + if (getAttackers(arg2).contains(arg1)) return true; + Collection supported = getSupported(arg1); + Collection attackers = getAttackers(arg2); + attackers.retainAll(supported); + return !attackers.isEmpty(); + } + + public boolean isIndirectAttack(Argument arg1, Argument arg2) { + Collection supporters = getSupporters(arg2); + Collection attacked = getAttacked(arg1); + attacked.retainAll(supporters); + return !attacked.isEmpty(); + } + + public boolean isMediatedAttack(Argument arg1, Argument arg2){ + if (getAttackers(arg2).contains(arg1)) return true; + Collection attacked = getAttacked(arg1); + Collection supported = getSupported(arg2); + attacked.retainAll(supported); + return !attacked.isEmpty(); + } + + + public Collection getSupportedAttacks(){ + Collection attacks = new HashSet<>(); + for (Argument a: this) { + for (Argument b: this) { + if (isSupportedAttack(a, b)) { + attacks.add(new Attack( a, b)); + } + } + } + return attacks; + } + + public Collection getIndirectAttacks() { + Collection attacks = new HashSet<>(); + for (Argument a: this) { + for (Argument b: this) { + if (isIndirectAttack(a, b)) { + attacks.add(new Attack(a, b)); + } + } + } + return attacks; + } + + public Collection getMediatedAttacks(){ + Collection attacks = new HashSet<>(); + for (Argument a: this) { + for (Argument b: this) { + if (isMediatedAttack(a, b)) { + attacks.add(new Attack(a, b)); + } + } + } + return attacks; + } + + public Collection getSupported(Collection ext){ + Collection supported = new HashSet<>(); + Stack unvisited = new Stack<>(); + unvisited.addAll(ext); + while (!unvisited.isEmpty()) { + Argument arg = unvisited.pop(); + Collection candidates = supportChildren.getOrDefault(arg, new HashSet<>()); + for (Argument b: candidates) { + if (!supported.contains(b)) { + supported.add(b); + unvisited.add(b); + } + } + } + return supported; + } + + public Collection getSupporters(Collection ext) { + Collection supporters = new HashSet<>(); + Stack unvisited = new Stack<>(); + unvisited.addAll(ext); + while (!unvisited.isEmpty()) { + Argument arg = unvisited.pop(); + Collection candidates = supportParents.getOrDefault(arg, new HashSet<>()); + for (Argument b: candidates) { + if (!supporters.contains(b)) { + supporters.add(b); + unvisited.add(b); + } + } + } + return supporters; + } + + public Collection getSupported(Argument arg){ + Extension ext = new Extension<>(); + ext.add(arg); + return getSupported(ext); + } + + public Collection getSupporters(Argument arg) { + Extension ext = new Extension<>(); + ext.add(arg); + return getSupporters(ext); + } + + /** + * Adds the given support to this bipolar argumentation framework. + * @param supp a support + * @return "true" if the set of supports has been modified. + */ + public boolean add(Support supp) { + return this.addSupport(supp.getSupporter(), supp.getSupported()); + } + + /** + * Adds a support from the first argument to the second to this bipolar argumentation framework. + * @param supporter some argument + * @param supported some argument + * @return "true" if the set of supports has been modified. + */ + public boolean addSupport(Argument supporter, Argument supported){ + boolean result = false; + if(!supportParents.containsKey(supported)) + supportParents.put(supported, new HashSet<>()); + result |= supportParents.get(supported).add(supporter); + if(!supportChildren.containsKey(supporter)) + supportChildren.put(supporter, new HashSet<>()); + result |= supportChildren.get(supporter).add(supported); + return result; + } + + public Collection getSupports(){ + Collection supports = new HashSet<>(); + for(Argument a: this) { + if(this.supportChildren.containsKey(a)) { + for(Argument b: this.supportChildren.get(a)) + supports.add(new Support(a, b)); + } + } + return supports; + } + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(org.tweetyproject.arg.bipolar.syntax.DeductiveArgumentationFramework) + */ + public int compareTo(BipolarArgumentationFramework o) { + return this.hashCode() - o.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + int result = super.hashCode(); + result = 43 * result + (this.supportParents == null ? 0 : this.supportParents.hashCode()); + return result; + } + + public String prettyPrint(){ + StringBuilder output = new StringBuilder(); + for (Argument argument : this) output.append("argument(").append(argument.toString()).append(").\n"); + output.append("\n"); + for (Attack attack : this.getAttacks()) output.append("attack").append(attack.toString()).append(".\n"); + output.append("\n"); + for (Support bArguments : this.getSupports()) + output.append("support").append(bArguments.toString()).append(".\n"); + return output.toString(); + } + + /** + * Check whether arg1 is directly supported by arg2 + * @param arg1 some argument + * @param arg2 some argument + * @return 'true' if arg1 is directly supported by arg2 + */ + public boolean isSupportedBy(Argument arg1, Argument arg2) { + return supportParents.getOrDefault(arg1, new HashSet<>()).contains(arg2); + } +} + diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarEntity.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CoalitionArgument.java similarity index 51% rename from org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarEntity.java rename to org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CoalitionArgument.java index b033880c2..384c9e260 100644 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarEntity.java +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CoalitionArgument.java @@ -1,40 +1,52 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.dung.syntax.DungEntity; -import org.tweetyproject.graphs.Node; - -/** - * This interface captures common methods of arguments and argument sets of - * bipolar abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public interface BipolarEntity extends DungEntity, Node, Iterable { - /** - * Checks if this entity contains the specified object. - * - * @param o the object to check for containment, typically a {@link BArgument} - * @return {@code true} if the object is contained within this entity, {@code false} otherwise - */ - boolean contains(Object o); -} +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.syntax; + +import org.tweetyproject.arg.dung.syntax.Argument; + +import java.util.Collection; +import java.util.HashSet; + +/** + * A representation of a set of arguments (called coalition) that represent an argument in a meta-graph. + * + * @author Lars Bengel + */ +public class CoalitionArgument extends Argument { + + /** the arguments of this coalition */ + private Collection args; + + /** + * Initializes a new Coalition-Argument for the given set + * @param args a set of arguments + */ + public CoalitionArgument(Collection args) { + super(args.toString()); + this.args = new HashSet<>(args); + } + + /** + * Returns the arguments associated with this entity + * @return a set of arguments + */ + public Collection getArguments() { + return args; + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CyclicException.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CyclicException.java deleted file mode 100644 index e29f448f5..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/CyclicException.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.tweetyproject.arg.bipolar.syntax; - -/** - * CyclicException is thrown only if the given PEAF has cyclic in the support links - * - * @author Taha Dogan Gunes - */ -public class CyclicException extends RuntimeException { - - /** - * default serial ID - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor for the exception - * - * @param message error message - */ - public CyclicException(String message) { - super(message); - } - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/DeductiveArgumentationFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/DeductiveArgumentationFramework.java deleted file mode 100644 index 433314d23..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/DeductiveArgumentationFramework.java +++ /dev/null @@ -1,487 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungTheory; - -import java.util.*; - -/** - * This class implements a bipolar abstract argumentation theory with support in a deductive sense. - * ie. if a supports b, then the acceptance of a implies the acceptance of b and as a consequence - * the non-acceptance of b implies the non-acceptance of a. - *
- *
See - *
- *
Cayrol, Lagasquie-Schiex. Bipolarity in argumentation graphs: Towards a better understanding. 2013 - *
- *
and - *
- *
Boella et al. Support in Abstract Argumentation. 2010 - * - * @author Lars Bengel - * - */ -public class DeductiveArgumentationFramework extends AbstractBipolarFramework implements Comparable { - /** - * Default constructor; initializes empty sets of arguments, attacks and supports - */ - public DeductiveArgumentationFramework() { - super(); - } - - /** - * Determines if ext is closed under the support relation of this framework - * i.e., if all arguments supported by ext are an element of ext - * @param ext an extension - * @return true if ext is closed under R_sup - */ - public boolean isClosed(ArgumentSet ext){ - for(BArgument a: ext) { - Set supportedArguments = this.getDirectSupported(a); - if(!ext.containsAll(supportedArguments)) - return false; - } - return true; - } - - /** - * Calculates the set of deductive complex attacks (d-attacks) in this bipolar argumentation framework - * i.e. all direct, supported, mediated and super-mediated attacks - * @return set of d-attacks in this bipolar argumentation framework - */ - public Set getDeductiveComplexAttacks(){ - Set dAttacks = this.getComplexAttacks(); - Set superMediatedAttacks = new HashSet<>(); - for(BinaryAttack attack: dAttacks) { - Set superMediatedOrigins = this.getSupporters(attack.getAttacker()); - Set superMediatedTargets = this.getSupporters(attack.getAttacked()); - - for(BArgument origin: superMediatedOrigins) { - superMediatedAttacks.add(new BinaryAttack(origin, attack.getAttacked())); - } - for(BArgument target: superMediatedTargets) { - superMediatedAttacks.add(new BinaryAttack(attack.getAttacker(), target)); - } - } - dAttacks.addAll(superMediatedAttacks); - return dAttacks; - } - - /** - * Calculates the set of complex attacks in this bipolar argumentation framework - * i.e. all direct, supported and mediated attacks - * @return set of complex attacks in this bipolar argumentation framework - */ - public Set getComplexAttacks(){ - Set attacks = this.getAttacks(); - Set cAttacks= new HashSet<>(); - for (Attack a: attacks) - cAttacks.add((BinaryAttack) a); - - for(BArgument argument: this) { - Set supportedArguments = this.getSupported(argument); - Set supportedAttackTargets = new HashSet<>(); - Set mediatedAttackOrigins = new HashSet<>(); - for(BArgument arg: supportedArguments) { - supportedAttackTargets.addAll(this.getAttacked(arg)); - for (BipolarEntity bipolarEntity: this.getAttackers(arg)) { - mediatedAttackOrigins.add((BArgument) bipolarEntity); - } - } - for(BArgument target: supportedAttackTargets) { - cAttacks.add(new BinaryAttack(argument, target)); - } - for(BArgument origin: mediatedAttackOrigins) { - cAttacks.add(new BinaryAttack(origin, argument)); - } - } - return cAttacks; - } - - /** - * Calculates the set of mediated attack from "arg1" to other arguments "y", i.e. whether there - * is a sequence of direct supports from "y" to "x" and a direct attack from "arg1" to "x". - * @param arg1 an argument. - * @return set of mediated attacks starting from "arg1". - */ - public Set getMediatedAttacks(BArgument arg1){ - Set attackedArguments = this.getAttacked(arg1); - Set mediatedAttackTargets = new HashSet<>(); - for(BArgument a: attackedArguments) { - mediatedAttackTargets.addAll(this.getSupporters(a)); - } - Set mediatedAttacks = new HashSet<>(); - for(BArgument target: mediatedAttackTargets) { - mediatedAttacks.add(new BinaryAttack(arg1, target)); - } - return mediatedAttacks; - } - - /** - * Checks whether there exists a mediated attack from "arg1" to "arg2", i.e. whether there - * is a sequence of direct supports from "arg2" to "x" and a direct attack from "arg1" to "x". - * @param arg1 an argument. - * @param arg2 an argument. - * @return "true" iff there is a mediated attack from "arg1" to "arg2". - */ - public boolean isMediatedAttack(BArgument arg1, BArgument arg2){ - Set supportedArguments = this.getSupported(arg2); - return this.isAttacking(arg1, supportedArguments); - } - - /** - * Checks whether there exists a super-mediated attack from "arg1" to "arg2", i.e. whether there - * is a sequence of direct supports from "arg2" to "x" and a direct or supported attack from "arg1" to "x". - * @param arg1 an argument. - * @param arg2 an argument. - * @return "true" iff there is a super-mediated attack from "arg1" to "arg2". - */ - public boolean isSuperMediatedAttack(BArgument arg1, BArgument arg2){ - Set supportedArguments1 = this.getSupported(arg1); - Set supportedArguments2 = this.getSupported(arg2); - return this.isMediatedAttack(arg1, arg2) || this.isAttacking(supportedArguments1, supportedArguments2); - } - - /** - * Calculates the set of supported attack from "arg1" to other arguments "y", i.e. whether there - * is a sequence of direct supports from "arg1" to "x" and a direct attack from "x" to "y". - * @param arg1 an argument. - * @return set of supported attacks starting from "arg1". - */ - public Set getSupportedAttacks(BArgument arg1){ - Set supportedAttacks = new HashSet<>(); - Set supportedArguments = this.getSupported(arg1); - Set supportedAttackTargets = new HashSet<>(); - for(BArgument a: supportedArguments) { - supportedAttackTargets.addAll(this.getAttacked(a)); - } - for(BArgument target: supportedAttackTargets) { - supportedAttacks.add(new BinaryAttack(arg1, target)); - } - return supportedAttacks; - } - - /** - * Checks whether there exists a supported attack from "arg1" to "arg2", i.e. whether there - * is a sequence of direct supports from "arg1" to "x" and a direct attack from "x" to "arg2". - * @param arg1 an argument. - * @param arg2 an argument. - * @return "true" iff there is a supported attack from "arg1" to "arg2". - */ - public boolean isSupportedAttack(BArgument arg1, BArgument arg2){ - Set supportedArguments = new HashSet<>(this.getSupported(arg1)); - return this.isAttacked(arg2, supportedArguments); - } - - /** - * returns true if some argument of argSet is attacked by argument. - * @param argument an argument - * @param argSet a set of arguments - * @return true if some argument of argSet is attacked by argument. - */ - public boolean isAttacking(BArgument argument, Set argSet) { - if(!this.attackChildren.containsKey(argument)) - return false; - for(BArgument attacked: this.attackChildren.get(argument)) { - if (argSet.contains(attacked)) - return true; - } - return false; - } - - /** - * returns true if some argument of argumentSet attacks argument. - * @param argument an argument - * @param argumentSet set of arguments - * @return true if some argument of argumentSet attacks argument. - */ - public boolean isAttacked(BArgument argument, Set argumentSet) { - if(!this.attackParents.containsKey(argument)) - return false; - for(BipolarEntity attacker: this.attackParents.get(argument)) { - if (argumentSet.contains((BArgument) attacker)) - return true; - } - return false; - } - - /** - * Checks whether argumentSet1 is attacking argumentSet2 - * ie any element of argumentSet1 is attacking any element of argumentSet2 - * @param argumentSet1 a set of arguments - * @param argumentSet2 a set of arguments - * @return "true" if an element of argumentSet1 is attacking any element of argumentSet2 - */ - public boolean isAttacking(Set argumentSet1, Set argumentSet2) { - for (BArgument argument: argumentSet1) { - if (this.isAttacked(argument, argumentSet2)) - return true; - } - return false; - } - - /** - * Computes the set {A | there is a sequence of direct supports from an element of ext to A - * @param ext an extension ie. a set of arguments - * @return the set of all arguments that are supported by ext. - */ - public Set getSupported(Collection ext){ - Set supported = new HashSet(); - for (BArgument argument: ext) - supported.addAll(this.getSupported(argument)); - - return supported; - } - - /** - * Computes the set {A | there is a sequence of direct supports from argument to A - * @param argument an argument - * @return the set of all arguments that are supported by argument. - */ - public Set getSupported(BArgument argument){ - return this.getSupported(argument, new HashSet()); - } - - /** - * Computes the set {A | there is a sequence of direct supports from argument to A}. - * @param argument an argument - * @param visited already visited arguments - * @return the set of all arguments that are supported by argument. - */ - private Set getSupported(BArgument argument, Set visited){ - if(!this.supportChildren.containsKey(argument)) - return new HashSet(); - Set directSupportedArguments = this.getDirectSupported(argument); - Set supportedArguments = new HashSet(directSupportedArguments); - - directSupportedArguments.removeAll(visited); - for(BArgument supported: directSupportedArguments){ - visited.add(supported); - supportedArguments.addAll(this.getSupported(supported, visited)); - } - return supportedArguments; - } - - /** - * Computes the set {A | there is a sequence of direct supports from A to argument - * @param argument an argument - * @return the set of all arguments that support argument. - */ - public Set getSupporters(BArgument argument){ - return this.getSupporters(argument, new HashSet()); - } - - /** - * Computes the set {A | there is a sequence of direct supports from A to argument}. - * @param argument an argument - * @param visited already visited arguments - * @return the set of all arguments that support argument. - */ - private Set getSupporters(BArgument argument, Set visited){ - if(!this.supportParents.containsKey(argument)) - return new HashSet<>(); - Set directSupportArguments = this.getDirectSupporters(argument); - Set supportArguments = new HashSet<>(); - for (BipolarEntity bipolarEntity: directSupportArguments) - supportArguments.add((BArgument) bipolarEntity); - - directSupportArguments.removeAll(visited); - for(BipolarEntity supporter: directSupportArguments){ - visited.add((BArgument) supporter); - supportArguments.addAll(this.getSupporters((BArgument) supporter, visited)); - } - return supportArguments; - } - - /** - * Adds the given support to this bipolar argumentation framework. - * @param supp a support - * @return "true" if the set of supports has been modified. - */ - public boolean add(Support supp) { - if (!(supp instanceof BinarySupport)) { - throw new IllegalArgumentException("Support of type BinarySupport expected"); - } else { - BinarySupport support = (BinarySupport) supp; - return this.addSupport(support.getSupporter(), support.getSupported()); - } - } - - /** - * Adds a support from the first argument to the second to this bipolar argumentation framework. - * @param bipolarEntity some argument - * @param supported some argument - * @return "true" if the set of supports has been modified. - */ - public boolean addSupport(BipolarEntity bipolarEntity, BArgument supported){ - boolean result = false; - if(!supportParents.containsKey(supported)) - supportParents.put(supported, new HashSet<>()); - result |= supportParents.get(supported).add(bipolarEntity); - if(!supportChildren.containsKey(bipolarEntity)) - supportChildren.put(bipolarEntity, new HashSet<>()); - result |= supportChildren.get(bipolarEntity).add(supported); - return result; - } - - @Override - public boolean add(Attack a) { - if (!(a instanceof BinaryAttack)) { - throw new IllegalArgumentException("Attack of type BinaryAttack expected"); - } else { - BinaryAttack attack = (BinaryAttack) a; - return this.addAttack(attack.getAttacker(), attack.getAttacked()); - } - } - - /** - * Adds an attack from the first argument to the second to this deductive argumentation system. - * @param attacker some argument - * @param attacked some argument - * @return "true" if the set of attacks has been modified. - */ - public boolean addAttack(BArgument attacker, BArgument attacked){ - boolean result = false; - if(!attackParents.containsKey(attacked)) - attackParents.put(attacked, new HashSet<>()); - result |= attackParents.get(attacked).add(attacker); - if(!attackChildren.containsKey(attacker)) - attackChildren.put(attacker, new HashSet<>()); - result |= attackChildren.get(attacker).add(attacked); - return result; - } - - @Override - public boolean isAcceptable(BArgument argument, Collection ext) { - throw new UnsupportedOperationException(); - } - - @Override - public Set getSupports(){ - Set supports = new HashSet<>(); - for(BArgument a: this) { - if(this.supportChildren.containsKey(a)) { - for(BArgument b: this.supportChildren.get(a)) - supports.add(new BinarySupport(a,b)); - } - } - return supports; - } - - @Override - public Set getAttacks() { - Set attacks = new HashSet<>(); - for(BArgument a: this) { - if(this.attackParents.containsKey(a)) { - for(BipolarEntity b: this.attackParents.get(a)) - attacks.add(new BinaryAttack((BArgument) b, a)); - } - } - return attacks; - } - - /** - * constructs the complete associated dung theory of this bipolar argumentation framework - * i.e. constructs all deductive complex attacks of BAF and returns dung theory without supports - * See Cayrol, Lagasquie-Schiex. Bipolarity in argumentation graphs: Towards a better understanding. 2013 - * @return the complete associated Dung Theory of this bipolar argumentation framework - */ - public DungTheory getCompleteAssociatedDungTheory(){ - DungTheory completeAssociatedDungTheory = new DungTheory(); - Set dAttacks = this.getDeductiveComplexAttacks(); - completeAssociatedDungTheory.addAll(this.getNodes()); - for (BinaryAttack att: dAttacks) { - completeAssociatedDungTheory.add(new org.tweetyproject.arg.dung.syntax.Attack((Argument) att.getAttacker(), (Argument) att.getAttacked())); - } - return completeAssociatedDungTheory; - } - - /** - * constructs the meta dung theory of this bipolar argumentation framework by adding - * meta-arguments for every attack and support relation - * See Boella et al. Support in Abstract Argumentation. 2010 - * @return the meta dung theory of this bipolar argumentation framework - */ - public DungTheory getMetaFramework() { - DungTheory metaFramework = new DungTheory(); - metaFramework.addAll(this); - - Set attacks = this.getAttacks(); - for (Attack attack: attacks){ - Argument a = (Argument) attack.getAttacker(); - Argument b = (Argument) attack.getAttacked(); - Argument x_ab = new Argument("X_" + a.getName() + b.getName()); - Argument y_ab = new Argument("Y_" + a.getName() + b.getName()); - metaFramework.add(x_ab); - metaFramework.add(y_ab); - metaFramework.addAttack(a, x_ab); - metaFramework.addAttack(x_ab, y_ab); - metaFramework.addAttack(y_ab, b); - } - Set supports = this.getSupports(); - for (Support support: supports) { - Argument a = (Argument) support.getSupporter(); - Argument b = (Argument) support.getSupported(); - Argument z_ab = new Argument("Z_" + a.getName() + b.getName()); - metaFramework.add(z_ab); - metaFramework.addAttack(b, z_ab); - metaFramework.addAttack(z_ab, a); - } - return metaFramework; - } - - /** - * translates this DAF into the corresponding framework with support in a necessary sense - * See Cayrol, Lagasquie-Schiex. Bipolarity in argumentation graphs: Towards a better understanding. 2013 - * @return the corresponding NAF - */ - public NecessityArgumentationFramework toNAF() { - NecessityArgumentationFramework naf = new NecessityArgumentationFramework(); - // arguments and attacks are the same - naf.addAll(this); - naf.addAllAttacks(this.getAttacks()); - // every support relation is reversed - for (Support supp: this.getSupports()) { - BinarySupport support = (BinarySupport) supp; - naf.addSupport(support.getSupported(), support.getSupporter()); - } - return naf; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(org.tweetyproject.arg.bipolar.syntax.DeductiveArgumentationFramework) - */ - public int compareTo(DeductiveArgumentationFramework o) { - return this.hashCode() - o.hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (this.attackParents == null ? 0 : this.attackParents.hashCode()); - result = 43 * result + (this.supportParents == null ? 0 : this.supportParents.hashCode()); - return result; - } -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAFTheory.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAFTheory.java deleted file mode 100644 index 8a89a4dec..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAFTheory.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - - - -import org.tweetyproject.arg.dung.syntax.Argument; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.tweetyproject.commons.util.Pair; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * This class implements an abstract argumentation theory in the sense of Evidential Argumentation Frameworks (EAF). - * see Li, Hengfei. Probabilistic argumentation. 2015. PhD Thesis. Aberdeen University. - * - * @author Taha Dogan Gunes - */ -public class EAFTheory extends AbstractEAFTheory { - - /** - * Default constructor; initializes an empty EAFTheory - */ - public EAFTheory() { - } - - /** - * Optional constructor; initializes an EAFTheory with arguments - * - * @param noArguments the number of arguments - */ - public EAFTheory(Set noArguments) { - for (BArgument i : noArguments) { - this.add(i); - } - } - - /** - * Creates a new EAFTheory from an PEAFTheory (the probabilities are eliminated) - * - * @param peafTheory PEAFTheory object - * @return a new EAFTheory - */ - public static EAFTheory newEAFTheory(PEAFTheory peafTheory) { - EAFTheory eafTheory = new EAFTheory(); - for (BArgument argument : peafTheory.getArguments()) { - eafTheory.addArgument(argument); - } - - for (Attack attack : peafTheory.getAttacks()) { - eafTheory.addAttack(attack.getAttacker(), attack.getAttacked()); - } - - for (Support support : peafTheory.getSupports()) { - eafTheory.addSupport((HashSet)support.getSupporter(), (HashSet)support.getSupported()); - } - - return eafTheory; - } - - - /** - * Creates an arguments with a name - * - * @param name the name of the argument - * @return EArgument object - */ - protected BArgument createArgument(String name) { - return new BArgument(name); - } - - - - - /** - * Add an argument with an integer identifier - * - * @param identifier the identifier of the argument - * @return EArgument object - */ - public BArgument addArgument(int identifier) { - BArgument argument = this.createArgument(Integer.toString(identifier)); - this.addArgument(argument); - return argument; - } - - - /** - * Add a support with index arrays (froms and tos) - * - * @param froms integer array with argument, represents indices of arguments - * @param tos integer array with argument, represents indices of arguments - */ - public void addSupport(HashSet froms, HashSet tos) { - - Support support = new SetSupport( froms, tos); - this.addSupport(support); - } - - /** - * Gets arguments of the EAF - * - * @return list of arguments inside the EAF (insert ordered) - */ - public ArrayList getArguments() { - return arguments; - } - - /** - * Gets supports of the EAF - * - * @return list of supports inside the EAF (insert ordered) - */ - public Set getSupports() { - return new HashSet(supports); - } - - /** - * Gets attacks of the EAF - * - * @return list of attacks inside the EAF (insert ordered) - */ - public Set getAttacks() { - return new HashSet(attacks); - } - - /** - * This method converts this EAF to a DAF with using Algorithm 1 from - * Oren et. al. 2010 "Moving Between Argumentation Frameworks" - * - * @return DungTheory object - */ - public DungTheory convertToDAFNaively() { - // This method is using Algorithm 1 from Oren et. al. 2010 "Moving Between Argumentation Frameworks" - Set> dungArguments = new HashSet<>(); // Line 1 - Set, Set>> dungAttacks = new HashSet<>(); // Line 2 - - // Line 3 - 7 - for (Set A : this.powerSet(this.getArgumentsAsSet())) { - boolean isSelfSupporting = checkIsSelfSupporting(A); - - if (A.size() > 0 && isSelfSupporting) { - dungArguments.add(A); - } - - } - // Line 8 - 12 - for (Attack attack : attacks) { // Line 8 - BipolarEntity X = attack.getAttacker(); - for (BArgument x : X) { // Line 8 - for (Attack xAttack : this.getAttacks()) { // Line 8 - for (BArgument a : xAttack.getAttacked()) { // Line 8 - for (Set D : dungArguments) { // Line 9 - if (D.contains(X)) { // Line 9: check X is subset of D - for (Set A : dungArguments) { // Line 9 - if (A.contains(a)) { // Line 9: check if a is in A, when A is in DARGS - dungAttacks.add(new Pair<>(D, A)); - } - } - } - } - } - } - } - } - - Map mapping = new HashMap<>(); - DungTheory dungTheory = new DungTheory(); - for (Set dungArgument : dungArguments) { - String nameOfArgument = dungArgument.stream() - .map(BArgument::getName) - .sorted() - .collect(Collectors.joining("_")); - Argument argument = new Argument(nameOfArgument); - mapping.put(nameOfArgument, argument); - dungTheory.add(argument); - } - - for (Pair, Set> dungAttack : dungAttacks) { - String nameOfFrom = dungAttack.getFirst().stream() - .map(BArgument::getName) - .sorted() - .collect(Collectors.joining("_")); - Argument from = mapping.get(nameOfFrom); - - String nameOfTo = dungAttack.getSecond().stream() - .map(BArgument::getName) - .sorted() - .collect(Collectors.joining("_")); - Argument to = mapping.get(nameOfTo); - - dungTheory.addAttack(from, to); - } - return dungTheory; - } - - - - /** - * Checks if a set of arguments whether they are self-supporting or not - * This is used for conversion from EAF to DAF. - * A set of arguments A is self-supporting if and only if for all a in A, A e-supports a - * - * @param A a set of arguments - * @return true if the set of arguments are self-supporting or not. - */ - public boolean checkIsSelfSupporting(Set A) { - // Check if the subset is self-supporting (Line 4, if A is self-supporting) - boolean isSelfSupporting = true; - for (BArgument a : A) { // for all a in A - if (a == eta) { - continue; - } - Set A_copy = new HashSet<>(A); - - // Definition 8 (Auxiliary Notions for EAFs) - // A set of arguments S is self-supporting iff for all x \in S, S e-supports x - - // Assume that there exists a T that is subset of A. - // if for all elements of T, (each of T is t) support a, then a has evidential support from A \ {a} - A_copy.remove(a); - - boolean supports = false; - - for (Set T : this.powerSet(A_copy)) { - for (BArgument x : T) { - if (a.isSupportedBy(this, (BipolarEntity)x)) { - supports = true; - } - } - if (supports) { - break; - } - } - - isSelfSupporting = isSelfSupporting && supports; - } - return isSelfSupporting; - } - - /** - * Pretty print of the EAFTheory - */ - public String toString() { - String res = ""; - res+=("-- Arguments --"); - int i = 0; - for (BArgument argument : this.getArguments()) { - res+=(i + ". " + argument); - i++; - } - - res+="\n"; - res+=("-- Supports --"); - i = 0; - for (Support support : this.getSupports()) { - res+=(i + ". " + support); - i++; - } - - res+="\n"; - res+=("-- Attacks --"); - i = 0; - for (Attack attack : this.getAttacks()) { - res+=(i + ". " + attack); - i++; - } - return res; - } - - @Override - public boolean isAcceptable(BArgument argument, Collection ext) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean add(Support support) { - this.addSupport(support); - return true; - } - - @Override - public boolean add(Attack attack) { - this.addAttack((EAttack) attack); - return true; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAttack.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAttack.java deleted file mode 100644 index bb7bf9968..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EAttack.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - -import java.util.Iterator; -import java.util.Objects; -import java.util.Set; - -import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; -import org.tweetyproject.commons.Signature; - -/** - * Evidential attack used for PEAF and EAF - * - * @author Taha Dogan Gunes - */ -public class EAttack implements Attack{ - - - - /** - * The arguments that originate the attack - */ - protected final ArgumentSet froms; - - /** - * The arguments that receive the attack - */ - protected final ArgumentSet tos; - - - /** - * The default constructor that creates EAttack object - * - * @param froms the arguments that originate this attack - * @param tos the arguments that receive this attack - */ - public EAttack(Set froms, Set tos) { - - this.froms = new ArgumentSet(froms); - this.tos = new ArgumentSet(tos); - } - - - - /** - * Get the arguments that originate this attack - * - * @return a set of arguments - */ - @Override - public BipolarEntity getAttacker() { - return froms; - } - - /** - * Get the arguments that receive this attack - * - * @return a set of arguments - */ - @Override - public ArgumentSet getAttacked() { - return tos; - } - - /** - * Returns the attack object in string format for debug purposes - * - * @return verbose format of the attack in string - */ - @Override - public String toString() { - return "EAtt{froms=" + froms + - ", tos=" + tos + - '}'; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - EAttack attack = (EAttack) o; - return Objects.equals(froms, attack.froms) && Objects.equals(tos, attack.tos); - } - - @Override - public int hashCode() { - return Objects.hash(froms, tos); - } - - @Override - public boolean contains(Object o) { - if(this.getAttacked().equals( o) || this.getAttacker().equals(o)) - return true; - return false; - } - - @Override - public LdoFormula getLdoFormula() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Signature getSignature() { - // TODO Auto-generated method stub - return null; - } - - - - @Override - public Iterator iterator() { - return null; - } - - -} - diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EvidentialArgumentationFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EvidentialArgumentationFramework.java deleted file mode 100644 index cae259330..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/EvidentialArgumentationFramework.java +++ /dev/null @@ -1,553 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.commons.util.SetTools; - -import java.util.*; - -/** - * This class implements a bipolar abstract argumentation theory with support in an evidential sense. - * ie. we distinguish between prima-facie and standard arguments. Prima-facie arguments do not - * require any support from other arguments to stand, while standard arguments must be supported - * by at least one prima-facie argument. - *
- *
See - *
- *
Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - * - * - * @author Lars Bengel - * - */ -public class EvidentialArgumentationFramework extends AbstractBipolarFramework implements Comparable { - - /** - * Special argument Eta, which serves as a representation of the evidence/environment. - */ - private BArgument eta; - - /** - * Default constructor; initializes empty sets of arguments, attacks and supports - */ - public EvidentialArgumentationFramework(){ - super(); - this.eta = new BArgument("eta"); - this.add(eta); - } - - /** - * creates an evidential argumentation framework from the given framework with necessities - * @param naf a argumentation framework with necessities - */ - public EvidentialArgumentationFramework(NecessityArgumentationFramework naf) { - this.add(naf.toEAF()); - } - - /** - * returns true if argument has evidential support from set ext. - * An argument a has e-support from ext iff a=eta or there exists a subset S - * of ext which supports a and all arguments in S have e-support from ext \ {a} - * @param argument an argument - * @param ext a set of arguments - * @return true if argument has e-support from ext. - */ - public boolean hasEvidentialSupport(BArgument argument, Collection ext){ - if(argument == this.getEta()) - return true; - Set extWithoutArgument = new HashSet<>(ext); - extWithoutArgument.remove(argument); - Set> subsets = new SetTools().subsets(ext); - for(Collection subExt: subsets) { - if (!subExt.isEmpty() && this.isDirectSupportedBy(argument, new ArgumentSet(subExt))) { - boolean evidentialSupport = true; - for (BArgument x : subExt) { - if (!this.hasEvidentialSupport(x, extWithoutArgument)) { - evidentialSupport = false; - break; - } - } - if (evidentialSupport) - return true; - } - } - return false; - } - - /** - * returns true if argument has minimal evidential support from set ext. - * An argument a has minimal e-support from ext iff ext e-supports a and - * no true subset of ext e-supports a - * @param argument an argument - * @param ext a set of arguments - * @return true if argument has e-support from ext. - */ - public boolean hasMinimalEvidentialSupport(BArgument argument, Collection ext){ - if (!this.hasEvidentialSupport(argument, ext)) - return false; - - Set> subsets = new SetTools().subsets(ext); - subsets.remove(ext); - for (Collection subExt: subsets) { - if (this.hasEvidentialSupport(argument, subExt)) - return false; - } - return true; - } - - /** - * computes all subsets which minimal e-support argument - * @param argument some argument - * @return set of minimal e-supporters of argument - */ - public Set> getMinimalEvidentialSupporters(BArgument argument) { - Set> result = new HashSet<>(); - Set supportingSets = this.getDirectSupporters(argument); - Set> subsets = new SetTools().subsets(this); - for (Set subSet: subsets) { - for (BipolarEntity bipolarEntity: supportingSets) { - ArgumentSet supportingSet = (ArgumentSet) bipolarEntity; - if (subSet.contains(this.getEta()) && subSet.containsAll(supportingSet) && this.hasMinimalEvidentialSupport(argument, subSet)) { - result.add(subSet); - } - } - } - return result; - } - - /** - * returns true if ext carries out an evidence supported attack on argument - * ext e-support-attacks an argument a iff a subset S of ext attacks a and all elements of S have e-support from ext. - * @param argument an argument - * @param ext a set of arguments - * @return true if ext e-support-attacks argument - */ - public boolean isEvidenceSupportedAttack(Collection ext, BArgument argument){ - Set> subsets = new SetTools().subsets(ext); - for(Collection subExt: subsets) { - if (this.isAttackedBy(argument, new ArgumentSet(subExt))) { - boolean evidentialSupport = true; - for (BArgument attacker : subExt) { - if (!this.hasEvidentialSupport(attacker, ext)) { - evidentialSupport = false; - break; - } - } - - if (evidentialSupport) - return true; - } - } - return false; - } - - /** - * returns true if ext carries out a minimal evidence supported attack on argument - * i.e. there is no true subset of ext which e-support-attacks argument - * @param argument an argument - * @param ext a set of arguments - * @return true if ext e-support-attacks argument - */ - public boolean isMinimalEvidenceSupportedAttack(Collection ext, BArgument argument){ - if (!this.isEvidenceSupportedAttack(ext, argument)) - return false; - Set> subsets = new SetTools().subsets(ext); - subsets.remove(ext); - for (Collection subExt: subsets) { - if (this.isEvidenceSupportedAttack(subExt, argument)) - return false; - } - return true; - } - - /** - * computes all subsets which carry out a minimal evidence supported attack on argument - * @param argument some argument - * @return set of minimal e-supported attackers of argument - */ - public Collection> getMinimalEvidenceSupportedAttackers(BArgument argument) { - Collection> result = new HashSet<>(); - Set attackingSets = this.getAttackingSets(argument); - Set> subsets = new SetTools().subsets(this); - for (Set subSet: subsets) { - for (BipolarEntity bipolarEntity: attackingSets) { - ArgumentSet attackingSet = (ArgumentSet) bipolarEntity; - if (subSet.contains(this.getEta()) && subSet.containsAll(attackingSet) && this.isMinimalEvidenceSupportedAttack(subSet, argument)) { - result.add(subSet); - } - } - } - return result; - - } - - /** - * return true if argument is acceptable with respect to ext - * argument is acceptable wrt. S iff argument is e-supported by S and if - * a set T minimal e-support-attacks argument, then S carries out an - * e-supported attack against a member of T. - * @param argument an argument - * @param ext a set of arguments - * @return true if argument is acceptable wrt. ext - */ - public boolean isAcceptable(BArgument argument, Collection ext){ - if (!this.hasEvidentialSupport(argument, ext)) { - return false; - } - boolean result = true; - for (Collection attackingSet: this.getMinimalEvidenceSupportedAttackers(argument)) { - boolean isAttackingSet = false; - for (BArgument attacker: attackingSet) { - if (this.isEvidenceSupportedAttack(ext, attacker)) { - isAttackingSet = true; - break; - } - } - if (!isAttackingSet) { - result = false; - break; - } - } - return result; - } - - /** - * Computes the set {A | there is a sequence of direct supports from argumentSet to A} - * @param argumentSet a set of arguments - * @return the set of all arguments that are supported by argumentSet. - */ - public Set getSupported(ArgumentSet argumentSet){ - Set supportedArguments = new HashSet<>(); - int size; - do{ - size = supportedArguments.size(); - supportedArguments.addAll(getSupported(new HashSet<>(argumentSet))); - argumentSet.addAll(supportedArguments); - }while(size!=supportedArguments.size()); - return supportedArguments; - } - - /** - * Computes the set {A | there is a sequence of direct supports from argument to A}. - * @param argumentSet a set of arguments - * @return the set of all arguments that are supported by argumentSet. - */ - private Set getSupported(Set argumentSet){ - Set supportedArguments = new HashSet<>(); - for (Set subset: new SetTools().subsets(argumentSet)) { - if (!this.supportChildren.containsKey(new ArgumentSet(subset))) { - continue; - } - Set directSupportedArguments = this.getDirectSupported(new ArgumentSet(subset)); - supportedArguments.addAll(directSupportedArguments); - } - return supportedArguments; - } - - /** - * Computes the set {S | (S, argument) in attacks}. - * @param argument an argument - * @return the set of all argument sets that are attacking argument. - */ - public Set getAttackingSets(BArgument argument){ - if(!this.attackParents.containsKey(argument)) - return new HashSet<>(); - return new HashSet<>(this.attackParents.get(argument)); - } - - /* (non-Javadoc) - * @see org.tweetyproject.arg.bipolar.syntax.AbstractBipolarFramework#add(org.tweetyproject.arg.bipolar.syntax.Support) - */ - public boolean add(Support s) { - if(s instanceof BinarySupport) { - return this.addSupport((BArgument) s.getSupporter(), (BArgument) s.getSupported()); - } else if(s instanceof SetSupport) { - return this.addSupport((ArgumentSet) s.getSupporter(), (BArgument) s.getSupported()); - } - return true; - } - - /** - * Adds a support from the first argument to the second to this argumentation framework. - * @param supporter some argument - * @param supported some argument - * @return "true" if the set of supports has been modified. - */ - public boolean addSupport(BArgument supporter, BArgument supported){ - return addSupport(new ArgumentSet(supporter), supported); - } - - /** - * Adds a support from a set of arguments to an argument to this argumentation framework. - * @param supporter a set of arguments - * @param supported some argument - * @return "true" if the set of supports has been modified. - */ - public boolean addSupport(ArgumentSet supporter, BArgument supported){ - if (supported.equals(this.getEta())) { - throw new IllegalArgumentException("Eta can not be supported by another argument"); - } - boolean result = false; - if(!supportParents.containsKey(supported)) - supportParents.put(supported, new HashSet<>()); - result |= supportParents.get(supported).add(supporter); - if(!supportChildren.containsKey(supporter)) - supportChildren.put(supporter, new HashSet<>()); - result |= supportChildren.get(supporter).add(supported); - return result; - } - - /* (non-Javadoc) - * @see org.tweetyproject.arg.bipolar.syntax.AbstractBipolarFramework#add(org.tweetyproject.arg.bipolar.syntax.Support) - */ - public boolean add(Attack att) { - if(att instanceof BinaryAttack) { - return this.addAttack((BArgument) att.getAttacker(), (BArgument) att.getAttacked()); - } else if(att instanceof SetAttack) { - return this.addAttack((ArgumentSet) att.getAttacker(), (BArgument) att.getAttacked()); - } - return true; - } - - /** - * Adds an attack from the first argument to the second to this evidential argumentation system. - * @param attacker some argument - * @param attacked some argument - * @return "true" if the set of attacks has been modified. - */ - public boolean addAttack(BArgument attacker, BArgument attacked){ - return addAttack(new ArgumentSet(attacker), attacked); - } - - /** - * Adds an attack from the set of arguments to the argument to this evidential argumentation system. - * @param attacker a set of arguments - * @param attacked some argument - * @return "true" if the set of attacks has been modified. - */ - public boolean addAttack(ArgumentSet attacker, BArgument attacked){ - if (attacked.equals(this.getEta()) || attacker.contains(this.getEta())) { - throw new IllegalArgumentException("Eta is not allowed to be part of any attack relation."); - } - boolean result = false; - if(!attackParents.containsKey(attacked)) - attackParents.put(attacked, new HashSet<>()); - result |= attackParents.get(attacked).add(attacker); - if(!attackChildren.containsKey(attacker)) - attackChildren.put(attacker, new HashSet<>()); - result |= attackChildren.get(attacker).add(attacked); - return result; - } - - /** - * Returns all supports of this theory. - * @return all supports of this theory. - */ - public Set getSupports(){ - Set supports = new HashSet(); - for(BArgument a: this) { - if(this.supportParents.containsKey(a)) { - for(BipolarEntity b: this.supportParents.get(a)) - supports.add(new SetSupport((ArgumentSet) b, new ArgumentSet(a))); - } - } - return supports; - } - - /** - * Returns all attacks of this theory. - * @return all attacks of this theory. - */ - public Set getAttacks(){ - Set attacks = new HashSet(); - for(BArgument a: this) { - if(this.attackParents.containsKey(a)) { - for(BipolarEntity b: this.attackParents.get(a)) - attacks.add(new SetAttack((ArgumentSet) b, a)); - } - } - return attacks; - } - - /** - * Adds a argument with evidential support to this evidential argumentation system - * If the argument is already in this evidential argumentation system, adds evidential support - * @param argument some argument - * @return "true" if the argument has been modified. - */ - public boolean addPrimaFacie(BArgument argument){ - boolean result = false; - if (!this.contains(argument)) { - result |= this.add(argument); - } - result |= this.addSupport(this.getEta(), argument); - - return result; - } - - /** - * removes evidential support from argument, does not remove argument itself - * @param argument some argument - * @return "true" if the argument has been modified - */ - public boolean removePrimaFacie(BArgument argument){ - return this.remove(new SetSupport(this.getEta(), argument)); - } - - /** - * returns all arguments that have evidential support in this framework - * @return set of evidence supported arguments - */ - public Set getEvidenceSupportedArguments() { - return this.getSupported(new ArgumentSet(this.getEta())); - } - - /** - * returns the special argument eta - * @return eta - */ - public BArgument getEta() { - return eta; - } - - /** - * calculates the minimal form of this argumentation framework - * ie. only attacks and supports with minimal attacker/supporter are kept - * @return the minimal form of this evidential argumentation framework - */ - public EvidentialArgumentationFramework getMinimalForm() { - Set attacks = this.getAttacks(); - Set supports = this.getSupports(); - - EvidentialArgumentationFramework minimalEvidentialArgSystem = new EvidentialArgumentationFramework(); - minimalEvidentialArgSystem.addAll(this); - - for (Attack a: attacks) { - if (!(a instanceof SetAttack)) { - throw new IllegalArgumentException("Attack of type SetAttack expected"); - } else { - SetAttack attack = (SetAttack) a; - Set> subsets = new SetTools().subsets(attack.getAttacker()); - subsets.remove(new HashSet(attack.getAttacker())); - boolean minimal = true; - for (Set subSet : subsets) { - if (this.isAttackedBy(attack.getAttacked(), new ArgumentSet(subSet))) { - minimal = false; - break; - } - } - if (minimal) - minimalEvidentialArgSystem.add(attack); - } - } - - for (Support support: supports) { - Set> subsets = new SetTools().subsets((ArgumentSet)support.getSupporter()); - subsets.remove(new HashSet((ArgumentSet)support.getSupporter())); - boolean minimal = true; - for (Set subSet: subsets) { - if (this.isDirectSupportedBy((BArgument)support.getSupported(), new ArgumentSet(subSet))) { - minimal = false; - break; - } - } - if (minimal) - minimalEvidentialArgSystem.add(support); - - - } - - return minimalEvidentialArgSystem; - } - - /** - * translates this EAF into the corresponding NAF - * can only translate framework which contain only binary attacks - * translation algorithm from: - * Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - * @return the corresponding NAF - */ - public NecessityArgumentationFramework toNAF() { - NecessityArgumentationFramework naf = new NecessityArgumentationFramework(); - //set of arguments stays the same - naf.addAll(this); - //attacks can only be translated when they are binary - for (Attack att: this.getAttacks()) { - SetAttack attack = (SetAttack) att; - Iterator iterator = attack.getAttacker().iterator(); - BArgument attacker = iterator.next(); - if (iterator.hasNext()){ - throw new IllegalArgumentException("Framework can only have binary attacks"); - } - naf.addAttack(attacker, attack.getAttacked()); - } - //handle supports - for (BArgument argument: this) { - if (argument == this.getEta()) - continue; - Set supporters = this.getDirectSupporters(argument); - if (supporters.isEmpty()) { - // an element without support in this EAF is disqualified in the corresponding NAF, - //since it has no evidential support in this EAF. - naf.addSupport(argument, argument); - } else { - // every argument that is supported in this EAF, is supported in the corresponding NAF - // by all subsets of the supporters in EAF, which have non-empty intersections with all supporting sets - Set> supportingSets = new HashSet<>(); - for (BipolarEntity bipolarEntity: supporters) { - supportingSets.add(new HashSet<>((ArgumentSet) bipolarEntity)); - } - Set supportingArguments = new SetTools().getUnion(supportingSets); - for (Set supportingSet: new SetTools().subsets(supportingArguments)) { - boolean nonEmptyIntersect = true; - for (Set s: supportingSets) { - Set> intersect = new HashSet<>(); - intersect.add(supportingSet); - intersect.add(s); - nonEmptyIntersect &= !(new SetTools().hasEmptyIntersection(intersect)); - } - if (nonEmptyIntersect) { - Support supp = new SetSupport(supportingSet, new ArgumentSet(argument)); - naf.add(supp); - } - } - } - } - - return naf; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(org.tweetyproject.arg.bipolar.syntax.EvidentialArgumentationFramework) - */ - public int compareTo(EvidentialArgumentationFramework o) { - return this.hashCode() - o.hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (this.attackParents == null ? 0 : this.attackParents.hashCode()); - result = 41 * result + (this.supportParents == null ? 0 : this.supportParents.hashCode()); - return result; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/InducibleEAF.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/InducibleEAF.java deleted file mode 100644 index f30c51212..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/InducibleEAF.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -/** - * This class is an intermediate representation of EAFs that are induced from a PEAF. - * This is used for making analysis and storing intermediate values while making probabilistic justification - * of some arguments. - * - * @author Taha Dogan Gunes - */ -public class InducibleEAF { - /** - * A subset of arguments from PEAF - */ - public final Set arguments; - /** - * A subset of supports from PEAF - */ - public final Set supports; - /** - * A subset of attacks from PEAF - */ - public final Set attacks; - /** - * A subset of arguments from PEAF that can be used to create a new EAF (connected to InducibleEAF) - */ - public final Set newArguments; - /** - * pInside - */ - public final double pInside; - /** - * inducePro - */ - public final double inducePro; - - /** - * Constructor - * @param arguments arguments - * @param supports supports - * @param attacks attacks - * @param newArguments new arguments - * @param pInside pInside - * @param inducePro induce pro - */ - public InducibleEAF(Set arguments, - Set supports, - Set attacks, - Set newArguments, - double pInside, double inducePro) { - - this.arguments = arguments; - this.supports = supports; - this.attacks = attacks; - this.newArguments = newArguments; - this.pInside = pInside; - this.inducePro = inducePro; - } - - /** - * - * @return the arguments - */ - public Set getArguments() { - return arguments; - } - - /** - * - * @return the supports - */ - public Set getSupports() { - return supports; - } - - /** - * - * @return new arguments - */ - public Set getNewArguments() { - return newArguments; - } - - /** - * - * @return pINside - */ - public double getpInside() { - return pInside; - } - - /** - * - * @return InducePro - */ - public double getInducePro() { - return Math.exp(inducePro); - } - - /** - * - * @return a new EAFTheory - */ - public EAFTheory toNewEAFTheory() { - EAFTheory eafTheory = new EAFTheory(); - Set arguments = new HashSet(); - - arguments.addAll(this.getArguments()); - - for (Support support : supports) { - eafTheory.addSupport(support); - } - - for (EAttack attack : attacks) { - eafTheory.addAttack(attack); - } - - List argsSorted = new ArrayList(); - argsSorted.addAll(arguments); - argsSorted.sort(Comparator.comparing(BArgument::getName)); - System.out.println(this.getArguments()); - for (BArgument argument : arguments) { - eafTheory.addArgument(argument); - } - - return eafTheory; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("InducibleEAF{"); - builder.append("arguments=["); - int i = 0; - - List sortedArgs = new ArrayList(); - sortedArgs.addAll(this.arguments); - sortedArgs.sort(Comparator.comparing(BArgument::getName)); - - for (BipolarEntity argument : sortedArgs) { - builder.append(argument.toString()); - if (i != arguments.size() - 1) { - builder.append(","); - } - i++; - } - builder.append("], supports=["); - i = 0; - - List sortedSupports = new ArrayList(); - sortedSupports.addAll(this.supports); - - - for (Support support : sortedSupports) { - builder.append(support.toString()); - if (i != supports.size() - 1) { - builder.append(","); - } - i++; - } - - List sortedAttacks = new ArrayList(); - sortedAttacks.addAll(this.attacks); - - builder.append("], attacks=["); - i = 0; - for (EAttack attack : sortedAttacks) { - builder.append(attack.toString()); - if (i != attacks.size() - 1) { - builder.append(","); - } - i++; - } - builder.append("] induce result="); - builder.append(Math.exp(inducePro)); - builder.append("}"); - - - return builder.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - InducibleEAF that = (InducibleEAF) o; - return arguments.containsAll(that.arguments) - && supports.containsAll(that.supports) - && attacks.containsAll(that.attacks) - && that.arguments.containsAll(arguments) - && that.supports.containsAll(supports) - && that.attacks.containsAll(attacks); - } - - @Override - public int hashCode() { - List all = new ArrayList(); - for(BArgument arg : this.arguments) { - Integer i = arg.hashCode(); - all.add(i.toString()); - } - for(EAttack att : this.attacks) { - Integer i = att.hashCode(); - all.add(i.toString()); - } - for(Support sup : this.supports) { - Integer i = sup.hashCode(); - all.add(i.toString()); - } - - return Objects.hash(all.toArray()); - } - - /** - * adds atack links - */ - public void addAttackLinks() { - this.attacks.clear(); - Set args = new HashSet(); - args.addAll(this.getArguments()); - - for (BipolarEntity arg : args) { - for (Attack attack : this.attacks) { - if(attack.contains(arg)) { - BipolarEntity froms = attack.getAttacker(); - BipolarEntity tos = attack.getAttacked(); - - if (args.containsAll((HashSet) froms) && args.contains(tos)) { - this.attacks.add((EAttack) attack); - } - } - } - } - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NamedPEAFTheory.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NamedPEAFTheory.java deleted file mode 100644 index acaa179ad..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NamedPEAFTheory.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * This class inherits PEAFTheory to store additional information regarding the arguments inserted - * - * @author Taha Dogan Gunes - */ -public class NamedPEAFTheory extends PEAFTheory { - - /** - * Internal map for getting names of the arguments given their reference - */ - private final Map namesMap = new HashMap(); - /** - * Internal map for getting arguments given the AIF identifier - */ - private final Map reverseAIFMap = new HashMap(); - private final Map aifMap = new HashMap(); - - /** - * Helper function to give the names of a set of arguments - * Static such that it can work with PEAFTheory nodes (EArgument, EAttack and PSupport) - * - * @param names the map that has arguments as keys and the names of arguments as string - * @param args the arguments that are queried - * @return the set of names - */ - public static Set giveNames(Map names, Set args) { - Set argumentNames = new HashSet(); - for (BArgument arg : args) { - argumentNames.add(names.get(arg)); - } - return argumentNames; - } - - /** - * Returns the argument's name give its identifier - * - * @param identifier the identifier of the argument - * @return the argument's name - */ - public String getArgumentNameFromIdentifier(String identifier) { - return namesMap.get(getArgumentByIdentifier(identifier)); - } - - /** - * Returns the EArgument object given its identifier - * - * @param identifier the identifier of the argument - * @return corresponding EArgument object - */ - public BArgument getArgumentByIdentifier(String identifier) { - return reverseAIFMap.get(identifier); - } - - /** - * Returns the name of the argument given EArgument object's reference - * - * @param argument EArgument reference - * @return the name in string - */ - public String getNameOfArgument(BArgument argument) { - return namesMap.get(argument); - } - - /** - * Add argument with names - * - * @param identifier PEAF identifier as an integer value (index of the argument for efficiency reasons) - * @param name The given name of the argument - * @param aifNodeIdentifier The aif node identifier - * @return EArgument object given - */ - public BArgument addArgument(int identifier, String name, String aifNodeIdentifier) { - BArgument argument = super.addArgument(identifier); - namesMap.put(argument, name); - reverseAIFMap.put(aifNodeIdentifier, argument); - aifMap.put(argument, aifNodeIdentifier); - return argument; - } - - /** - * Print the NamedPEAFTheory for debugging purposes - */ - public String toString() { - String res = ""; - res += ("NamedPEAF:"); - res += ("-- Arguments --"); - int i = 0; - for (BArgument argument : this.getArguments()) { - res += (i + ". " + namesMap.get(argument)); - i++; - } - - res += "\n"; - res += ("-- Supports --"); - i = 0; - for (Support support : this.getSupports()) { - res += (i + ". " + support.toString()); - i++; - } - - res += "\n"; - res += ("-- Attacks --"); - i = 0; - for (Attack attack : this.getAttacks()) { - res += (i + ". " + attack.toString()); - i++; - } - - res += ("\n"); - return res; - } - - /** - * prints string reprsentation without names - */ - public void prettyPrintWithoutNames() { - super.prettyPrint(); - } - - /** - * - * @param args aruments - * @return copy of thory without args - */ - public NamedPEAFTheory createCopyWithoutArguments(Set args) { - NamedPEAFTheory newPEAFTheory = new NamedPEAFTheory(); - - int noArgs = 0; - -// peafTheory.addArgument(noArgs, argument.getName(), argument.getIdentifier()); - for (BArgument argument : this.arguments) { - if (!args.contains(argument)) { - newPEAFTheory.addArgument(noArgs++, namesMap.get(argument), this.aifMap.get(argument)); - } - } - newPEAFTheory.addSupport(new HashSet(), new HashSet(new ArrayList(Arrays.asList(newPEAFTheory.getArguments().get(0)))), 1.0); - - for (Attack attack : this.attacks) { - Set froms = this.filter(attack.getAttacker(), args); - Set tos = this.filter(attack.getAttacked(), args); - - if (froms.isEmpty() || tos.isEmpty()) { - continue; - } - - Set newFroms = this.convert(froms, newPEAFTheory); - Set newTos = this.convert(tos, newPEAFTheory); - - newPEAFTheory.addAttack(newFroms, newTos); - } - - for (Support support : this.supports) { - Set froms = this.filter(support.getSupporter(), args); - Set tos = this.filter(support.getSupported(), args); - - if (froms.isEmpty() || tos.isEmpty()) { - continue; - } - - Set newFroms = this.convert(froms, newPEAFTheory); - Set newTos = this.convert(tos, newPEAFTheory); - - newPEAFTheory.addSupport(newFroms, newTos, support.getConditionalProbability()); - } - - - return newPEAFTheory; - } - - /** - * - * @param originalArgs original arguments - * @param newPEAFTheory new peaf theory - * @return set of arguments - */ - private Set convert(Set originalArgs, NamedPEAFTheory newPEAFTheory) { - Set conversions = new HashSet(); - - for (BArgument originalArg : originalArgs) { - String aifIdentifier = this.aifMap.get(originalArg); - BArgument newArg = newPEAFTheory.getArgumentByIdentifier(aifIdentifier); - conversions.add(newArg); - } - - return conversions; - } - - /** - * - * @param originalArgs original arguments - * @param filter arguments for filtering - * @return a set of arguments - */ - private Set filter(BipolarEntity originalArgs, Set filter) { - Set filteredSet = new HashSet(); - - for (BArgument arg : originalArgs) { - if (!filter.contains(arg)) { - filteredSet.add(arg); - } - } - - return filteredSet; - } - - /** - * - * @param e an argument - * @return string reprentation of argument - */ - public String getIdentifier(BArgument e) { - return this.aifMap.get(e); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NecessityArgumentationFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NecessityArgumentationFramework.java deleted file mode 100644 index 8f8da790a..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/NecessityArgumentationFramework.java +++ /dev/null @@ -1,424 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.commons.util.SetTools; -import java.util.*; - -/** - * This class implements a bipolar abstract argumentation framework with necessities. - * ie. if an argument a supports b, then the acceptance of a is required for the acceptance of b. - * If a set of arguments E supports an argument b, then the acceptance of b requires the acceptance of at least one argument of E. - *
- *
See - *
- *
Nouioua. AFs with Necessities: Further Semantics and Labelling Characterization. 2013 - *
- *
and - *
- *
Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - * - * @author Lars Bengel - * - */ -public class NecessityArgumentationFramework extends AbstractBipolarFramework implements Comparable { - /** - * Default constructor; initializes empty sets of arguments, attacks and supports - */ - public NecessityArgumentationFramework() { - super(); - } - - /** - * creates a necessity argumentation framework from the given evidential argumentation framework - * @param eaf a bipolar evidential argumentation framework - */ - public NecessityArgumentationFramework(EvidentialArgumentationFramework eaf) { - super(); - this.add(eaf.toNAF()); - } - - /** - * creates a necessity argumentation framework from the given deductive argumentation framework - * @param daf a bipolar deductive argumentation framework - */ - public NecessityArgumentationFramework(DeductiveArgumentationFramework daf) { - super(); - this.add(daf.toNAF()); - } - - /** - * checks whether ext defends argument - * a set of arguments S defends an argument a iff S u {a} is coherent and S attacks - * each coherent set T, which attacks a - * @param argument some argument - * @param ext a set of arguments - * @return "true" if ext defends argument - */ - public boolean isAcceptable(BArgument argument, Collection ext) { - Set extWithA = new HashSet<>(ext); - extWithA.add(argument); - if (!this.isCoherent(extWithA)) { - return false; - } - for (Set subset: new SetTools().subsets(this)) { - for (BipolarEntity attacker: this.getAttackers(argument)) { - if (subset.contains((BArgument)attacker) && !this.isAttackedBy(subset, ext) && this.isCoherent(subset)) { - return false; - } - } - } - return true; - } - - /** - * computes the set of deactivated arguments of argumentSet - * a set of arguments S deactivates an argument a iff either S attacks a or S does not support a - * @param argumentSet a set of arguments - * @return the set of deactivated arguments - */ - public Set getDeactivatedArguments(Collection argumentSet) { - Set deactivatedArguments = new HashSet<>(); - for (BArgument argument: this) { - if (this.isAttackedBy(argument, argumentSet)) { - deactivatedArguments.add(argument); - continue; - } - for (BipolarEntity supporter: this.getDirectSupporters(argument)) { - Set> intersect = new HashSet<>(); - intersect.add(new HashSet<>((ArgumentSet)supporter)); - intersect.add(new HashSet<>(argumentSet)); - if (new SetTools().hasEmptyIntersection(intersect)) { - deactivatedArguments.add(argument); - } - } - } - return deactivatedArguments; - } - - /** - * checks whether the given set of arguments is strongly coherent in this argumentation framework - * a set of arguments is strongly coherent iff it is coherent an conflict-free - * @param argumentSet a set of arguments - * @return "true" if argumentSet is strongly coherent - */ - public boolean isStronglyCoherent(Collection argumentSet) { - return this.isConflictFree(argumentSet) && this.isCoherent(argumentSet); - } - - /** - * checks if the set of arguments S is coherent in his argumentation framework - * S is coherent iff it is closed and N-Cycle-Free - * @param argumentSet a set of arguments - * @return "true" if argumentSet is coherent - */ - public boolean isCoherent(Collection argumentSet) { - return this.isClosed(argumentSet) && this.isNCycleFree(argumentSet); - } - - /** - * checks if the given set of arguments is closed under the support relation - * a set of arguments S is closed iff every argument a in S has - * support from a non-empty subset of S - * @param argumentSet a set of arguments - * @return "true" if argumentSet is closed under the support relation - */ - public boolean isClosed(Collection argumentSet) { - for (BArgument argument: argumentSet) { - for (BipolarEntity s: this.getDirectSupporters(argument)) { - ArgumentSet supporter = (ArgumentSet) s; - Set> intersect = new HashSet<>(); - intersect.add(new HashSet<>(supporter)); - intersect.add((Set) argumentSet); - if (new SetTools().hasEmptyIntersection(intersect)) { - return false; - } - } - } - return true; - } - - /** - * checks if a set of arguments S is N-Cycle-Free in this argumentation framework - * ie. if all arguments in S are N-Cycle-Free in S - * @param argumentSet a set of arguments - * @return "true" the set of arguments isN-Cycle-Free - */ - public boolean isNCycleFree(Collection argumentSet) { - for (BArgument argument: argumentSet) { - if (!isNCycleFreeIn(argument, argumentSet)) - return false; - } - return true; - } - - /** - * checks if argument is N-Cycle-Free in the set of arguments - * @param argument some argument - * @param argumentSet a set of arguments - * @return "true" if argument in N-Cycle-Free in the set of arguments - */ - public boolean isNCycleFreeIn(BArgument argument, Collection argumentSet) { - return this.isNCycleFreeIn(argument, argumentSet, new HashSet<>()); - - } - - /** - * checks if argument is N-Cycle-Free in the set of arguments - * an argument a is N-Cycle-Free in a set S iff every supporting set E of a has either - * an empty intersection with S or one of the arguments in the intersection is N-Cycle-Free in S. - * @param argument some argument - * @param argumentSet a set of arguments - * @param visited set of already checked arguments - * @return "true" if argument in N-Cycle-Free in the set of arguments - */ - private boolean isNCycleFreeIn(BArgument argument, Collection argumentSet, Collection visited) { - if (!argumentSet.contains(argument)) - throw new IllegalArgumentException("argument needs to be in argumentSet"); - Set supporters = this.getDirectSupporters(argument); - if (supporters.isEmpty()) - return true; - for (BipolarEntity s: supporters) { - ArgumentSet supporter = new ArgumentSet((ArgumentSet)s); - (supporter).retainAll(argumentSet); - if (supporter.isEmpty()) { - return true; - } else { - supporter.removeAll(visited); - for (BArgument arg: supporter) { - visited.add(argument); - if (this.isNCycleFreeIn(arg, argumentSet, visited)) - return true; - } - } - } - return false; - } - - /** - * checks whether the given set is conflict-free wrt. the attack relation - * @param argumentSet a set of arguments - * @return "true" if argumentSet is Conflict-Free - */ - public boolean isConflictFree(Collection argumentSet) { - for (BArgument argument: argumentSet) { - for (BipolarEntity attacker: this.getAttackers(argument)) { - if (argumentSet.contains((BArgument) attacker)) { - return false; - } - } - } - return true; - } - - /** - * checks whether argument is attacked by any argument in argumentSet - * @param argument some argument - * @param argumentSet a set of arguments - * @return "true" if some argument in argumentSet attacks argument - */ - public boolean isAttackedBy(BArgument argument, Collection argumentSet) { - for (BArgument arg: argumentSet) { - if (this.isAttackedBy(argument, arg)) { - return true; - } - } - return false; - } - - /** - * checks whether some argument in argumentSet1 is attacked by any argument in argumentSet2 - * @param argumentSet1 a set of arguments - * @param argumentSet2 a set of arguments - * @return "true" if some argument in argumentSet2 attacks any argument in argumentSet1 - */ - public boolean isAttackedBy(Collection argumentSet1, Collection argumentSet2) { - for (BArgument argument: argumentSet1) { - if (this.isAttackedBy(argument, argumentSet2)) { - return true; - } - } - return false; - } - - @Override - public boolean add(Support s) { - if(s instanceof BinarySupport) { - return this.addSupport((BArgument) s.getSupporter(), (BArgument) s.getSupported()); - } else if(s instanceof SetSupport) { - return this.addSupport((ArgumentSet) s.getSupporter(), (BArgument) s.getSupported()); - } - return true; - } - - /** - * Adds a support from the first argument to the second to this argumentation framework. - * @param supporter some argument - * @param supported some argument - * @return "true" if the set of supports has been modified. - */ - public boolean addSupport(BArgument supporter, BArgument supported){ - return addSupport(new ArgumentSet(supporter), supported); - } - - /** - * Adds a support from a set of arguments to an argument to this argumentation framework. - * @param supporter a set of arguments - * @param supported some argument - * @return "true" if the set of supports has been modified. - */ - public boolean addSupport(ArgumentSet supporter, BArgument supported){ - if (supporter.isEmpty()) - throw new IllegalArgumentException("Supporting set cannot be empty"); - boolean result = false; - if(!supportParents.containsKey(supported)) - supportParents.put(supported, new HashSet<>()); - result |= supportParents.get(supported).add(supporter); - if(!supportChildren.containsKey(supporter)) - supportChildren.put(supporter, new HashSet<>()); - result |= supportChildren.get(supporter).add(supported); - return result; - } - - @Override - public boolean add(Attack a) { - if (!(a instanceof BinaryAttack)) { - throw new IllegalArgumentException("Attack of type BinaryAttack expected"); - } else { - BinaryAttack attack = (BinaryAttack) a; - return this.addAttack(attack.getAttacker(), attack.getAttacked()); - } - } - - /** - * Adds an attack from the first argument to the second to this necessity argumentation system. - * @param attacker some argument - * @param attacked some argument - * @return "true" if the set of attacks has been modified. - */ - public boolean addAttack(BArgument attacker, BArgument attacked){ - boolean result = false; - if(!attackParents.containsKey(attacked)) - attackParents.put(attacked, new HashSet<>()); - result |= attackParents.get(attacked).add(attacker); - if(!attackChildren.containsKey(attacker)) - attackChildren.put(attacker, new HashSet<>()); - result |= attackChildren.get(attacker).add(attacked); - return result; - } - - @Override - public Set getSupports() { - Set supports = new HashSet<>(); - for(BArgument a: this) { - if(this.supportParents.containsKey(a)) { - for(BipolarEntity b: this.supportParents.get(a)) - supports.add(new SetSupport((ArgumentSet) b, new ArgumentSet(a))); - } - } - return supports; - } - - @Override - public Set getAttacks(){ - Set attacks = new HashSet<>(); - for(BArgument a: this) { - if(this.attackParents.containsKey(a)) { - for(BipolarEntity b: this.attackParents.get(a)) - attacks.add(new BinaryAttack((BArgument) b, a)); - } - } - return attacks; - } - - /** - * translates this necessity argumentation framework into an evidential argumentation framework - * Translation algorithm from: - * Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - * @return the corresponding evidential argumentation framework - */ - public EvidentialArgumentationFramework toEAF() { - EvidentialArgumentationFramework eaf = new EvidentialArgumentationFramework(); - // arguments and attacks are identical - eaf.addAll(this); - eaf.addAllAttacks(this.getAttacks()); - //handle support relations - for (BArgument argument: this) { - Set supporters = this.getDirectSupporters(argument); - if (supporters.isEmpty()) { - // an argument with no supporters in this NAF is considered prima-facie in the corresponding EAF - eaf.addPrimaFacie(argument); - } else { - //arguments with support from any argument in NAF are supported in EAF - // by all permutations of the supporters in NAF - Set> supportingSets = new HashSet<>(); - for (BipolarEntity bipolarEntity: supporters) { - supportingSets.add(new HashSet<>((ArgumentSet)bipolarEntity)); - } - for (Set supporter: new SetTools().permutations(supportingSets)) { - Support supp = new SetSupport(supporter, new ArgumentSet(argument)); - eaf.add(supp); - } - } - } - return eaf; - } - - /** - * translates this NAF into the corresponding framework with support in a deductive sense - * only works for NAFs which contain only binary support relations - * See Cayrol, Lagasquie-Schiex. Bipolarity in argumentation graphs: Towards a better understanding. 2013 - * @return the corresponding DAF - */ - public DeductiveArgumentationFramework toDAF() { - DeductiveArgumentationFramework daf = new DeductiveArgumentationFramework(); - // arguments and attacks are the same - daf.addAll(this); - daf.addAllAttacks(this.getAttacks()); - // every support relation is reversed - for (Support supp: this.getSupports()) { - SetSupport support = (SetSupport) supp; - Iterator iterator = support.getSupporter().iterator(); - BArgument supporter = iterator.next(); - if (iterator.hasNext()){ - throw new IllegalArgumentException("Framework can only have binary supports"); - } - daf.addSupport(support.getSupported(), supporter); - } - return daf; - } - - @Override - public int compareTo(NecessityArgumentationFramework o) { - return this.hashCode() - o.hashCode(); - } - - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - - int result = super.hashCode(); - result = 31 * result + (this.attackParents == null ? 0 : this.attackParents.hashCode()); - result = 37 * result + (this.supportParents == null ? 0 : this.supportParents.hashCode()); - return result; - } -} \ No newline at end of file diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEAFTheory.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEAFTheory.java deleted file mode 100644 index f2d9e2534..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEAFTheory.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.bipolar.io.EdgeListWriter; - -import java.util.Collection; -import java.util.Set; - -/** - * This class implements an abstract argumentation theory - * in the sense of Probabilistic Evidential Argumentation Frameworks (PrEAF). - * see Li, Hengfei. Probabilistic argumentation. 2015. PhD Thesis. Aberdeen University. - * - * @author Taha Dogan Gunes - */ -public class PEAFTheory extends AbstractEAFTheory { - - /** - * Default constructor; initializes an empty PEAFTheory - */ - public PEAFTheory() { - } - - /** - * Optional constructor; initializes an PEAFTheory with arguments - * - * @param noArguments the number of arguments - */ - public PEAFTheory(Set noArguments) { - this.addAll(noArguments); - - } - - - - /** - * Add an argument with an integer identifier - * - * @param identifier the identifier of the argument - * @return EArgument object - */ - public BArgument addArgument(int identifier) { - BArgument argument = this.createArgument(Integer.toString(identifier)); - this.addArgument(argument); - return argument; - } - - - - - - /** - * Add a support with sets for many to many mapping - * - * @param froms set with arguments that originate the support - * @param tos set with arguments that receive the support - * @param cp the result assigned to the support link (must be in range [0.0, 1.0]) - */ - public void addSupport(Set froms, Set tos, double cp) { - - WeightedSetSupport support = new WeightedSetSupport( new ArgumentSet(froms), new ArgumentSet(tos), cp); - this.addSupport(support); - } - - /** - * Add attack between arguments with indices - * - * @param froms the index of the EArgument that originates the attack - * @param tos the index of the EArgument that receieves the attack - */ - public void addAttack(BipolarEntity froms, BipolarEntity tos) { - this.addAttack(froms, tos); - } - - /** - * Returns an ascii tree for debug purposes. - * This is usually used in the unit tests. - * - * @return the ascii tree in string - */ - public String getASCIITree() { - StringBuilder builder = new StringBuilder(); - for (Support support : supports) { - StringBuilder builder1 = EdgeListWriter.getStringBuilder((ArgumentSet) support.getSupporter(), (ArgumentSet) support.getSupported(), " -> "); - if (builder1 != null) { - builder.append(builder1); - builder.append("\n"); - } - } - - return builder.toString(); - } - - /** - * Helper function to print the ascii tree - */ - public void printASCIITree() { - System.out.println(this.getASCIITree()); - } - - @Override - public boolean isAcceptable(BArgument argument, Collection ext) { - // TODO Auto-generated method stub - return true; - } - - @Override - public boolean add(Support support) { - this.addSupport((WeightedSetSupport) support); - return true; - } - - @Override - public boolean add(Attack attack) { - this.attacks.add((EAttack) attack); - return true; - } - - - - -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEEAFTheory.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEEAFTheory.java deleted file mode 100644 index 544110a58..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/PEEAFTheory.java +++ /dev/null @@ -1,548 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - - - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; - -/** - * This class implements an abstract argumentation theory - * in the sense of Probabilistic Extended Evidential Argumentation Frameworks (PrEEAF). - * see Li, Hengfei. Probabilistic argumentation. 2015. PhD Thesis. Aberdeen University. - * - * @author Taha Dogan Gunes - */ -public class PEEAFTheory { - - /** - * Creates an argument with identifier and textContent and adds the argument - * - * @param identifier the identifier of the argument - * @param textContent explanation of the argument - */ - public void addArgument(String identifier, String textContent) { - Argument arg = new Argument(identifier, textContent); - this.arguments.add(arg); - identifierElementMap.put(identifier, arg); - } - - /** - * Argument is a class, that is used for PEEAFTheory - */ - public class Argument extends Element { - /** - * Used for specifying the name of the argument - */ - private final String name; - - /** - * The default constructor of the PEEAF.Argument - * - * @param identifier the identifier of the argument as string - * @param name the name of the argument as string - */ - Argument(String identifier, String name) { - super(identifier); - this.name = name; - } - - /** - * Returns Argument as a string (good for debugging) - * - * @return a verbose string output of stored variables - */ - @Override - public String toString() { - return "Arg{" + - "id=`" + identifier + "` - " + - name + - '}'; - } - - /** - * @return the name of the argument - */ - public String getName() { - return name; - } - } - - /** - * Adds attack from the identifier of an argument to the identifier of the argument, support or attack. - * - * @param identifier the name of the attack - * @param fromIdentifier the identifier of argument that originate the attack - * @param toIdentifier the identifier of the targeted argument - * @param probability the uncertainty regarding the attack link (must be in range [0.0, 1.0]) - */ - public void addAttack(String identifier, String fromIdentifier, String toIdentifier, double probability) { - Attack attack = new Attack(identifier, probability); - - Argument from = checkAndGetArgument(fromIdentifier); - Element to = checkAndGetElement(toIdentifier); - - attack.setFrom(from); - attack.setTo(to); - - attacks.add(attack); - identifierElementMap.put(identifier, attack); - } - - /** - * Attack is a class, that is used for PEEAFTheory - *

- * Each link has one-to-one relationship with some result in PEEAF. - */ - public class Attack extends Element { - - /** - * The argument that the attack originates from - */ - private Argument from; - - /** - * The element (attack, support or argument) that originates the attack - */ - private Element to; - - /** - * The result assigned to the attack link - */ - private final double probability; - - - /** - * The default constructor of Attack - * - * @param identifier identifier as string - * @param probability the result assigned to the attack link - */ - Attack(String identifier, double probability) { - super(identifier); - this.probability = probability; - } - - /** - * Sets the argument that the attack originates from - * - * @param from The argument that the attack originates from - */ - public void setFrom(Argument from) { - this.from = from; - } - - /** - * The element (attack, support or argument) that originates the attack - * - * @param to element - */ - public void setTo(Element to) { - this.to = to; - } - - /** - * Return the argument that originates the attack - * - * @return the argument - */ - public Argument getFrom() { - return from; - } - - /** - * Get the element (attack, support or argument) that originates the attack - * - * @return the element - */ - public Element getTo() { - return to; - } - - /** - * Returns Attack as a string (good for debugging) - * - * @return a verbose string output of stored variables - */ - @Override - public String toString() { - return "Att{" + identifier + ", " + - "from=" + from + - ", to=" + to + - ", result=" + probability + - '}'; - } - - /** - * @return the result assigned to the attack link - */ - public double getProbability() { - return probability; - } - } - - /** - * The argument that is the root argument (that argument that is the initial point) - */ - protected Argument eta; - - /** - * This is for quickly checking or retrieving existing elements - */ - protected Map identifierElementMap = new HashMap(); - - /** - * Ordered list of arguments - */ - protected ArrayList arguments = new ArrayList<>(); - - /** - * Ordered list of supports - */ - protected ArrayList supports = new ArrayList<>(); - - /** - * Ordered list of attacks - */ - protected ArrayList attacks = new ArrayList<>(); - - /** - * Default constructor that initializes an empty PEEAFTheory - */ - public PEEAFTheory() { - } - - /** - * Element is the parent of PEEAFTheory.Argument, PEEAFTheory.Support and PEEAFTheory.Attack - */ - @SuppressWarnings("InnerClassMayBeStatic") - public abstract class Element { - /** - * Identifier is used internally during conversion to PEEAF - */ - protected final String identifier; - - /** - * Default constructor of Element - * - * @param identifier identifier denotes the Element - */ - Element(String identifier) { - this.identifier = identifier; - } - - /** - * @return identifier as string - */ - public String getIdentifier() { - return identifier; - } - } - - /** - * Adds support to PEEAF with from identifiers of arguments and to the identifier of the targeted argument - * - * @param identifier the identifier for the support - * @param fromIdentifiers the identifiers of arguments that originate the support - * @param toIdentifier the identifier of the targeted argument - * @param probability the uncertainty regarding the support link (must be in range [0.0, 1.0]) - */ - public void addSupport(String identifier, String[] fromIdentifiers, String toIdentifier, double probability) { - Support support = new Support(identifier, probability); - - for (String fromIdentifier : fromIdentifiers) { - Argument from = checkAndGetArgument(fromIdentifier); - support.addFrom(from); - } - - Argument to = checkAndGetArgument(toIdentifier); - support.setTo(to); - - supports.add(support); - identifierElementMap.put(identifier, support); - } - - /** - * Support is a class, that is used for PEEAFTheory - *

- * The difference between support links of PEAFTheory and EAFTheory - * is that, each link has many-to-one relationship with some result. - */ - public class Support extends Element { - - /** - * A set of arguments that the support originates from - */ - private final Set froms = new HashSet(); - /** - * The result assigned to the support link - */ - private final double probability; - /** - * The argument that originates the support - */ - private Argument to; - - /** - * The default constructor of Support - * - * @param identifier identifier as string - * @param probability the result assigned to the support link - */ - Support(String identifier, double probability) { - super(identifier); - this.probability = probability; - } - - /** - * Adds the argument into the set of arguments that originates the support - * - * @param from the argument that originates the support - */ - public void addFrom(Argument from) { - this.froms.add(from); - } - - /** - * Return the set of arguments that originates the support - * - * @return the set of the arguments - */ - public Set getFroms() { - return froms; - } - - /** - * Return the argument that is targeted - * - * @return the argument that is targeted - */ - public Argument getTo() { - return to; - } - - /** - * Set the argument that the support link targets - * - * @param to the argument that is targeted - */ - public void setTo(Argument to) { - this.to = to; - } - - /** - * Returns Argument as a string (good for debugging) - * - * @return a verbose string output of stored variables - */ - @Override - public String toString() { - return "Supp{" + identifier + ", " + - "froms=" + froms + - ", to=" + to + - ", result=" + probability + - '}'; - } - - /** - * @return the result assigned to the support link - */ - public double getProbability() { - return probability; - } - } - - /** - * Get the argument with the identifier - * - * @param identifier an argument's identifier - * @return the argument - */ - public Argument checkAndGetArgument(String identifier) { - Object obj = this.identifierElementMap.get(identifier); - if (!(obj instanceof Argument)) { - throw new NotAnArgumentException("The given argument `" + obj + "` is not instance of Argument."); - } - Argument to = (Argument) this.identifierElementMap.get(identifier); - if (to == null) { - throw new NotAnArgumentException("The argument with id=`" + identifier + "` was not found."); - } - return to; - } - - /** - * Get the element with the identifier - * - * @param identifier an element's argument - * @return the element - */ - private Element checkAndGetElement(String identifier) { - Element to = this.identifierElementMap.get(identifier); - if (to == null) { - throw new ElementNotFoundException("The element with id=`" + identifier + "` was not found."); - } - return to; - } - - /** - * Get the insert ordered list of arguments. - * - * @return array list of the arguments - */ - public ArrayList getArguments() { - return arguments; - } - - /** - * Get the insert ordered list of supports. - * - * @return array list of the supports - */ - public ArrayList getSupports() { - return supports; - } - - /** - * Get the insert ordered list of attacks. - * - * @return array list of the attacks - */ - public ArrayList getAttacks() { - return attacks; - } - - /** - * Print the PEEAF for debugging purposes. - */ - public void prettyPrint() { - System.out.println("\nPEEAF:"); - System.out.println("-- Arguments --"); - int i = 0; - for (Argument argument : this.getArguments()) { - System.out.println(i + ". " + argument.toString()); - i++; - } - - System.out.println(); - System.out.println("-- Supports --"); - i = 0; - for (Support support : this.getSupports()) { - System.out.println(i + ". " + support.toString()); - i++; - } - - System.out.println(); - System.out.println("-- Attacks --"); - i = 0; - for (Attack attack : this.getAttacks()) { - System.out.println(i + ". " + attack.toString()); - i++; - } - - System.out.println("\n"); - } - - /** - * The exception occurs when the argument requested is not found. - * The exception has an internal atomic variable for keeping track of the number of times this occurs. - */ - public static class NotAnArgumentException extends RuntimeException { - - /** - * The atomic variable to store the occurrence of this exception. - */ - private static final AtomicLong atomicLong = new AtomicLong(0); - - /** - * Default constructor - * - * @param message the reason for the exception - */ - public NotAnArgumentException(String message) { - super(message); - atomicLong.getAndIncrement(); - } - - /** - * Get the occurrence count of exception thrown. - * - * @return the count - */ - public static long getOccurrenceCount() { - return atomicLong.get(); - } - } - - /** - * The exception occurs when the element requested is not found. - * The exception has an internal atomic variable for keeping track of the number of times this occurs. - */ - public static class ElementNotFoundException extends RuntimeException { - - /** - * The atomic variable to store the occurrence of this exception. - */ - private static final AtomicLong atomicLong = new AtomicLong(0); - - /** - * The atomic variable to store the occurrence of this exception. - * @param message the message - */ - public ElementNotFoundException(String message) { - super(message); - atomicLong.getAndIncrement(); - } - - /** - * Get the occurrence count of exception thrown. - * - * @return the count - */ - public static long getOccurrenceCount() { - return atomicLong.get(); - } - } - - /** - * Helper class for displaying associated exceptions' occurrence - */ - public static class Exceptions { - - /** - * Outputs the occurrence of PEEAF exceptions. - * - * @return the count of the total occurrence of exceptions - */ - public static long describe() { - long count = 0; - System.out.println("PEEAF.NotAnArgumentException count: " + NotAnArgumentException.getOccurrenceCount()); - count += NotAnArgumentException.getOccurrenceCount(); - System.out.println("PEEAF.ElementNotFoundException count: " + ElementNotFoundException.getOccurrenceCount()); - count += ElementNotFoundException.getOccurrenceCount(); - return count; - } - - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetAttack.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetAttack.java deleted file mode 100644 index b5d147cc3..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetAttack.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; -import org.tweetyproject.arg.dung.ldo.syntax.LdoNegation; -import org.tweetyproject.arg.dung.ldo.syntax.LdoRelation; -import org.tweetyproject.arg.dung.syntax.DungSignature; -import org.tweetyproject.commons.Signature; -import org.tweetyproject.graphs.DirectedEdge; - -import java.util.Collection; -import java.util.Iterator; - -/** - * This class models an attack between a set of arguments and an argument. It comprises of a set of BArgument and is used by - * bipolar abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public class SetAttack extends DirectedEdge implements Attack{ - - /** - * Default constructor; initializes the arguments used in this attack relation - * @param supporter the attacking set of arguments - * @param supported the attacked argument - */ - public SetAttack(ArgumentSet supporter, BArgument supported){ - super(supporter, supported); - } - - /** - * initializes the arguments used in this attack relation - * @param supporter a collection of attacking arguments arguments - * @param supported the attacked argument - */ - public SetAttack(Collection supporter, BArgument supported){ - this(new ArgumentSet(supporter), supported); - } - - /** - * initializes the arguments used in this attack relation - * @param supporter the attacking argument - * @param supported the attacked argument - */ - public SetAttack(BArgument supporter, BArgument supported){ - super(new ArgumentSet(supporter), supported); - } - - /** - * returns the attacked argument of this attack relation. - * @return the attacked argument of this attack relation. - */ - public BArgument getAttacked() { - return (BArgument) this.getNodeB(); - } - - /** - * returns the attacking set of arguments of this attack relation. - * @return the attacking set of arguments of this attack relation. - */ - public ArgumentSet getAttacker() { - return (ArgumentSet) this.getNodeA(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString(){ - return "("+this.getAttacker().toString()+","+this.getAttacked().toString()+")"; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o){ - if(!o.getClass().equals(this.getClass())) return false; - if(!this.getAttacker().equals(((SetAttack)o).getAttacker())) return false; - if(!this.getAttacked().equals(((SetAttack)o).getAttacked())) return false; - return true; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode(){ - return this.getAttacked().hashCode() + 7 * this.getAttacker().hashCode(); - } - - @Override - public boolean contains(Object o) { - return this.getAttacked().equals(o) || this.getAttacker().contains(o); - } - - /* (non-Javadoc) - * @see org.tweetyproject.arg.dung.syntax.DungEntity#getLdoFormula() - */ - public LdoFormula getLdoFormula() { - return new LdoRelation(this.getAttacker().getLdoFormula(), new LdoNegation(this.getAttacked().getLdoFormula())); - } - - /* (non-Javadoc) - * @see org.tweetyproject.kr.Formula#getSignature() - */ - public Signature getSignature() { - DungSignature sig = new DungSignature(); - sig.add(this.getAttacked()); - sig.add(this.getAttacker()); - return sig; - } - - @Override - public Iterator iterator() { - return null; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetSupport.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetSupport.java deleted file mode 100644 index 83a78c703..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/SetSupport.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; -import org.tweetyproject.arg.dung.ldo.syntax.LdoRelation; -import org.tweetyproject.arg.dung.syntax.DungSignature; -import org.tweetyproject.commons.Signature; -import org.tweetyproject.graphs.DirectedEdge; - -import java.util.Collection; -import java.util.Iterator; - -/** - * This class models a support between a set of arguments and an argument. It comprises of a set of BArgument and is used by - * bipolar abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public class SetSupport extends DirectedEdge implements Support { - - private double getConditionalProbability = 1.0; - - public void setConditionality(double c){ - this.getConditionalProbability = c; - } - public double getConditionalProbability(){ - return this.getConditionalProbability; - } - /** - * Default constructor; initializes the arguments used in this support relation - * @param supporter the supporting set of arguments - * @param supported the supported argument - */ - public SetSupport(ArgumentSet supporter, ArgumentSet supported){ - super(supporter, supported); - } - - /** - * initializes the arguments used in this support relation - * @param supporter a collection of arguments - * @param supported some argument - */ - public SetSupport(Collection supporter, Collection supported) { - this(new ArgumentSet(supporter), new ArgumentSet(supported)); - } - - /** - * initializes the arguments used in this support relation - * @param supporter the supporting argument - * @param supported the supported argument - */ - public SetSupport(BArgument supporter, BArgument supported){ - super(new ArgumentSet(supporter), supported); - } - - /** - * returns the supported argument of this support relation. - * @return the supported argument of this support relation. - */ - public BipolarEntity getSupported() { - return this.getNodeB(); - } - - /** - * returns the supporting set of arguments of this support relation. - * @return the supporting set of arguments of this support relation. - */ - public BipolarEntity getSupporter() { - return this.getNodeA(); - } - - /** - * Return true if the given argument is in this support relation. - * @param argument some argument - * @return true if the given argument is in this support relation. - */ - public boolean contains(BArgument argument){ - return this.getSupported().equals(argument) || this.getSupporter().contains(argument); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString(){ - return "("+this.getSupporter().toString()+","+this.getSupported().toString()+")"; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o){ - if(!o.getClass().equals(this.getClass())) return false; - if(!this.getSupporter().equals(((SetSupport)o).getSupporter())) return false; - if(!this.getSupported().equals(((SetSupport)o).getSupported())) return false; - return true; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode(){ - return this.getSupported().hashCode() + 11 * this.getSupporter().hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#contains(java.lang.Object) - */ - public boolean contains(Object o) { - return this.getSupported().equals(o) || this.getSupporter().contains(o); - } - - /* (non-Javadoc) - * @see org.tweetyproject.arg.dung.syntax.DungEntity#getLdoFormula() - */ - public LdoFormula getLdoFormula() { - return new LdoRelation(this.getSupporter().getLdoFormula(), this.getSupported().getLdoFormula()); - } - - /* (non-Javadoc) - * @see org.tweetyproject.kr.Formula#getSignature() - */ - public Signature getSignature(){ - DungSignature sig = new DungSignature(); - sig.add(this.getSupported()); - sig.add(this.getSupporter()); - return sig; - } - - @Override - public Iterator iterator() { - return null; - } -} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Support.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Support.java index d6b8e91f6..a4282dba6 100644 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Support.java +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/Support.java @@ -1,83 +1,121 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar.syntax; - -/** - * This interface captures common methods of different interpretations of the support relation in - * bipolar abstract argumentation theories. - * - * @author Lars Bengel - * - */ -public interface Support extends BipolarEntity { - - /** - * Returns the argument that is supported by the supporter. - *

- * This method retrieves the argument that is being supported by the current supporter argument. - *

- * - * @return the supported argument - */ - BipolarEntity getSupported(); - - /** - * Returns the argument that provides support to another argument. - *

- * This method retrieves the argument that is providing support to the current supported argument. - *

- * - * @return the supporter argument - */ - BipolarEntity getSupporter(); - - /** - * Sets the conditionality of the support, represented by a probability value. - *

- * The conditionality or strength of the support is represented by a conditional probability - * value, which reflects how strongly the supporter influences the supported argument. - *

- * - * @param c the conditional probability of the support - */ - void setConditionality(double c); - - /** - * Returns the conditional probability of the support. - *

- * This method retrieves the conditional probability associated with the support, indicating - * the strength of the support. - *

- * - * @return the conditional probability of the support - */ - double getConditionalProbability(); - - /** - * Returns a string representation of the support relation. - *

- * This method provides a textual description of the support relation, including information - * about the supporter, the supported argument, and the conditional probability. - *

- * - * @return a string representation of the support relation - */ - String toString(); -} +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.arg.bipolar.syntax; + +import org.tweetyproject.arg.dung.ldo.syntax.LdoFormula; +import org.tweetyproject.arg.dung.ldo.syntax.LdoRelation; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungSignature; +import org.tweetyproject.commons.Signature; +import org.tweetyproject.graphs.DirectedEdge; + +/** + * This class models a support between two arguments. It comprises two attributes of Argument and is used by + * bipolar abstract argumentation theories. + * + * @author Lars Bengel + * + */ +public class Support extends DirectedEdge { + + /** + * Default constructor; initializes the two arguments used in this support relation + * @param supporter the supporting argument + * @param supported the supported argument + */ + public Support(Argument supporter, Argument supported){ + super(supporter, supported); + } + + /** + * returns the supported argument of this support relation. + * @return the supported argument of this support relation. + */ + public Argument getSupported() { + return this.getNodeB(); + } + + /** + * returns the supporting argument of this support relation. + * @return the supporting argument of this support relation. + */ + public Argument getSupporter() { + return this.getNodeA(); + } + + /* (non-Javadoc) + * @see org.tweetyproject.kr.Formula#getSignature() + */ + public Signature getSignature(){ + DungSignature sig = new DungSignature(); + sig.add(this.getSupported()); + sig.add(this.getSupporter()); + return sig; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString(){ + return "("+this.getSupporter().toString()+","+this.getSupported().toString()+")"; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object o){ + if(!o.getClass().equals(this.getClass())) return false; + if(!this.getSupporter().equals(((Support)o).getSupporter())) return false; + if(!this.getSupported().equals(((Support)o).getSupported())) return false; + return true; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode(){ + return this.getSupported().hashCode() + 11 * this.getSupporter().hashCode(); + } + + /* (non-Javadoc) + * @see org.tweetyproject.arg.dung.syntax.DungEntity#getLdoFormula() + */ + public LdoFormula getLdoFormula() { + return new LdoRelation(this.getSupporter().getLdoFormula(), this.getSupported().getLdoFormula()); + } + + /* (non-Javadoc) + * @see java.lang.Object#contains(java.lang.Object) + */ + public boolean contains(Object o) { + return this.getSupported().equals(o) || this.getSupporter().equals(o); + } + + /** + * Value for distinguishing between different interpretations of the support relation + */ + public enum Type { + DEFAULT, + SIMPLE_DEDUCTIVE, + DEDUCTIVE, + NECESSITY, + SIMPLE_NECESSITY, + EVIDENTIAL + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/WeightedSetSupport.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/WeightedSetSupport.java deleted file mode 100644 index dd442e353..000000000 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/WeightedSetSupport.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2022 The TweetyProject Team - */ -package org.tweetyproject.arg.bipolar.syntax; - -/** - * Represents a weighted support relationship between two argument sets. - *

- * This class extends the {@link SetSupport} class to include a weight parameter, - * which quantifies the strength or significance of the support relationship. - *

- */ -public class WeightedSetSupport extends SetSupport { - - /** The weight of the support relationship. */ - public double cp; - - /** - * Constructs a new {@code WeightedSetSupport} instance. - * - * @param supporter The set of arguments providing support. - * This is the argument set that supports the other set. - * @param supported The set of arguments being supported. - * This is the argument set that is being supported. - * @param cp The weight of the support relationship, indicating the strength or significance of the support. - * This value should be a positive number, where a higher value represents a stronger support. - */ - public WeightedSetSupport(ArgumentSet supporter, ArgumentSet supported, double cp) { - super(supporter, supported); - this.cp = cp; - } -} - diff --git a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/BasicFunctionalityTest.java b/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/BasicFunctionalityTest.java deleted file mode 100644 index e3e815d6a..000000000 --- a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/BasicFunctionalityTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2019 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar; - -import static org.junit.Assert.*; - -import org.tweetyproject.arg.bipolar.syntax.*; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author Lars Bengel - * - */ -public class BasicFunctionalityTest { - static BArgument a = new BArgument("a"); - static BArgument b = new BArgument("b"); - static BArgument c = new BArgument("c"); - static BArgument x = new BArgument("x"); - - // Example used by C. Cayrol in "Bipolarity in argumentation graphs: Towards a better understanding" (2013) - static DeductiveArgumentationFramework cayrolExample7; - static DeductiveArgumentationFramework cayrolExample7_1; - static DeductiveArgumentationFramework cayrolExample7_2; - static DeductiveArgumentationFramework cayrolExample7_3; - - @BeforeClass - public static void setUpBeforeClass() { - cayrolExample7_1 = new DeductiveArgumentationFramework(); - cayrolExample7_2 = new DeductiveArgumentationFramework(); - cayrolExample7_3 = new DeductiveArgumentationFramework(); - - cayrolExample7_1.add(b); - cayrolExample7_1.add(c); - cayrolExample7_1.add(x); - - cayrolExample7_1.addAttack(x, c); - - cayrolExample7_1.addSupport(b, c); - - cayrolExample7_2.add(a); - cayrolExample7_2.add(b); - cayrolExample7_2.add(c); - cayrolExample7_2.add(x); - - cayrolExample7_2.addSupport(a, x); - cayrolExample7_2.addSupport(b, c); - - cayrolExample7_3.add(a); - cayrolExample7_3.add(b); - cayrolExample7_3.add(c); - cayrolExample7_3.add(x); - - cayrolExample7_3.addAttack(x, c); - - cayrolExample7_3.addSupport(a, x); - } - - @Before - public void setUpBefore() { - cayrolExample7 = new DeductiveArgumentationFramework(); - - cayrolExample7.add(a); - cayrolExample7.add(b); - cayrolExample7.add(c); - cayrolExample7.add(x); - - cayrolExample7.addAttack(x, c); - - cayrolExample7.addSupport(a, x); - cayrolExample7.addSupport(b, c); - - } - - @Test - public void removeArgument() { - assertTrue(cayrolExample7.remove(a)); - assertFalse(cayrolExample7.remove(a)); - assertEquals(cayrolExample7_1, cayrolExample7); - } - - @Test - public void removeAttack() { - Attack att = new BinaryAttack(x, c); - assertTrue(cayrolExample7.remove(att)); - assertFalse(cayrolExample7.remove(att)); - assertEquals(cayrolExample7_2, cayrolExample7); - } - - @Test - public void removeSupport() { - Support supp = new BinarySupport(b, c); - assertTrue(cayrolExample7.remove(supp)); - assertFalse(cayrolExample7.remove(supp)); - assertEquals(cayrolExample7_3, cayrolExample7); - } - -} - diff --git a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/DeductiveArgumentationTest.java b/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/DeductiveArgumentationTest.java deleted file mode 100644 index 6e4c7592e..000000000 --- a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/DeductiveArgumentationTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar; - -import static org.junit.Assert.*; - -import org.tweetyproject.arg.bipolar.syntax.*; -import org.tweetyproject.arg.dung.syntax.DungTheory; -import org.junit.BeforeClass; -import org.junit.Test; - -public class DeductiveArgumentationTest { - static BArgument a = new BArgument("a"); - static BArgument b = new BArgument("b"); - static BArgument c = new BArgument("c"); - static BArgument x = new BArgument("x"); - - // Example used by C. Cayrol in "Bipolarity in argumentation graphs: Towards a better understanding" (2013) - static DeductiveArgumentationFramework cayrolExample7; - static DungTheory cayrolExample7_1; - - @BeforeClass - public static void setUpBeforeClass() { - cayrolExample7 = new DeductiveArgumentationFramework(); - cayrolExample7_1 = new DungTheory(); - - cayrolExample7.add(a); - cayrolExample7.add(b); - cayrolExample7.add(c); - cayrolExample7.add(x); - - cayrolExample7.addAttack(x, c); - - cayrolExample7.addSupport(a, x); - cayrolExample7.addSupport(b, c); - - - cayrolExample7_1.add(a); - cayrolExample7_1.add(b); - cayrolExample7_1.add(c); - cayrolExample7_1.add(x); - - cayrolExample7_1.addAttack(a, b); - cayrolExample7_1.addAttack(a, c); - cayrolExample7_1.addAttack(x, b); - cayrolExample7_1.addAttack(x, c); - } - - @Test - public void toDungTheory() { - assertEquals(cayrolExample7_1, cayrolExample7.getCompleteAssociatedDungTheory()); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/EvidentialArgumentationTest.java b/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/EvidentialArgumentationTest.java deleted file mode 100644 index 01b87801d..000000000 --- a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/EvidentialArgumentationTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar; - -import static org.junit.Assert.*; - -import org.tweetyproject.arg.bipolar.reasoner.evidential.*; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.Collection; -import java.util.HashSet; - -/** - * @author Lars Bengel - * - */ -public class EvidentialArgumentationTest { - static BArgument a = new BArgument("a"); - static BArgument b = new BArgument("b"); - static BArgument c = new BArgument("c"); - static BArgument d = new BArgument("d"); - static BArgument e = new BArgument("e"); - static BArgument f = new BArgument("f"); - - // Example from Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - static EvidentialArgumentationFramework polberg_example3; - static EvidentialArgumentationFramework polberg_example3_1; - - static Collection stableExtensions = new HashSet<>(); - static Collection groundedExtensions = new HashSet<>(); - static Collection preferredExtensions = new HashSet<>(); - static Collection completeExtensions = new HashSet<>(); - - @BeforeClass - public static void setUpBeforeClass() { - polberg_example3_1 = new EvidentialArgumentationFramework(); - polberg_example3_1.add(a); - polberg_example3_1.add(b); - polberg_example3_1.add(c); - polberg_example3_1.add(d); - polberg_example3_1.add(e); - polberg_example3_1.add(f); - - polberg_example3_1.addAttack(b, a); - polberg_example3_1.addAttack(b, c); - polberg_example3_1.addAttack(c, b); - polberg_example3_1.addAttack(c, d); - polberg_example3_1.addAttack(d, f); - polberg_example3_1.addAttack(f, f); - - polberg_example3_1.addSupport(d, e); - - polberg_example3_1.addPrimaFacie(a); - polberg_example3_1.addPrimaFacie(e); - - ArgumentSet set1 = new ArgumentSet(); - set1.add(b); - set1.add(d); - set1.add(e); - set1.add(polberg_example3_1.getEta()); - - ArgumentSet set2 = new ArgumentSet(); - set2.add(c); - set2.add(polberg_example3_1.getEta()); - - ArgumentSet set3 = new ArgumentSet(); - set3.add(polberg_example3_1.getEta()); - - stableExtensions.add(set1); - preferredExtensions.add(set1); - preferredExtensions.add(set2); - completeExtensions.add(set1); - completeExtensions.add(set2); - completeExtensions.add(set3); - groundedExtensions.add(set3); - } - - @Before - public void setUpBefore() { - polberg_example3 = new EvidentialArgumentationFramework(); - polberg_example3.add(a); - polberg_example3.add(b); - polberg_example3.add(c); - polberg_example3.add(d); - polberg_example3.add(e); - polberg_example3.add(f); - - polberg_example3.addAttack(b, a); - polberg_example3.addAttack(b, c); - polberg_example3.addAttack(c, b); - polberg_example3.addAttack(c, d); - polberg_example3.addAttack(d, f); - polberg_example3.addAttack(f, f); - - polberg_example3.addSupport(d, e); - - polberg_example3.addPrimaFacie(b); - polberg_example3.addPrimaFacie(c); - polberg_example3.addPrimaFacie(d); - polberg_example3.addPrimaFacie(f); - - } - - @Test - public void primaFacie() { - polberg_example3.removePrimaFacie(b); - polberg_example3.removePrimaFacie(c); - polberg_example3.removePrimaFacie(d); - polberg_example3.removePrimaFacie(f); - polberg_example3.addPrimaFacie(a); - polberg_example3.addPrimaFacie(e); - assertEquals(polberg_example3, polberg_example3_1); - } - - @Test - public void StableReasoning() { - Collection extensions = new StableReasoner().getModels(polberg_example3); - assertEquals(stableExtensions, extensions); - } - - @Test - public void CompleteReasoning() { - Collection extensions = new CompleteReasoner().getModels(polberg_example3); - assertEquals(completeExtensions, extensions); - } - - @Test - public void GroundedReasoning() { - Collection extensions = new GroundedReasoner().getModels(polberg_example3); - assertEquals(groundedExtensions, extensions); - } - - @Test - public void PreferredReasoning() { - Collection extensions = new PreferredReasoner().getModels(polberg_example3); - assertEquals(preferredExtensions, extensions); - } - -} diff --git a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/NecessityArgumentationTest.java b/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/NecessityArgumentationTest.java deleted file mode 100644 index ad1966ca9..000000000 --- a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/NecessityArgumentationTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar; - -import static org.junit.Assert.*; - -import org.tweetyproject.arg.bipolar.reasoner.necessity.*; -import org.tweetyproject.arg.bipolar.syntax.*; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.Collection; -import java.util.HashSet; - -/** - * @author Lars Bengel - * - */ -public class NecessityArgumentationTest { - static BArgument a = new BArgument("a"); - static BArgument b = new BArgument("b"); - static BArgument c = new BArgument("c"); - static BArgument d = new BArgument("d"); - static BArgument e = new BArgument("e"); - - // Example from Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - static NecessityArgumentationFramework polberg_example4; - - static Collection> stableExtensions = new HashSet<>(); - static Collection> groundedExtensions = new HashSet<>(); - static Collection> preferredExtensions = new HashSet<>(); - static Collection> completeExtensions = new HashSet<>(); - static Collection> admissibleExtensions = new HashSet<>(); - - @BeforeClass - public static void setUpBeforeClass() { - ArgumentSet aS1 = new ArgumentSet(); - aS1.add(b); - aS1.add(d); - - polberg_example4 = new NecessityArgumentationFramework(); - polberg_example4.add(a); - polberg_example4.add(b); - polberg_example4.add(c); - polberg_example4.add(d); - polberg_example4.add(e); - - polberg_example4.addAttack(b, a); - polberg_example4.addAttack(e, a); - polberg_example4.addAttack(c, d); - - polberg_example4.addSupport(a, c); - polberg_example4.addSupport(b, b); - polberg_example4.addSupport(aS1, e); - - ArgumentSet set1 = new ArgumentSet(); - set1.add(a); - set1.add(c); - - ArgumentSet set2 = new ArgumentSet(); - set2.add(d); - set2.add(e); - - stableExtensions.add(set1); - stableExtensions.add(set2); - preferredExtensions.add(set1); - preferredExtensions.add(set2); - completeExtensions.add(set1); - completeExtensions.add(set2); - completeExtensions.add(new ArgumentSet()); - groundedExtensions.add(new ArgumentSet()); - admissibleExtensions.add(set1); - admissibleExtensions.add(set2); - admissibleExtensions.add(new ArgumentSet()); - } - - @Test - public void StableReasoning() { - Collection> extensions = new StableReasoner().getModels(polberg_example4); - assertEquals(stableExtensions, extensions); - } - - @Test - public void CompleteReasoning() { - Collection> extensions = new CompleteReasoner().getModels(polberg_example4); - assertEquals(completeExtensions, extensions); - } - - @Test - public void AdmissibleReasoning() { - Collection> extensions = new AdmissibleReasoner().getModels(polberg_example4); - assertEquals(admissibleExtensions, extensions); - } - - @Test - public void GroundedReasoning() { - Collection> extensions = new GroundedReasoner().getModels(polberg_example4); - assertEquals(groundedExtensions, extensions); - } - - @Test - public void PreferredReasoning() { - Collection> extensions = new PreferredReasoner().getModels(polberg_example4); - assertEquals(preferredExtensions, extensions); - } -} diff --git a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/TranslationTest.java b/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/TranslationTest.java deleted file mode 100644 index b9b4e4e47..000000000 --- a/org-tweetyproject-arg-bipolar/src/test/java/org/tweetyproject/arg/bipolar/TranslationTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ - -package org.tweetyproject.arg.bipolar; - -import static org.junit.Assert.*; - -import org.tweetyproject.arg.bipolar.syntax.*; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author Lars Bengel - * - */ -public class TranslationTest { - static BArgument a = new BArgument("a"); - static BArgument b = new BArgument("b"); - static BArgument c = new BArgument("c"); - static BArgument d = new BArgument("d"); - static BArgument e = new BArgument("e"); - - // Example from Polberg, Oren. Revisiting Support in Abstract Argumentation Systems. 2014 - static NecessityArgumentationFramework polberg_example4; - static EvidentialArgumentationFramework polberg_example4_1; - static NecessityArgumentationFramework polberg_example4_2; - - @BeforeClass - public static void setUpBeforeClass() { - ArgumentSet aS1 = new ArgumentSet(); - aS1.add(b); - aS1.add(d); - - BArgument eta = new EvidentialArgumentationFramework().getEta(); - - polberg_example4 = new NecessityArgumentationFramework(); - polberg_example4.add(a); - polberg_example4.add(b); - polberg_example4.add(c); - polberg_example4.add(d); - polberg_example4.add(e); - - polberg_example4.addAttack(b, a); - polberg_example4.addAttack(e, a); - polberg_example4.addAttack(c, d); - - polberg_example4.addSupport(a, c); - polberg_example4.addSupport(b, b); - polberg_example4.addSupport(aS1, e); - - polberg_example4_1 = new EvidentialArgumentationFramework(); - polberg_example4_1.add(a); - polberg_example4_1.add(b); - polberg_example4_1.add(c); - polberg_example4_1.add(d); - polberg_example4_1.add(e); - - polberg_example4_1.addAttack(b, a); - polberg_example4_1.addAttack(e, a); - polberg_example4_1.addAttack(c, d); - - polberg_example4_1.addSupport(a, c); - polberg_example4_1.addSupport(b, b); - polberg_example4_1.addSupport(b, e); - polberg_example4_1.addSupport(d, e); - - polberg_example4_1.addPrimaFacie(a); - polberg_example4_1.addPrimaFacie(d); - - polberg_example4_2 = new NecessityArgumentationFramework(); - polberg_example4_2.add(a); - polberg_example4_2.add(b); - polberg_example4_2.add(c); - polberg_example4_2.add(d); - polberg_example4_2.add(e); - polberg_example4_2.add(eta); - - polberg_example4_2.addAttack(b, a); - polberg_example4_2.addAttack(e, a); - polberg_example4_2.addAttack(c, d); - - polberg_example4_2.addSupport(a, c); - polberg_example4_2.addSupport(b, b); - polberg_example4_2.addSupport(eta, a); - polberg_example4_2.addSupport(eta, d); - polberg_example4_2.addSupport(aS1, e); - } - - @Test - public void necessityToEvidential() { - assertEquals(polberg_example4_1, polberg_example4.toEAF()); - } - - @Test - public void evidentialToNecessity() { - assertEquals(polberg_example4_2, polberg_example4_1.toNAF()); - } - - @Test - public void necessityToEvidentialToNecessity() { - assertEquals(polberg_example4_2, polberg_example4.toEAF().toNAF()); - } - - -} diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarExtensionReasonerFactory.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarExtensionReasonerFactory.java index 94a5bd84a..8a875e636 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarExtensionReasonerFactory.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarExtensionReasonerFactory.java @@ -19,8 +19,7 @@ package org.tweetyproject.web.services.bipolar; import org.tweetyproject.arg.bipolar.reasoner.*; -import org.tweetyproject.arg.bipolar.reasoner.deductive.*; -import org.tweetyproject.arg.bipolar.reasoner.necessity.*; +import org.tweetyproject.arg.dung.semantics.Semantics; /** * Main factory for retrieving bipolar extension reasoners as supported by the web service @@ -41,21 +40,30 @@ public static BipolarSemantics[] getSemantics() { * Creates a new reasoner measure of the given semantics with default * settings. * - * @param sem some identifier of an semantics. + * @param sem some identifier of a semantics. * @return the requested reasoner. */ public static AbstractBipolarExtensionReasoner getReasoner(BipolarSemantics sem) { return switch (sem) { - case CF -> new ConflictFreeReasoner(); - case SA -> new SafetyReasoner(); - case CL -> new ClosureReasoner(); - case CAD -> new CAdmissibleReasoner(); - case DAD -> new DAdmissibleReasoner(); - case NAD -> new AdmissibleReasoner(); - case NCO -> new CompleteReasoner(); - case NGR -> new GroundedReasoner(); - case NPR -> new PreferredReasoner(); - case NST -> new StableReasoner(); + case BCF -> new SimpleStronglyConflictFreeReasoner(); + case BCOH -> new SimpleCoherentReasoner(); + case BAD -> new SimpleCoherentAdmissibleReasoner(); + case CAD -> new SimpleCoalitionReasoner(Semantics.ADM); + case CCO -> new SimpleCoalitionReasoner(Semantics.CO); + case CGR -> new SimpleCoalitionReasoner(Semantics.GR); + case CPR -> new SimpleCoalitionReasoner(Semantics.PR); + case CST -> new SimpleCoalitionReasoner(Semantics.ST); + case DAD -> new SimpleDeductiveReasoner(Semantics.ADM); + case DCO -> new SimpleDeductiveReasoner(Semantics.CO); + case DGR -> new SimpleDeductiveReasoner(Semantics.GR); + case DPR -> new SimpleDeductiveReasoner(Semantics.PR); + case DST -> new SimpleDeductiveReasoner(Semantics.ST); + case NAD -> new SimpleNecessityReasoner(Semantics.ADM); + case NCO -> new SimpleNecessityReasoner(Semantics.CO); + case NGR -> new SimpleNecessityReasoner(Semantics.GR); + case NPR -> new SimpleNecessityReasoner(Semantics.PR); + case NST -> new SimpleNecessityReasoner(Semantics.ST); + default -> throw new RuntimeException("No reasoner found for semantics " + sem.toString()); }; } diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarFrameworkFactory.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarFrameworkFactory.java index 11c18026b..6b1662e38 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarFrameworkFactory.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/AbstractBipolarFrameworkFactory.java @@ -18,9 +18,9 @@ */ package org.tweetyproject.web.services.bipolar; -import org.tweetyproject.arg.bipolar.reasoner.deductive.*; -import org.tweetyproject.arg.bipolar.reasoner.necessity.*; import org.tweetyproject.arg.bipolar.syntax.*; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.Attack; import java.util.ArrayList; import java.util.List; @@ -42,18 +42,18 @@ public abstract class AbstractBipolarFrameworkFactory { * @param supports supports * @return the requested reasoner. */ - public static AbstractBipolarFramework getArgumentationFramework(BipolarSemantics semantics, + public static BipolarArgumentationFramework getArgumentationFramework(BipolarSemantics semantics, int numberOfArguments, List> attacks, List> supports) { - var argumentationFramework = switch (semantics.input) { - case DeductiveArgumentationFramework -> new DeductiveArgumentationFramework(); - case NecessityArgumentationFramework -> new NecessityArgumentationFramework(); + var argumentationFramework = switch (semantics.type) { + case DEDUCTIVE,SIMPLE_DEDUCTIVE,DEFAULT,NECESSITY,SIMPLE_NECESSITY -> new BipolarArgumentationFramework(); + case EVIDENTIAL -> throw new UnsupportedOperationException("Not implemented yet"); }; - var arguments = new ArrayList(); + var arguments = new ArrayList(); for (int i = 1; i <= numberOfArguments; i++){ - var argument = new BArgument(Integer.toString(i)); + var argument = new Argument(Integer.toString(i)); arguments.add(argument); argumentationFramework.add(argument); } @@ -61,14 +61,14 @@ public static AbstractBipolarFramework getArgumentationFramework(BipolarSemantic for (List attackInput : attacks) { var attacker = arguments.get(attackInput.get(0) - 1); var attacked = arguments.get(attackInput.get(1) - 1); - Attack attack = new BinaryAttack(attacker, attacked); + Attack attack = new Attack(attacker, attacked); argumentationFramework.add(attack); } for (List supportInput : supports) { var supporter = arguments.get(supportInput.get(0) - 1); var supported = arguments.get(supportInput.get(1) - 1); - Support attack = new BinarySupport(supporter, supported); + Support attack = new Support(supporter, supported); argumentationFramework.add(attack); } diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarArgumentationFrameworkType.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarArgumentationFrameworkType.java deleted file mode 100644 index f51ceace5..000000000 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarArgumentationFrameworkType.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2026 The TweetyProject Team - */ -package org.tweetyproject.web.services.bipolar; - -/** - * @author Oleksandr Dzhychko - */ -public enum BipolarArgumentationFrameworkType { - DeductiveArgumentationFramework, - NecessityArgumentationFramework, -} diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerCalleeFactory.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerCalleeFactory.java index 9fcc23f9c..b1ecc755c 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerCalleeFactory.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerCalleeFactory.java @@ -19,7 +19,7 @@ package org.tweetyproject.web.services.bipolar; import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.AbstractBipolarFramework; +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; import org.tweetyproject.web.services.Callee; @@ -88,7 +88,7 @@ public static Command[] getCommands() { * @return A Callee instance corresponding to the specified command * @throws RuntimeException If the specified command is not found */ - public static Callee getCallee(Command cmd, AbstractBipolarExtensionReasoner reasoner, AbstractBipolarFramework bbase) { + public static Callee getCallee(Command cmd, AbstractBipolarExtensionReasoner reasoner, BipolarArgumentationFramework bbase) { switch (cmd) { case GET_MODELS: return new BipolarReasonerGetModelsCallee(reasoner, bbase); diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelCallee.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelCallee.java index 877e1e4f2..46861075a 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelCallee.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelCallee.java @@ -19,8 +19,8 @@ package org.tweetyproject.web.services.bipolar; import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.AbstractBipolarFramework; -import org.tweetyproject.arg.bipolar.syntax.BArgument; +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.syntax.Argument; import org.tweetyproject.web.services.Callee; import java.util.Collection; @@ -38,7 +38,7 @@ public class BipolarReasonerGetModelCallee extends Callee { private AbstractBipolarExtensionReasoner reasoner; /** The AbstractBipolarFramework on which the getModel operation is performed */ - private AbstractBipolarFramework bbase; + private BipolarArgumentationFramework bbase; /** * Constructs a new BipolarReasonerGetModelCallee with the specified reasoner and base AbstractBipolarFramework. @@ -46,7 +46,7 @@ public class BipolarReasonerGetModelCallee extends Callee { * @param reasoner The AbstractBipolarExtensionReasoner to be used for obtaining the model * @param bbase The base AbstractBipolarFramework on which the getModel operation is performed */ - public BipolarReasonerGetModelCallee(AbstractBipolarExtensionReasoner reasoner, AbstractBipolarFramework bbase) { + public BipolarReasonerGetModelCallee(AbstractBipolarExtensionReasoner reasoner, BipolarArgumentationFramework bbase) { this.reasoner = reasoner; this.bbase = bbase; } @@ -58,7 +58,7 @@ public BipolarReasonerGetModelCallee(AbstractBipolarExtensionReasoner reasoner, * @throws Exception If an error occurs during the getModel operation */ @Override - public Collection call() throws Exception { + public Collection call() throws Exception { return this.reasoner.getModel(this.bbase); } } \ No newline at end of file diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelsCallee.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelsCallee.java index 7813527ae..64401a6cf 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelsCallee.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarReasonerGetModelsCallee.java @@ -19,8 +19,8 @@ package org.tweetyproject.web.services.bipolar; import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; -import org.tweetyproject.arg.bipolar.syntax.BArgument; -import org.tweetyproject.arg.bipolar.syntax.AbstractBipolarFramework; +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.semantics.Extension; import org.tweetyproject.web.services.Callee; import java.util.Collection; @@ -38,7 +38,7 @@ public class BipolarReasonerGetModelsCallee extends Callee { private AbstractBipolarExtensionReasoner reasoner; /** The AbstractBipolarFramework on which the getModels operation is performed */ - private AbstractBipolarFramework bbase; + private BipolarArgumentationFramework bbase; /** * Constructs a new BipolarReasonerGetModelsCallee with the specified reasoner and base AbstractBipolarFramework. @@ -46,7 +46,7 @@ public class BipolarReasonerGetModelsCallee extends Callee { * @param reasoner The AbstractBipolarExtensionReasoner to be used for obtaining multiple models * @param bbase The base AbstractBipolarFramework on which the getModels operation is performed */ - public BipolarReasonerGetModelsCallee(AbstractBipolarExtensionReasoner reasoner, AbstractBipolarFramework bbase) { + public BipolarReasonerGetModelsCallee(AbstractBipolarExtensionReasoner reasoner, BipolarArgumentationFramework bbase) { this.reasoner = reasoner; this.bbase = bbase; } @@ -58,7 +58,7 @@ public BipolarReasonerGetModelsCallee(AbstractBipolarExtensionReasoner reasoner, * @throws Exception If an error occurs during the getModels operation */ @Override - public Collection> call() throws Exception { + public Collection> call() throws Exception { return this.reasoner.getModels(this.bbase); } } \ No newline at end of file diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarSemantics.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarSemantics.java index e800d3b4b..ea762674c 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarSemantics.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/bipolar/BipolarSemantics.java @@ -18,8 +18,8 @@ */ package org.tweetyproject.web.services.bipolar; -import static org.tweetyproject.web.services.bipolar.BipolarArgumentationFrameworkType.DeductiveArgumentationFramework; -import static org.tweetyproject.web.services.bipolar.BipolarArgumentationFrameworkType.NecessityArgumentationFramework; +import org.tweetyproject.arg.bipolar.syntax.Support; + /** * An enumeration of all available semantics through the web service. @@ -31,22 +31,36 @@ public enum BipolarSemantics { /** * General Semantics */ - CF("cf", "Conflict-Free", DeductiveArgumentationFramework), - SA("sa", "Safe", DeductiveArgumentationFramework), - CL("cl", "Closed", DeductiveArgumentationFramework), + BCF("b-cf", "Conflict-Free", Support.Type.DEFAULT), + BCOH("b-coh", "Coherent", Support.Type.DEFAULT), + BAD("b-ad", "Coherent Admissible", Support.Type.DEFAULT), + + /** + * Coalition Semantics + */ + CAD("b-coal-ad", "Coalition-Admissible", Support.Type.DEFAULT), + CCO("b-coal-co", "Coalition-Complete", Support.Type.DEFAULT), + CGR("b-coal-gr", "Coalition-Grounded", Support.Type.DEFAULT), + CPR("b-coal-pr", "Coalition-Preferred", Support.Type.DEFAULT), + CST("b-coal-st", "Coalition-Stable", Support.Type.DEFAULT), + /** * Semantics for Deductive Interpretation */ - CAD("c-ad", "c-Admissible", DeductiveArgumentationFramework), - DAD("d-ad", "d-Admissible", DeductiveArgumentationFramework), + DAD("d-ad", "Admissible", Support.Type.DEDUCTIVE), + DCO("d-co", "Complete", Support.Type.DEDUCTIVE), + DGR("d-gr", "Grounded", Support.Type.DEDUCTIVE), + DPR("d-pr", "Preferred", Support.Type.DEDUCTIVE), + DST("d-st", "Stable", Support.Type.DEDUCTIVE), + /** - * Semantics for Necessary Interpretation + * Semantics for Necessity Interpretation */ - NAD("n-ad", "Admissible", NecessityArgumentationFramework), - NCO("n-co", "Complete", NecessityArgumentationFramework), - NGR("n-gr", "Grounded", NecessityArgumentationFramework), - NPR("n-pr", "Preferred", NecessityArgumentationFramework), - NST("n-st", "Stable", NecessityArgumentationFramework); + NAD("n-ad", "Admissible", Support.Type.NECESSITY), + NCO("n-co", "Complete", Support.Type.NECESSITY), + NGR("n-gr", "Grounded", Support.Type.NECESSITY), + NPR("n-pr", "Preferred", Support.Type.NECESSITY), + NST("n-st", "Stable", Support.Type.NECESSITY); /** * id @@ -59,12 +73,12 @@ public enum BipolarSemantics { /** * What type of input is expected for this semantic. */ - public BipolarArgumentationFrameworkType input; + public Support.Type type; - BipolarSemantics(String id, String label, BipolarArgumentationFrameworkType input) { + BipolarSemantics(String id, String label, Support.Type input) { this.id = id; this.label = label; - this.input = input; + this.type = input; } /** diff --git a/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerBipolarTest.java b/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerBipolarTest.java index 8015528f5..1dbfed9c7 100644 --- a/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerBipolarTest.java +++ b/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerBipolarTest.java @@ -62,11 +62,19 @@ public void getInfos() throws Exception { "email": null, "backend_timeout": 600, "semantics": [ - "cf", - "sa", - "cl", - "c-ad", + "b-cf", + "b-coh", + "b-ad", + "b-coal-ad", + "b-coal-co", + "b-coal-gr", + "b-coal-pr", + "b-coal-st", "d-ad", + "d-co", + "d-gr", + "d-pr", + "d-st", "n-ad", "n-co", "n-gr", @@ -91,7 +99,7 @@ public void getModels() throws Exception { "nr_of_arguments": 3, "attacks": [[1, 2]], "supports": [[2, 3]], - "semantics": "c-ad", + "semantics": "b-ad", "timeout": 10, "unit_timeout": "s" } @@ -116,9 +124,9 @@ public void getModels() throws Exception { 3 ] ], - "semantics": "c-ad", + "semantics": "b-ad", "solver": null, - "answer": "[{1}, {3}, {1,3}, {2,3}]", + "answer": "[{1}, {}]", "time": 0.0, "unit_time": "s", "status": "SUCCESS" @@ -136,7 +144,7 @@ public void getModel() throws Exception { "nr_of_arguments": 3, "attacks": [[1, 2]], "supports": [[2, 3]], - "semantics": "c-ad", + "semantics": "b-ad", "timeout": 10, "unit_timeout": "s" } @@ -161,7 +169,7 @@ public void getModel() throws Exception { 3 ] ], - "semantics": "c-ad", + "semantics": "b-ad", "solver": null, "answer": "{1}", "time": 0.0, From 1a09353aeec5ba72b55120c0afa6c77d77b74e07 Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Tue, 26 May 2026 20:05:13 +0200 Subject: [PATCH 02/43] bugfix in unit tests --- .../org/tweetyproject/arg/adf/syntax/test/AccEqualityTest.java | 2 +- .../src/test/java/org/tweetyproject/arg/delp/TestDeLP.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org-tweetyproject-arg-adf/src/test/java/org/tweetyproject/arg/adf/syntax/test/AccEqualityTest.java b/org-tweetyproject-arg-adf/src/test/java/org/tweetyproject/arg/adf/syntax/test/AccEqualityTest.java index f3fb95761..bf662089f 100644 --- a/org-tweetyproject-arg-adf/src/test/java/org/tweetyproject/arg/adf/syntax/test/AccEqualityTest.java +++ b/org-tweetyproject-arg-adf/src/test/java/org/tweetyproject/arg/adf/syntax/test/AccEqualityTest.java @@ -66,7 +66,7 @@ public void testUnequality1() { public void testUnequality2() { Argument a = new Argument("a"); Argument b = new Argument("a"); - assertFalse(a.equals(b)); + assertTrue(a.equals(b)); } } diff --git a/org-tweetyproject-arg-delp/src/test/java/org/tweetyproject/arg/delp/TestDeLP.java b/org-tweetyproject-arg-delp/src/test/java/org/tweetyproject/arg/delp/TestDeLP.java index fefffb510..95a7a978e 100644 --- a/org-tweetyproject-arg-delp/src/test/java/org/tweetyproject/arg/delp/TestDeLP.java +++ b/org-tweetyproject-arg-delp/src/test/java/org/tweetyproject/arg/delp/TestDeLP.java @@ -67,7 +67,7 @@ public void displayHelp() throws IOException, CmdLineException { DefeasibleLogicProgram.main(new String[] {"--help"}); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = UnsupportedOperationException.class) public void unknownComp1() throws IOException, CmdLineException { DefeasibleLogicProgram.main(new String[] {"-c", "PRIORITY"}); } From 6429e87722f0695200a881243ad9be8f972b7113 Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Tue, 26 May 2026 20:10:55 +0200 Subject: [PATCH 03/43] refactoring of dung-web interface --- .../AbstractExtensionReasonerFactory.java | 206 +----------------- 1 file changed, 4 insertions(+), 202 deletions(-) diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/AbstractExtensionReasonerFactory.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/AbstractExtensionReasonerFactory.java index e29cb6c75..3150b5f9c 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/AbstractExtensionReasonerFactory.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/AbstractExtensionReasonerFactory.java @@ -18,172 +18,15 @@ */ package org.tweetyproject.web.services.dung; -import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleAdmissibleReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleCompleteReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleConflictFreeReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleEagerReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleGroundedReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleIdealReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleInitialReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleNaiveReasoner; -import org.tweetyproject.arg.dung.reasoner.SimplePreferredReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleSemiStableReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleStableReasoner; -import org.tweetyproject.arg.dung.reasoner.SimpleStageReasoner; -import org.tweetyproject.arg.dung.reasoner.SolidAdmissibleReasoner; -import org.tweetyproject.arg.dung.reasoner.Stage2Reasoner; -import org.tweetyproject.arg.dung.reasoner.StronglyAdmissibleReasoner; -import org.tweetyproject.arg.dung.reasoner.WeaklyAdmissibleReasoner; -import org.tweetyproject.arg.dung.reasoner.WeaklyCompleteReasoner; -import org.tweetyproject.arg.dung.reasoner.WeaklyGroundedReasoner; -import org.tweetyproject.arg.dung.reasoner.WeaklyPreferredReasoner; +import org.tweetyproject.arg.dung.reasoner.*; +import org.tweetyproject.arg.dung.semantics.Semantics; -/* - * This file is part of "TweetyProject", a collection of Java libraries for - * logical aspects of artificial intelligence and knowledge representation. - * - * TweetyProject is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Copyright 2016 The TweetyProject Team - */ /** * Main factory for retrieving abstract extension reasoners. * - * @author Jonas Klein + * @author Jonas Klein, Lars Bengel */ public abstract class AbstractExtensionReasonerFactory { - - /** An enumeration of all available semantics. */ - public enum Semantics { - /** - * Weakly Admissible semantics - */ - WAD("wad", "Weakly Admissible"), - - /** - * Weakly Complete semantics - */ - WCO("wco", "Weakly Complete"), - - /** - * Weakly Grounded semantics - */ - WGR("wgr", "Weakly Grounded"), - - /** - * Weakly Preferred semantics - */ - WPR("wpr", "Weakly Preferred"), - - /** - * Solid Admissible semantics - */ - SOAD("soad", "Solid Admissible"), - - /** - * Strongly Admissible semantics - */ - SAD("sad", "Strongly Admissible"), - - /** - * Stage semantics - */ - STAGE("stage", "Stage"), - - /** - * Stage2 semantics - */ - STAGE2("stage2", "Stage2"), - - /** - * Semi Stable semantics - */ - SST("SST", "Semi Stable"), - - /** - * Conflict-free semantics - */ - CF("cf", "Conflict-free"), - - /** - * Ideal semantics - */ - ID("id", "Ideal"), - - /** - * Grounded semantics - */ - GR("gr", "Grounded"), - - /** - * Preferred semantics - */ - PR("pr", "Preferred"), - - /** - * Complete semantics - */ - CO("co", "Complete"), - - /** - * Stable semantics - */ - ST("st", "Stable"), - - /** - * Eager semantics - */ - EA("ea", "Eager"), - - /** - * Initial semantics - */ - IN("in", "Initial"), - - /** - * Admissible semantics - */ - AD("ad", "Admissible"), - - /** - * Naive semantics - */ - NA("na", "Naive"); - - /** id */ - public String id; - /** label */ - public String label; - - Semantics(String id, String label) { - this.id = id; - this.label = label; - } - - /** - * - * @param id ID - * @return the semantics - */ - public static Semantics getSemantics(String id) { - for (Semantics m : Semantics.values()) - if (m.id.equals(id)) - return m; - return null; - } - } - /** * Returns an array of all available semantics. * @@ -201,47 +44,6 @@ public static Semantics[] getSemantics() { * @return the requested reasoner. */ public static AbstractExtensionReasoner getReasoner(Semantics sem) { - switch (sem) { - case WAD: - return new WeaklyAdmissibleReasoner(); - case WCO: - return new WeaklyCompleteReasoner(); - case WGR: - return new WeaklyGroundedReasoner(); - case WPR: - return new WeaklyPreferredReasoner(); - case AD: - return new SimpleAdmissibleReasoner(); - case SAD: - return new StronglyAdmissibleReasoner(); - case SOAD: - return new SolidAdmissibleReasoner(); - case STAGE: - return new SimpleStageReasoner(); - case STAGE2: - return new Stage2Reasoner(); - case SST: - return new SimpleSemiStableReasoner(); - case ID: - return new SimpleIdealReasoner(); - case GR: - return new SimpleGroundedReasoner(); - case CO: - return new SimpleCompleteReasoner(); - case ST: - return new SimpleStableReasoner(); - case PR: - return new SimplePreferredReasoner(); - case EA: - return new SimpleEagerReasoner(); - case IN: - return new SimpleInitialReasoner(); - case NA: - return new SimpleNaiveReasoner(); - case CF: - return new SimpleConflictFreeReasoner(); - default: - throw new RuntimeException("No reasoner found for semantics " + sem.toString()); - } + return AbstractExtensionReasoner.getSimpleReasonerForSemantics(sem); } } From 592ccee8f9561808623f7068467a50e7c1253ff9 Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Tue, 26 May 2026 20:15:33 +0200 Subject: [PATCH 04/43] bugfix RequestController --- .../org/tweetyproject/web/services/RequestController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java index 93eddd65e..72a79499c 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java @@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; +import org.tweetyproject.arg.dung.semantics.Semantics; import org.tweetyproject.arg.dung.syntax.Argument; import org.tweetyproject.arg.dung.syntax.Attack; import org.tweetyproject.arg.dung.syntax.DungTheory; @@ -90,7 +91,6 @@ import org.tweetyproject.web.services.dung.DungReasonerPost; import org.tweetyproject.web.services.dung.DungReasonerResponse; import org.tweetyproject.web.services.dung.DungServicesInfoResponse; -import org.tweetyproject.web.services.dung.AbstractExtensionReasonerFactory.Semantics; import org.tweetyproject.web.services.dung.DungReasonerCalleeFactory.Command; import org.tweetyproject.web.services.incmes.InconsistencyGetMeasuresResponse; import org.tweetyproject.web.services.incmes.InconsistencyPost; @@ -413,7 +413,7 @@ public DungServicesInfoResponse getInfo(@RequestBody DungReasonerPost dungPost) Semantics[] sem = AbstractExtensionReasonerFactory.getSemantics(); ArrayList semantics_ids = new ArrayList(); for (Semantics s : sem) { - semantics_ids.add(s.id); + semantics_ids.add(s.abbreviation()); } response.setSemantics(semantics_ids); From b02478f4812a0d5d41b55dfdcc88c90912e84e92 Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Wed, 27 May 2026 13:29:30 +0200 Subject: [PATCH 05/43] added web interface for acceptability reasoner added test for dung web-interface --- .../web/services/RequestController.java | 18 +- .../dung/DungReasonerCalleeFactory.java | 10 +- .../dung/DungReasonerGetCredulousCallee.java | 69 +++++ .../dung/DungReasonerGetSkepticalCallee.java | 69 +++++ .../services/RequestControllerDungTest.java | 274 ++++++++++++++++++ 5 files changed, 428 insertions(+), 12 deletions(-) create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java create mode 100644 org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java index 72a79499c..fb9736671 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/RequestController.java @@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; import org.tweetyproject.arg.bipolar.reasoner.AbstractBipolarExtensionReasoner; +import org.tweetyproject.arg.dung.reasoner.AbstractAcceptabilityReasoner; import org.tweetyproject.arg.dung.semantics.Semantics; import org.tweetyproject.arg.dung.syntax.Argument; import org.tweetyproject.arg.dung.syntax.Attack; @@ -86,11 +87,7 @@ import org.tweetyproject.web.services.delp.DeLPCallee; import org.tweetyproject.web.services.delp.DeLPPost; import org.tweetyproject.web.services.delp.DeLPResponse; -import org.tweetyproject.web.services.dung.AbstractExtensionReasonerFactory; -import org.tweetyproject.web.services.dung.DungReasonerCalleeFactory; -import org.tweetyproject.web.services.dung.DungReasonerPost; -import org.tweetyproject.web.services.dung.DungReasonerResponse; -import org.tweetyproject.web.services.dung.DungServicesInfoResponse; +import org.tweetyproject.web.services.dung.*; import org.tweetyproject.web.services.dung.DungReasonerCalleeFactory.Command; import org.tweetyproject.web.services.incmes.InconsistencyGetMeasuresResponse; import org.tweetyproject.web.services.incmes.InconsistencyPost; @@ -330,20 +327,19 @@ public Response handleRequest( if (dungReasonerPost.getCmd().equals("info")) return (Response) getInfo(dungReasonerPost); - if (dungReasonerPost.getCmd().equals("get_models") || dungReasonerPost.getCmd().equals("get_model")) { + if (dungReasonerPost.getCmd().equals("get_models") || dungReasonerPost.getCmd().equals("get_model") || dungReasonerPost.getCmd().equals("get_credulous") || dungReasonerPost.getCmd().equals("get_skeptical")) { DungTheory dungTheory = Utils.getDungTheory(dungReasonerPost.getNr_of_arguments(), dungReasonerPost.getAttacks()); - - AbstractExtensionReasoner reasoner = AbstractExtensionReasonerFactory.getReasoner( - Semantics.getSemantics(dungReasonerPost.getSemantics())); ExecutorService executor = Executors.newSingleThreadExecutor(); DungReasonerResponse reasonerResponse = new DungReasonerResponse(dungReasonerPost.getCmd(), dungReasonerPost.getEmail(), dungReasonerPost.getNr_of_arguments(), dungReasonerPost.getAttacks(), dungReasonerPost.getSemantics(), dungReasonerPost.getSolver(), null, 0, dungReasonerPost.getUnit_timeout(), "ERRORs"); TimeUnit unit = Utils.getTimoutUnit(dungReasonerPost.getUnit_timeout()); - Callee callee = DungReasonerCalleeFactory.getCallee(Command.getCommand(dungReasonerPost.getCmd()), reasoner, - dungTheory); + AbstractExtensionReasoner reasoner = AbstractExtensionReasonerFactory.getReasoner( + Semantics.getSemantics(dungReasonerPost.getSemantics())); + Callee callee = DungReasonerCalleeFactory.getCallee( + Command.getCommand(dungReasonerPost.getCmd()), reasoner, dungTheory); int user_timeout = Utils.checkUserTimeout(dungReasonerPost.getTimeout(), SERVICES_TIMEOUT_DUNG, unit); try { // handle timeout diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerCalleeFactory.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerCalleeFactory.java index 3efe36f7b..28d51366b 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerCalleeFactory.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerCalleeFactory.java @@ -37,7 +37,11 @@ public enum Command { /** get models */ GET_MODELS("get_models", "Get all models"), /** get model */ - GET_MODEL("get_model", "Get some model"); + GET_MODEL("get_model", "Get some model"), + /** get credulously acceptable arguments */ + GET_CREDULOUS("get_credulous", "Get credulous arguments"), + /** get skeptically acceptable arguments */ + GET_SKEPTICAL("get_skeptical", "Get skeptical arguments"); /** ID of the command */ public String id; @@ -94,6 +98,10 @@ public static Callee getCallee(Command cmd, AbstractExtensionReasoner reasoner, return new DungReasonerGetModelsCallee(reasoner, bbase); case GET_MODEL: return new DungReasonerGetModelCallee(reasoner, bbase); + case GET_CREDULOUS: + return new DungReasonerGetCredulousCallee(reasoner, bbase); + case GET_SKEPTICAL: + return new DungReasonerGetSkepticalCallee(reasoner, bbase); default: throw new RuntimeException("Command not found: " + cmd.toString()); } diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java new file mode 100644 index 000000000..f2c9c45ab --- /dev/null +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java @@ -0,0 +1,69 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.web.services.dung; + +import org.tweetyproject.arg.dung.reasoner.AbstractAcceptabilityReasoner; +import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; +import org.tweetyproject.arg.dung.reasoner.EeeAcceptabilityReasoner; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; +import org.tweetyproject.commons.InferenceMode; +import org.tweetyproject.web.services.Callee; + +import java.util.Collection; + +/** + * The DungReasonerGetModelCallee class represents a callee for obtaining the credulous arguments + * using a specified AbstractExtensionReasoner and DungTheory. + * + * This class extends the Callee class and implements the call() method to execute + * the getModel operation using the provided reasoner and base DungTheory. + * + * @author Lars Bengel + */ +public class DungReasonerGetCredulousCallee extends Callee { + + /** The AbstractExtensionReasoner used for obtaining the model */ + private final AbstractAcceptabilityReasoner reasoner; + + /** The DungTheory on which the getModel operation is performed */ + private final DungTheory bbase; + + /** + * Constructs a new DungReasonerGetModelCallee with the specified reasoner and base DungTheory. + * + * @param reasoner The AbstractAcceptabilityReasoner to be used for obtaining the model + * @param bbase The base DungTheory on which the getModel operation is performed + */ + public DungReasonerGetCredulousCallee(AbstractExtensionReasoner reasoner, DungTheory bbase) { + this.reasoner = new EeeAcceptabilityReasoner(reasoner, InferenceMode.CREDULOUS); + this.bbase = bbase; + } + + /** + * Executes the getModel operation using the specified reasoner and base DungTheory. + * + * @return An Extension representing the obtained model + * @throws Exception If an error occurs during the getModel operation + */ + @Override + public Collection call() throws Exception { + return this.reasoner.getAcceptableArguments(this.bbase); + } +} \ No newline at end of file diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java new file mode 100644 index 000000000..ecf4f40e5 --- /dev/null +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java @@ -0,0 +1,69 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.web.services.dung; + +import org.tweetyproject.arg.dung.reasoner.AbstractAcceptabilityReasoner; +import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; +import org.tweetyproject.arg.dung.reasoner.EeeAcceptabilityReasoner; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungTheory; +import org.tweetyproject.commons.InferenceMode; +import org.tweetyproject.web.services.Callee; + +import java.util.Collection; + +/** + * The DungReasonerGetModelCallee class represents a callee for obtaining the credulous arguments + * using a specified AbstractExtensionReasoner and DungTheory. + * + * This class extends the Callee class and implements the call() method to execute + * the getModel operation using the provided reasoner and base DungTheory. + * + * @author Lars Bengel + */ +public class DungReasonerGetSkepticalCallee extends Callee { + + /** The AbstractExtensionReasoner used for obtaining the model */ + private AbstractAcceptabilityReasoner reasoner; + + /** The DungTheory on which the getModel operation is performed */ + private DungTheory bbase; + + /** + * Constructs a new DungReasonerGetModelCallee with the specified reasoner and base DungTheory. + * + * @param reasoner The AbstractAcceptabilityReasoner to be used for obtaining the model + * @param bbase The base DungTheory on which the getModel operation is performed + */ + public DungReasonerGetSkepticalCallee(AbstractExtensionReasoner reasoner, DungTheory bbase) { + this.reasoner = new EeeAcceptabilityReasoner(reasoner, InferenceMode.SKEPTICAL); + this.bbase = bbase; + } + + /** + * Executes the getModel operation using the specified reasoner and base DungTheory. + * + * @return An Extension representing the obtained model + * @throws Exception If an error occurs during the getModel operation + */ + @Override + public Collection call() throws Exception { + return this.reasoner.getAcceptableArguments(this.bbase); + } +} \ No newline at end of file diff --git a/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java b/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java new file mode 100644 index 000000000..bc0f0746f --- /dev/null +++ b/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java @@ -0,0 +1,274 @@ +/* + * This file is part of "TweetyProject", a collection of Java libraries for + * logical aspects of artificial intelligence and knowledge representation. + * + * TweetyProject is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright 2026 The TweetyProject Team + */ +package org.tweetyproject.web.services; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.tweetyproject.arg.dung.semantics.Semantics; +import org.tweetyproject.web.services.bipolar.BipolarSemantics; + +import java.util.stream.Stream; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + + +/** + * @author Lars Bengel + */ +@SpringBootTest +@AutoConfigureMockMvc +class RequestControllerDungTest { + @Autowired + private MockMvc mvc; + + @Test + public void getInfos() throws Exception { + var post = post("/dung").contentType(MediaType.APPLICATION_JSON) + // language=JSON + .content(""" + { + "cmd": "info" + } + """); + + mvc.perform(post).andExpect(status().isOk()) + // language=JSON + .andExpect(content().json(""" + { + "reply": "info", + "email": null, + "backend_timeout": 600, + "semantics": [ + "CF","ADM","CO","GR","PR","ST","STG","STG2","SST","ID","EA","CF2","SCF2","NA","SAD","IS","UC","UD","SUD","WAD","WCO","WPR","WGR","div" + ], + "commands": [ + "get_models", + "get_model", + "get_credulous", + "get_skeptical" + ] + } + """, true)); + } + + @Test + public void getModels() throws Exception { + var post = post("/dung").contentType(MediaType.APPLICATION_JSON) + // language=JSON + .content(""" + { + "cmd": "get_models", + "nr_of_arguments": 3, + "attacks": [[1, 2],[2,3]], + "semantics": "ADM", + "timeout": 10, + "unit_timeout": "s" + } + """); + + mvc.perform(post).andExpect(status().isOk()) + // language=JSON + .andExpect(content().json(""" + { + "reply": "get_models", + "email": null, + "nr_of_arguments": 3, + "attacks": [ + [ + 1, + 2 + ], + [ + 2, + 3 + ] + ], + "semantics": "ADM", + "solver": null, + "answer": "[{1}, {1,3}, {}]", + "time": 0.0, + "unit_time": "s", + "status": "SUCCESS" + } + """, true)); + } + + @Test + public void getModel() throws Exception { + var post = post("/dung").contentType(MediaType.APPLICATION_JSON) + // language=JSON + .content(""" + { + "cmd": "get_model", + "nr_of_arguments": 3, + "attacks": [[1, 2],[2, 3]], + "semantics": "ADM", + "timeout": 10, + "unit_timeout": "s" + } + """); + + mvc.perform(post).andExpect(status().isOk()) + // language=JSON + .andExpect(content().json(""" + { + "reply": "get_model", + "email": null, + "nr_of_arguments": 3, + "attacks": [ + [ + 1, + 2 + ], + [ + 2, + 3 + ] + ], + "semantics": "ADM", + "solver": null, + "answer": "{}", + "time": 0.0, + "unit_time": "s", + "status": "SUCCESS" + } + """, true)); + } + + @Test + public void getCredulous() throws Exception { + var post = post("/dung").contentType(MediaType.APPLICATION_JSON) + // language=JSON + .content(""" + { + "cmd": "get_credulous", + "nr_of_arguments": 3, + "attacks": [[1, 2],[2,3]], + "semantics": "ADM", + "timeout": 10, + "unit_timeout": "s" + } + """); + + mvc.perform(post).andExpect(status().isOk()) + // language=JSON + .andExpect(content().json(""" + { + "reply": "get_credulous", + "email": null, + "nr_of_arguments": 3, + "attacks": [ + [ + 1, + 2 + ], + [ + 2, + 3 + ] + ], + "semantics": "ADM", + "solver": null, + "answer": "[1, 3]", + "time": 0.0, + "unit_time": "s", + "status": "SUCCESS" + } + """, true)); + } + + @Test + public void getSkeptical() throws Exception { + var post = post("/dung").contentType(MediaType.APPLICATION_JSON) + // language=JSON + .content(""" + { + "cmd": "get_skeptical", + "nr_of_arguments": 3, + "attacks": [[1, 2],[2,3]], + "semantics": "ADM", + "timeout": 10, + "unit_timeout": "s" + } + """); + + mvc.perform(post).andExpect(status().isOk()) + // language=JSON + .andExpect(content().json(""" + { + "reply": "get_skeptical", + "email": null, + "nr_of_arguments": 3, + "attacks": [ + [ + 1, + 2 + ], + [ + 2, + 3 + ] + ], + "semantics": "ADM", + "solver": null, + "answer": "[]", + "time": 0.0, + "unit_time": "s", + "status": "SUCCESS" + } + """, true)); + } + + private static Stream availableSemantics() { + return Stream.of(Semantics.values()); + } + + @ParameterizedTest(name = "semantics {0}") + @MethodSource("availableSemantics") + public void getModelsForSemantics(Semantics semantics) throws Exception { + if (semantics.equals(Semantics.diverse)) return; + var post = post("/dung").contentType(MediaType.APPLICATION_JSON) + // language=JSON + .content(String.format(""" + { + "cmd": "get_models", + "nr_of_arguments": 3, + "attacks": [[1, 2],[2, 3]], + "semantics": "%s", + "timeout": 10, + "unit_timeout": "s" + } + """, semantics.abbreviation())); + + mvc.perform(post).andExpect(status().isOk()) + .andExpect(content().json(""" + { + "status": "SUCCESS" + } + """)); + } +} \ No newline at end of file From 4c5adf304717414e008a73134e3c3aa798c752ce Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Wed, 27 May 2026 14:19:12 +0200 Subject: [PATCH 06/43] bugfix in dung web-interface --- .../web/services/dung/DungReasonerGetCredulousCallee.java | 3 ++- .../web/services/dung/DungReasonerGetSkepticalCallee.java | 3 ++- .../tweetyproject/web/services/RequestControllerDungTest.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java index f2c9c45ab..6b7731fb5 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetCredulousCallee.java @@ -21,6 +21,7 @@ import org.tweetyproject.arg.dung.reasoner.AbstractAcceptabilityReasoner; import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; import org.tweetyproject.arg.dung.reasoner.EeeAcceptabilityReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; import org.tweetyproject.arg.dung.syntax.Argument; import org.tweetyproject.arg.dung.syntax.DungTheory; import org.tweetyproject.commons.InferenceMode; @@ -64,6 +65,6 @@ public DungReasonerGetCredulousCallee(AbstractExtensionReasoner reasoner, DungTh */ @Override public Collection call() throws Exception { - return this.reasoner.getAcceptableArguments(this.bbase); + return new Extension<>(this.reasoner.getAcceptableArguments(this.bbase)); } } \ No newline at end of file diff --git a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java index ecf4f40e5..6cb85df57 100644 --- a/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java +++ b/org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/dung/DungReasonerGetSkepticalCallee.java @@ -21,6 +21,7 @@ import org.tweetyproject.arg.dung.reasoner.AbstractAcceptabilityReasoner; import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner; import org.tweetyproject.arg.dung.reasoner.EeeAcceptabilityReasoner; +import org.tweetyproject.arg.dung.semantics.Extension; import org.tweetyproject.arg.dung.syntax.Argument; import org.tweetyproject.arg.dung.syntax.DungTheory; import org.tweetyproject.commons.InferenceMode; @@ -64,6 +65,6 @@ public DungReasonerGetSkepticalCallee(AbstractExtensionReasoner reasoner, DungTh */ @Override public Collection call() throws Exception { - return this.reasoner.getAcceptableArguments(this.bbase); + return new Extension<>(this.reasoner.getAcceptableArguments(this.bbase)); } } \ No newline at end of file diff --git a/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java b/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java index bc0f0746f..165ccf243 100644 --- a/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java +++ b/org-tweetyproject-web/src/test/java/org/tweetyproject/web/services/RequestControllerDungTest.java @@ -193,7 +193,7 @@ public void getCredulous() throws Exception { ], "semantics": "ADM", "solver": null, - "answer": "[1, 3]", + "answer": "{1,3}", "time": 0.0, "unit_time": "s", "status": "SUCCESS" @@ -235,7 +235,7 @@ public void getSkeptical() throws Exception { ], "semantics": "ADM", "solver": null, - "answer": "[]", + "answer": "{}", "time": 0.0, "unit_time": "s", "status": "SUCCESS" From cf36b9765ff836fca11ae3f14904e0fa4cadc80e Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Fri, 29 May 2026 17:27:26 +0200 Subject: [PATCH 07/43] some experimental QBAF stuff --- .../gradual/AbstractAggregationFunction.java | 16 +++++++ .../gradual/AbstractInfluenceFunction.java | 13 ++++++ .../gradual/LinearInfluenceFunction.java | 14 +++++++ .../gradual/ProductAggregationFunction.java | 18 ++++++++ ...titativeBipolarArgumentationFramework.java | 42 +++++++++++++++++++ .../bipolar/gradual/StrengthAssignment.java | 20 +++++++++ .../gradual/SumAggregationFunction.java | 17 ++++++++ .../syntax/BipolarArgumentationFramework.java | 24 +++++++++++ .../arg/dung/syntax/DungTheory.java | 2 +- 9 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractAggregationFunction.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractInfluenceFunction.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/LinearInfluenceFunction.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/ProductAggregationFunction.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/QuantitativeBipolarArgumentationFramework.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java create mode 100644 org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/SumAggregationFunction.java diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractAggregationFunction.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractAggregationFunction.java new file mode 100644 index 000000000..93d7c45c3 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractAggregationFunction.java @@ -0,0 +1,16 @@ +package org.tweetyproject.arg.bipolar.gradual; + +import org.tweetyproject.commons.util.Pair; +import org.tweetyproject.math.func.SimpleFunction; + +import java.util.List; + +public abstract class AbstractAggregationFunction implements SimpleFunction,List>,Double> { + + @Override + public Double eval(Pair, List> values) { + return eval(values.getFirst(), values.getSecond()); + } + + public abstract Double eval(List attackers, List supporters); +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractInfluenceFunction.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractInfluenceFunction.java new file mode 100644 index 000000000..98d2f2c06 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/AbstractInfluenceFunction.java @@ -0,0 +1,13 @@ +package org.tweetyproject.arg.bipolar.gradual; + +import org.tweetyproject.commons.util.Pair; +import org.tweetyproject.math.func.SimpleFunction; + +public abstract class AbstractInfluenceFunction implements SimpleFunction,Double> { + @Override + public Double eval(Pair x) { + return eval(x.getFirst(), x.getSecond()); + } + + public abstract Double eval(Double base, Double update); +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/LinearInfluenceFunction.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/LinearInfluenceFunction.java new file mode 100644 index 000000000..a5222de0f --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/LinearInfluenceFunction.java @@ -0,0 +1,14 @@ +package org.tweetyproject.arg.bipolar.gradual; + +public class LinearInfluenceFunction extends AbstractInfluenceFunction { + private final Double k; + + public LinearInfluenceFunction(Double k) { + this.k = k; + } + + @Override + public Double eval(Double base, Double update) { + return base + ((base/k) * Math.min(0, update)) + (((1-base)/k) * Math.max(0, update)); + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/ProductAggregationFunction.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/ProductAggregationFunction.java new file mode 100644 index 000000000..79990b4b8 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/ProductAggregationFunction.java @@ -0,0 +1,18 @@ +package org.tweetyproject.arg.bipolar.gradual; + +import java.util.List; + +public class ProductAggregationFunction extends AbstractAggregationFunction { + @Override + public Double eval(List attackers, List supporters) { + double result = 1d; + for (Double a : attackers) { + result *= 1 - a; + } + double tmp = 1d; + for (Double s : supporters) { + tmp *= 1 - s; + } + return result - tmp; + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/QuantitativeBipolarArgumentationFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/QuantitativeBipolarArgumentationFramework.java new file mode 100644 index 000000000..40e070551 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/QuantitativeBipolarArgumentationFramework.java @@ -0,0 +1,42 @@ +package org.tweetyproject.arg.bipolar.gradual; + +import org.tweetyproject.arg.bipolar.syntax.BipolarArgumentationFramework; +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.graphs.Graph; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class QuantitativeBipolarArgumentationFramework extends BipolarArgumentationFramework { + private Map strengths; + + public QuantitativeBipolarArgumentationFramework() { + super(); + this.strengths = new StrengthAssignment(); + } + + public QuantitativeBipolarArgumentationFramework(BipolarArgumentationFramework graph) { + super(graph); + this.strengths = new StrengthAssignment(); + for (Argument arg : this) { + strengths.put(arg, 1d); + } + } + + public Number getStrength(Argument argument) { + return strengths.get(argument); + } + + public List getStrength(List arguments) { + List result = new ArrayList<>(); + for (Argument argument : arguments) { + result.add(getStrength(argument)); + } + return result; + } + + public Number setStrength(Argument argument, Number value) { + return this.strengths.put(argument, value); + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java new file mode 100644 index 000000000..eecc71198 --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java @@ -0,0 +1,20 @@ +package org.tweetyproject.arg.bipolar.gradual; + +import org.tweetyproject.arg.dung.syntax.Argument; +import org.tweetyproject.arg.dung.syntax.DungSignature; +import org.tweetyproject.commons.BeliefBase; +import org.tweetyproject.commons.Signature; + +import java.util.Collection; +import java.util.HashMap; + +public class StrengthAssignment extends HashMap implements BeliefBase { + + @Override + public Signature getMinimalSignature() { + DungSignature sig = new DungSignature(); + for(Argument a: this.keySet()) + sig.add(a); + return sig; + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/SumAggregationFunction.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/SumAggregationFunction.java new file mode 100644 index 000000000..50486b16a --- /dev/null +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/SumAggregationFunction.java @@ -0,0 +1,17 @@ +package org.tweetyproject.arg.bipolar.gradual; + +import java.util.List; + +public class SumAggregationFunction extends AbstractAggregationFunction { + @Override + public Double eval(List attackers, List supporters) { + Double result = 0d; + for (Double x: supporters) { + result += x; + } + for (Double x : attackers) { + result -= x; + } + return result; + } +} diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java index ef8d05749..db9d3948a 100644 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/syntax/BipolarArgumentationFramework.java @@ -26,6 +26,8 @@ import org.tweetyproject.arg.dung.syntax.DungTheory; import org.tweetyproject.commons.util.SetTools; +import org.tweetyproject.graphs.Edge; +import org.tweetyproject.graphs.GeneralEdge; import org.tweetyproject.graphs.Graph; import java.util.*; @@ -53,6 +55,12 @@ public BipolarArgumentationFramework() { super(); } + public BipolarArgumentationFramework(BipolarArgumentationFramework graph) { + this.addAll(graph.getNodes()); + this.addAllAttacks(graph.getAttacks()); + this.addAllSupports(graph.getSupports()); + } + /** * Determines whether 'args' is coherent, i.e., whether there exists no argument that is both (indirectly) supported and attacked (either supported or indirectly) by 'args' * @@ -370,6 +378,22 @@ public boolean addSupport(Argument supporter, Argument supported){ return result; } + /** + * Adds the set of supports to this framework. + * @param c a collection of supports + * @return "true" if this framework has been modified. + */ + public boolean addAllSupports(Collection c){ + boolean result = false; + for(Support att: c) + result |= this.add(att); + return result; + } + + /** + * Returns the set of supports of this framework + * @return the set of supports + */ public Collection getSupports(){ Collection supports = new HashSet<>(); for(Argument a: this) { diff --git a/org-tweetyproject-arg-dung/src/main/java/org/tweetyproject/arg/dung/syntax/DungTheory.java b/org-tweetyproject-arg-dung/src/main/java/org/tweetyproject/arg/dung/syntax/DungTheory.java index f277c55e9..e15511cd0 100644 --- a/org-tweetyproject-arg-dung/src/main/java/org/tweetyproject/arg/dung/syntax/DungTheory.java +++ b/org-tweetyproject-arg-dung/src/main/java/org/tweetyproject/arg/dung/syntax/DungTheory.java @@ -82,7 +82,7 @@ public DungTheory(Graph graph){ if(!children.containsKey(((Edge) e).getNodeA())) children.put(((Edge) e).getNodeA(), new HashSet()); children.get(((Edge) e).getNodeA()).add(((Edge) e).getNodeB()); - } + } } public DungTheory clone() { From c37d45ac5a35673f142536991d107a57a7d3a070 Mon Sep 17 00:00:00 2001 From: larsbengel <77848869+larsbengel@users.noreply.github.com> Date: Fri, 29 May 2026 17:29:06 +0200 Subject: [PATCH 08/43] some experimental QBAF stuff --- .../arg/bipolar/gradual/StrengthAssignment.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java index eecc71198..e92e81d08 100644 --- a/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java +++ b/org-tweetyproject-arg-bipolar/src/main/java/org/tweetyproject/arg/bipolar/gradual/StrengthAssignment.java @@ -5,8 +5,9 @@ import org.tweetyproject.commons.BeliefBase; import org.tweetyproject.commons.Signature; -import java.util.Collection; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; public class StrengthAssignment extends HashMap implements BeliefBase { @@ -17,4 +18,12 @@ public Signature getMinimalSignature() { sig.add(a); return sig; } + + public List get(List keys) { + List result = new ArrayList<>(); + for (Argument key : keys) { + result.add(this.get(key)); + } + return result; + } } From 51eeb0b66e4f363d45cb58c6d642743ea200e7ea Mon Sep 17 00:00:00 2001 From: Lars Bengel Date: Sun, 31 May 2026 16:42:14 +0200 Subject: [PATCH 09/43] updated reasoner for bipolar argumentation --- org-tweetyproject-web/pom.xml | 6 + .../web/services/RequestController.java | 98 ++++- .../AbstractRankingReasonerFactory.java | 63 +++ .../RankingReasonerCalleeFactory.java | 98 +++++ .../RankingReasonerGetModelCallee.java | 37 ++ .../rankings/RankingReasonerPost.java | 196 +++++++++ .../rankings/RankingReasonerResponse.java | 411 ++++++++++++++++++ .../rankings/RankingServicesInfoResponse.java | 244 +++++++++++ 8 files changed, 1152 insertions(+), 1 deletion(-) create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/rankings/AbstractRankingReasonerFactory.java create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/rankings/RankingReasonerCalleeFactory.java create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/rankings/RankingReasonerGetModelCallee.java create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/rankings/RankingReasonerPost.java create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/rankings/RankingReasonerResponse.java create mode 100644 org-tweetyproject-web/src/main/java/org/tweetyproject/web/services/rankings/RankingServicesInfoResponse.java diff --git a/org-tweetyproject-web/pom.xml b/org-tweetyproject-web/pom.xml index 3a4d7e771..329dac729 100644 --- a/org-tweetyproject-web/pom.xml +++ b/org-tweetyproject-web/pom.xml @@ -144,6 +144,12 @@ bipolar 1.30-SNAPSHOT + + org.tweetyproject.arg + rankings + 1.30 + compile +