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

Weird behavior in simple problem #4

Open
markjreed opened this issue Sep 18, 2022 · 1 comment
Open

Weird behavior in simple problem #4

markjreed opened this issue Sep 18, 2022 · 1 comment
Assignees

Comments

@markjreed
Copy link

markjreed commented Sep 18, 2022

Tried to implement the municipal department numbers problem. Obviously this is a trivial problem that is amenable to a brute-force solution, but I thought it would be a good toy exercise for the constraint solver. However, I'm getting inconsistent results from run to run; it only produces the correct result about half the time, so I wonder if I'm doing something incorrectly.

This is my attempt:

use ProblemSolver;

my ProblemSolver $p .= new;
my @vars = «police sanitation fire»;
for @vars -> $dept {
  $p.add-variable($dept, 1..7);
}
$p.unique-vars(@vars);
$p.add-constraint: -> :$police! { $police %% 2 };
$p.add-constraint: -> :$police!, :$sanitation!, :$fire! { $police + $sanitation + $fire == 12 };

.say for $p.solve;

One run will output the correct 14 solutions, while the next will include 16 additional solutions in which the value for police is odd, ignoring the middle constraint above.

@markjreed markjreed reopened this Sep 18, 2022
@markjreed markjreed changed the title What's happening here? Weird behavior in simple problem Sep 18, 2022
@FCO
Copy link
Owner

FCO commented Jul 25, 2023

Thanks for your message. Sorry for taking so long to respond. I’ll take a look at it as soon as possible, when I’m back home from vacation. Thanks

@FCO FCO self-assigned this Jul 25, 2023
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