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

net.automatalib.util.automata.ads.SplitTree Maven / Gradle / Ivy

Go to download

This artifact provides various common utility operations for analyzing and manipulating automata and graphs, such as traversal, minimization and copying.

There is a newer version: 0.11.0
Show newest version
/* Copyright (C) 2013-2019 TU Dortmund
 * This file is part of AutomataLib, http://www.automatalib.net/.
 *
 * 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 net.automatalib.util.automata.ads;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import net.automatalib.words.Word;

/**
 * Utility class originally used by the algorithm of {@link LeeYannakakis} but utilized by other ADS computations as
 * well.
 *
 * @param 
 *         (hypothesis) state type
 * @param 
 *         input alphabet type
 * @param 
 *         output alphabet type
 *
 * @author frohme
 */
class SplitTree {

    private final Map> successors;
    private final Map mapping;
    private final Set partition;

    private Word sequence;

    SplitTree(final Set partition) {
        this.partition = partition;

        this.successors = new HashMap<>();
        this.mapping = new HashMap<>();
        this.sequence = Word.epsilon();
    }

    public Map> getSuccessors() {
        return successors;
    }

    public Map getMapping() {
        return mapping;
    }

    public Set getPartition() {
        return partition;
    }

    public Word getSequence() {
        return sequence;
    }

    public void setSequence(Word sequence) {
        this.sequence = sequence;
    }

    public Optional> findLowestSubsetNode(final Set nodes) {

        for (final SplitTree st : successors.values()) {
            final Optional> candidate = st.findLowestSubsetNode(nodes);

            if (candidate.isPresent()) {
                return candidate;
            }
        }

        if (this.partition.containsAll(nodes)) {
            return Optional.of(this);
        }

        return Optional.empty();
    }

    @Override
    public String toString() {
        return String.format("[states: %s, seq=%s]", this.partition.toString(), this.sequence.toString());
    }
}