DragonBreath An Optimization Engine based on Constraint Programming and Local Search |
[HOMEPAGE] -> [Documentation] -> [Interfaces to the Engine] -> [Java] -> [Costs] -> [Cost Mappings]
To use cost mappings, at least the following classes must be imported:
import com.ai_center.dragonbreath.GlobalSearchControl; import com.ai_center.dragonbreath.Registry; import com.ai_center.dragonbreath.costs.CostMapping;
New cost mappings are created for a specific GlobalSearchControl object and can optionally be given a user-defined name. The creation is done by the following member functions of the GlobalSearchControl object:
CostMapping createCostMapping(int costMappingID); CostMapping createCostMapping(int costMappingID, String name);
The costMappingID represents one of the available cost mappings that are managed by the Registry:
The default BigDecimal factor used by both cost mapping types is 1.0. However, this general default can be overridden by defaults for specific constraint types. This is done by a FactorCostMapping object's following function:
void setDefaultFactor(int constraintID, BigDecimal defaultFactor);
The constraintID is one of the Registry's constants for constraints. Here is an example, using a GlobalSearchControl object gsc:
CostMapping costMapping =
gsc.createCostMapping(Registry.FACTOR_BINARY_COST_MAPPING);
((FactorCostMapping) costMapping).setDefaultFactor(Registry.SUM_CONSTRAINT,
new BigDecimal("2.5"));
Default factors are not considered if the createConstraint or addCosts functions are called with a specific cost mapping parameter/option (which represents the factor for the factor cost mappings).
If no specific cost mapping has been provided for the initialization of the related GlobalSearchControl object, a default cost mapping of type com.ai_center.dragonbreath.costs.FactorCostMapping was created automatically.
New cost mapping classes written by the user can also easily be integrated. A new cost mapping class is registered by calling the following function of the Registry class (a new cost mapping ID is returned):
int registerCostMapping(String classPathString, String name);
The classPathString must include the full path and class name, and the name defines a default name that is used as default name if no specific name is given for creating instances later on. The returned cost mapping ID can then be used to create cost mapping instances.
Here is a registration example, using a GlobalSearchControl object gsc:
int SQR_COSTMAPPING =
Registry.registerCostMapping("mydirectory.mysubdirectory.SquareFactorCostMapping",
"Squared Factorized Cost Mapping");
CostMapping costMapping =
gsc.createCostMapping(SQR_COSTMAPPING, "My cost mapping");
The name of a cost mapping can be retrieved by its following member functions (equivalent results):
String getName(); String toString();
Examples, using a GlobalSearchControl object gsc:
CostMapping costMapping1 =
gsc.createCostMapping(Registry.FACTOR_COST_MAPPING);
System.out.println(costMapping1);
CostMapping costMapping2 =
gsc.createCostMapping(Registry.FACTOR_BINARY_COST_MAPPING, "My second cost mapping");
System.out.println(costMapping2.getName());
The execution results in:
Factorized Cost Mapping
My second cost mapping
To select a specific cost mapping to be applied to cost additions (or to be adopted as default for cost function creations), apply the following member function of the related GlobalSearchControl object:
void selectCostMapping(CostMapping costMapping);
Engine Developers Only: If this function is to be called from inside the engine, you should use the following version for speed optimization:
void selectCostMapping_internal(CostMapping costMapping);
WARNING: No consistency checks will be applied in this version if Registry.SAFE_MODE is set to false!
The cost mapping currently selected can be retrieved by the following member function of the related GlobalSearchControl object:
CostMapping getSelectedCostMapping();
To select the default cost mapping of the related GlobalSearchControl object, use its following function:
void selectDefaultCostMapping();
The default cost mapping of the related GlobalSearchControl object can be retrieved by its following function:
CostMapping getDefaultCostMapping();
When a cost function is created, the selected cost mapping at this time gets the function's default mapping. However, when costs are added (e.g., by constraint creation), this default is usually abandoned in favor of the currently selected cost mapping. To indicate that a cost function's default mapping is to be applied, use the related GlobalSearchControl object's following function:
void selectCostMappingOfCostFunction();
Once the selectCostMapping or selectDefaultCostMapping function is called after this, the cost function defaults get abandoned again in favor of the currently selected cost mapping. Here is an example that shows the active cost mapping selections:
GlobalSearchControl gsc = new GlobalSearchControl(0);
CostMapping costMapping =
gsc.createCostMapping(Registry.FACTOR_BINARY_COST_MAPPING, "My cost mapping");
/* Default cost mapping is still selected */
gsc.selectCostMapping(costMapping);
/* The new cost mapping is now selected */
CostFunction costFunction = gsc.createCostFunction("My cost function");
gsc.selectDefaultCostMapping();
/* Default cost mapping is selected again */
gsc.selectCostMappingOfCostFunction();
/* Default cost mapping is still selected */
gsc.selectCostFunction(costFunction);
/* The new cost mapping is now selected */
[HOMEPAGE] -> [Documentation] -> [Interfaces to the Engine] -> [Java] -> [Costs] -> [Cost Mappings]
For questions, comments or suggestions, please visit our feedback forum.
Last update:
August 29, 2002 by Alexander Nareyek