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

de.learnlib.algorithm.observationpack.vpa.hypothesis.DTree 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.List;
import java.util.function.Predicate;

import de.learnlib.datastructure.discriminationtree.model.AbstractDiscriminationTree;
import de.learnlib.oracle.MembershipOracle;
import de.learnlib.query.DefaultQuery;
import net.automatalib.word.Word;

/**
 * @param 
 *         input symbol type
 */
public class DTree extends AbstractDiscriminationTree, I, Boolean, HypLoc, DTNode> {

    public DTree(MembershipOracle oracle) {
        super(new DTNode<>(null, false), oracle);
    }

    @Override
    public DTNode sift(DTNode start, Word prefix) {
        return sift(start, prefix, true);
    }

    @Override
    public List> sift(List> starts, List> prefixes) {
        return sift(starts, prefixes, true);
    }

    public DTNode sift(DTNode start, Word as, boolean hard) {
        return super.sift(start, as, getSiftPredicate(hard));
    }

    public List> sift(List> starts, List> prefixes, boolean hard) {
        return super.sift(starts, prefixes, getSiftPredicate(hard));
    }

    @Override
    protected DefaultQuery buildQuery(DTNode node, Word prefix) {
        final ContextPair discr = node.getDiscriminator();
        final Word completePrefix = discr.getPrefix().concat(prefix);
        return new DefaultQuery<>(completePrefix, node.getDiscriminator().getSuffix());
    }

    private static  Predicate> getSiftPredicate(boolean hard) {
        return n -> n.isInner() && (hard || !n.isTemp());
    }

}