001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of LearnLib, http://www.learnlib.de/.
003 * 
004 * LearnLib 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 * LearnLib 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 LearnLib; if not, see
015 * <http://www.gnu.de/documents/lgpl.en.html>.
016 */
017package de.learnlib.algorithms.lstargeneric.closing;
018
019import java.util.ArrayList;
020import java.util.List;
021import java.util.Random;
022
023import de.learnlib.algorithms.lstargeneric.table.ObservationTable;
024import de.learnlib.algorithms.lstargeneric.table.Row;
025import de.learnlib.api.MembershipOracle;
026
027public class CloseRandomStrategy implements ClosingStrategy<Object,Object> {
028        
029        private final Random random;
030        
031        public CloseRandomStrategy() {
032                this(new Random());
033        }
034        
035        public CloseRandomStrategy(Random random) {
036                this.random = random;
037        }
038
039        @Override
040        public <RI,RO>
041        List<Row<RI>> selectClosingRows(List<List<Row<RI>>> unclosedClasses,
042                        ObservationTable<RI,RO> table, MembershipOracle<RI,RO> oracle) {
043                List<Row<RI>> result = new ArrayList<>(unclosedClasses.size());
044                
045                for(List<Row<RI>> clazz : unclosedClasses) {
046                        int card = clazz.size();
047                        result.add(clazz.get(random.nextInt(card)));
048                }
049                
050                return result;
051        }
052        
053}