ai.libs.jaicore.planning.hierarchical.algorithms.forwarddecomposition.graphgenerators.tfd.TFDNodeInfoGenerator Maven / Gradle / Ivy
package ai.libs.jaicore.planning.hierarchical.algorithms.forwarddecomposition.graphgenerators.tfd;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import ai.libs.jaicore.graphvisualizer.plugin.nodeinfo.NodeInfoGenerator;
import ai.libs.jaicore.logic.fol.structure.Literal;
import ai.libs.jaicore.planning.core.Action;
public class TFDNodeInfoGenerator implements NodeInfoGenerator> {
private static final String HTML_LI_OPEN = "";
private static final String HTML_LI_CLOSE = " ";
private static final String HTML_UL_OPEN = "";
private static final String HTML_UL_CLOSE = "
";
@Override
public String generateInfoForNode(final List path) {
TFDNode head = path.get(path.size() - 1);
StringBuilder sb = new StringBuilder();
if (head.getAppliedMethodInstance() != null || head.getAppliedAction() != null) {
sb.append("Applied Instance
");
sb.append(head.getAppliedMethodInstance() != null ? head.getAppliedMethodInstance().getEncoding() : head.getAppliedAction().getEncoding());
}
sb.append("Remaining Tasks
");
sb.append(HTML_UL_OPEN);
for (Literal l : head.getRemainingTasks()) {
sb.append(HTML_LI_OPEN);
sb.append(l);
sb.append(HTML_LI_CLOSE);
}
sb.append(HTML_UL_CLOSE);
sb.append("Current State
");
List monomStrings = head.getProblem().getState().stream().sorted((l1, l2) -> l1.getPropertyName().compareTo(l2.getPropertyName())).map(Literal::toString).collect(Collectors.toList());
sb.append(HTML_UL_OPEN);
for (String literal : monomStrings) {
sb.append(HTML_LI_OPEN);
sb.append(literal);
sb.append(HTML_LI_CLOSE);
}
sb.append(HTML_UL_CLOSE);
sb.append("Current Plan
");
sb.append(HTML_UL_OPEN);
for (Action a : path.stream().map(TFDNode::getAppliedAction).filter(Objects::nonNull).collect(Collectors.toList())) {
sb.append(HTML_LI_OPEN);
sb.append(a.getEncoding());
sb.append(HTML_LI_CLOSE);
}
sb.append(HTML_UL_CLOSE);
return sb.toString();
}
}