Menu

Constraints print error.

2016-11-21
2016-11-22
  • A. M. Grubb

    A. M. Grubb - 2016-11-21

    I think there may be an error in the printing of constraints. I seem to be missing a bracket.

    Below is code to generate one constraint (it is a small example I made to show this, my actual code is much more complex):

        Store store = new Store(); 
        BooleanVar cn = new BooleanVar(store, "CON");
        BooleanVar a = new BooleanVar(store, "a"); 
        BooleanVar b = new BooleanVar(store, "b"); 
        BooleanVar c = new BooleanVar(store, "c");
        ArrayList<PrimitiveConstraint> orConst = new ArrayList<PrimitiveConstraint>();
        PrimitiveConstraint[] andConst = new PrimitiveConstraint[2];
    
        andConst[0] = new XeqC(a, 1);
        andConst[1] = new XeqC(b, 1);
        orConst.add(new And(andConst));
        orConst.add(new XeqC(c, 1));
        store.impose(new IfThen(new XeqC(cn, 1), new Or(orConst)));
    
        IntVar[] vars = {cn, a, b, c};
    
        Search<IntVar> label = new DepthFirstSearch<IntVar>();
        label.setPrintInfo(true);
    
        SelectChoicePoint <IntVar> select = new SimpleSelect<IntVar>(vars, null,
                                     new IndomainMin<IntVar>());
        label.setSolutionListener(new PrintOutListener<IntVar>()); 
        label.getSolutionListener().searchAll(true);
    
        boolean result = label.labeling(store, select);
    
        if (result) {
          System.out.println("Yes");
    
        } else {
          System.out.println("No solution.");
        }
    

    Store.print() returns:
    Constraint:
    IfThen1 : IfThen(
    XeqC4 : XeqC(CON::{0..1}, 1 ),
    Or1 : Or( And1 : And(XeqC1 : XeqC(a::{0..1}, 1 )XeqC2 : XeqC(b::{0..1}, 1 ),, XeqC3 : XeqC(c::{0..1}, 1 )), )

    when I think it should be:
    IfThen1 : IfThen(
    XeqC4 : XeqC(CON::{0..1}, 1 ),
    Or1 : Or( And1 : And(XeqC1 : XeqC(a::{0..1}, 1 )XeqC2 : XeqC(b::{0..1}, 1 )),, XeqC3 : XeqC(c::{0..1}, 1 )), )

    if I have them both Or instead I get:
    IfThen1 : IfThen(
    XeqC4 : XeqC(CON::{0..1}, 1 ),
    Or2 : Or( Or1 : Or( XeqC1 : XeqC(a::{0..1}, 1 ), XeqC2 : XeqC(b::{0..1}, 1 )),, XeqC3 : XeqC(c::{0..1}, 1 )), )

    Can you confirm that this is a bug with the printing? When I generate all solutions, they appear to be correct.

    Thanks!

     
  • kris

    kris - 2016-11-22

    Yes, you are right. There is a bug in method toString in And class (constraint).
    /Kris

     
    • A. M. Grubb

      A. M. Grubb - 2016-11-22

      Thank you!

       

Log in to post a comment.