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

net.automatalib.util.automata.fsa.DFAs 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.automata.fsa;

import java.util.Collection;

import net.automatalib.automata.fsa.DFA;
import net.automatalib.automata.fsa.MutableDFA;
import net.automatalib.automata.fsa.impl.FastDFA;
import net.automatalib.commons.util.mappings.Mapping;
import net.automatalib.commons.util.mappings.Mappings;
import net.automatalib.ts.acceptors.DeterministicAcceptorTS;
import net.automatalib.util.automata.copy.AutomatonCopy;
import net.automatalib.util.ts.acceptors.AcceptanceCombiner;
import net.automatalib.util.ts.acceptors.Acceptors;
import net.automatalib.words.Alphabet;


public abstract class DFAs {
	
	private static final Mapping NEGATE
		= new Mapping() {
			@Override
			public Boolean get(Boolean elem) {
				return !elem;
			}
	};
	
	public static >
	A combine(DFA dfa1, DFA dfa2,
			Collection inputs,
			A out,
			AcceptanceCombiner combiner) {
		DeterministicAcceptorTS acc
			= Acceptors.combine(dfa1, dfa2, combiner);
		
		AutomatonCopy.copyUniversalDfs(acc, inputs, out, Mappings.identity());
		return out;
	}
	
	
	
	public static  FastDFA combine(DFA dfa1, DFA dfa2,
			Alphabet inputAlphabet,
			AcceptanceCombiner combiner) {
		return combine(dfa1, dfa2, inputAlphabet, new FastDFA(inputAlphabet), combiner);
	}
	
	public static > 
	A and(DFA dfa1, DFA dfa2,
			Collection inputs, A out) {
		return combine(dfa1, dfa2, inputs, out, AcceptanceCombiner.AND);
	}
	
	public static 
	FastDFA and(DFA dfa1, DFA dfa2, Alphabet inputAlphabet) {
		return and(dfa1, dfa2, inputAlphabet, new FastDFA(inputAlphabet));
	}
	
	public static >
	A or(DFA dfa1, DFA dfa2,
			Collection inputs, A out) {
		return combine(dfa1, dfa2, inputs, out, AcceptanceCombiner.OR);
	}
	
	public static 
	FastDFA or(DFA dfa1, DFA dfa2, Alphabet inputAlphabet) {
		return or(dfa1, dfa2, inputAlphabet, new FastDFA(inputAlphabet));
	}
	
	public static >
	A xor(DFA dfa1, DFA dfa2,
			Collection inputs, A out) {
		return combine(dfa1, dfa2, inputs, out, AcceptanceCombiner.XOR);
	}
	
	public static 
	FastDFA xor(DFA dfa1, DFA dfa2,
			Alphabet inputAlphabet) {
		return xor(dfa1, dfa2, inputAlphabet, new FastDFA(inputAlphabet));
	}
	
	public static >
	A equiv(DFA dfa1, DFA dfa2,
			Collection inputs, A out) {
		return combine(dfa1, dfa2, inputs, out, AcceptanceCombiner.EQUIV);
	}
	public static  FastDFA equiv(DFA dfa1, DFA dfa2,
			Alphabet inputAlphabet) {
		return equiv(dfa1, dfa2, inputAlphabet, new FastDFA(inputAlphabet));
	}
	
	public static >
	A impl(DFA dfa1, DFA dfa2,
			Collection inputs, A out) {
		return combine(dfa1, dfa2, inputs, out, AcceptanceCombiner.IMPL);
	}
	
	public static  FastDFA impl(DFA dfa1, DFA dfa2,
			Alphabet inputAlphabet) {
		return impl(dfa1, dfa2, inputAlphabet, new FastDFA(inputAlphabet));
	}
	
	public static > A complement(DFA dfa,
			Collection inputs, A out) {
		AutomatonCopy.copyUniversalDfs(dfa, inputs, out, NEGATE, Mappings.nullMapping());
		return out;
	}
	
	public static  FastDFA complement(DFA dfa,
			Alphabet inputAlphabet) {
		return complement(dfa, inputAlphabet, new FastDFA(inputAlphabet));
	}
	
	
	


}