Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraint with higher priority don't have effect. #28

Closed
yihuang opened this issue Jun 28, 2016 · 1 comment
Closed

Constraint with higher priority don't have effect. #28

yihuang opened this issue Jun 28, 2016 · 1 comment

Comments

@yihuang
Copy link

yihuang commented Jun 28, 2016

from kiwisolver import Solver, Variable
s = Solver()
w = Variable('w')
s.addConstraint((w==1) | 1001)
s.addConstraint((w==2) | 1002)
s.addConstraint((w==3) | 1003)
s.addConstraint((w==4) | 1004)
s.updateVariables()
s.dump()
print('value of w:', w.value())

Output:

Objective
---------
4008 + 2002 * e3 + 2004 * e5 + 2002 * e6 + 4 * e7 + 2008 * e8

Tableau
-------
v1 | 3 + 1 * e6 + -1 * e7
e2 | 2 + 1 * e3 + 1 * e6 + -1 * e7
e4 | 1 + 1 * e5 + 1 * e6 + -1 * e7
e9 | 1 + -1 * e6 + 1 * e7 + 1 * e8

Infeasible
----------

Variables
---------
w = v1

Edit Variables
--------------

Constraints
-----------
1 * w + -4 == 0  | strength = 1004
1 * w + -3 == 0  | strength = 1003
1 * w + -2 == 0  | strength = 1002
1 * w + -1 == 0  | strength = 1001


('value of w:', 3.0)

The value of w should be 4.0.

@sccolbert
Copy link
Member

sccolbert commented Jun 28, 2016

The value of w should not be 4. You have three constraints with weights that say w should be less than 4. The cumulative effect of those weights is such that they overpower the last weight. It should be noted that your weights are extremely close together. You need large variations in weights to establish one as dominant.

For reference, the default weights have the following values:

  • strength.weak == strength.create(0, 0, 1) == 1
  • strength.medium == strength.create(0, 1, 0) == 1000
  • strength.strong == strength.create(1, 0, 0) == 1000000
  • strength.required == strength.create(1000, 1000, 1000) = 1001001000

So you can see that the default weights have quite a large variation in value. This is what allows medium to always outweigh weak and strong to outweigh medium, etc.

You could certainly craft a large enough system of constraints where a huge number of medium constraints would outweigh a strong constraint, but that's an edge case that wasn't worth the performance hit of implementing lexicographic strength comparisons internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants