Skip to content
Michael Iatauro edited this page Dec 5, 2014 · 3 revisions

Tutorial for adding a custom constraint.

Adding a Constraint to EUROPA

A new project automatically includes its own module that is loaded into the EUROPA engine and stub C++ files to hold custom code (see makeproject). Therefore, extending EUROPA components simply requires C++ code be added to those existing files. Consider the Example project here, which can be downloaded with:

svn co http://europa-pso.googlecode.com/svn/benchmarks/tags/EUROPA-2.2/ExampleCustomConstraint ExampleCustomConstraint

We have added an 'ExampleConstraint' that restricts a variable to have integer bounds. To create and use the constraint involved these steps:

  1. Declare and define the constraint in ExampleCustomConstraintCustomCode.hh and ExampleCustomConstraintCustomCode.cc.
  2. Register the constraint. In ModuleExampleCustomConstraint.cc:
CESchema* schema = (CESchema*)engine->getComponent("CESchema");
REGISTER_CONSTRAINT(schema, ExampleConstraint, "example", "Default");
  1. Use the constraint. In ExampleCustomConstraint-initial-state.nddl:
float x = [3.5 0.5];
example(x);  // will be constrained to [1 3]

The result is that the global variable x will have range [1 3] once EUROPA has been run. This range is output in the 'RUN_ExampleCustomConstraint-planner_g_rt.ExampleCustomConstraint-initial-state.xml.PlannerConfig.xml.output' log file; notice these lines in ExampleCustomConstraint-Main.cc:

    PSVariable* v = engine->getVariableByName("x");
    std::cout << "x lower bound: " << v->getLowerBound() << std::endl;
    std::cout << "x upper bound: " << v->getUpperBound() << std::endl;

For many other examples of how to write EUROPA constraints, see Constraints.cc.

Clone this wiki locally