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

net.automatalib.util.minimizer.MinimizationResult 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 TU Dortmund
 * This file is part of AutomataLib, http://www.automatalib.net/.
 * 
 * AutomataLib is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 3.0 as published by the Free Software Foundation.
 * 
 * AutomataLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with AutomataLib; if not, see
 * http://www.gnu.de/documents/lgpl.en.html.
 */
package net.automatalib.util.minimizer;

import java.util.Collection;

import net.automatalib.commons.util.mappings.Mapping;



/**
 * The result structure of a minimization process. The result of a minimization
 * process is a partition on the original set of states. This is represented
 * by a collection of {@link Block}s containing states that are equivalent
 * and thus can be merged.
 * 

* Since all states in a block are equivalent (and thus especially have the * same set of outgoing edge labels), a minimized automaton can be created * from this partition by instantiating a state for each block. The edges * between those states are created in the following way: For each state/block, * an original state is chosen arbitrarily from this block. The edges are * created according to the edges of this state, only that they point to * the states representing the blocks the respective target states belong to * (using {@link #getBlockForState(Object)}). *

* The blocks in the result partition are guaranteed to have contiguous IDs * (see {@link Block#getId()}), starting at 0. This allows an efficient * construction of the resulting automaton. *

* A more convenient way to obtain a representation of the resulting, minimized * automaton is using a {@link BlockAutomaton}. * * @author Malte Isberner * * @param state class. * @param transition label class. */ public final class MinimizationResult { // the state storage, used for retrieving the State records // for an original state private final Mapping> stateStorage; // the blocks in the final partition private final Collection> blocks; /** * Constructor. * @param stateStorage the state storage, * @param blocks the final partition. */ MinimizationResult(Mapping> stateStorage, Collection> blocks) { this.stateStorage = stateStorage; this.blocks = blocks; } /** * Retrieves the number of blocks in the final partition. * @return the number of blocks. */ public int getNumBlocks() { return blocks.size(); } /** * Retrieves all blocks in the final partition. * @return the final partition. */ public Collection> getBlocks() { return blocks; } /** * Retrieves all (original) states in a block. * @param block the block. * @return a collection containing all original states in this * block. */ public static Collection getStatesInBlock(Block block) { return new OriginalStateCollection(block.getStates()); } /** * Chooses a representative (i.e., an arbitrary element of the * set of states) from a block. * @param block the block. * @return an arbitrary element of the state set of the given block. */ public S getRepresentative(Block block) { return block.getStates().choose().getOriginalState(); } /** * Retrieves the block to which a given original state belongs. * @param origState the original state. * @return the corresponding block. */ public Block getBlockForState(S origState) { State state = stateStorage.get(origState); return state.getBlock(); } /** * Creates a {@link BlockAutomaton} using this results structure. * @return the block automaton. */ public BlockAutomaton asBlockAutomaton() { return new BlockAutomaton(this); } }