//============================================================================== // // Copyright (c) 2002- // Authors: // * Dave Parker (University of Oxford) // * Christian von Essen (Verimag, Grenoble) // //------------------------------------------------------------------------------ // // This file is part of PRISM. // // PRISM is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // PRISM 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with PRISM; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //============================================================================== package explicit; import java.util.HashSet; import prism.PrismUtils; import strat.MDStrategy; /** * Base class for explicit-state representations of an MDP. */ public abstract class MDPExplicit extends ModelExplicit implements MDP { // Accessors (for Model) @Override public String infoString() { String s = ""; s += numStates + " states (" + getNumInitialStates() + " initial)"; s += ", " + getNumTransitions() + " transitions"; s += ", " + getNumChoices() + " choices"; s += ", dist max/avg = " + getMaxNumChoices() + "/" + PrismUtils.formatDouble2dp(((double) getNumChoices()) / numStates); return s; } @Override public String infoStringTable() { String s = ""; s += "States: " + numStates + " (" + getNumInitialStates() + " initial)\n"; s += "Transitions: " + getNumTransitions() + "\n"; s += "Choices: " + getNumChoices() + "\n"; s += "Max/avg: " + getMaxNumChoices() + "/" + PrismUtils.formatDouble2dp(((double) getNumChoices()) / numStates) + "\n"; return s; } // Accessors (for NondetModel) @Override public boolean areAllChoiceActionsUnique() { HashSet sActions = new HashSet(); for (int s = 0; s < numStates; s++) { int n = getNumChoices(s); if (n > 1) { sActions.clear(); for (int i = 0; i < n; i++) { if (!sActions.add(getAction(s, i))) { return false; } } } } return true; } // Accessors (for MDP) @Override public Model constructInducedModel(MDStrategy strat) { return new DTMCFromMDPAndMDStrategy(this, strat); } }