Debian Codegraph @

src/dr/inference/mcmcmc/MCMCMCRunner.java

raw symbols SCIP
1 /*
2 * MCMCMCRunner.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.inference.mcmcmc;
27
28 import dr.inference.markovchain.MarkovChain;
29
30 /**
31 * @author rambaut
32 * Date: Jan 5, 2005
33 * Time: 5:05:59 PM
34 */
35 public class MCMCMCRunner extends Thread {
36
37 public MCMCMCRunner(MarkovChain markovChain, long length, long totalLength, boolean disableCoerce) {
38
39 this.markovChain = markovChain;
40 this.length = length;
41 this.totalLength = totalLength;
42 this.disableCoerce = disableCoerce;
43 }
44
45 public void run() {
46 long i = 0;
47 while (i < totalLength) {
48 markovChain.runChain(length, disableCoerce/*, 0*/);
49
50 i += length;
51
52 chainDone();
53
54 if (i < totalLength) {
55 while (isChainDone()) {
56 try {
57 synchronized(this) {
58 wait();
59 }
60 } catch (InterruptedException e) {
61 // continue...
62 }
63 }
64 }
65 }
66 }
67
68 private synchronized void chainDone() {
69 chainDone = true;
70 }
71
72 public synchronized boolean isChainDone() {
73 return chainDone;
74 }
75
76 public synchronized void continueChain() {
77 this.chainDone = false;
78 notify();
79 }
80
81
82 private final MarkovChain markovChain;
83 private final long length;
84 private final long totalLength;
85 private final boolean disableCoerce;
86
87 private boolean chainDone;
88 }
89