DragonBreath An Optimization Engine based on Constraint Programming and Local Search |
[HOMEPAGE] -> [Documentation] -> [Interfaces to the Engine] -> [Java] -> [Costs]
Here is an example for quick loop-ups ( - see subsections above for detailed descriptions - ):
GlobalSearchControl gsc = new GlobalSearchControl(0);
/* Defining a cost mapping */
CostMapping costMapping =
gsc.createCostMapping(Registry.FACTOR_BINARY_COST_MAPPING, "My cost mapping");
((FactorCostMapping) costMapping).setDefaultFactor(Registry.SUM_CONSTRAINT,
new BigDecimal("5"));
/* Defining a cost function */
gsc.selectCostMapping(costMapping);
CostFunction costFunction = gsc.createCostFunction("My cost function");
costFunction.setConstraintSelectionMethod(CostFunction.SELECTION_PROBABILITY_DISTRIBUTION);
/* Defining variables */
Variable varA = gsc.createVariable("a");
Variable varB = gsc.createVariable("b");
gsc.setVariable(varA, 101);
gsc.setVariable(varB, 1);
/* Defining constraints */
gsc.selectDefaultCostMapping();
Embedding embedding = new Embedding(2);
gsc.extendEmbedding(embedding, varA, Registry.LESS_EDGE, Registry.INCOMING);
gsc.extendEmbedding(embedding, varB, Registry.MORE_EDGE, Registry.OUTGOING);
ConventionalConstraint leConstraint =
gsc.createConstraint(Registry.LESSEQUAL_CONSTRAINT, embedding, new BigDecimal("1.5"));
gsc.selectCostFunction(costFunction);
gsc.selectCostMappingOfCostFunction();
embedding = new Embedding(2);
gsc.extendEmbedding(embedding, varA, Registry.ADD_EDGE, Registry.INCOMING);
gsc.extendEmbedding(embedding, varB, Registry.SUM_EDGE, Registry.OUTGOING);
ConventionalConstraint sumConstraint =
gsc.createConstraint(Registry.SUM_CONSTRAINT, embedding);
System.out.print(gsc.getCostFunctionInfo());
The execution results in:
costs[Maximization Function]<Factorized Cost Mapping> = 0
costs[My cost function]<My cost mapping> = 5
costs[Default Cost Function]<Factorized Cost Mapping> = 150
costs[Structural Costs]<Factorized Cost Mapping> = 0
(The Sum and the LessEqual constraint both producing subjective costs of 100.)
[HOMEPAGE] -> [Documentation] -> [Interfaces to the Engine] -> [Java] -> [Costs]
For questions, comments or suggestions, please visit our feedback forum.
Last update:
August 22, 2002 by Alexander Nareyek