use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.
the class ParameterSpecGroupSet method validate.
// ////////
// MISC //
// ////////
public void validate() throws ParameterSpecGroupSetValidationException {
Set<Object> paramKeys = new HashSet<Object>();
Set<Integer> specHashCodes = new HashSet<Integer>();
for (ParameterSpecGroup group : this) {
for (Object paramKey : group.keySet()) {
ParameterSpecification spec = group.get(paramKey);
// Validate
if (specHashCodes.contains(spec.objectHashCode())) {
throw new ParameterSpecGroupSetValidationException("Multiple parameter groups contain the same specification object '" + spec.getClass().getSimpleName() + "@" + spec.hashCode() + "'. A specification object should be added to only a single group because it is permitted to save state between calls.");
}
if (group != defaultValueGroup && paramKeys.contains(paramKey)) {
throw new ParameterSpecGroupSetValidationException("Multiple parameter groups contain a specification for the parameter '" + paramKey + "'.");
}
// Save
specHashCodes.add(spec.objectHashCode());
if (group != defaultValueGroup) {
// Default value parameters do not prevent
paramKeys.add(paramKey);
// other groups from having the same parameters.
}
// Max values
int max = spec.getMaxValues();
if (max != -1 && group.getRunCount() > max) {
throw new ParameterSpecGroupSetValidationException("Specification for parameter '" + paramKey + "' has a maximum run count less than the run count of its group.");
}
}
}
}
use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.
the class CompositeParameterSpecification method getValue.
// /////////
// VALUE //
// /////////
@Override
public Object getValue(int groupRunCount, int idx) {
int total = 0;
for (SubSpecification sspec : subSpecs) {
int howMany = sspec.howMany;
ParameterSpecification spec = sspec.spec;
if (idx < total + howMany) {
return spec.getValue(howMany, idx - total);
}
total += howMany;
}
throw new RuntimeException("Composite parameter specification is misconfigured.");
}
use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.
the class ParameterSpecGroupPanel method initPanel.
private void initPanel(ParameterSpecGroup group) {
for (Object key : group.keySet()) {
ParameterSpecification spec = group.get(key);
String keyStr = key.toString();
String[] path = keyStr.split("\\.");
List<ParameterDomain> d = new ArrayList<ParameterDomain>();
for (int i = 0; i < path.length - 1; i++) {
String seg = path[i];
d.add(new ParameterDomain(seg));
}
// , dv, desc,icon);
Parameter param = new Parameter(path[path.length - 1]);
ParameterBundle bundle = new ParameterBundle(d, param);
addParam(bundle, spec);
}
}
use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.
the class ParameterSpecGroupPanel method addParam.
public ParameterSpecPanel addParam(ParameterBundle bundle, ParameterSpecification useThisSpec) {
ParameterSpecification spec;
GroupType type = (GroupType) cboGroupType.getSelectedItem();
Object defaultValue = bundle.getParameter().getDefaultValue();
if (useThisSpec == null) {
spec = chooseDefaultSpecification(type, defaultValue);
} else {
spec = useThisSpec;
}
final ParameterSpecPanel pnlSpec = new ParameterSpecPanel(bundle, spec, readOnly);
pnlSpec.addRemoveListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
pnlParams.remove(specPanels.get(pnlSpec));
specPanels.remove(pnlSpec);
pnlParams.updateUI();
fireChangeNotifier();
}
});
pnlSpec.addEditListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
ParameterSpecification spec = pnlSpec.getSpecification();
GroupType type = (GroupType) cboGroupType.getSelectedItem();
switch(type) {
case LATIN_HYPERCUBE:
if (!(spec instanceof EvenSpacingParameterSpecification)) {
cboGroupType.setSelectedItem(GroupType.MIXED);
}
break;
case MONTE_CARLO:
if (!(spec instanceof EvenSpacingParameterSpecification)) {
cboGroupType.setSelectedItem(GroupType.MIXED);
}
break;
}
fireChangeNotifier();
}
});
JPanel cont = Lay.p(pnlSpec, "eb=10t,opaque=false");
specPanels.put(pnlSpec, cont);
pnlParams.add(cont);
updateUI();
fireChangeNotifier();
return pnlSpec;
}
use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.
the class ParameterSpecGroupSet method addGroupParamsToParamSet.
private void addGroupParamsToParamSet(ParameterSet set, ParameterSpecGroup group, int idx, Set<Object> skipDVGroupParams) {
for (Object paramKey : group.keySet()) {
// are contained in other non-default value groups.
if (group == defaultValueGroup && skipDVGroupParams.contains(paramKey)) {
continue;
}
ParameterSpecification paramSpec = group.get(paramKey);
Object value;
if (!paramSpec.isStable() && group.isEnforceStability(paramKey)) {
// Save and reload values from cache.
if (group.isInStabilityCache(paramKey, idx)) {
value = group.getFromStabilityCache(paramKey, idx);
} else {
value = paramSpec.getValue(group.getRunCount(), idx);
group.putInStabilityCache(paramKey, idx, value);
}
} else {
value = paramSpec.getValue(group.getRunCount(), idx);
}
set.put(paramKey, value);
}
}
Aggregations