DragonBreath An Optimization Engine based on Constraint Programming and Local Search |
[HOMEPAGE] -> [Documentation] -> [Interfaces to the Engine] -> [Java] -> [Variables]
To use variables, at least the following classes must be imported:
import com.ai_center.dragonbreath.GlobalSearchControl; import com.ai_center.dragonbreath.constraintgraph.Variable;
Variables are created for a specific GlobalSearchControl object and can be given a user-defined name. The creation is done by the following member functions of the GlobalSearchControl object:
Variable createVariable(String name); Variable createVariable(String name, int x, int y);
The x and y parameters of the second function only have an effect if the graphics are turned on. The graphical object representing the variable will then be centered at the given (x, y) coordinates. If the graphics are turned on and no coordinates are specified for a variable, i.e., the first function is applied, a default coordinate of (200, 100) will be used.
Examples, using a GlobalSearchControl object gsc:
Variable varA = gsc.createVariable("a");
Variable varB = gsc.createVariable("b", 60, 350);
Per default, a new variable takes a value of 0.0.
Engine Developers Only: If these functions are to be called from inside the engine, you should use the following versions for speed optimization:
Variable createVariable_internal(String name); Variable createVariable_internal(String name, int x, int y);
WARNING: No consistency checks will be applied in these versions if Registry.SAFE_MODE is set to false!
At any time, a variable can be set to a specific value using the following member functions of the related GlobalSearchControl object:
void setVariable(Variable variable, long value); void setVariable(Variable variable, double value);
Examples, using the GlobalSearchControl object gsc and the previously defined Variable objects varA and varB:
gsc.setVariable(varA, -5);
gsc.setVariable(varB, 14.6);
Engine Developers Only: If these functions are to be called from inside the engine, you should use the following versions for speed optimization:
void setVariable_internal(Variable variable, long value); void setVariable_internal(Variable variable, double value);
WARNING: No consistency checks will be applied in these versions if Registry.SAFE_MODE is set to false!
The following member functions of a Variable object can be used to retrieve information:
String getName(); double value(); boolean isInteger(); double lowerBound(); double upperBound(); boolean isConstant(); int compare(java.lang.Object o1, java.lang.Object o2); String toString();
The getName() function returns the name that was given to the createVariable() function. The value() function returns the variable's current value. isInteger() returns true if any IntegerConstraints are connected to the variable. lowerBound() and upperBound() return bounds imposed by connected RangeConstraints, and the isConstant() function returns true if the variable's lower bound equals its upper bound. The compare() function implements java.util.Comparator. The output function toString() returns a description of the form name = value.
Additionally, the following functions are provided by the related GlobalSearchControl object:
String getVariableDescription(Variable variable); StringBuffer getVariableDescriptions();
The getVariableDescription() function returns the same as the specified variable's toString(). getVariableDescriptions() returns the descriptions of all variables of the GlobalSearchControl object, separated by newlines.
Here are some examples, using the GlobalSearchControl object gsc and the Variable objects varA and varB from before:
System.out.println(varA.getName());
System.out.println(varA.value());
System.out.println(varA.isInteger());
System.out.println(varA.lowerBound());
System.out.println(varA.upperBound());
System.out.println(varA.isConstant());
System.out.println(varA.compare(varA, varB));
System.out.println(varA);
System.out.println(gsc.getVariableDescription(varB));
System.out.println(gsc.getVariableDescriptions());
The execution results in:
a
-5.0
false
-Infinity
Infinity
false
-1
a = -5.0
b = 14.6
b = 14.6
a = -5.0
Note that a variable to be deleted must be disconnected from any constraints before. The variable can then be deleted using the following member function of the related GlobalSearchControl object:
void deleteVariable(Variable variable);
Example, using the GlobalSearchControl object gsc and the previously defined Variable object varA:
gsc.deleteVariable(varA);
Engine Developers Only: If this function is to be called from inside the engine, you should use the following version for speed optimization:
void deleteVariable_internal(Variable variable);
WARNING: No consistency checks will be applied in this version if Registry.SAFE_MODE is set to false!
[HOMEPAGE] -> [Documentation] -> [Interfaces to the Engine] -> [Java] -> [Variables]
For questions, comments or suggestions, please visit our feedback forum.
Last update:
August 22, 2002 by Alexander Nareyek