## Wrong solution document.SUBSCRIPTION_OPTIONS = { "thing": "thread", "subscribed": false, "url": "subscribe", "icon": { "css": "fa fa-envelope-o" } };

Help
2013-02-23
2013-05-30
• Karel Durkota - 2013-02-23

Hello,
I am a student of CTU in Prague and I am working on my Master Thesis, where I use CSP Solver for finding a solution of Graphplan Algorithm (instead of Backsearching).  I've tried Choco and Minion Solvers, but I feel they are quite slow, and want to implement  JaCoP for comparison and hopefully getting better results, but so far JaCoP returns wrong solution. Could I ask you to look at it? I could not figure out what goes wrong. I used basically the same constraint for the former solvers, and it worked.
Here is the snippet of the constraints I am giving to the JaCoP:

```....
Or135 : Or( XneqC259 : XneqC(goal-(at package2 loc1)::{10..11, 41}, 10 ), And15 : And(XneqC257 : XneqC(level2(in package2 truck1)::{-1, 6}, -1 )XneqC258 : XneqC(level2(at truck1 loc1)::{-1, 18, 25}, -1 ),),
Or136 : Or( XneqC262 : XneqC(goal-(at package2 loc1)::{10..11, 41}, 11 ), And16 : And(XneqC260 : XneqC(level2(at truck2 loc1)::{-1, 19, 23}, -1 )XneqC261 : XneqC(level2(in package2 truck2)::{-1, 7, 39}, -1 ),),
Or138 : Or( XneqC263 : XneqC(level2dp-(agent2-load-truck ag2 package1 truck2 loc2)::{-1, 55}, 55 ), Or137 : Or( ),
Or139 : Or( XneqC264 : XneqC(level2dp-(agent2-load-truck ag2 package2 truck1 loc2)::{-1, 51}, 51 ), XneqC265 : XneqC(level1dp-(agent2-load-truck ag2 package2 truck1 loc2)::{-1, 51}, -1 )),
....
```

The main part is the first constraint, which says:
either

```goal-(at package2 loc1)::{10..11, 41} =/= 10
```

or

```And15 : And(XneqC257 : XneqC(level2(in package2 truck1)::{-1, 6}, -1 )XneqC258 : XneqC(level2(at truck1 loc1)::{-1, 18, 25}, -1 ),),
```

(or both)
which originally was an implication:

```goal-(at package2 loc1)::{10..11, 41}=10
```

=>

```(level2(in package2 truck1)::{-1, 6} =/= -1)  & (level2(at truck1 loc1)::{-1, 18, 25} =/= -1),
```

. But it's basically the same.
But unfortunatelly the JaCoP returns me as a solution this:

```Solution : [level2(at package2 loc1)=-1, level2(in package1 truck2)=-1, level2(in package1 truck1)=-1, level1dp-(agent3-drive-truck2 ag3 truck1 loc2 loc1)=-1, level1dp-(agent2-load-truck ag2 package2 truck1 loc2)=-1, level2dp-(agent2-load-truck ag2 package2 truck2 loc2)=-1, level2(in package2 truck2)=-1, level2(at package1 loc1)=-1, level2dp-(agent2-load-truck ag2 package1 truck2 loc2)=-1, level1(at truck1 loc1)=-1, level2dp-(agent3-drive-truck2 ag3 truck1 loc2 loc1)=-1, level1dp-(agent3-drive-truck2 ag3 truck2 loc2 loc1)=-1, level1(in package1 truck1)=-1, level1dp-(agent2-load-truck ag2 package2 truck2 loc2)=-1, goal-(at package2 loc1)=10, level1(at truck2 loc1)=-1, level1(in package2 truck2)=-1, level2dp-(agent3-drive-truck2 ag3 truck2 loc2 loc1)=-1, level2(at truck1 loc1)=-1, level2(in package2 truck1)=-1, level2dp-(agent2-load-truck ag2 package2 truck1 loc2)=-1, level2(at truck2 loc1)=-1, level2dp-(agent2-load-truck ag2 package1 truck1 loc2)=-1, level1(at package1 loc1)=-1]
```

where the most important is that:

``` goal-(at package2 loc1)=10
```

, and

```level2(at truck2 loc1)=-1
```

and

```level2(at truck1 loc1)=-1
```

, which was not allowed according to the constraint.
The whole constraint with the solution follows:

```*** Store
*** Constraints for evaluation:
{SimpleHashSet[]
SimpleHashSet[]
SimpleHashSet[]
SimpleHashSet[]
}
Depth First Search DFS7
JaCoP.search.InputOrderSelect@105dd2c
Solution : [level2(at package2 loc1)=-1, level2(in package1 truck2)=-1, level2(in package1 truck1)=-1, level1dp-(agent3-drive-truck2 ag3 truck1 loc2 loc1)=-1, level1dp-(agent2-load-truck ag2 package2 truck1 loc2)=-1, level2dp-(agent2-load-truck ag2 package2 truck2 loc2)=-1, level2(in package2 truck2)=-1, level2(at package1 loc1)=-1, level2dp-(agent2-load-truck ag2 package1 truck2 loc2)=-1, level1(at truck1 loc1)=-1, level2dp-(agent3-drive-truck2 ag3 truck1 loc2 loc1)=-1, level1dp-(agent3-drive-truck2 ag3 truck2 loc2 loc1)=-1, level1(in package1 truck1)=-1, level1dp-(agent2-load-truck ag2 package2 truck2 loc2)=-1, goal-(at package2 loc1)=10, level1(at truck2 loc1)=-1, level1(in package2 truck2)=-1, level2dp-(agent3-drive-truck2 ag3 truck2 loc2 loc1)=-1, level2(at truck1 loc1)=-1, level2(in package2 truck1)=-1, level2dp-(agent2-load-truck ag2 package2 truck1 loc2)=-1, level2(at truck2 loc1)=-1, level2dp-(agent2-load-truck ag2 package1 truck1 loc2)=-1, level1(at package1 loc1)=-1]
Nodes : 22
Decisions : 22
Wrong Decisions : 0
Backtracks : 0
Max Depth : 22
```

Thank you very much for taking look at it, really appreciate it.
Karel

Dear Karel,

Before I try to figure out the problem, can I ask you for one thing?

Can you implement your And, Or, XneqC constraints (e.g. Or138) in your first printout as ExtensionalSupport or ExtensionalConflict (whatever has smaller number of tuples or is easier to use for you).

This approach of using Extensional* constraints may help you immensely in solving your problem efficiently. Or constraint should be used as rarely as possible.

Each time you implement one type of constraint as Extensional one try to see if the problem persists. As soon as the problem disappears please send the code of your solution to me by email (radoslaw dot szymanek at gmail . com ). I will run few tests to check if there is a bug in JaCoP. It will help to locate the bug/wrong usage pattern, etc.

Please make sure you are using good quality JVM, with newest bug fixes. I had few times weird behavior because of bugs in JVM.

best,

• kris - 2013-02-23

Hi!

Do you check if your search succeeded? Do you check whether labeling method of DepthFirstSearch returns true?Your printout-out of the store suggests that there are still constraints for evaluation, that means that your search has finished with unconsistent store and your problem has **no solution**.

To make it short. Check what is returned by labeling method and continue only if the result is true!

Best regards,
/Kris

PS. To implement implication you can use IfThen constraint, for example.