1 /* 2 * Copyright 2013 University of Glasgow. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package broadwick.montecarlo.markovchain.observer; 17 18 import broadwick.montecarlo.markovchain.MarkovChainMonteCarlo; 19 import lombok.EqualsAndHashCode; 20 21 /** 22 * Implementing classes are used to take measurements during a Monte Carlo run. 23 */ 24 @EqualsAndHashCode 25 @SuppressWarnings("squid:S1210") 26 public abstract class MarkovChainObserver implements Comparable<MarkovChainObserver> { 27 28 /** 29 * Creates an observer dedicated to one Monte Carlo process. 30 * @param mc the Monte Carlo process 31 */ 32 public MarkovChainObserver(final MarkovChainMonteCarlo mc) { 33 this.monteCarlo = mc; 34 } 35 36 @Override 37 public final int compareTo(final MarkovChainObserver o) { 38 // We really are only interested in determining if the Observers are equal so that a tree based table 39 // can distinguish between observers. Order does NOT matter so we return 1 if the objects are not equal. 40 if (this == o) { 41 return 0; 42 } 43 return 1; 44 } 45 46 /** 47 * Gets called when the simulation has started after the initialization and before the termination condition is 48 * checked the first time. 49 */ 50 public abstract void started(); 51 52 /** 53 * Gets called when the simulation has taken a step, whether or not the step is accepted or not or if the 54 * burn-in period has elapsed. 55 */ 56 public abstract void step(); 57 58 59 /** 60 * Gets called by the Monte Carlo process after the burnin period has elaspsed. 61 */ 62 public abstract void takeMeasurements(); 63 64 /** 65 * Gets called when a simulation has finished, directly after the termination check. 66 */ 67 public abstract void finished(); 68 @SuppressWarnings("PMD.UnusedPrivateField") 69 protected final MarkovChainMonteCarlo monteCarlo; 70 }