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

Adding stay with required strength #25

Closed
hfossli opened this issue Nov 25, 2014 · 6 comments
Closed

Adding stay with required strength #25

hfossli opened this issue Nov 25, 2014 · 6 comments

Comments

@hfossli
Copy link
Collaborator

hfossli commented Nov 25, 2014

I'm not sure if this is a bug or not. I wrote some unit tests derived from the test required_strength which I expect to pass. Am I missing something?

BOOST_AUTO_TEST_CASE(required_strength_stay)
{
    variable v(0);
    simplex_solver solver;

    solver.add_stay(v, strength::required(), 1);

    BOOST_CHECK_EQUAL(v.value(), 0);

    solver.add_edit_var(v, strength::required(), 2);
    solver.begin_edit();
    solver.suggest_value(v, 2);
    solver.end_edit();

    BOOST_CHECK_EQUAL(v.value(), 2);
}

BOOST_AUTO_TEST_CASE(required_strength_stay_and_constraint)
{
    variable v(0), y(0);
    simplex_solver solver;

    solver.add_stay(v, strength::required(), 2);

    BOOST_CHECK_EQUAL(v.value(), 0);
    BOOST_CHECK_EQUAL(y.value(), 2);

    solver.add_edit_var(v, strength::required(), 3);
    solver.begin_edit();
    solver.suggest_value(v, 2);
    solver.end_edit();

    solver.add_constraint(y == v + 2);

    BOOST_CHECK_EQUAL(v.value(), 2);
    BOOST_CHECK_EQUAL(y.value(), 4);
}
@hfossli
Copy link
Collaborator Author

hfossli commented Nov 25, 2014

Test report

Running 39 test cases...
/Users/hfossli/Projects/Rhea/unit_tests/unit_tests.cpp:758: error in "required_strength_stay": check v.value() == 2 failed [0 != 2]
/Users/hfossli/Projects/Rhea/unit_tests/unit_tests.cpp:769: error in "required_strength_stay_and_constraint": check y.value() == 2 failed [0 != 2]
/Users/hfossli/Projects/Rhea/unit_tests/unit_tests.cpp:778: error in "required_strength_stay_and_constraint": check v.value() == 2 failed [0 != 2]
/Users/hfossli/Projects/Rhea/unit_tests/unit_tests.cpp:779: error in "required_strength_stay_and_constraint": check y.value() == 4 failed [2 != 4]

*** 4 failures detected in test suite "rhea"

@Nocte-
Copy link
Owner

Nocte- commented Nov 25, 2014

'required' is a special value, the weight factor isn't meaningful here. (Now we know what happens when the immovable object meets the unstoppable force, it appears the stay constraint wins. ;) )

@Nocte- Nocte- closed this as completed Nov 25, 2014
@hfossli
Copy link
Collaborator Author

hfossli commented Nov 26, 2014

If I got you right you are saying that the weight factor is the problem. Removing that from the unit test still yields the same output/error.

BOOST_AUTO_TEST_CASE(required_strength_stay)
{
    variable v(0);
    simplex_solver solver;

    solver.add_stay(v, strength::required());

    BOOST_CHECK_EQUAL(v.value(), 0);

    solver.add_edit_var(v);
    solver.begin_edit();
    solver.suggest_value(v, 2);
    solver.end_edit();

    BOOST_CHECK_EQUAL(v.value(), 2);
}

Result

 error in "required_strength_stay": check v.value() == 2 failed [0 != 2]

@Nocte-
Copy link
Owner

Nocte- commented Nov 27, 2014

The value remains 0 because the edit constraint is weaker than the stay constraint in this case. (Stays are weak and edits are strong by default.)

@hfossli
Copy link
Collaborator Author

hfossli commented Nov 27, 2014

Aha. It's details like this that would be awesome to have documented.

This is quite good, but it too short IMO http://cassowary.readthedocs.org/en/latest/

@Nocte-
Copy link
Owner

Nocte- commented Nov 27, 2014

For some reason, people started starring this project left and right in the past couple of days. Maybe this is a good time to get some documentation going. ;)

That Python implementation you linked to explains the concepts of Cassowary very well, that's definitely a good basis.

@hfossli hfossli mentioned this issue Nov 28, 2014
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