001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * <http://www.gnu.de/documents/lgpl.en.html>. 016 */ 017 018package de.learnlib.examples.dfa; 019 020import net.automatalib.automata.fsa.DFA; 021import net.automatalib.automata.fsa.MutableDFA; 022import net.automatalib.automata.fsa.impl.compact.CompactDFA; 023import net.automatalib.words.Alphabet; 024import net.automatalib.words.impl.FastAlphabet; 025import net.automatalib.words.impl.Symbol; 026 027/** 028 * This class implements a sad love story - DFA style. 029 * 030 * @author Maik Merten <maikmerten@googlemail.com> 031 */ 032public class ExamplePaulAndMary { 033 034 private static final class InstanceHolder { 035 public static final DFA<?,Symbol> INSTANCE; 036 037 static { 038 INSTANCE = constructMachine(); 039 } 040 } 041 042 public static final Symbol IN_PAUL = new Symbol("Paul"); 043 public static final Symbol IN_LOVES = new Symbol("loves"); 044 public static final Symbol IN_MARY = new Symbol("Mary"); 045 046 private static final Alphabet<Symbol> ALPHABET = new FastAlphabet<>(IN_PAUL, IN_LOVES, IN_MARY); 047 048 049 public static DFA<?,Symbol> getInstance() { 050 return InstanceHolder.INSTANCE; 051 } 052 053 public static Alphabet<Symbol> getInputAlphabet() { 054 return ALPHABET; 055 } 056 057 058 /** 059 * Construct and return a machine representation of this example 060 * 061 * @return machine instance of the example 062 */ 063 public static CompactDFA<Symbol> constructMachine() { 064 return constructMachine(new CompactDFA<>(ALPHABET)); 065 } 066 067 public static <A extends MutableDFA<S,? super Symbol>,S> 068 A constructMachine(A dfa) { 069 S s0 = dfa.addInitialState(false), 070 s1 = dfa.addState(false), 071 s2 = dfa.addState(false), 072 s3 = dfa.addState(true), 073 s4 = dfa.addState(false); 074 075 dfa.addTransition(s0, IN_PAUL, s1); 076 dfa.addTransition(s0, IN_LOVES, s4); 077 dfa.addTransition(s0, IN_MARY, s4); 078 079 dfa.addTransition(s1, IN_PAUL, s4); 080 dfa.addTransition(s1, IN_LOVES, s2); 081 dfa.addTransition(s1, IN_MARY, s4); 082 083 dfa.addTransition(s2, IN_PAUL, s4); 084 dfa.addTransition(s2, IN_LOVES, s4); 085 dfa.addTransition(s2, IN_MARY, s3); 086 087 dfa.addTransition(s3, IN_PAUL, s4); 088 dfa.addTransition(s3, IN_LOVES, s4); 089 dfa.addTransition(s3, IN_MARY, s4); 090 091 dfa.addTransition(s4, IN_PAUL, s4); 092 dfa.addTransition(s4, IN_LOVES, s4); 093 dfa.addTransition(s4, IN_MARY, s4); 094 095 return dfa; 096 } 097}