Menu

IfThen with AndBool

Help
2017-07-14
2017-07-14
  • A. M. Grubb

    A. M. Grubb - 2017-07-14

    I think I have a misunderstanding on how AndBool works (and by extension OrBool).

    AndBool(IntVar[] a, IntVar result)
    I think it works where AND(a1, a2, .. an) = result.

    Can I use it as the "then" component in a IfThen?
    If (L0 > TA0) Then (AND(a1, a2, .. an) = result)

    Just AndBool Gives me the results I expect:
    AndBoolSimple1 : andBoolSimple([ N0001_0_FS=0, N0002_0_FS::{0..1}], N0000_0_FS::{0..1})

    AndBool as the result of Then results in conflicting constraints:
    IfThen1 : IfThen(
    XgtY1 : XgtY(L0::{1..100}, TA0 = 0 ),
    AndBoolSimple1 : andBoolSimple([ N0001_0_FS=0, N0002_0_FS::{0..1}], N0000_0_FS=0))

    I'm not quite sure what I am missing, guidence appreciated.

    Thanks!
    Alicia

     
  • Radoslaw Szymanek

    Hi,

    XgtY1 : XgtY(L0::{1..100}, TA0 = 0 ) is a satisfied constraint because L0 is certain to be greater than TA0.

    andBoolSimple([ N0001_0_FS=0, N0002_0_FS::{0..1}], N0000_0_FS=0) is also a satisfied constraint as first argument is 0 and result is 0. The constraint can be satisfied even if result is equal 0.

    Both of the constraint are satisfied so IfThen should also be satisfied. The fact that N0000_0_FS=0 does not mean that constraint is not satisfied. It is satisfied because result is 0 and one of the parameters is 0 too.

    Therefore, the constraints should not be conflicting. I do not understand what you mean by conflict. If you mean that there is a perceived conflict by you then it is misunderstanding of how IfThen and andBoolSimple work.

    Hope that helps.

    best,
    Radoslaw Szymanek

     
  • A. M. Grubb

    A. M. Grubb - 2017-07-14

    Hi Radoslaw,

    I agree with everything you've written.

    The problem is that after I add this constraint to the store, store.consistency() returns false.
    Do you know any reason why store.consistency() would return false?

    Thanks,

    Alicia

     

    Last edit: A. M. Grubb 2017-07-14
  • kris

    kris - 2017-07-15

    Hi Alicia,

    I have tried your constraint example and it is satisifed. I used the following code.

    void ex() {
    
    store = new Store();
    
    IntVar L0 = new IntVar(store, "L0", 1, 100);
    IntVar TA0 = new IntVar(store, "TA0", 0, 0);
    IntVar N0001_0_FS = new IntVar(store, "N0001_0_FS", 0, 0);
    IntVar N0002_0_FS = new IntVar(store, "N0002_0_FS", 0, 1);
    IntVar N0000_0_FS = new IntVar(store, "N0000_0_FS", 0, 0);
    
    store.impose(new IfThen(
                new XgtY(L0, TA0), 
                new AndBoolSimple(N0001_0_FS, N0002_0_FS, N0000_0_FS)));
    
    boolean result = store.consistency();
    
    System.out.println("result = " + result);
    System.out.println(store);
    }
    

    and got the following result

    result = true

    Store
    L0::{1..100}
    TA0 = 0
    N0001_0_FS = 0
    N0002_0_FS::{0..1}
    N0000_0_FS = 0
    Constraint:
    IfThen1 : IfThen(
    XgtY1 : XgtY(L0::{1..100}, TA0 = 0 ),
    AndBoolSimple1 : andBoolSimple([ N0001_0_FS = 0, N0002_0_FS::{0..1}], N0000_0_FS = 0) )

    *** Constraints for evaluation:
    {SimpleHashSet[]
    SimpleHashSet[]
    SimpleHashSet[]
    SimpleHashSet[]
    SimpleHashSet[]
    }

    It migt be possible that you do store.consistency() before this one and the store was already non consistent.

    Best,
    /Kris

     
    • A. M. Grubb

      A. M. Grubb - 2017-07-16

      Yes when I run your code it works as expected. But I am using AndBool not AndBoolSimple.

      When I run a small varient of your code (see below) I get false.

          store = new Store();
      
          IntVar L0 = new IntVar(store, "L0", 1, 100);
          IntVar TA0 = new IntVar(store, "TA0", 0, 0);
      
          IntVar[] links = new IntVar[2];
          links[0] = new IntVar(store, "N0001_0_FS", 0, 0);
          links[1] = new IntVar(store, "N0002_0_FS", 0, 1);
      
          IntVar N0000_0_FS = new IntVar(store, "N0000_0_FS", 0, 0);
      
          store.impose(new IfThen(
                      new XgtY(L0, TA0), 
                      new AndBool(links, N0000_0_FS)));
      
          boolean result = store.consistency();
      
          System.out.println("result = " + result);
          System.out.println(store);
      

      Output:

      result = false

      Store
      L0::{1..100}
      TA0 = 0
      N0001_0_FS = 0
      N0002_0_FS::{0..1}
      N0000_0_FS = 0
      Constraint:
      IfThen1 : IfThen(
      XgtY1 : XgtY(L0::{1..100}, TA0 = 0 ),
      AndBoolSimple1 : andBoolSimple([ N0001_0_FS = 0, N0002_0_FS::{0..1}], N0000_0_FS = 0) )

      *** Constraints for evaluation:
      {SimpleHashSet[]
      SimpleHashSet[]
      SimpleHashSet[]
      SimpleHashSet[]
      SimpleHashSet[]
      }

      I thought that AndBool and AndBoolSimple work the same way but AndBool can take more than two values in the "a" value. AndBool(IntVar[] a, IntVar result)

      Thanks,

      Alicia

       
  • Radoslaw Szymanek

    Hi,

    Please use store.print to print all the constraints. It may give you a hint what bad constraints you added to the store that together with the constraints you have already shown may be causing a conflict and a failure.

    best,
    Radek

     
  • A. M. Grubb

    A. M. Grubb - 2017-07-16

    I thought there might be a problem with the automatic conversion between AndBool and AndBoolSimple, so I added an additional variable and I still get the store.consistency() = false.

        store = new Store();
    
        IntVar L0 = new IntVar(store, "L0", 1, 100);
        IntVar TA0 = new IntVar(store, "TA0", 0, 0);
    
        IntVar[] links = new IntVar[3];
        links[0] = new IntVar(store, "N0001_0_FS", 0, 0);
        links[1] = new IntVar(store, "N0002_0_FS", 0, 1);
        links[2] = new IntVar(store, "N0001_0_FS", 0, 1);
    
        IntVar N0000_0_FS = new IntVar(store, "N0000_0_FS", 0, 0);
    
        store.impose(new IfThen(
                    new XgtY(L0, TA0), 
                    new AndBool(links, N0000_0_FS)));
    
        boolean result = store.consistency();
    
        System.out.println("result = " + result);
        System.out.println(store);
    

    Output:

    result = false

    Store
    L0::{1..100}
    TA0 = 0
    N0001_0_FS = 0
    N0002_0_FS::{0..1}
    N0001_0_FS::{0..1}
    N0000_0_FS = 0
    Constraint:
    IfThen1 : IfThen(
    XgtY1 : XgtY(L0::{1..100}, TA0 = 0 ),
    AndBoolVector1 : andBool([ N0002_0_FS::{0..1}, N0001_0_FS = 0, N0001_0_FS::{0..1}], N0000_0_FS = 0) )

    *** Constraints for evaluation:
    {SimpleHashSet[]
    SimpleHashSet[]
    SimpleHashSet[]
    SimpleHashSet[]
    SimpleHashSet[]
    }

    Thoughts?

    Thanks,

    Alicia

     
  • kris

    kris - 2017-07-16

    Hi!

    You are right. it is a bug in version 4.4. It works with AndBoolSimple but not with AndBool that makes conversion to AndBoolSimple or AndBooVector. However, it should work with AndBoolVector.

    Thanks for pointing this problem. It is already fixed for the new release.

    Best,
    /Kris

     
    • A. M. Grubb

      A. M. Grubb - 2017-07-16

      Alright, I can use AndBoolVector in the mean time. Approximately, when is the new version coming out?

      Thanks for your help diagnosing the problem!

      Alicia

       
  • kris

    kris - 2017-07-17

    Hi again,

    Yes, please use AndBoolVector. AndBoolSimple is only in the solver to define 2-input parameter constraints and to be a little bit more efficient than general n-input parameter AndBoolVector. In most cases it does not matter very much. AndBool is a wrapper that generates either AndBoolSimple or AndBoolVector

    In the forthcomming release of version 4.5 we define AndBool as a decomposed constraint and therefore it cannot be used as parameter to other constraints (it must be primitive constraint). It means that you will not be able to use it in the new version for IfThen constraints. Of course, you can generate yourself IfThen with AndBoolSimple or AndBoolVector depeneding on the number of parameters if you want to improve performance a little bit.

    Hope, I explained you the internals of the solver a little bit.

    Best regards,
    /Kris

     

Log in to post a comment.