View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
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 p3j.simulation;
17  
18  import p3j.simulation.assignments.exhaustive.ExhaustiveParamAssignmentGenFactory;
19  import p3j.simulation.assignments.random.RandomParamAssignmentGenFactory;
20  
21  /**
22   * Simple enumeration to easily summarise all execution modes.
23   * 
24   * @author Christina Bohk
25   * @author Roland Ewald
26   * 
27   */
28  public enum ExecutionMode {
29  
30  	/** Draw parameter instances at random. */
31  	MONTE_CARLO,
32  
33  	/** Draw parameter instances in highest-overall-probability order. */
34  	EXHAUSTIVE;
35  
36  	/** The string representation of the monte-carlo method. */
37  	public static final String DESC_MONTE_CARLO = "Monte-Carlo";
38  
39  	/** The string representation of the exhaustive method. */
40  	public static final String DESC_EXHAUSTIVE = "Exhaustive";
41  
42  	@Override
43  	public String toString() {
44  		switch (this) {
45  		case MONTE_CARLO:
46  			return DESC_MONTE_CARLO;
47  		case EXHAUSTIVE:
48  			return DESC_EXHAUSTIVE;
49  		default:
50  			return "unknown";
51  		}
52  	}
53  
54  	/**
55  	 * Gets the execution mode associated with the given text.
56  	 * 
57  	 * @param text
58  	 *          the text (retrievable via toString())
59  	 * @return the execution mode associated with the given text, null if none was
60  	 *         found
61  	 */
62  	public static ExecutionMode forString(String text) {
63  		if (text.equals(DESC_EXHAUSTIVE)) {
64  			return EXHAUSTIVE;
65  		} else if (text.equals(DESC_MONTE_CARLO)) {
66  			return MONTE_CARLO;
67  		}
68  		return null;
69  	}
70  
71  	/**
72  	 * Gets the parameter assignment generator factory name for a given execution
73  	 * name.
74  	 * 
75  	 * @return the parameter assignment generator factory name
76  	 */
77  	public String getFactoryName() {
78  		switch (this) {
79  		case MONTE_CARLO:
80  			return RandomParamAssignmentGenFactory.class.getName();
81  		case EXHAUSTIVE:
82  			return ExhaustiveParamAssignmentGenFactory.class.getName();
83  		default:
84  			return "";
85  		}
86  	}
87  
88  }