Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public DeductiveKnowledgeBase next() {
return kb;
}


/**
* Description missing
* @param <C> Description missing
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* Copyright 2025 The TweetyProject Team <http://tweetyproject.org/contact/>
*/
package org.tweetyproject.arg.dung.examples;

import org.tweetyproject.arg.dung.semantics.Semantics;
import org.tweetyproject.arg.dung.serialisability.util.AigSerialisationPlotter;
import org.tweetyproject.arg.dung.syntax.Argument;
import org.tweetyproject.arg.dung.syntax.DungTheory;
import org.tweetyproject.arg.dung.util.DefaultDungTheoryGenerator;
import org.tweetyproject.graphs.util.AigGraphPlotter;

import java.io.IOException;
import java.net.URISyntaxException;

/**
* Example Usage of the {@link AigGraphPlotter} which renders a given graph via html in the webbrowser
*
* @author Lars Bengel
*/
public class GraphPlotterExample {
public static void main(String[] args) throws URISyntaxException, IOException {
DungTheory theory = new DefaultDungTheoryGenerator(9, 0.2).next();

// Initialize plotter for argumentation framework
AigGraphPlotter<DungTheory,Argument> plotter = new AigGraphPlotter<>(theory);

// Set options for rendering of the graph, eg
plotter.setLinkDeletable(false);

// Render graph
plotter.show();

// Plot an argumentation framework and its serialisation wrt. complete semantics
//AigSerialisationPlotter.showSerialisation(theory, Semantics.CO);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.tweetyproject.arg.dung.serialisability.semantics;

import org.tweetyproject.arg.dung.reasoner.AbstractExtensionReasoner;
import org.tweetyproject.arg.dung.reasoner.SerialisedExtensionReasoner;
import org.tweetyproject.arg.dung.semantics.Extension;
import org.tweetyproject.arg.dung.semantics.Semantics;
Expand Down Expand Up @@ -46,6 +45,8 @@ public class SerialisationGraph implements Graph<SerialisationState> {
/** explicit storage of children for each node */
private Map<SerialisationState, Set<SerialisationState>> children = new HashMap<>();

private Collection<GeneralEdge<SerialisationState>> edges = new HashSet<>();


/**
* Construct a serialisation graph for the given argumentation framework and serialisation reasoner
Expand All @@ -65,7 +66,7 @@ public SerialisationGraph(DungTheory theory, SerialisedExtensionReasoner reasone
DungTheory reduct = theory.getReduct(ext);
SerialisationState node = new SerialisationState(reduct, new Extension<>(ext), reasoner.isTerminal(reduct, ext));
this.add(node);
this.add(new DirectedEdge<>(predecessor, node));
this.add(new DirectedEdge<>(predecessor, node, set.toString()));
predecessor = node;
}
predecessor = root;
Expand All @@ -84,7 +85,7 @@ public SerialisationGraph(DungTheory theory, Semantics semantics) {
/** Pretty print of the graph.
* @return the pretty print of the graph.
*/
public String prettyPrint(){
public String prettyPrint() {
StringBuilder output = new StringBuilder();
for (SerialisationState serialisationNode : this)
output.append("node(").append(serialisationNode.toString()).append(").\n");
Expand Down Expand Up @@ -162,6 +163,7 @@ public boolean add(GeneralEdge<SerialisationState> edge) {
result |= this.add(e.getNodeB());
result |= children.get(e.getNodeA()).add(e.getNodeB());
result |= parents.get(e.getNodeB()).add(e.getNodeA());
result |= edges.add(e);
return result;
}

Expand Down Expand Up @@ -190,19 +192,18 @@ public boolean areAdjacent(SerialisationState a, SerialisationState b) {

@Override
public GeneralEdge<SerialisationState> getEdge(SerialisationState a, SerialisationState b) {
return new DirectedEdge<>(a, b);
for (GeneralEdge<SerialisationState> edge : edges) {
DirectedEdge<SerialisationState> e = (DirectedEdge<SerialisationState>) edge;
if (e.getNodeA().equals(a) && e.getNodeB().equals(b)) {
return new DirectedEdge<>(e.getNodeA(), e.getNodeB(), e.getLabel());
}
}
return null;
}

@Override
public Collection<? extends GeneralEdge<? extends SerialisationState>> getEdges() {
Collection<DirectedEdge<SerialisationState>> edges = new HashSet<>();
for (SerialisationState node: this) {
for (SerialisationState succ: this.children.get(node)) {
DirectedEdge<SerialisationState> edge = new DirectedEdge<>(node, succ);
edges.add(edge);
}
}
return edges;
return new HashSet<>(this.edges);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.tweetyproject.arg.dung.serialisability.util;

import org.tweetyproject.arg.dung.reasoner.SerialisedExtensionReasoner;
import org.tweetyproject.arg.dung.semantics.Extension;
import org.tweetyproject.arg.dung.semantics.Semantics;
import org.tweetyproject.arg.dung.serialisability.semantics.SerialisationGraph;
import org.tweetyproject.arg.dung.serialisability.semantics.SerialisationState;
import org.tweetyproject.arg.dung.syntax.Argument;
import org.tweetyproject.arg.dung.syntax.DungTheory;
import org.tweetyproject.graphs.util.AigGraphPlotter;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


public abstract class AigSerialisationPlotter extends AigGraphPlotter<DungTheory,Argument> {

public AigSerialisationPlotter(DungTheory graph) {
super(graph);
}

public static void showSerialisation(DungTheory theory, Semantics semantics) {
SerialisedExtensionReasoner reasoner = new SerialisedExtensionReasoner(semantics);

SerialisationGraph serialisation = reasoner.getSerialisationGraph(theory);
SerialisationState root = new SerialisationState(theory, new Extension<>(), reasoner.isTerminal(theory, new Extension<>()));

AigGraphPlotter<DungTheory,Argument> plotter1 = new AigGraphPlotter<>(theory);
AigGraphPlotter<SerialisationGraph,SerialisationState> plotter2 = new AigGraphPlotter<>(serialisation);
plotter2.makeLeveled(root);

Path outputPath = Paths.get("index.html");
try {
String template = Files.readString(Paths.get(getResource("aiggraph/serialisation.template")));
String output = String.format(template,
plotter1.write(), plotter2.write(),
getResource("aiggraph/favicon.ico"), getResource("aiggraph/style.css"),
getResource("aiggraph/load-mathjax.js"), getResource("aiggraph/graph-component.js")
);

Files.writeString(outputPath, output);

// show graph in web browser
File htmlFile = new File("index.html");
Desktop.getDesktop().browse(htmlFile.toURI());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Loading