All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.learnlib.algorithm.observationpack.vpa.hypothesis.DTNode Maven / Gradle / Ivy

Go to download

This artifact provides the implementation of the VPA adaption of the Observation-Pack learning algorithm as discussed in the PhD thesis "Foundations of Active Automata Learning: An Algorithmic Perspective" (https://dx.doi.org/10.17877/DE290R-16359) by Malte Isberner.

The newest version!
/* Copyright (C) 2013-2023 TU Dortmund
 * This file is part of LearnLib, http://www.learnlib.de/.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.learnlib.algorithm.observationpack.vpa.hypothesis;

import java.util.Iterator;
import java.util.Map;

import de.learnlib.datastructure.discriminationtree.iterators.DiscriminationTreeIterators;
import de.learnlib.datastructure.discriminationtree.model.AbstractTemporaryIntrusiveDTNode;
import de.learnlib.datastructure.discriminationtree.model.BooleanMap;
import de.learnlib.datastructure.list.IntrusiveListElem;

/**
 * @param 
 *         input symbol type
 */
public class DTNode
        extends AbstractTemporaryIntrusiveDTNode, Boolean, HypLoc, TransList, DTNode>
        implements IntrusiveListElem> {

    private final TransList nonTreeIncoming = new TransList<>();

    public DTNode(DTNode parent, boolean parentLabel) {
        this(parent, parentLabel, null);
    }

    public DTNode(DTNode parent, boolean parentLabel, HypLoc data) {
        super(parent, parentLabel, data);
    }

    public void updateIncoming() {
        for (AbstractHypTrans inc : nonTreeIncoming) {
            assert !inc.isTree();
            inc.setNonTreeTarget(this);
        }
    }

    public void split(ContextPair discriminator, Map> children) {
        assert isLeaf();
        assert children.values().stream().allMatch(c -> c.parent == this);
        assert children.entrySet().stream().allMatch(e -> e.getKey().equals(e.getValue().getParentOutcome()));

        this.discriminator = discriminator;
        this.children = children;
    }

    public Iterator> subtreeLocsIterator() {
        return DiscriminationTreeIterators.transformingLeafIterator(this, DTNode::getData);
    }

    public Iterable> subtreeLocations() {
        return this::subtreeLocsIterator;
    }

    public void addIncoming(AbstractHypTrans trans) {
        nonTreeIncoming.add(trans);
    }

    public TransList getIncoming() {
        return nonTreeIncoming;
    }

    @Override
    protected Map> createChildMap() {
        return new BooleanMap<>();
    }

    @Override
    protected DTNode createChild(Boolean outcome, HypLoc data) {
        return new DTNode<>(this, outcome, data);
    }
}