Search in sources :

Example 1 with Constraint

use of org.dkpro.lab.task.Constraint in project dkpro-lab by dkpro.

the class ParameterSpaceTest method testWithConstraint.

@Test
public void testWithConstraint() {
    Dimension<String> letters = Dimension.create("letters", "a", "b", "c");
    Dimension<Integer> numbers = Dimension.create("numbers", 1, 2);
    Dimension<Character> symbols = Dimension.create("symbols", '!', '&');
    int n = 0;
    ParameterSpace pSpace = new ParameterSpace(letters, numbers, symbols);
    pSpace.addConstraint(new Constraint() {

        @Override
        public boolean isValid(Map<String, Object> aConfiguration) {
            // a implies 1
            return !aConfiguration.get("letters").equals("a") || aConfiguration.get("symbols").equals('!');
        }
    });
    for (Map<String, Object> config : pSpace) {
        System.out.println(config);
        if ("a".equals(config.get("letters")) && !config.get("symbols").equals('!')) {
            fail();
        }
        n++;
    }
    assertEquals((3 * 2 * 2) - 2, n);
    assertEquals((3 * 2 * 2), pSpace.getStepCount());
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace) Constraint(org.dkpro.lab.task.Constraint) Constraint(org.dkpro.lab.task.Constraint) Test(org.junit.Test)

Aggregations

Constraint (org.dkpro.lab.task.Constraint)1 ParameterSpace (org.dkpro.lab.task.ParameterSpace)1 Test (org.junit.Test)1