use of cbit.vcell.opt.Constraint in project vcell by virtualcell.
the class OptXmlWriter method getConstraintDescriptionXML.
public static Element getConstraintDescriptionXML(OptimizationSpec optimizationSpec) {
Element constraintDescriptionElement = new Element(OptXmlTags.ConstraintDescription_Tag);
Constraint[] constraints = optimizationSpec.getConstraints();
for (int i = 0; i < constraints.length; i++) {
Element constraintElement = new Element(OptXmlTags.Constraint_Tag);
if (constraints[i].getConstraintType().equals(ConstraintType.LinearEquality)) {
constraintElement.setAttribute(OptXmlTags.ConstraintType_Attr, OptXmlTags.ConstraintType_Attr_LinearEquality);
} else if (constraints[i].getConstraintType().equals(ConstraintType.LinearInequality)) {
constraintElement.setAttribute(OptXmlTags.ConstraintType_Attr, OptXmlTags.ConstraintType_Attr_LinearInequality);
} else if (constraints[i].getConstraintType().equals(ConstraintType.NonlinearEquality)) {
constraintElement.setAttribute(OptXmlTags.ConstraintType_Attr, OptXmlTags.ConstraintType_Attr_NonlinearEquality);
} else if (constraints[i].getConstraintType().equals(ConstraintType.NonlinearInequality)) {
constraintElement.setAttribute(OptXmlTags.ConstraintType_Attr, OptXmlTags.ConstraintType_Attr_NonlinearInequality);
} else {
throw new RuntimeException("unsupported constraint type " + constraints[i].getConstraintType());
}
constraintElement.addContent(constraints[i].getExpression().infix());
constraintDescriptionElement.addContent(constraintElement);
}
return constraintDescriptionElement;
}
use of cbit.vcell.opt.Constraint in project vcell by virtualcell.
the class OptUtils method getAugmentedObjectiveFunction.
/**
* Insert the method's description here.
* Creation date: (8/4/2005 3:26:14 PM)
* @return function.AugmentedObjectiveFunction
* @param optSpec cbit.vcell.opt.OptimizationSpec
* @param power double
* @param mu double
*/
public static AugmentedObjectiveFunction getAugmentedObjectiveFunction(OptimizationSpec optSpec, double power, double mu, OptSolverCallbacks optSolverCallbacks) throws cbit.vcell.parser.ExpressionException {
Parameter[] parameters = optSpec.getParameters();
//
// build symbol list
//
String[] origSymbols = optSpec.getParameterNames();
String[] scaledSymbols = optSpec.getScaledParameterNames();
double[] scaleFactors = optSpec.getScaleFactors();
ScalarFunction objFunction = null;
if (optSpec.getObjectiveFunction() instanceof ExplicitObjectiveFunction) {
ExplicitObjectiveFunction explicitObjectiveFunction = (ExplicitObjectiveFunction) optSpec.getObjectiveFunction();
//
// build objective function
//
objFunction = new DynamicScalarFunction(explicitObjectiveFunction.getScaledExpression(origSymbols, scaledSymbols, scaleFactors), scaledSymbols);
} else if (optSpec.getObjectiveFunction() instanceof ImplicitObjectiveFunction) {
ImplicitObjectiveFunction implicitObjectiveFunction = (ImplicitObjectiveFunction) optSpec.getObjectiveFunction();
//
// build objective function
//
objFunction = implicitObjectiveFunction.getObjectiveFunction();
} else if (optSpec.getObjectiveFunction() instanceof ExplicitFitObjectiveFunction) {
ExplicitFitObjectiveFunction explicitFitObjectiveFunction = (ExplicitFitObjectiveFunction) optSpec.getObjectiveFunction();
objFunction = explicitFitObjectiveFunction.getScalarFunction();
} else {
throw new RuntimeException("unsupported objective function type : " + optSpec.getObjectiveFunction().getClass().getName());
}
//
// build equality and inequality constraints
//
DynamicVectorFunction equalityConstraints = null;
DynamicVectorFunction inequalityConstraints = null;
Constraint[] constraints = optSpec.getConstraints();
Vector equExpList = new Vector();
Vector inequExpList = new Vector();
//
for (int i = 0; i < constraints.length; i++) {
ConstraintType type = constraints[i].getConstraintType();
if (type.equals(ConstraintType.LinearEquality) || type.equals(ConstraintType.NonlinearEquality)) {
equExpList.add(constraints[i].getExpression());
} else {
inequExpList.add(constraints[i].getExpression());
}
}
//
for (int i = 0; i < parameters.length; i++) {
if (!Double.isInfinite(parameters[i].getLowerBound())) {
inequExpList.add(new Expression("(" + parameters[i].getLowerBound() + " - " + parameters[i].getName() + ")/" + scaleFactors[i]));
}
if (!Double.isInfinite(parameters[i].getUpperBound())) {
inequExpList.add(new Expression("(" + parameters[i].getName() + " - " + parameters[i].getUpperBound() + ")/" + scaleFactors[i]));
}
}
if (equExpList.size() > 0) {
Expression[] exps = (Expression[]) org.vcell.util.BeanUtils.getArray(equExpList, Expression.class);
equalityConstraints = new DynamicVectorFunction(exps, origSymbols);
}
if (inequExpList.size() > 0) {
Expression[] exps = (Expression[]) org.vcell.util.BeanUtils.getArray(inequExpList, Expression.class);
inequalityConstraints = new DynamicVectorFunction(exps, origSymbols);
}
AugmentedObjectiveFunction augmentedObjFunc = new AugmentedObjectiveFunction(objFunction, equalityConstraints, inequalityConstraints, power, mu, optSolverCallbacks);
return augmentedObjFunc;
}
Aggregations