Cassowary non-deterministic?

93 views
Skip to first unread message

Alex Birkett

unread,
Oct 9, 2014, 2:36:42 PM10/9/14
to overcon...@googlegroups.com

I'm working on a layout for Android based on the Cassowary java implementation. If find it interesting that the solver can find different solutions each time it's run. (Every time I rotate the phone a new layout, and hence solver, is instantiated.) 

Is this to be expected? I makes writing constraints more challenging. 


Russell Keith-Magee

unread,
Oct 9, 2014, 8:33:22 PM10/9/14
to overcon...@googlegroups.com
Hi Alex,

In short - yes. 

If you look at the test suite for the Java implementation of Cassowary, there's an example of this - the "casso1" test will return either x=10 and y=13, or x=7 any y=10. Both answers completely satisfy the requirements of the linear system that is defined (required x<y, required y = x+3, weak x=10, weak y=10). The answer returned depends on which of the weak constraints is discarded first, which comes down to HashSet ordering.

If you're getting unstable results in your constraint system, then my understanding is that you need to look at your constraints and specify (or remove) something to remove the inconsistency - in this case, removing one of the x=10 or y=10 constraints, or making one of those constraints STRONG rather than WEAK, would resolve the inconsistency.

Yours,
Russ Magee %-)
Reply all
Reply to author
Forward
0 new messages