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

de.learnlib.algorithms.lstargeneric.closing.ClosingStrategies Maven / Gradle / Ivy

There is a newer version: 0.12.0
Show newest version
/* Copyright (C) 2013 TU Dortmund
 * This file is part of LearnLib, http://www.learnlib.de/.
 * 
 * LearnLib 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.
 * 
 * LearnLib 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 LearnLib; if not, see
 * .
 */
package de.learnlib.algorithms.lstargeneric.closing;

import java.util.ArrayList;
import java.util.List;

import net.automatalib.commons.util.comparison.CmpUtil;
import net.automatalib.words.Alphabet;

import de.learnlib.algorithms.lstargeneric.table.ObservationTable;
import de.learnlib.algorithms.lstargeneric.table.Row;
import de.learnlib.api.MembershipOracle;

/**
 * Collection of predefined observation table closing strategies.
 * 
 * @see ClosingStrategy
 * 
 * @author Malte Isberner 
 *
 */
public class ClosingStrategies {
	
	/**
	 * Closing strategy that randomly selects one representative row to close from each equivalence
	 * class.
	 */
	public static final ClosingStrategy CLOSE_RANDOM
		= new CloseRandomStrategy();
	
	/**
	 * Closing strategy that selects the first row from each equivalence class as representative.
	 */
	public static final ClosingStrategy CLOSE_FIRST
		= new ClosingStrategy() {
			@Override
			public  List> selectClosingRows(
					List>> unclosedClasses,
					ObservationTable table,
					MembershipOracle oracle) {
				List> result = new ArrayList>(unclosedClasses.size());
				for(List> clazz : unclosedClasses)
					result.add(clazz.get(0));
				return result;
			}
	};
	
	/**
	 * Closing strategy that selects the shortest row of each equivalence class (more precisely:
	 * a row which's prefix has minimal length in the respective class) as representative. 
	 */
	public static final ClosingStrategy CLOSE_SHORTEST
		= new ClosingStrategy() {
			@Override
			public  List> selectClosingRows(
					List>> unclosedClasses,
					ObservationTable table,
					MembershipOracle oracle) {
				
				List> result = new ArrayList>();
				for(List> clazz : unclosedClasses) {
					Row shortest = null;
					int shortestLen = Integer.MAX_VALUE;
					for(Row row : clazz) {
						int prefixLen = row.getPrefix().length();
						if(shortest == null || prefixLen < shortestLen) {
							shortest = row;
							shortestLen = prefixLen;
						}
					}
					result.add(shortest);
				}
				return result;
			}
	};
	
	/**
	 * Closing strategy that selects the lexicographically minimal row (wrt. its prefix)
	 * of each equivalence class as representative.
	 */
	public static final ClosingStrategy CLOSE_LEX_MIN
		= new ClosingStrategy() {
			@Override
			public  List> selectClosingRows(
					List>> unclosedClasses,
					ObservationTable table,
					MembershipOracle oracle) {
				List> result = new ArrayList>(unclosedClasses.size());
				Alphabet alphabet = table.getInputAlphabet();
				for(List> clazz : unclosedClasses) {
					Row lexMin = null;
					for(Row row : clazz) {
						if(lexMin == null)
							lexMin = row;
						else if(CmpUtil.lexCompare(row.getPrefix(), lexMin.getPrefix(), alphabet) < 0)
							lexMin = row;
					}
					result.add(lexMin);
				}
				return result;
			}
	};

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy