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

net.automatalib.util.minimizer.TransitionLabel 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.minimizer;

import java.util.BitSet;
import java.util.Collection;

import net.automatalib.commons.smartcollections.AbstractBasicLinkedListEntry;
import net.automatalib.commons.smartcollections.IntrusiveLinkedList;
import net.automatalib.commons.smartcollections.UnorderedCollection;

/**
 * Represents a transition label in the automaton model the minimizer operates on.
 *
 * @param 
 *         state class.
 * @param 
 *         edge property class.
 *
 * @author Malte Isberner
 */
final class TransitionLabel extends AbstractBasicLinkedListEntry, TransitionLabel> {

    // The original label
    private final EP originalLabel;
    // The list of states that have an outgoing transition
    // with this label, considered in the respective step.
    private final UnorderedCollection> list = new UnorderedCollection<>();
    // Keeps track of the states that are contained in the above list.
    private final BitSet setContents = new BitSet();

    // The bucket, used for the weak sort of the algorithm.
    private final IntrusiveLinkedList> bucket = new IntrusiveLinkedList<>();

    /**
     * Constructor.
     *
     * @param originalLabel
     *         the original transition label.
     */
    TransitionLabel(EP originalLabel) {
        this.originalLabel = originalLabel;
    }

    /**
     * Retrieves the bucket.
     *
     * @return the bucket.
     */
    public IntrusiveLinkedList> getBucket() {
        return bucket;
    }

    /**
     * Adds a state to this label's bucket.
     *
     * @param state
     *         the state to be added to the bucket.
     *
     * @return true if this is the first state to be added to the bucket, false otherwise.
     */
    public boolean addToBucket(State state) {
        boolean first = false;

        if (bucket.isEmpty()) {
            first = true;
        }
        bucket.pushBack(state);

        return first;
    }

    /**
     * Retrieves the original transition label.
     *
     * @return the original transition label.
     */
    public EP getOriginalLabel() {
        return originalLabel;
    }

    /**
     * Clears the state set associated with this label.
     */
    public void clearSet() {
        setContents.clear();
        list.quickClear();
    }

    /**
     * Adds a state to the associated state set. Note that a state can be in the sets of various transition labels.
     *
     * @param state
     *         the state to be added.
     *
     * @return true if this was the first state to be added to the set, false otherwise.
     */
    public boolean addToSet(State state) {
        boolean first = list.isEmpty();
        if (first || !setContents.get(state.getId())) {
            list.add(state);
            setContents.set(state.getId());
        }
        return first;
    }

    /**
     * Retrieves the state set associated with this transition label. Note that despite the fact that no {@link
     * java.util.Set} is returned, each state is guaranteed to occur at most once.
     *
     * @return the state set of this label.
     */
    public Collection> getSet() {
        return list;
    }

    @Override
    public String toString() {
        return originalLabel.toString();
    }

    @Override
    public TransitionLabel getElement() {
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy