| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.beauti.options; |
| 27 |
|
| 28 |
import dr.app.beauti.types.OperatorType; |
| 29 |
|
| 30 |
import java.io.Serializable; |
| 31 |
import java.util.Map; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class Operator implements Serializable { |
| 39 |
|
| 40 |
private static final long serialVersionUID = -1165043783660638155L; |
| 41 |
private String prefix = null; |
| 42 |
|
| 43 |
|
| 44 |
private String baseName; |
| 45 |
private final String description; |
| 46 |
private final OperatorType operatorType; |
| 47 |
private Parameter parameter1; |
| 48 |
private Parameter parameter2; |
| 49 |
private final PartitionOptions options; |
| 50 |
private final String tag; |
| 51 |
|
| 52 |
|
| 53 |
private double tuning; |
| 54 |
private double weight; |
| 55 |
private boolean tuningEdited = false; |
| 56 |
private boolean isUsed = true; |
| 57 |
|
| 58 |
private boolean autoOptimize = true; |
| 59 |
|
| 60 |
private String idref; |
| 61 |
|
| 62 |
public static class Builder { |
| 63 |
|
| 64 |
private final String baseName; |
| 65 |
private final String description; |
| 66 |
private final Parameter parameter1; |
| 67 |
|
| 68 |
private final OperatorType operatorType; |
| 69 |
private final double tuning; |
| 70 |
private final double weight; |
| 71 |
|
| 72 |
|
| 73 |
private Parameter parameter2 = null; |
| 74 |
private PartitionOptions options = null; |
| 75 |
private String tag = null; |
| 76 |
private String idref = null; |
| 77 |
|
| 78 |
private boolean autoOptimize = true; |
| 79 |
|
| 80 |
public Builder(String name, String description, Parameter parameter, OperatorType type, double tuning, double weight) { |
| 81 |
this.baseName = name; |
| 82 |
this.description = description; |
| 83 |
this.parameter1 = parameter; |
| 84 |
this.operatorType = type; |
| 85 |
this.tuning = tuning; |
| 86 |
this.weight = weight; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
public Builder parameter2(Parameter parameter2) { |
| 91 |
this.parameter2 = parameter2; |
| 92 |
return this; |
| 93 |
} |
| 94 |
|
| 95 |
public Builder partitionOptions(PartitionOptions options) { |
| 96 |
this.options = options; |
| 97 |
return this; |
| 98 |
} |
| 99 |
|
| 100 |
public Builder tag(String tag) { |
| 101 |
this.tag = tag; |
| 102 |
return this; |
| 103 |
} |
| 104 |
|
| 105 |
public Builder idref(String idref) { |
| 106 |
this.idref = idref; |
| 107 |
return this; |
| 108 |
} |
| 109 |
|
| 110 |
public Builder autoOptimize(boolean autoOptimize) { |
| 111 |
this.autoOptimize = autoOptimize; |
| 112 |
return this; |
| 113 |
} |
| 114 |
|
| 115 |
public Operator build() { |
| 116 |
return new Operator(this); |
| 117 |
} |
| 118 |
|
| 119 |
public Operator build(Map<String, Operator> map) { |
| 120 |
final Operator operator = new Operator(this); |
| 121 |
map.put(baseName, operator); |
| 122 |
return operator; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
private Operator(Builder builder) { |
| 127 |
baseName = builder.baseName; |
| 128 |
description = builder.description; |
| 129 |
parameter1 = builder.parameter1; |
| 130 |
operatorType = builder.operatorType; |
| 131 |
tuning = builder.tuning; |
| 132 |
weight = builder.weight; |
| 133 |
parameter2 = builder.parameter2; |
| 134 |
options = builder.options; |
| 135 |
tag = builder.tag; |
| 136 |
idref = builder.idref; |
| 137 |
isUsed = true; |
| 138 |
tuningEdited = false; |
| 139 |
autoOptimize = builder.autoOptimize; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
public String getDescription() { |
| 144 |
if (description == null || description.length() == 0) { |
| 145 |
String prefix = ""; |
| 146 |
if (operatorType == OperatorType.SCALE || operatorType == OperatorType.SCALE_ALL) { |
| 147 |
prefix = "Scales the "; |
| 148 |
} else if (operatorType == OperatorType.RANDOM_WALK) { |
| 149 |
prefix = "A random-walk on the "; |
| 150 |
} |
| 151 |
return prefix + parameter1.getDescription(); |
| 152 |
} else { |
| 153 |
return description; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
public boolean isTunable() { |
| 158 |
return tuning > 0; |
| 159 |
} |
| 160 |
|
| 161 |
public String getTag() { |
| 162 |
return tag; |
| 163 |
} |
| 164 |
|
| 165 |
public String getIdref() { |
| 166 |
return idref; |
| 167 |
} |
| 168 |
|
| 169 |
public double getWeight() { |
| 170 |
return weight; |
| 171 |
} |
| 172 |
|
| 173 |
public void setWeight(double weight) { |
| 174 |
this.weight = weight; |
| 175 |
} |
| 176 |
|
| 177 |
public double getTuning() { |
| 178 |
return tuning; |
| 179 |
} |
| 180 |
|
| 181 |
public void setTuning(double tuning) { |
| 182 |
this.tuning = tuning; |
| 183 |
tuningEdited = true; |
| 184 |
} |
| 185 |
|
| 186 |
public boolean isTuningEdited() { |
| 187 |
return tuningEdited; |
| 188 |
} |
| 189 |
|
| 190 |
public OperatorType getOperatorType() { |
| 191 |
return operatorType; |
| 192 |
} |
| 193 |
|
| 194 |
public boolean isUsed() { |
| 195 |
return isParameterFixed() ? false : isUsed; |
| 196 |
} |
| 197 |
|
| 198 |
public void setUsed(boolean used) { |
| 199 |
this.isUsed = used; |
| 200 |
} |
| 201 |
|
| 202 |
public boolean isAutoOptimize() { |
| 203 |
return autoOptimize; |
| 204 |
} |
| 205 |
|
| 206 |
public boolean isParameterFixed() { |
| 207 |
return parameter1 != null && parameter1.isFixed(); |
| 208 |
} |
| 209 |
|
| 210 |
public Parameter getParameter1() { |
| 211 |
return parameter1; |
| 212 |
} |
| 213 |
|
| 214 |
public void setParameter1(Parameter parameter1) { |
| 215 |
this.parameter1 = parameter1; |
| 216 |
} |
| 217 |
|
| 218 |
public Parameter getParameter2() { |
| 219 |
return parameter2; |
| 220 |
} |
| 221 |
|
| 222 |
public void setParameter2(Parameter parameter2) { |
| 223 |
this.parameter2 = parameter2; |
| 224 |
} |
| 225 |
|
| 226 |
public void setPrefix(String prefix) { |
| 227 |
this.prefix = prefix; |
| 228 |
} |
| 229 |
|
| 230 |
public PartitionOptions getOptions() { |
| 231 |
return options; |
| 232 |
} |
| 233 |
|
| 234 |
public String getPrefix() { |
| 235 |
return prefix; |
| 236 |
} |
| 237 |
|
| 238 |
public String getName() { |
| 239 |
String name = baseName; |
| 240 |
if (prefix != null) { |
| 241 |
name = prefix + baseName; |
| 242 |
} |
| 243 |
return name; |
| 244 |
} |
| 245 |
|
| 246 |
public void setName(String name) { |
| 247 |
this.baseName = name; |
| 248 |
} |
| 249 |
|
| 250 |
public String getBaseName() { |
| 251 |
return baseName; |
| 252 |
} |
| 253 |
|
| 254 |
} |